/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 - }; } } }