#!/usr/bin/perl #=============================================================================== # # DESCRIPTION: Get library # # AUTHOR: DawnFantasy, # 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 <); @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 - }; } } }