123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $image = "/home/graybeard/etherboot/dachstein-v1.0.2-1680.bin";
-
-
-
-
-
-
-
- my $uniqdir = shift || 'firewall';
-
- $mntdir = "/mnt/floppy";
- $tftpbase = "/tftpboot";
- $tftpboot = "$tftpbase/$uniqdir";
- $base = "/usr/src/LRP";
- $dachorg = "$base/dach-org-$uniqdir";
- $dachnew = "$base/lrp-$uniqdir";
- $packages = "$dachnew/var/lib/lrpkg";
-
-
-
-
- if ( !-e $image ) {
- print
- "\n\tA valid LRP file and directory are required\n\tdownload one then edit $0\n\n";
- exit 1;
- }
- if ( !-d $base ) {
- mkdir( $base, 0700 );
- }
-
- if ( !-d $dachorg ) {
- mkdir( $dachorg, 0700 );
- }
-
- if ( !-d $dachnew ) {
- mkdir( $dachnew, 0700 );
- `umount $mntdir`;
- `mount -o ro,loop $image $mntdir`;
-
- `cp -vr $mntdir/* $dachorg/`;
-
- @cfg = `cat $mntdir/syslinux.cfg`;
-
- unless ( defined(@cfg) ) {
- print "Cannot find syslinux.cfg on $mntdir\n";
- exit 1;
- }
- print "cfg = @cfg\n";
- ($append) = grep( /append/, @cfg );
- print "append = \n$append\n";
- chomp($append);
- $append =~ s/append=//;
- print "strip append = \n$append\n\n";
- @args = split ( / /, $append );
- ($root) = grep( /^initrd=/, @args );
- $root =~ s/^initrd=//;
- $root =~ s/\.lrp$//;
- print "strip initrd = \n$root\n\n";
- ($lrp) = grep( /^LRP=/, @args );
- $lrp =~ s/^LRP=//;
- print "strip LRP =\n$lrp\n\n";
- @lrp = split ( /,/, $lrp );
- unshift ( @lrp, $root );
- @pack = @lrp;
- print "LRP =\n@lrp\n\n";
- $append = '';
-
- foreach $i (@args) {
- next if ( $i =~ /^initrd=/ );
- next if ( $i =~ /^LRP=/ );
- next if ( $i =~ /^boot=/ );
- next if ( $i =~ /^PKGPATH=/ );
- print "$i = i\n";
- $append .= "$i ";
- }
-
- print "final append = \n$append\n";
-
- chdir($dachnew) or die "$dachnew: $!\n";
- foreach $i (@lrp) {
- $i .= '.lrp' if $i !~ /\.lrp$/;
- print "\n\n\nUnpacking $i\n";
- system("ln -svf $dachorg/$i ${dachorg}/${i}.tar.gz");
- chmod 0600, "$dachorg/$i";
- system("cat $mntdir/$i | tar zxvf -");
- }
-
-
- open( PACKAGES, ">$packages/packages" )
- || print "unable to modify $packages:$!\n";
- foreach $line (@pack) {
- print PACKAGES "$line\n";
- }
- close PACKAGES;
-
-
-
- open( LINUXRC, "$packages/root.linuxrc" );
- @text = <LINUXRC>;
- close LINUXRC;
- open( LINUXRC, ">$packages/root.linuxrc" );
- foreach $line (@text) {
- $line =~ s/PFX\/packages/PFX\/packages-old \
- \t\t\t\t# packages changed to packages-old for netboot setup/;
- $line =~
- s/^rc=1/# rc=1 changed to rc=0 to suppress error messages for netboot setup \
- rc=0/;
- $line =~
- s/echo -n \" \(nf\!\)\"/#echo -n \" \(nf\!\)\" changed to reflect ToDo list \
- \t\t\techo -n \" netboot setup - No backups possible from this machine - ToFix ?"/;
- print LINUXRC $line;
- }
- close LINUXRC;
-
-
-
- open( NETWORK, "$dachnew/etc/network.conf" )
- || print "Unable to modify NETWORK:$!\n";
- @text = <NETWORK>;
- close NETWORK;
- open( NETWORK, ">$dachnew/etc/network.conf" )
- || print "Unable to modify NETWORK:$!\n";
- foreach $line (@text) {
- $line =~ s/eth0/eth00/;
- $line =~ s/eth1/eth0/;
- $line =~ s/eth00/eth1/;
- print NETWORK $line;
- }
- close NETWORK;
-
- `echo $append > $dachorg/appendstr`;
-
- `umount /mnt/floppy`;
- print "\nThe files have been extracted to $dachnew\n";
- system("ls -al $dachnew");
- }
- else {
- print "\n\n\t$image \n \thas already been extracted to $dachnew \
- \tNow skipping to the next step where the netboot file\
- \twill be created.\n";
-
- $append = `cat $dachorg/appendstr`;
- print "\nThe new append string will be...\n$append\n";
-
- chdir($dachnew);
- if ( !-d $tftpbase ) {
- mkdir( $tftpbase, 0710 );
- system("chgrp nobody $tftpbase");
- }
-
- unlink($tftpboot);
-
-
- mkdir( $tftpboot, 0710 );
- system("chgrp nobody $tftpboot");
- print "\tRepacking to $tftpboot/lrp.lrp\n";
- system("tar zcf $tftpboot/lrp.lrp *");
- print "\tExtracting kernel image from $dachorg\n";
- system("cat $dachorg/linux > $tftpboot/lrp.ker");
- print "\tCreating netboot image $tftpboot/lrp.nb\n";
- system(
- "mknbi-linux --append='$append' --output=$tftpboot/lrp.nb $tftpboot/lrp.ker $tftpboot/lrp.lrp"
- );
- chmod 0604, "$tftpboot/lrp.nb", "$tftpboot/lrp.ker", "$tftpboot/lrp.lrp";
- print "\nThese netboot files are in $tftpboot\n";
- system("ls -al $tftpboot");
- print "\n The owner and permissions for $tftpboot \
- and files should be checked for security. The above\
- permissions assume that tftp is running chroot (nobody)
- drwx--r--- root:nobody /tftpboot\n\n";
- }
-
- exit 0;
|