ldd 库文件拷贝

/livecd/gld.pl(感谢 DawnFantasy 提供的这个 perl 脚本! )

这个脚本复制文件以及所依赖的库到指定位置.

由于这个脚本中包含一些特殊字符, 在使用 cat 生成时会有一定困难, 所以请自己创建这个文件.

vi /livecd/gld.pl
...
chmod +x /livecd/gld.pl
#!/usr/bin/perl 
#===============================================================================
#
#  DESCRIPTION:  Get library
#
#       AUTHOR:  DawnFantasy, <goldenshore999 # gmail # com>
#      VERSION:  1.1
#         DATE:  2008-02-04
#
#===============================================================================
use strict;
use warnings;
use Getopt::Long;
my %opts;
$opts{target} = 'initrd';
usage(), exit -1
    if ( not GetOptions( /%opts, 'import=s', 'verbose', 'target|t=s' ) );
usage(), exit -1
    if ( ( not @ARGV ) xor ( defined $opts{import} ) );
sub usage {
    print <<EOU;
Usage:
    $0 file1 [file2...fileX]  [-t DIR]  [-v]
    or 
    $0 -i list  [-t DIR]  [-v]
Options:
    -i, --import=FILE       Process files listed in FILE
    -t, --target=DIR        Use DIR as root. (Default ./initrd)
    -v, --verbose           Be verbose.
EOU
    return;
}

## files to process
my @files;
{
    my @filess;
    {
        ## files in @ARGV
        if ( not defined $opts{import} ) {
            push @filess, @ARGV;
            last;
        }
        ## import list
        open my $fh, '<', $opts{import}
            or die "$!/n";
        @filess = (<$fh>);
        @filess = map { chomp; $_ } @filess;
        close $fh;
    }
    print "File to process: (! means file NOT found.)/n";
    foreach (@filess) {
        print " !  $_ /n" and next if not -f $_;
        push @files, $_;
        print "    $_/n";
    }
}
## parse libs to copy
my @libs;
{
    print "/n";
    foreach (@files) {
        my $ldd = qx{/usr/bin/ldd $_};
        chomp $ldd;
        print "$ldd/n/n" if defined $opts{verbose};
        my @files = split //s+/, $ldd;
        push @libs, grep { -f $_ } @files;    ## check for existence
    }
    ## Unified them
    my %h = map { ( $_, 1 ) } @libs;
    @libs = sort keys %h;
    if ( defined $opts{verbose} ) {
        print "Libraries to copy:/n";
        print "    $_  => $opts{target}$_/n" foreach @libs;
    }
}
## Do the real work
print "/n";
{
    print "Copying files, please wait.../n";
    ## Add those files in the original list
    push @libs, @files;
    if ( not -d $opts{target} ) {
        print "Creating directory $opts{target}/n";
        system qq{ mkdir -p $opts{target} };
    }
    my $v = $opts{verbose} ? 'v' : '';
    foreach (@libs) {
        if (/^///) {
            ## 绝对目录
            s/^;
            system
                qq{ tar -C / -hpmcf - $_ | tar -C $opts{target} -pmx$v -f - };
        } else {
            ## 相对目录
            system
                qq{ tar      -hpmcf - $_ | tar -C $opts{target} -pmx$v -f - };
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值