nph-debian_image.in from LinuxCOE at Krugle
Show nph-debian_image.in syntax highlighted
#!/usr/bin/perl
##############################################################################################
# File: nph-debian_image
# Description: Build a Autoinstall||Preseed image
# Author: Lee Mayes ( email leem@hp.com )
# Created: 25 Jul 2001
# Language: perl
# Package: LinuxCOE
##############################################################################################
# © Copyright 2000-2007 Hewlett-Packard Development Company, L.P
#
# This program is free software; you can redistribute it and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program;
# if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##############################################################################################
# Create the boot image
# Init - Initalize interactive HTML
# Step1 - Create the preseed and final script files
# Step2 - Create the loopback filesys, insert them, cleanup
# Step3 - Copy image and files to final destination
# Step4 - Cleanup & Create final HTML
##############################################################################################
use strict;
my $debug = 0;
my $nonav = 0;
use CGI;
my $qin = new CGI;
use lib qw (@prefix@/lib @prefix@/includes);
use binaries;
use sysdes_paths;
use LinuxCOE;
my $db = new LinuxCOE;
$db->debug($debug);
$db->nonav($nonav);
use COEHtml;
my $qout = new COEHtml;
my $COE_VER=$db->def('COE_VER');
my $defs = $qin->param('defs');
if ( $defs ) {
$db->LoadDefs($defs);
}
my $replay = 0;
if ($qin->param('action') eq 'replay') {
print STDERR "Replay detected, disabling interactive HTML\n" if $debug;
$db->def('FINAL_INTERACTIVE',0);
$replay = 1;
$nonav = 1; # no need for lipstick
}
$db->InitDB;
# Disable interactive HTML if requested || SECURITY_LEVEL = SECURE
my $privpath = "image$$";
my $sec_level = $db->def('SECURITY_LEVEL');
if ( $sec_level eq 'SECURE' ) {
$db->def('FINAL_INTERACTIVE',0);
$db->def('FINAL_URL_METHOD','https://');
my $path = $db->def('FINAL_ABS_PATH');
if ( $path =~ /\/$/ ) { chop($path) }
$db->def('FINAL_ABS_PATH',"$path/$privpath");
}
unless ( $db->def('FINAL_INTERACTIVE') ) { $qout->do_nothing(1) }
my @vars = qw(hostname ip method profile os waystation netmask
kbd lang timezone mouse gateway namesvr utc);
# Filenames/paths/directories
my $docroot = $ENV{'DOCUMENT_ROOT'} || $db->def('HTDOCS');
my $iesux = 0;
my $htmlpath = "$docroot/scratch_monkey"; # Scratch directory
$htmlpath = "$htmlpath/$privpath" if ( $sec_level eq 'SECURE' );
my $htmlfile;
my $conf_dir = "$htmlpath/conf$$"; # Where do I dump the conf files
my $ftp_dir = $db->def('FINAL_ABS_PATH'); # Where to it when I'm done
my $age = 600 || $db->def('AGE'); # how soon do I age off images..
my $custimg = "$htmlpath/img$$.img"; # Custom floppy image
my $custiso = "$htmlpath/iso$$.iso"; # Custom ISO image
my $imgmount = "$htmlpath/imagedir$$"; # Where I loopback mount $custimg
my $initrdmount = "$htmlpath/initrdmount$$"; # Where I explode initrd if needed
my $conf_html = "$htmlpath/conf$$.html"; # Where to store the conf files
my $final = "$htmlpath/LinuxCOE-final.$$"; # Path to final script for preseed
my $cust_file = "$htmlpath/custom_final.$$"; # Path to customers final script for preseed
my $confstore = "conf$$.html"; # Config info for autoinstall
my $preseed = "$htmlpath/preseed$$.txt"; # Preseed path if needed
my $preseed_file = "preseed$$.txt";
my $mounted = 0; # Image is mounted (for cleanup)
my $method = $qin->param('method');
my $ISO = 1;
my $bundle_error = 0;
my $sum_this_image;
# Let's slurp in the web parms for use everywhere....
my $interface = $qin->param('netdev') || 'auto';
my $ip = $qin->param('ip');
my $gw = $qin->param('gateway') || $ip;
my $nm = $qin->param('netmask');
my $ns = $qin->param('namesvr');
my ($hostname,$nw,$bc,$dom) = $db->do_dns($ip,$nm);
$hostname = $hostname || "localhost";
$dom = $dom || "localdomain";
my $kbd=$qin->param('kbd');
my $mouse=$qin->param('mouse');
my $lang=$qin->param('lang');
my $timezone=$qin->param('timezone');
my $arch = $db->clean_var($qin->param('arch'));
my $profile = $db->clean_var($qin->param('profile'));
my $os = $db->clean_var($qin->param('os'));
my ($distro,$version) = split(' ',$db->clean_var($qin->param('os')));
my $waystation = $qin->param('waystation');
my @langs = $qin->param('lang');
# Slurp in SIM stuff if in play
my ($serial,@serials);
if ( $db->def('SIM') ) {
@serials = split(':::',$qin->param('serial'));
$serial = pop(@serials);
}
unless ($debug) { $MKISOFS .= " -quiet" } # Tone down mkisofs output
my $msgtail = "0c[F1-Main] [F2-Local] [F3-Disk] [F4-Debian] [F5-COE] [F6-Final]07\n";
my ($misc,$parts,@bundles,$debs,$patch_me,$patch_freq,@coe_bundles,$skipx,$cust_final,$trig_img,$trig_conf);
#########################
######### MAIN ##########
#########################
&Init; # start html # Let's get this party started
my ($passwd,$userpasswd) = &check_pass; # If they supplied passwds, check 'em
&Step1; # Create preseed file
if ( $arch eq 'hppa' ) { # Poke it into install image
&Step2hppa; # Riscy business this one
} elsif ( $arch eq 'ia64' ) {
&Step2ia64; # Do it for itanium
} else {
&Step2; # x86 (32 or 64)
}
&Step3; # Make it accessible
&Step4; # Cleanup and create final HTML
##########################
###### End of MAIN #######
##########################
sub Step1 {
# OK kids, lets create the preseed files!
print STDERR "Entering Step1\n" if $debug;
$qout->message("Creating preseed file");
$qout->updatehtml(1);
my $method = lc($qin->param('method'));
my $wayip = $db->get_ip($waystation);
my $path;
if ( $method ne 'CDROM' ) {
my $inmethod = uc($method);
$path = $db->show_os($distro,$version,$arch,$inmethod,$waystation);
unless ($path) {
&end_it_now("$waystation is NOT exporting $distro $version via $inmethod");
}
} elsif ( $method eq 'CDROM' ) {
# This makes all CDROM installs fetch ADDONS from the default waystation
$waystation = $db->def('WAYSTATION');
}
# Extract the profile from DB (profile) or calling env (Custom)
if ( $profile ne 'Custom' ) {
my ($b,$c);
($parts,$misc,$cust_final,$debs,$patch_me,$patch_freq,$c,$b) = $db->parse_profile($profile,$arch,$version,$distro);
unless ($parts) {
&end_it_now($db->errmsg);
}
@coe_bundles = @{$c};
@bundles = @{$b};
# May have overridden parts/misc
if ( $qin->param('override') eq 'YES' ) {
$parts = $qin->param('parts');
$misc = $qin->param('misc');
}
} else {
$parts = $qin->param('parts');
$cust_final = $qin->param('final');
$debs = $qin->param('rpms');
@bundles = $qin->param('bundles');
@coe_bundles = $qin->param('coe_bundles');
}
$cust_final =~ s/
//g;
$cust_final =~ s/^#.*$//gm;
$cust_final =~ s/\n+/\n/gs;
$debs =~ s/
//g;
$debs =~ s/^#.*$//gm;
$debs =~ s/\n+/\n/gs;
# Note, we no longer support 3.0/Woody Autoinstall, check just in case.
if ( $os =~ /Debian 3.0/ ) {
&end_it_now("Unsupported $distro $version $arch!");
}
# Build the PRESEED file
print STDERR "Building Preseed file $preseed\n" if $debug;
unless ( -d $htmlpath ) { mkdir $htmlpath,0775 }
open(PRESEED,">$preseed") ||
&end_it_now("Error opening PRESSED file '$preseed' for writing : $!\n");
my $datestr = localtime;
&preseed_header(" PRESEED - Created $datestr");
print PRESEED "# Wiki: http://wiki.debian.org/DebianInstaller/Preseed\n";
print PRESEED "# Great work! Thanks for preseed and the d-i installer\n\n";
# Older preseed used base-config for many entries (vs. d-i). Deal with it
my $preamb = 'd-i';
my @zigs = qw(Hoary Breezy);
if ( grep(/^${version}$/,@zigs)) {
$preamb = 'base-config'; # Are belong to us
}
# Find our path to the install bits
my $inmethod = $qin->param('method');
my $lmeth = lc($inmethod);
&preseed_header("Installation Sources");
&preseed_sources($waystation,$path,$version,$preamb,$preamb,$lmeth); # Pick our install source
# Setup Networking
&preseed_header("Networking");
if ( $ip ) {
&preseed_static; # We've got networking details
} else {
&preseed_dhcp; # Let's boot and hope for the best
}
&preseed_common; # Common network stuff (proxy/etc.)
# Do the Disk Part
my $part_choice = $qin->param('part_choice');
if ( $part_choice eq 'NONE' ) {
&preseed_header("No disk info entered, you'll be prompted");
} else {
&preseed_header("Disk Partitioning/Boot loader");
&preseed_partition($part_choice,$parts,$profile);
}
# Do the localizations
my $tz = $qin->param('timezone');
&preseed_header("Localizations");
&preseed_localization($preamb,$tz);
# Do the user creation
&preseed_header("User Creation");
&preseed_user;
# Do the Software
&preseed_header("Software Selections");
&preseed_software($debs);
# Setup LinuxCOE post processing Environment
my ($coe_command,$cust_command);
unless ( $db->def('NO_COE') ) {
&preseed_coe($patch_me,$patch_freq);
$coe_command = "/usr/bin/perl /opt/LinuxCOE/bin/LinuxCOE-final >/var/log/LinuxCOE-final.log 2>&1";
}
if ( $cust_final ) {
&preseed_cust($cust_final);
$cust_command = "/bin/bash /opt/LinuxCOE/bin/custom_final >/var/log/customer_final.log 2>&1";
}
# Set up the Post-Install script
if (( $coe_command ) || ( $cust_command )) {
&preseed_header("LinuxCOE Post processing");
print PRESEED "# Put final script(s) in place and execute\n";
if ( ! ( $os =~ /Debian 3.1/ ) ) {
print PRESEED "d-i preseed/late_command string mkdir -p /target/opt/LinuxCOE/bin; mkdir -p /target/etc/opt/LinuxCOE/; [ -r /replay ] && cp /replay /target/etc/opt/LinuxCOE/replay; ";
if ( $coe_command ) {
print PRESEED "/bin/cp /LinuxCOE-final /target/opt/LinuxCOE/bin; in-target $coe_command;";
}
if ( $cust_command ) {
print PRESEED "/bin/cp /custom_final /target/opt/LinuxCOE/bin; in-target $cust_command;";
}
} else {
print PRESEED qq[d-i preseed/late_command string mkdir -p /target/opt/LinuxCOE/bin; cp /cdrom/LinuxCOE-final /target/opt/LinuxCOE/bin; [ -r /cdrom/replay ] && mkdir -p /target/etc/opt/LinuxCOE && cp /cdrom/replay /target/etc/opt/LinuxCOE/replay
base-config base-config/late_command string /usr/bin/perl /opt/LinuxCOE/bin/LinuxCOE-final >/var/log/LinuxCOE-final.log 2>&1
];
}
print PRESEED "\n";
}
# Toss in the extras if applicable
my @info = $db->valid_entries($os,$arch,'debconf');
if (@info) {
&preseed_header("Additional preseed entries (from data/debconf)");
foreach my $answer (@info) { print PRESEED "$answer\n" }
}
close(PRESEED);
} # End of Step1 - preseed file is built
sub Step4 {
# It's done, create final HTML page
my $title = "LinuxCOE Custom Image - Completed";
$qout->persist($title);
$qout->message("Your image is now ready for retrieval!");
# Who am I?
my $host = `/bin/hostname`;
chomp $host;
my $hostname = $db->def('HOSTNAME') || (gethostbyname($host))[0];
my ($image_type,$target,$inst_type,$img_path,$preseed_path,$final_path);
$image_type = 'ISO';
$target = "iso$$.iso";
if ( $sec_level eq 'SECURE' ) {
$img_path = "$privpath/$target";
$preseed_path = "$privpath/$preseed_file";
$final_path = "$privpath/LinuxCOE-final.txt";
} else {
$img_path = $target;
$preseed_path = $preseed_file;
$final_path = "LinuxCOE-final.txt";
}
# Note, AUTOINST no longer supported
$inst_type = 'PRESEED';
my $warnings;
if ( $bundle_error ) {
$warnings = qq[<P><B><font color=red>Warning:</font></B> One or more bundles you requested have no debs associated with them!</P>];
}
if (( ! $ip ) && ( $method ne 'CDROM')) {
$warnings .= qq[ <P><B>Warning:</B> Since you do not have static network information, you <B>MUST</B> have a working <B>DHCP</B> server on your subnet!</P>];
}
my %sr_array = (
COE_WAYSTATION => $hostname,
IMG_NAME => $target,
IMG_PATH => $img_path,
LINUXCOE_WARNINGS => $warnings,
PRESEED => $preseed_file,
PRESEED_PATH => $preseed_path,
FINAL => "$final.txt",
FINAL_PATH => $final_path
);
if ($replay) {
print STDERR "replay detected, emebedding data\n" if $debug;
my $method = $db->def('FINAL_URL_METHOD') || 'ftp://';
my $path = $db->def('FINAL_URL_PATH');
my $url = "${method}${hostname}${path}${img_path}";
my $bmsg = "START_OF_LINUXCOE_BEAM_DATA\n";
$bmsg .= "$url\n";
$bmsg .= "END_OF_LINUXCOE_BEAM_DATA\n";
print "\n$bmsg\n";
print $qin->end_html;
exit;
}
my $serial = $qin->param('serial');
my $msg = $db->Create_Final_HTML($distro,$version,$arch,$inst_type,$image_type,$sec_level,$htmlpath,$sum_this_image,$serial,%sr_array);
print STDERR "Calling CleanUp($htmlpath,$ftp_dir,$distro,$version,$arch,$trig_img,$trig_conf)\n" if $debug;
$db->CleanUp($htmlpath,$ftp_dir,$distro,$version,$arch,$trig_img,$trig_conf);
if ( $db->def('FINAL_INTERACTIVE') ) {
$msg .= "\n</body></html>\n";
$qout->trailer("$msg\n");
$qout->updatehtml(0);
} else {
print $qin->header;
$db->ShowNav($title);
print $msg;
print $qin->end_html;
$db->ShowFooter;
exit;
}
}
sub Step3 {
# Copy preseed and image file to final distination
$qout->message("Step3 : Making it accessible");
$qout->updatehtml(1);
my $ftp_dir = $db->def('FINAL_ABS_PATH');
if ( $db->def('SIM') ) {
my $simdir = $db->def('SIM');
$ftp_dir = $simdir; # Pig pile
&my_sys("/bin/mv $custimg $simdir/$serial/boot.iso");
$trig_img = "$simdir/$serial/boot.iso";
&my_sys("/bin/mv $preseed_file $simdir/$serial/preseed_file.cfg");
$trig_conf = "$simdir/$serial/ks.cfg";
open(SIM,">$simdir/$serial/CUSTOM_SETTINGS");
my $sdist = uc($distro);
my $sver = $version;
$sver =~ s/[AEW]S.*//;
my $sarch = 'x86';
$sarch = 'x86_64' if ($arch eq 'x86_64');
print SIM "DISTRO=${sdist}$sver\n";
print SIM "ARCH=$sarch\n";
close(SIM);
open(ARGS,">$simdir/$serial/args");
foreach my $parm ($qin->param) {
next if ( $parm =~ /Pass/ );
my $val = $qin->param($parm);
$parm = uc($parm);
print ARGS "$parm=\"$val\"\n";
}
close(ARGS);
} else {
&my_sys("/bin/mv $custiso ${ftp_dir}/iso$$.iso") unless ("$custiso" eq "${ftp_dir}/iso$$.iso" || $db->def('SIM'));
}
&my_sys("/bin/mv $preseed ${ftp_dir}/$preseed_file") if ("$preseed" ne "${ftp_dir}/$preseed_file");
&my_sys("/bin/mv $final ${ftp_dir}/LinuxCOE-final.txt") unless ($db->def('NO_COE'));
&my_sys("/bin/mv $cust_file ${ftp_dir}/cust-final.txt") if ($cust_final);
$sum_this_image = "${ftp_dir}/iso$$.iso";
$trig_img = $sum_this_image;
$trig_conf = "${ftp_dir}/$preseed_file";
}
sub Step2hppa {
# Make the dir we'll run palo against
my $isodir = "$htmlpath/isop$$";
mkdir($isodir,0755);
# It's preseed time baby, yeah!
# Explode the virgin image
chdir $isodir;
my $isofile = $db->find_file("images/$distro-$version-$arch-iso.tar");
unless ($isofile) { &end_it_now("Cannot find base iso file for $distro-$version-$arch!") }
my $sys = "$TAR -xf $isofile";
&my_sys($sys);
# Poke preseed in there
$sys = "/bin/cp $preseed $isodir/preseed";
&my_sys($sys);
$sys = "/bin/cp $final $isodir/LinuxCOE-final";
&my_sys($sys);
&create_replay("$imgmount/replay");
# Run mkisofs against it
$sys = "$MKISOFS -r -T -J -o $custiso $htmlpath/isop$$";
&my_sys($sys);
# Do the palo thang....
# /opt/SysDes/3.1/bin/palo -f /dev/null -k sargeiso/install/vmlinux-2.4.27-32 -b sargeiso/install/iplboot -r sargeiso/install/initrd.gz -c '0/vmlinux initrd=0/ramdisk ramdisk_size=8096 init=/linuxrc root=/dev/ram debconf/priority=critical languagechooser/language-name=English' -C pasarge.iso
$sys = qq[$PALO -f /dev/null -k $isodir/install/vmlinux-2.6.8-2-32 -b $isodir/install/iplboot \-r $isodir/install/initrd.gz -c \'0/vmlinux initrd=0/ramdisk ramdisk_size=32768 init=/linuxrc root=/dev/ram debconf/priority=critical preseed/file=/cdrom/preseed languagechooser/language-name=English' -C $custiso >/dev/null 2>&1];
&my_sys($sys);
# Nuke the temp dirs
$sys = "/bin/rm -rf $isodir";
&my_sys($sys);
}
sub Step2ia64 {
# Make the dir we'll run palo against
print STDERR "I AM IN Step2ia64!!!\n";
my $isodir = "$htmlpath/isop$$";
mkdir($isodir,0755);
# It's preseed time baby, yeah!
# Explode the virgin image
chdir $isodir;
my $isofile = $db->find_file("images/$distro-$version-$arch-iso.tar");
unless ($isofile) { &end_it_now("Cannot find base iso file for $distro-$version-$arch!") }
my $sys = "$TAR -xf $isofile";
&my_sys($sys);
# Post sarge, things get a little more complicated
my $mounted;
my $uid = $>; # What's my UID
if ( $version ne '3.1' ) {
# Loopmount boot.img
my $imgmount = "$htmlpath/img$$";
mkdir($imgmount,0775);
&my_sys("$SUDO /bin/mount -o loop,user,uid=$uid,rw -t vfat $isodir/boot/boot.img $imgmount");
$mounted = $imgmount;
# Poke in our elilo.conf
my $elilo = $db->find_file("boot/elilo.conf-$distro-$version");
unless($elilo) { $elilo = $db->find_file("boot/elilo.conf-$distro") }
unless($elilo) { $elilo = $db->find_file("boot/elilo.conf") }
unless($elilo) { &end_it_now("Cannot locate elilo.conf for $distro-$version") }
&my_sys("/bin/cp $elilo $imgmount/elilo.conf"); # Update elilo.conf to ref our lipstick
&my_sys("/bin/cp $elilo $imgmount/efi/boot/elilo.conf"); # There's 2 copies, figure out the right one later (BUG?)
# Snag initrd.img
my $initrdmount = "$htmlpath/initrd$$"; # Scratch area
mkdir("$initrdmount",0766) || &end_it_now("Cannot mkdir $initrdmount : $!\n"); # Make a playground
&my_sys("cd $initrdmount; $GZIP -dc $imgmount/initrd.gz | $CPIO -i"); # Extract CPIO image
# Poke in preseed/replay/etc.
&my_sys("/bin/cp $preseed $initrdmount/preseed"); # Poke in preseed
&my_sys("/bin/cp $final $initrdmount/LinuxCOE-final") unless ($db->def('NO_COE')); # Poke in final
&create_replay("$initrdmount/replay"); # Poke in replay
# Poke in boottime lipstick
$db->boot_lipstick("$initrdmount",$distro,$version,$arch,$waystation,$method,$profile,$ip,$nm,$gw,$ns,"final_text not implemented",$parts,$msgtail,$interface,$hostname,$kbd,$mouse,$lang,$timezone,\@bundles,\@coe_bundles,$defs);
$db->boot_lipstick("$initrdmount/efi/boot",$distro,$version,$arch,$waystation,$method,$profile,$ip,$nm,$gw,$ns,"final_text not implemented",$parts,$msgtail,$interface,$hostname,$kbd,$mouse,$lang,$timezone,\@bundles,\@coe_bundles,$defs);
# Poke initrd back into boot.img, umount, cleanup
&my_sys("cd $initrdmount; $FIND . | $CPIO -H newc -o | $GZIP -c --best >$imgmount/initrd.gz");
&my_sys("$SUDO /bin/umount $imgmount");
&my_sys("/bin/rm -rf $initrdmount"); # Get rid of playground
&my_sys("/bin/rmdir $imgmount"); # Get rid of playground
# MAKE the bootable image/remove scratch dir
&my_sys("$MKISOFS -o $custiso -b boot/boot.img -c boot/boot.catalog -no-emul-boot -J -r -T -v -pad $isodir");
&my_sys("/bin/rm -rf $isodir");
} else { # IT's still Sarge
# Poke preseed in there
&my_sys("/bin/cp $preseed $isodir/preseed");
&my_sys($sys);
$sys = "/bin/cp $final $isodir/LinuxCOE-final";
&my_sys($sys);
# Let's tweak elilo and put our lipstick in boot.img
# Loopmount boot.img for abuse
my $bootdir = "$htmlpath/bootdir$$";
mkdir($bootdir,0755);
$sys = "$SUDO /bin/mount -o loop,user,uid=$uid,rw -t vfat $isodir/boot/boot.img $bootdir";
&my_sys($sys);
# Poke our elilo.conf in there...
my $elilo = $db->find_file("boot/elilo.conf-$distro-$version");
unless ($elilo) { $elilo = $db->find_file("boot/elilo.conf-$distro") }
unless ($elilo) { &end_it_now("Cannot locate elilo.conf for $distro $version") }
$sys = "/bin/cp $elilo $bootdir/elilo.conf";
&my_sys($sys);
$sys = "/bin/cp $elilo $bootdir/efi/boot/elilo.conf";
&my_sys($sys);
# Put in our boot msg stuff
$qout->message("Inserting configuration information");
$qout->updatehtml(3);
$db->boot_lipstick("$bootdir",$distro,$version,$arch,$waystation,$method,$profile,$ip,$nm,$gw,$ns,"final_text not implemented",$parts,$msgtail,$interface,$hostname,$kbd,$mouse,$lang,$timezone,\@bundles,\@coe_bundles,$defs);
$db->boot_lipstick("$bootdir/efi/boot",$distro,$version,$arch,$waystation,$method,$profile,$ip,$nm,$gw,$ns,"final_text not implemented",$parts,$msgtail,$interface,$hostname,$kbd,$mouse,$lang,$timezone,\@bundles,\@coe_bundles,$defs);
# Umount boot.img
$sys = "$SUDO /bin/umount $bootdir";
&my_sys($sys);
&create_replay("$isodir/replay");
# Run mkisofs against it
$sys = "$MKISOFS -o $custiso -b boot/boot.img -c boot/boot.catalog -no-emul-boot -J -r -T -v -pad $isodir";
&my_sys($sys);
# Cleanup the workdirs
$sys = "/bin/rm -rf $isodir";
&my_sys($sys);
$sys = "/bin/rm -rf $bootdir";
&my_sys($sys);
} # End of if sarge
} # End of Step2ia64
sub Step2 {
# Extract the virgin ISO image for mangling
my $uid = $>; # What's my UID
umask 000;
mkdir("$imgmount",0755) ||
&end_it_now("Cannot mkdir $imgmount : $!\n");
unless ( -d "$imgmount" ) {
&end_it_now("mkdir $imgmount failed?!?!?!\n");
}
my $isofile = $db->find_file("images/$distro-$version-$arch-iso.tar");
my $sys = "$TAR -C $imgmount -xf $isofile";
$qout->message("Extracting base install system for configuration insertion");
$qout->updatehtml(5);
print STDERR "$sys\n" if $debug;
&my_sys($sys);
# OK, no more top level CD preseeding, have to poke it in inird to be be able to
# preseed with a netinst/buscard iso :(
# http://d-i.alioth.debian.org/manual/en.i386/apbs01.html
# So let's explode initrd (CPIO archive @ 2.6 ) and poke preseed in there
# If we need a custom isolinux.cfg (vs. what distro has by default), use it!
my $cfgmap = $db->find_file("data/isolinux.map");
if ( open(CFGMAP,"$cfgmap") ) {
my %cfgmap;
while (<CFGMAP>) {
next if /^#/;
chomp;
# DIST-VER-ARCH data/filename path_to_iso_location
my ($tuple,$path,$destination,$initrd) = split;
next unless ($destination); # skip blank/incomplete lines
$cfgmap{$tuple} = "$path $destination $initrd";
}
close(CFGMAP);
# If there's a cfgmap entry, we need to jam preseed/final into initrd
if ($cfgmap{"$distro-$version-$arch"} ) {
#Debian-Etch-x86_64 boot/isolinux.cfg.Debian-Etch-x86_64 isolinux/isolinux.cfg install.amd/initrd.gz
my ($path,$destination,$initrdpath) = split(' ',$cfgmap{"$distro-$version-$arch"});
print STDERR "\$cfgmap{$distro-$version-$arch} = $path $destination $initrdpath\n" if $debug;
my $infile = $db->find_file($path);
unless ($infile) {
&end_it_now("Whoa!, I thought I could find an isolinux.cfg at $path for $distro-$version-$arch, but it's not there. Color me confused, and <b>GONE</b>!");
}
my $sys = "/bin/cp $infile $imgmount/$destination";
&my_sys($sys);
# Explode initrd.img - poke in preseed - overwrite it w/new
mkdir("$initrdmount",0766) || &end_it_now("Cannot mkdir $initrdmount : $!\n"); # Create a tempdir
# RHEL3's CPIO throws an error return here, I have no idea why, so don't check return on this cpio
system("cd $initrdmount; $GZIP -dc $imgmount/$initrdpath | $CPIO -i"); # Extract CPIO image
&my_sys("/bin/cp $preseed $initrdmount/preseed.cfg");
&my_sys("/bin/cp $preseed $initrdmount/preseed"); # For Dapper
&my_sys("/bin/cp $final $initrdmount/LinuxCOE-final") unless $db->def('NO_COE'); # Poke final in there
&my_sys("/bin/cp $cust_file $initrdmount/custom_final") if ( $profile ne 'Custom'); # BUG - other archs
$qout->message("Recreating initrd");
$qout->updatehtml(3);
&create_replay("$initrdmount/replay");
&my_sys("cd $initrdmount; $FIND . | $CPIO -H newc -o | $GZIP --best -c >$imgmount/$initrdpath"); # Put it back
&my_sys("/bin/rm -rf $initrdmount"); # What body?
} else {
&end_it_now("I can't find initrd/isolinux info for $distro-$version-$arch, check data/isolinux.map for completeness");
}
}
# Put in our boot msg stuff
$qout->message("Inserting preseed file into boot image");
$qout->updatehtml(3);
my ($hostname,$nw,$bc,$dom) = $db->do_dns($ip,$nm);
$hostname = $hostname || "localhost";
$dom = $dom || "localdomain";
if ( $qin->param('system')) { $hostname = $qin->param('system') };
if ( $os =~ /buntu/ ) {
$db->boot_lipstick("$imgmount",$distro,$version,$arch,$waystation,$method,$profile,$ip,$nm,$gw,$ns,"final_text not implemented",$parts,$msgtail,$interface,$hostname,$kbd,$mouse,$lang,$timezone,\@bundles,\@coe_bundles,$defs);
} else {
$db->boot_lipstick("$imgmount/isolinux",$distro,$version,$arch,$waystation,$method,$profile,$ip,$nm,$gw,$ns,"final_text not implemented",$parts,$msgtail,$interface,$hostname,$kbd,$mouse,$lang,$timezone,\@bundles,\@coe_bundles,$defs);
}
# Stick preseed into directory, create ISO
$sys = "/bin/cp $preseed $imgmount/preseed";
&my_sys($sys);
$sys = "/bin/cp $final $imgmount/LinuxCOE-final" unless $db->def('NO_COE');
&my_sys($sys);
&create_replay("$imgmount/replay");
$qout->message("Creating ISO image");
$qout->updatehtml(3);
$sys = "$MKISOFS -b isolinux/isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o $custiso -r -publisher \"LinuxCOE / Hewlett Packard / http://linuxcoe.sourceforge.net\" -A \"LinuxCOE Boot Image\" -p LinuxCOE -J -V LinuxCOE -T $imgmount/";
if ( $os =~ /buntu/ ) {
$sys = "$MKISOFS -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o $custiso -r -publisher \"LinuxCOE / Hewlett Packard / http://linuxcoe.sourceforge.net\" -A \"LinuxCOE Boot Image\" -p LinuxCOE -J -V LinuxCOE -T $imgmount/";
}
&my_sys($sys);
# If SIM is in play, make a tarball
if ( $db->def('SIM') ) {
my $simdir = $db->def('SIM');
unless ( -d "$simdir/$serial") { mkdir "$simdir/$serial",0755 }
&my_sys("/bin/ln -sf CUSTOM_SETTINGS $simdir/$serial/$serial");
#set symlinks to the "real" directory
foreach my $serial_sym (@serials){
&my_sys("/bin/ln -sf $serial $simdir/$serial_sym");
&my_sys("/bin/ln -sf CUSTOM_SETTINGS $simdir/$serial/$serial_sym");
}
$sys = "cd $imgmount && $TAR -cf $simdir/$serial/boot.tar *";
&my_sys($sys);
}
# Just in case I don't have write access there (even though I should, depends on virgin image, let's try and not check return)
system "/bin/chmod -R 777 $imgmount";
$sys = "/bin/rm -rf $imgmount";
&my_sys($sys);
} # End of Step2
sub Init {
# Kick off the interactive HTML stuff
$htmlfile = "/scratch_monkey/id$$.html";
my $iesux = 0;
if (( $ENV{HTTP_USER_AGENT} =~ /MSIE/ ) || ( $ENV{HTTP_USER_AGENT} =~ /Konq/ )) {
$qout->htmlfile("$htmlfile");
$iesux = 1;
}
$htmlfile = "/var/opt/wwrmn/htdocs/scratch_monkey/id$$.html";
$qout->title("Linux Install Image Creation");
$qout->persist("Linux Install Image Creation - working<blink>.</blink>");
$qout->message("Initalizing");
$qout->kickstart();
} # End if Init
sub check_pass {
# Validate root passwd, KISS here, non-null and the same
my @passwd = $qin->param('Root_Pass');
if ( $os =~ /Debian/ ) {
if ((! $passwd[0] ) || (! $passwd[1] )) {
&end_it_now("You must enter a root password, and do it twice!");
}
unless ( $passwd[0] eq $passwd[1] ) {
&end_it_now("Sorry, your two root passwords don't match!");
}
}
my $upass;
my @upass = $qin->param('User_Pass');
if (( $qin->param('User_Name')) && ($upass[0] ne $upass[1] )) {
&end_it_now("Sorry, your two mortal user passwords don't match!");
} else {
$upass = $upass[0];
}
return($passwd[0],$upass);
}
sub end_it_now {
# Exit with extreme predjudice
if ( $mounted ) {
system "$SUDO /bin/umount $imgmount";
rmdir($imgmount);
}
if ( -f $custimg ) { unlink $custimg }
my $errmsg = shift(@_);
my $admin = $db->def('SITE_ADMIN');
$errmsg .= "<hr>If this error message looks bogus, contact <a href=\"mailto:$admin>$admin</a>\n" if $admin;
if ($replay) {
print "START_OF_LINUXCOE_BEAM_DATA\nERR: $errmsg\nEND_OF_LINUXCOE_BEAM_DATA\n";
}
my $yikes = $db->err_msg;
if ( $db->def('FINAL_INTERACTIVE') ) {
$qout->persist("$yikes A catastrophic error!");
$qout->message("$errmsg");
$qout->updatehtml(0);
} else {
print $qin->header;
$db->ShowNav("$yikes A catastrophic error!");
print "<h2>$yikes A catastrophic error!</h2>\n";
print $errmsg;
print $qin->end_html;
$db->ShowFooter;
}
exit;
}
sub my_sys {
my $sys = shift;
print STDERR "$sys\n" if $debug;
system $sys;
if ($? == -1) {
&end_it_now("$sys returned $!");
}
elsif ($?){
my $ret_code = $? >> 8; # <-- 'perldoc -f system' for details
&end_it_now("$sys gave a non-zero return code, $ret_code\n");
}
}
sub preseed_header {
my $msg = shift;
print PRESEED qq[
####################################################################
# $msg
####################################################################
];
print STDERR "PRESEED creating $msg\n" if $debug;
}
sub preseed_sources {
# BUG - Security Updates? Add here
my ($waystation,$path,$version,$preamb,$lmeth) = @_;
# Load the dist mapper
my $mapfile = $db->find_file("data/distmap");
unless ( -r $mapfile ) {
&end_it_now("Cannot locate Version->Name mapping file 'distmap'");
}
open(DIST,"$mapfile") || &end_it_now("open $mapfile : $!");
my %distmap;
while(<DIST>) {
next if /^#/;
chomp;
next unless $_;
my ($ver,$dist) = split;
$distmap{$ver} = $dist;
}
close(DIST);
print PRESEED qq[# Where are we pulling bits from?
d-i mirror/http/hostname string $waystation
d-i mirror/http/directory string $path
d-i mirror/suite string $distmap{$version}
# Post install APT setup
$preamb apt-setup/uri_type select $lmeth
$preamb apt-setup/hostname string $waystation
$preamb apt-setup/directory string $path
$preamb apt-setup/another boolean false
$preamb apt-setup/security-updates boolean false
$preamb finish-install/reboot_in_progress note
$preamb prebaseconfig/reboot_in_progress note
];
if ( $os =~ /Debian/ ) {
print PRESEED qq[$preamb apt-setup/non-free boolean true
$preamb apt-setup/contrib boolean true
];
} else {
print PRESEED qq[d-i apt-setup/mirror/error select Change mirror
d-i apt-setup/multiverse boolean true
d-i apt-setup/restricted boolean true
d-i apt-setup/universe boolean true
d-i archive-copier/desktop-task string
d-i archive-copier/ship-task string
];
}
}
sub preseed_static {
my $ip = $qin->param('ip');
my $gw = $qin->param('gateway') || $ip;
my $nm = $qin->param('netmask');
my $ns = $qin->param('namesvr');
my ($hostname,$nw,$bc,$dom) = $db->do_dns($ip,$nm);
$hostname = $hostname || "localhost";
$dom = $dom || "localdomain";
print PRESEED qq[# Network Configuration
d-i netcfg/get_hostname string $hostname
d-i netcfg/get_domain string $dom
d-i netcfg/disable_dhcp boolean true
d-i netcfg/get_nameservers string $ns
d-i netcfg/get_ipaddress string $ip
d-i netcfg/get_netmask string $nm
d-i netcfg/get_gateway string $gw
d-i netcfg/confirm_static boolean true
];
}
sub preseed_dhcp {
my $hostname = $qin->param('system') || 'localhost';
my @data = split('\.',$hostname);
shift(@data); # Drop hostname
my $domain = join('.',@data) || 'localdomain';
print PRESEED qq[# Network Configuration
d-i netcfg/get_hostname string $hostname
d-i netcfg/get_domain string $domain
d-i netcfg/disable_dhcp boolean false
];
}
sub preseed_common {
my $proxy = $qin->param('proxy');
print PRESEED "d-i\tmirror/http/proxy\tstring\t$proxy\n";
print PRESEED qq[d-i netcfg/choose_interface select $interface
d-i netcfg/wireless_wep string
];
}
sub preseed_partition {
my ($part_choice,$parts,$profile) = @_;
if ( $profile ne 'Custom' ) {
print PRESEED "$parts\n";
return;
}
my $disk;
if (( $part_choice eq 'Autopartition' ) || ( $part_choice eq 'Multi-user workstation' ) || ( $part_choice eq 'Desktop Machine' )) {
$disk = $parts;
} else {
$disk = $qin->param('ddisk');
}
# Tell ELILO where to find its disk if ia64
if ( $arch eq 'ia64' ) {
if (( $disk =~ /cciss/ ) || ( $disk =~ /ida/ )) {
print PRESEED "d-i elilo-installer/bootpart select ${disk}p1\n";
} else {
print PRESEED "d-i elilo-installer/bootpart select ${disk}1\n";
}
}
print PRESEED "d-i partman-auto/disk string $disk\n";
print PRESEED "d-i partman-auto/method string regular\n";
# Determine if they are using a canned recipe or Simple, do the right thing....
if ( $part_choice eq 'Multi-user workstation' ) {
if (( $version eq '3.1' ) || ( $version eq 'Dapper' )) {
print PRESEED "d-i partman-auto/choose_recipe select $part_choice\n";
} else {
print PRESEED "d-i partman-auto/choose_recipe select Separate /home, /usr, /var, and /tmp partitions\n";
}
} elsif ( $part_choice eq 'Desktop Machine' ) {
if (( $version eq '3.1' ) || ( $version eq 'Dapper' )) {
print PRESEED "d-i partman-auto/choose_recipe select $part_choice\n";
} else {
print PRESEED "d-i partman-auto/choose_recipe select Separate /home partition\n";
}
} elsif ( $part_choice eq 'Simple' ) {
print PRESEED $qin->param('parts')."\n";
}
print PRESEED qq[
# This makes partman automatically partition without confirmation.
d-i partman/choose_partition select Finish partitioning and write changes to disk
d-i partman/confirm boolean true
# This one makes grub-installer install to the MBR even if finds some other OS
# too, which is less safe as it might not be able to boot that other OS.
d-i grub-installer/with_other_os boolean true
];
}
sub preseed_localization {
my ($preamb,$tz) = @_;
my $utc;
if ( $qin->param('utc') eq 'Yes' ) {
$utc = 'true';
} else {
$utc = 'false';
}
my ($country,$zone) = split('/',$tz);
my $xfree = 'xorg';
if (( $version eq '3.1' ) || ( $version eq 'Hoary' )) {
$xfree = 'xfree86';
}
print PRESEED qq[# Install Time
d-i console-tools/archs string skip-config
d-i debian-installer/locale string en_US
d-i console-keymaps-at/keymap select us
] if ( $version ne 'Dapper' );
print PRESEED qq[
d-i languagechooser/language-name-fb select English
d-i debian-installer/locale select en_US.UTF-8
# Timezone
$preamb tzconfig/gmt boolean $utc
$preamb tzconfig/choose_country_zone/$country select $zone
$preamb tzconfig/choose_country_zone_single boolean true
d-i time/zone select $tz
d-i clock-setup/utc boolean true
d-i kbd-chooser/method select American English
d-i mirror/country string enter information manually
# X11 config
xserver-$xfree xserver-$xfree/autodetect_monitor boolean true
xserver-$xfree xserver-$xfree/config/monitor/selection-method select medium
xserver-$xfree xserver-$xfree/config/monitor/mode-list select 1024x768 @ 60 Hz
xserver-$xfree xserver-$xfree/config/display/modes multiselect 1024x768, 800x600
];
}
sub preseed_user {
# Note, there is a perl module that provides this feature (Crypt::PasswdMD5). It's
# not part of base Perl installs so I'm forking mkpasswd to keep the code more
# portable.
# Also, on RHEL (so I assume Fedora/CentOS/etc.) mkpasswd can't do this, default to
# plaintext passwords as its mkpasswd just can't do a MD5 hash
my $good_mkpasswd = 1; # mkpassword works
my $have_crypt = 0; # user installed Crypt::PasswdMD5
# Test for Crypt::PasswdMD5 here
my $sys = "/usr/bin/mkpasswd -H MD5 test >/dev/null 2>&1";
system $sys;
if ($?) {
$good_mkpasswd = 0;
}
if ( $os =~ /Debian/ ) {
if (( $os =~ /Etch/ ) && ($good_mkpasswd )) {
open(PASS,"/usr/bin/mkpasswd -H MD5 $passwd |");
$passwd = <PASS>;
close(PASS); wait;
chomp($passwd);
print PRESEED qq[# Root User
d-i passwd/root-password-crypted passwd $passwd
];
} else {
print PRESEED qq[# Root User
passwd passwd/root-password password $passwd
passwd passwd/root-password-again password $passwd
];
}
} else {
print PRESEED "# Root User\n";
print PRESEED "d-i\tpasswd/root-login\tboolean\tfalse\n";
}
my $uname = $qin->param('User_Name');
if ( $uname ) {
my $realname = $qin->param('Real_Name');
if ((( $os =~ /E/ ) || ( $os =~ /Dapper/ )) && ($good_mkpasswd)) {
open(PASS,"/usr/bin/mkpasswd -H MD5 $userpasswd |");
$userpasswd = <PASS>;
close(PASS); wait;
chomp($userpasswd);
print PRESEED qq[
# Mortal User
d-i passwd/user-fullname string $realname
d-i passwd/username string $uname
d-i passwd/user-password-crypted passwd $userpasswd
];
} else {
print PRESEED qq[
# Mortal User
passwd passwd/user-fullname string $realname
passwd passwd/username string $uname
passwd passwd/user-password password $userpasswd
passwd passwd/user-password-again password $userpasswd
];
}
}
}
sub preseed_software {
my ($debs) = @_;
# This is the tasksel level
my $tasksel;
my @bundles = $qin->param('bundles');
if ( $os =~ /Etch/ ) { push(@bundles,"standard") }
if ( @bundles ) {
if ( $os =~ /buntu/ ) {
$tasksel = join(" ",@bundles);
print STDERR "\$tasksel == >$tasksel<\n" if $debug;
if (( $tasksel ) && ( @langs )) { $tasksel .= " " }
$tasksel .= join(" ",@langs);
} else {
$tasksel = join(", ",@bundles);
print STDERR "\$tasksel == >$tasksel<\n" if $debug;
if (( $tasksel ) && ( @langs )) { $tasksel .= ", " }
$tasksel .= join(" ",@langs);
$tasksel = "tasksel\ttasksel/first\tmultiselect\t$tasksel\n" if ( $tasksel);
print PRESEED $tasksel;
undef($tasksel);
}
}
if ( $debs ) {
my @debs = split(' ',$debs);
$tasksel .= " " . join(' ',@debs);
}
my $taskstr = "d-i\tpkgsel/include\tstring\t$tasksel";
print PRESEED "$taskstr\n" if ( $tasksel );
}
sub preseed_cust {
# Here's the customer's final script from the profile...
#
# Hey, Jude, don't make it bad
# Take this profile and make it better
# Remember to exit with a good code
# Then you can start to make it better
#
# LinuxCOE welcomes Jude, and wishes her Godspeed on her journey through this world.
# (apologies to Lennon and MCartney, congratulations to the Slaters)
my ($final_script) = @_;
print STDERR "Creating $cust_file\n" if $debug;
open(FINAL,">$cust_file") || &end_it_now("Cannot open FINAL '$cust_file' for writing : $!\n");
print FINAL "$final_script\n";
print FINAL "# In case they have a bad final exit code, don't red-screen the whole install\n";
print FINAL "exit 0\n";
close(FINAL);
}
sub preseed_coe {
my ($patch_me,$patch_freq) = @_;
# Create final script (value add apt depots, install them)
my $datestr = localtime;
open(FINAL,">$final") || &end_it_now("Cannot open FINAL '$final' for writing : $!\n");
print FINAL "#!/usr/bin/perl\n";
print FINAL "# Install COE bundles (leem\@hp.com)\n# Generated by LinuxCOE SystemDesigner on $datestr\n";
print FINAL qq[system "/bin/mkdir -p /etc/opt/LinuxCOE/apt /etc/opt/LinuxCOE/apt.sources";\n];
# Do they want patches?? If so, touch PATCH_ME
if ( $patch_me ) {
print FINAL qq[ open(PATCH,">/etc/opt/LinuxCOE/apt/PATCH_ME");
close(PATCH);\n];
}
# Do they want continued patching?
if (( $patch_freq ) && ( $patch_freq ne 'never' )) {
print FINAL qq[open(OUT,">/etc/cron.${patch_freq}/apt_patch");
print OUT qq{#!/bin/bash
/bin/touch /etc/opt/LinuxCOE/apt/PATCH_ME
/etc/rc.d/init.d/LinuxCOE-Bundles start
};
system "/bin/chmod +x /etc/cron.${patch_freq}/apt_patch"; ];
}
# Populate /etc/opt/LinuxCOE/apt.sources with what we'll need
# Let's drop a little file wiht the tuple we were installed with
print FINAL qq[open(OUT,">/etc/opt/LinuxCOE/INSTALLED");\n];
print FINAL "print OUT qq[$distro $version $arch];\n";
print FINAL "close(OUT);\n";
# First do the base (OS and Patch Trees)
my $t = $method;
if (($t eq 'CDROM' ) || ($t eq 'NFS' )) {
$t = $db->def('METHOD') || "HTTP";
}
$t = lc($t) . '://';
# Look for base/security, overwrite if needed
my $infile = $db->find_file("depots/apt-$distro-$version-$arch");
unless ($infile) { $infile = $db->find_file("depots/apt-$distro-$version") }
unless ($infile) { $infile = $db->find_file("depots/apt-$distro") }
if (open(SOURCES,"$infile")) {
print FINAL qq[open(OUT,">/etc/opt/LinuxCOE/apt.sources/COE_BASE");\n];
print FINAL "print OUT qq[";
my $lines;
while($lines = <SOURCES>) {
$lines =~ s/\@METHOD\@/$t/g;
$lines =~ s/\@WAYSTATION\@/$waystation/g;
$lines =~ s/\@ARCH\@/$arch/g;
$lines =~ s/\@DISTRO\@/$distro/g;
$lines =~ s/\@VERSION\@/$version/g;
print FINAL "$lines";
}
close(SOURCES);
print FINAL "];\nclose(OUT);\n";
}
# Then do additional depots
# WARNING! This looks wierd, because it's perl writing perl, beware the Jabberwocky (and \deref's)
my @NAMES = split(' ',$db->def('ADDONS'));
foreach my $addon (@NAMES) {
my ($config,$helpurl,$rpmapt,$debapt,$rpmyum,@needs) = $db->parse_addon_config($addon,$distro,$version,$arch);
my ($d,$f,$count) = $db->parse_coe_bundles($arch,$distro,$version,$config);
next unless ($count);
next unless ($debapt);
$debapt =~ s/\@METHOD\@/$t/g;
$debapt =~ s/\@WAYSTATION\@/$waystation/g;
$debapt =~ s/\@ARCH\@/$arch/g;
$debapt =~ s/\@DISTRO\@/$distro/g;
$debapt =~ s/\@VERSION\@/$version/g;
chomp($debapt);
my @lines = split("\n",$debapt);
my $temp = $debapt;
undef($debapt);
foreach my $line (@lines) {
if ( $line =~ /^KEY: /) {
my @data = split(' ',$line);
print FINAL qq[system "wget $data[1] -O - | apt-key add -";\n];
} else {
$debapt .= "$line\n";
}
}
print FINAL qq[open(OUT,">>/etc/opt/LinuxCOE/apt.sources/$addon");
print OUT "# Depots for $addon\\n";
print OUT "$debapt\\n";
close(OUT);
];
}
# This used to be done by %final, now drop bundle files in placeand call installer
my ($d,$f) = $db->parse_coe_bundles($arch, $distro, $version, 'ALL');
foreach my $bundle (@coe_bundles) {
print STDERR "coe_bundle_roller: I have bundle $bundle!\n" if $debug;
print STDERR "coe_bundle_roller: files: ${$f}{$bundle}!\n" if $debug;
my @files = split(' ',${$f}{$bundle});
my $archin = shift(@files);
my $debs = join(' ',@files);
$bundle_error = 1 unless ($debs); # Bundle requested but does not exist
my $name = $bundle;
$bundle =~ tr/a-zA-z0-9/_/cs;
print FINAL qq[open(OUT,">/etc/opt/LinuxCOE/apt/$bundle");
print OUT "$name\\n$debs\\n";
close(OUT);
];
}
my $skel = $db->find_file("data/deb_final_skel");
open(IN,"$skel") || &end_it_now("Error opening $skel : $!\n");
while(<IN>) {
# Stick in top of file
last if /^# REAL_DATA_HERE/;
next if /^#/; # drop comments
next if ( $_ eq "\n" ); # drop MT lines
print FINAL;
}
print FINAL qq['WaYsTaTiOn' => "$waystation",\n];
my %extra_rpms = $db->make_Base($method,$waystation,$distro,$version,$arch);
foreach my $key (sort(keys(%extra_rpms))) {
next unless ( $extra_rpms{$key} );
print FINAL qq["$key" => "$extra_rpms{$key}",\n];
}
while(<IN>) {
next if /^#/; # drop comments
next if ( $_ eq "\n" ); # drop MT lines
print FINAL;
}
close(IN);
close(FINAL);
}
sub create_replay {
# Create a file with all the args we were called with, pick it up later on client
my $replay_file = shift(@_);
foreach my $parm ($qin->param) {
$qin->delete($parm) if ( $parm =~ /Pass/i ); # Skip plaintext passwords :)
}
if (open(PARMOUT,">$replay_file")) {
$qin->save(\*PARMOUT);
close(PARMOUT);
} else {
print STDERR "Cannot open PARMOUT ($replay_file) : $!\n";
}
}
See more files for this project here