#!/usr/bin/perl
# Простой искатель отсутствующих в chroot нужных библиотек
# Copyright (c) 2000 by Maxim Chirkov <mc@tyumen.ru>

$chroot_path="/home/vhome";
$prog_ldd="/bin/ldd";

use File::Find;
chroot($chroot_path);

find (\&check_bin, "/");

exit;



sub check_bin{
  my($file_name, $file_dir);
 
  $file_name  = $_;
  $file_fullpath  = $File::Find::name;
  $file_dir  = $File::Find::dir;

  if (((-x $file_fullpath && ! -d  $file_fullpath) || ($file_name =~ /\.so[\.\d]*$/)) && (! -l $file_fullpath)){
    open (BIN, "<$file_fullpath");
    binmode(BIN);
    read (BIN, $elf_buff, 4);
    close(BIN);
    if ($elf_buff !~ /ELF$/){
	return;
    }
    # print "$file_fullpath\n";
    open (LDD, "$prog_ldd '$file_fullpath' 2>&1 |");
    while(<LDD>){
	chomp($line = $_);
	if ($line =~ /not\ found/ || $line !~ /\(0x/){
	    print "$file_fullpath: $line\n";
	}
    }
    close(LDD);
  }
}
