|
发表于 2011-5-30 15:27:17
|
显示全部楼层
这是我用来制作 bootcd 用到的脚本,是现实可用的
详细请参照 http://imghch.com/doc/bk02ch02s04.html 2.4.3 节
[php]
cat > $WORK/gld.pl << 'EOF' && chmod +x $WORK/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: ong;
my %opts;
$opts{target} = 'tmpfs';
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 (/^\//) {
## Absolute path
s/^\///;
system
qq{ tar -C / -hpmcf - $_ | tar -C $opts{target} -pmx$v -f - };
} else {
## Opposite path
system
qq{ tar -hpmcf - $_ | tar -C $opts{target} -pmx$v -f - };
}
}
}
EOF
[/php] |
|