#!/usr/bin/perl use Net::Syslog; my $syslog; my $SyslogFacility = "local3"; print "Content-type: text/plain\n\n"; sysInfo("Received KickStart config request from $ENV{REMOTE_ADDR} QS=$ENV{QUERY_STRING}"); my $c; my $query_has_disktype = 0; $c->{KS_ALLOWLIST} = ''; $c->{DIST} = "default"; $c->{DEBUG} = 0; $c->{PTYPE} = "probe"; $c->{PRE} = 'y'; $c->{POST} = 'y'; $c->{POSTNR} = 'y'; $c->{PREPOSTNR} = 'y'; $c->{IG_HOME} = "/opt/iglass"; $c->{IG_ETC} = "/etc/iglass"; #$c->{KSRV} = "10.1.1.1"; $c->{KSRV} = "kserver.iglass.net"; $c->{SSHHOST} = $c->{KSRV}; $c->{SSHPORT} = 22; # Load QUERY_STRING variables cuz I need to see if DIST is defined foreach my $pair ( split(/\&/,$ENV{QUERY_STRING}) ) { if ( $pair =~ /(\S+)\=(\S+)/ ) { if ( $1 eq "TYPE" ) { eval "\$c->{PTYPE} = '$2'"; Debug("PTYPE = '$c->{$1}'"); } elsif ( $1 eq "DISKTYPE" ) { $query_has_disktype = 1; eval "\$c->{$1} = '$2'"; Debug("$1 = '$c->{$1}'"); } else { eval "\$c->{$1} = '$2'"; Debug("$1 = '$c->{$1}'"); } } else { $c->{DIST} = $ENV{QUERY_STRING}; last; } } if ( $c->{PTYPE} =~ /^(?:VM)|(?:container)$/ ) { print "#!/bin/bash\n"; } # Find who is Asking my $MAC = `ifconfig eth0 |grep HWaddr | awk '{print \$5}'`; if ( $ENV{REMOTE_ADDR} ) { if ( !$MAC ) { `/bin/ping -c 1 $ENV{REMOTE_ADDR} > /dev/null`; $MAC = `arp -na $ENV{REMOTE_ADDR} |cut -d ' ' -f 4`; chomp($MAC); } if ( $ENV{REMOTE_ADDR} =~ /^(?:192\.168\.|10\.1\.1\.)/ ) { $c->{KSRV} = "monolith.iglass.net"; if ( !defined($c->{SSHHOST}) || $c->{SSHHOST} eq "kserver.iglass.net" ) { $c->{SSHHOST} = $c->{KSRV}; } } } my $KDIR = "/home/KickStart/cfg"; # Load custom config file variables if ( open(C, "$KDIR/stag.d/$MAC.cfg") ) { #print "\n"; Debug("$KDIR/stag.d/$MAC.cfg:"); while ( ) { chomp; if ( /^\s*#/ ) { next; } elsif ( /([^#\s]+)\='([^#\s]*)'/ || /([^#\s]+)\=([^#\s]*)/ ) { Debug(" $1 = '$2'"); eval "\$c->{$1} = '$2'"; Debug(" $1 = '$c->{$1}'"); } else { Warn("What is this '$_' in $MAC.cfg?"); } } close C; } else { Debug("No $MAC.cfg"); } my $URL = "http://$c->{KSRV}/KickStart"; if ( -d "$KDIR/$c->{DIST}" ) { Info("Using config directory $KDIR"); $KDIR .= "/$c->{DIST}"; $URL .= "/$c->{DIST}"; } else { Warn("KS directory '$KDIR' for $c->{DIST}/ does not exist! Using default CentOS"); $KDIR .= "/default"; $URL .= "/default"; } # Load config file variables if ( open(C, "$KDIR/ks.config") ) { #print "\n"; Debug("$KDIR/ks.config:"); while ( ) { chomp; if ( /^\s*#/ ) { next; } elsif ( /([^#\s]+)\='([^#\s]*)'/ || /([^#\s]+)\=([^#\s]*)/ ) { Debug(" $1 = '$2'"); eval "\$c->{$1} = '$2'"; Debug(" $1 = '$c->{$1}'"); } else { Warn("What is this '$_' in ks.config?"); } } close C; } else { Warn("No $KDIR/ks.config!"); } # Load these variables (yes again) to override config file mainly for DIST foreach my $pair ( split(/\&/,$ENV{QUERY_STRING}) ) { if ( $pair =~ /(\S+)\=(\S+)/ ) { if ( $1 eq "DISKTYPE" ) { $query_has_disktype = 1; } eval "\$c->{$1} = '$2'"; Debug("Reset $1 = '$2'"); } else { $c->{DIST} = $ENV{QUERY_STRING}; last; } } if ( $MAC =~ /^52:54:00:/ ) { # kvm/qemu mac prefix $DISK = 'vda'; if ( $ENV{QUERY_STRING} !~ /(?:^|&)DISKTYPE=/ ) { $c->{DISKTYPE} = 'vda'; Debug(" Reset DISKTYPE = '$c->{DISKTYPE}'"); } } else { $DISK = 'sda'; } if ( open(C, "$KDIR/../stag.d/$MAC.cfg") ) { #print "\n"; Debug("$KDIR/../stag.d/$MAC.cfg:"); while ( ) { chomp; if ( /^\s*#/ ) { next; } elsif ( /([^#\s]+)\='([^#\s]*)'/ || /([^#\s]+)\=([^#\s]*)/ ) { Debug(" $1 = '$2'"); eval "\$c->{$1} = '$2'"; Debug(" $1 = '$c->{$1}'"); } else { Warn("What is this '$_' in $MAC.cfg?"); } } close C; } else { Debug("No $MAC.cfg"); } Break(); foreach my $key ( keys %{$c} ) { Info("$key = $c->{$key}") unless ($key =~ /PASS$/); } # Find iGlass release version my $IGRELEASE=`cd /home/KickStart/iglass-releases; ls -v probe*rpm | tail -1`; chomp $IGRELEASE; Break(); Info("IP=$ENV{REMOTE_ADDR}"); Info("MAC=$MAC"); Info("IGRELEASE=$IGRELEASE"); Break(); my $FLOG = `date +custom-%F.log`; chomp $FLOG; if ( $c->{PTYPE} =~ /^container$/ ) { } elsif ( $c->{PTYPE} =~ /^VM$/ ) { # PTYPE = V print "if [ `id -u` != 0 ]; then\n"; print " echo Please run as root\n"; print " exit 1\n"; print "fi\n\n"; print "export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/opt/iglass/bin\n\n"; $c->{KSRV} = "$ENV{HTTP_HOST}"; if ( my ($host, $port) = ($c->{KSRV} =~ /^(\w+):(\d+)$/) ) { $c->{SSHHOST} = $host; $c->{SSHPORT} = ++$port; } else { Warn("No ssh port from http port found"); } $LOGGER = "cat"; print "cp -a /etc/resolv.conf /etc/resolv.conf.orig\n"; #print "yum -y install epel-release\n"; my @groupList; my @plusList; my @minusList; my @vmList; if ( open(P,"$KDIR/KS_Packages.cfg") ) { while (

) { if ( /^\@(.+)$/ ) { #push @groupList, $1; } elsif ( /^\-(.+)$/ ) { #push @minusList, $1; } elsif ( /^(.+)$/ ) { push @plusList, $1; } } close P; } else { Warn("No packages found"); } if ( open(P,"$KDIR/KS_Packages-$c->{PTYPE}.cfg") ) { while (

) { if ( /^\@(.+)$/ ) { push @groupList, $1; } elsif ( /^\-(.+)$/ ) { push @minusList, $1; } elsif ( /^(.+)$/ ) { push @plusList, $1; } } close P; } my $toLong = 75; print "\n"; print "yum groupinstall ", join(" ",@groupList), "\n\n" if ( $#groupList >= 0 ); print "\n"; if ( $#plusList >= 0 ) { print "yum -y install "; my $len=15; foreach ( @plusList ) { $len += length " $_"; print " $_"; if ( $len > $toLong ) { print " \\\n"; $len=0; } } } print "\n\n"; print "yum erase ", join(" ",@minusList), "\n\n" if ( $#minusList >= 0 ); } else { if ( $c->{DIST} =~ /^[a-zA-Z]+\-(?:8|9|10)/ ) { print "eula --agreed\n"; } else { print "install\n"; print "authconfig --enableshadow --enablemd5\n"; } print "\n"; print "url --url $URL\n"; print "\n"; if ( $c->{INTERACTIVE} eq "y" ) { print "interactive\n"; } print "text\n"; if ( $c->{DIST} eq "CentOS-3.7" ) { print "mouse genericps/2 --device psaux --emulthree\n"; } print "\n"; print "\n"; #print "network --device eth0 --bootproto dhcp\n"; #print "network --device eth0 --bootproto static --ip 192.168.177.80 --netmask 255.255.255.0 --gateway 192.168.177.254 --nameserver 192.168.176.2,192.168.177.2 --hostname iprobe017\n"; if ( ($c->{DIST} =~ /^[a-zA-Z]+-(\d+)/) && ($1 >= 6) ) { print "network --bootproto dhcp --nodns --noipv6\n"; print "sshpw --username=root $c->{MD5PASS} --iscrypted\n"; } else { print "network --device eth0 --bootproto dhcp --nodns --noipv6\n"; } print "\n"; print "\n"; print "xconfig\n"; print "\n"; if ( $c->{MD5PASS} ) { print "rootpw --iscrypted $c->{MD5PASS}\n"; print "\n"; } print "firstboot --disabled\n"; print "\n"; if ( $c->{DIST} =~ /^CentOS\-[56][\.]/ ) { print "lang en_US\n"; print "keyboard us\n"; print "logging --host $c->{KSRV} --level debug\n"; #print "vnc --host $c->{KSRV} --port 5500 --password=kickMe\n"; #sysInfo("Ask for vnc install from \%pre"); #print "%include /tmp/vnc.cfg\n"; #print "bootloader --location=mbr --driveorder=sda,sdb --append=\"rhgb quiet\""; print "bootloader --location=mbr --driveorder=$DISK --append=\"rhgb quiet\" --md5pass=$c->{MD5PASS}\n"; } elsif ( $c->{DIST} =~ /^[a-zA-Z]+\-[78]\./ ) { print "lang en_US.UTF-8\n"; print "keyboard --vckeymap=us --xlayouts='us'\n"; print "logging --host $c->{KSRV} --level debug\n"; print "bootloader --append=\"rhgb quiet crashkernel=auto\" --location=mbr --driveorder=$DISK --boot-drive=$DISK --iscrypted --password=\"$c->{GRUB2}\"\n"; } elsif ( $c->{DIST} =~ /^[a-zA-Z]+\-(?:9|10)\./ ) { print "lang en_US.UTF-8\n"; print "keyboard --vckeymap=us --xlayouts='us'\n"; print "logging --host $c->{KSRV}\n"; print "bootloader --append=\"rhgb quiet crashkernel=auto\" --iscrypted --password=\"$c->{GRUB2}\"\n"; } else { print "lang en_US\n"; print "keyboard us\n"; print "langsupport --default en_US en_US\n"; print "bootloader --location=mbr --md5pass=$c->{MD5PASS}\n"; } if ( $c->{FIREWALL} eq "n" ) { print "firewall --disabled\n"; } elsif ( $c->{FIREWALL} eq "enabled" ) { print "firewall --enabled --port=22:tcp, 1024:tcp, 5432:tcp, 5432:udp\n"; } elsif ( $c->{FIREWALL} ) { print "firewall --$c->{FIREWALL}\n"; } if ( $c->{SELINUX} eq "n" ) { print "selinux --disabled\n"; } elsif ( $c->{SELINUX} ) { print "selinux --$c->{SELINUX}\n"; } if ( $c->{TZ} ) { print "timezone $c->{TZ}\n"; } else { print "timezone US/Eastern\n"; } if ( $c->{REBOOT} eq "y" ) { print "reboot\n"; } elsif ( $c->{REBOOT} eq "h" ) { print "halt\n"; } print "\n"; # Setup Disk Partitions print "## Disk Partition Information\n"; if ( $c->{DISKTYPE} eq "prompt" ) { print "# Prompt for partiion setup\n"; } elsif ( $c->{DISKTYPE} eq "hd" ) { print "clearpart --all\n"; print "part /boot --fstype ext3 --size=100 --ondisk=hda\n"; print "part swap --size=2048 --ondisk=hda\n"; print "part swap --size=2048 --ondisk=hda\n"; #print "part swap --size=2048 --ondisk=hda\n"; #print "part swap --size=2048 --ondisk=hda\n"; print "part / --fstype ext3 --size=1100 --grow --ondisk=hda\n"; } elsif ( $c->{DISKTYPE} eq "one" ) { print "clearpart --all\n"; print "part /boot --fstype ext3 --size=100\n"; print "part swap --size=2048\n"; print "part swap --size=2048\n"; print "part / --fstype ext3 --size=1100 --grow\n"; } elsif ( $c->{DISKTYPE} eq "hdc" ) { print "clearpart --all\n"; print "part /boot --fstype ext3 --size=100 --ondisk=hdc\n"; print "part swap --size=2048 --ondisk=hdc\n"; print "part swap --size=2048 --ondisk=hdc\n"; print "part swap --size=2048 --ondisk=hdc\n"; print "part swap --size=2048 --ondisk=hdc\n"; print "part / --fstype ext3 --size=1100 --grow --ondisk=hdc\n"; } elsif ( $c->{DISKTYPE} eq "sd" ) { print "clearpart --all\n"; print "part /boot --fstype ext3 --size=100 --ondisk=sda\n"; print "part swap --size=2048 --ondisk=sda\n"; print "part swap --size=2048 --ondisk=sda\n"; print "part swap --size=2048 --ondisk=sda\n"; print "part swap --size=2048 --ondisk=sda\n"; print "part / --fstype ext3 --size=1100 --grow --ondisk=sda\n"; } elsif ( $c->{DISKTYPE} eq "vda" ) { print "clearpart --all\n\n"; print "part /boot --size=100 --ondisk=vda --fstype ext3\n"; print "part pv.11 --size=1 --ondisk=vda --grow\n\n"; print "volgroup vga pv.11\n\n"; print "logvol swap --fstype swap --name=iGlassOpt --vgname=vga --size=256\n"; print "logvol swap --fstype swap --name=swapVol01 --vgname=vga --size=4096\n"; print "logvol / --fstype ext4 --name=rootVol --vgname=vga --size=1 --grow\n\n"; } elsif ( $c->{DISKTYPE} eq "ssd" ) { # Created in %pre sysInfo("Solid State Disk partition config handled with sfdisk in \%pre"); print "%include /tmp/ks-diskpart.cfg\n"; #print "partition /boot --fstype ext3 --onpart=${DISK}1\n"; ## /opt/iglass will be sda2 #print "partition swap --onpart=${DISK}3\n"; #print "partition / --fstype ext4 --onpart=${DISK}4 --noformat\n"; ##print "partition /export --fstype ext4 --size=100 --ondisk=sdb --grow\n\n"; #print "partition /export --fstype ext4 --onpart=sdb1 --noformat\n\n"; } else { # Created in %pre sysInfo("Disk partition info will be included from \%pre"); print "%include /tmp/ks-diskpart.cfg\n"; } print "\n"; # List of packages to install print "%packages\n"; sysInfo("Generating package list from $KDIR/KS_Packages[-$c->{PTYPE}].cfg"); print "# Packages from $KDIR/KS_Packages.cfg\n"; if ( open(P,"$KDIR/KS_Packages.cfg") ) { while (

) { print; } close P; } else { Warn("No packages found"); } if ( open(P,"$KDIR/KS_Packages-$c->{PTYPE}.cfg") ) { while (

) { print; } close P; } print "\n%end\n\n" if ( ($c->{DIST} =~ /^[a-zA-Z]+-(\d+)/) && ($1 >= 6) ); # # Pre # print "\n%pre\n\n"; if ( $c->{PRE} eq "y" ) { sysInfo("Generating \%pre section"); print "DISKTYPE=$c->{DISKTYPE}\n"; # NOTE: NO perl and no syslog yet in %pre so let python do it print "\n"; print "KSRV=$c->{KSRV}\n"; print "DIST=$c->{DIST}\n"; print "PTYPE=$c->{PTYPE}\n"; if ( $c->{DIST} =~ /^[a-zA-Z]+\-8/ ) { print "LOGGER='logger -s -t KickStart[\$\$] -p $SyslogFacility.debug -n 10.1.1.1 --rfc3164'\n"; print "\$LOGGER new logger setup worked\n" } else { print "LOGGER=/tmp/syslog.py\n"; print "wget -q -O \$LOGGER http://\$KSRV/KickStart/cfg/syslog.py\n"; print "chmod 755 \$LOGGER\n"; print "python /tmp/syslog.py Python syslog logger \$LOGGER setup worked\n"; } print "\n"; print "chvt 3\n"; print "PRELOG=/tmp/ks-pre-$FLOG"; print "\n"; printConfig('P', $c->{PTYPE}, 'PRELOG'); print "chvt 1\n"; } print "\n%end\n\n" if ( ($c->{DIST} =~ /^[a-z-A-Z]+-(\d+)/) && ($1 >= 6) ); # # Install happens here # # # Post No chroot # sysInfo("Generating \%post NO chroot"); print "\n"; print "%post --nochroot\n"; print "\n"; print "chvt 3\n\n"; print "FLOG=$FLOG\n"; print "mkdir /mnt/sysimage/root/ks\n"; print "LOG=/mnt/sysimage/root/ks/ks-pre-post-nochrt-$FLOG\n\n"; print "\n"; print "/mnt/sysimage/usr/bin/logger -t KickStart[\$\$] -p $SyslogFacility.info Pre-Post NO chroot Starting\n\n"; if ( $c->{PREPOSTNR} eq "y" ) { print "\n"; printConfig('R', $c->{PTYPE}, 'LOG'); } print "\n"; print "/mnt/sysimage/usr/bin/logger -t KickStart[\$\$] -p $SyslogFacility.info Pre-Post NO chroot Finished\n\n"; print "chvt 1\n"; print "\n%end\n\n" if ( ($c->{DIST} =~ /^[a-z-A-Z]+-(\d+)/) && ($1 >= 6) ); # # Post chroot to /mnt/sysimage # sysInfo("Generating \%post with chroot"); print "\n"; print "%post\n"; print "\n"; print "chvt 3\n\n"; if ( $c->{DIST} =~ /^[a-z-A-Z]+\-(?:8|9|10)/ ) { $LOGGER = "logger -t KickStart[\$\$] -p $SyslogFacility.info -s -n 10.1.1.1 --rfc3164"; } else { $LOGGER = "logger -t KickStart[\$\$] -p $SyslogFacility.info"; } } print "FLOG=$FLOG\n"; print "mkdir /root/ks/\n"; print "LOG=/root/ks/ks-post-chrt-$FLOG\n"; print "\n"; print "echo -e 'Post chroot Starting\\n\\n' | $LOGGER\n"; if ( $c->{POST} eq "y" ) { print "MAC=$MAC\n"; print "DIST=$c->{DIST}\n"; print "PTYPE=$c->{PTYPE}\n"; print "DISKTYPE=$c->{DISKTYPE}\n"; print "IGRELEASE=$IGRELEASE\n"; print "KSRV=$c->{KSRV}\n"; print "TZ=$c->{TZ}\n"; print "SSHPORT=\"$c->{SSHPORT}\"\n"; print "SSHHOST=\"$c->{SSHHOST}\"\n"; print "IG_HOME=$c->{IG_HOME}\n"; print "IG_ETC=$c->{IG_ETC}\n"; print "NOCPASS='$c->{NOCPASS}'\n"; print "\n"; print "echo \"MAC=\$MAC\" | tee -a \$LOG | $LOGGER\n"; print "echo \"DIST=\$DIST\" | tee -a \$LOG | $LOGGER\n"; print "echo \"PTYPE=\$PTYPE\" | tee -a \$LOG | $LOGGER\n"; print "echo \"DISKTYPE=\$DISKTYPE\" | tee -a \$LOG | $LOGGER\n"; print "echo \"IGRELEASE=\$IGRELEASE\" | tee -a \$LOG | $LOGGER\n"; print "echo \"KSRV=\$KSRV\" | tee -a \$LOG | $LOGGER\n"; print "echo \"TZ=\$TZ\" | tee -a \$LOG | $LOGGER\n"; print "echo \"SSHPORT=\$SSHPORT\" | tee -a \$LOG | $LOGGER\n"; print "echo \"SSHHOST=\$SSHHOST\" | tee -a \$LOG | $LOGGER\n"; print "echo \"IG_HOME=\$IG_HOME\" | tee -a \$LOG | $LOGGER\n"; print "echo \"IG_ETC=\$IG_ETC\" | tee -a \$LOG | $LOGGER\n"; print "\n"; printConfig('S', $c->{PTYPE}, 'LOG'); } print "echo -e 'Post chroot Finished\\n\\n' | $LOGGER\n"; if ( $c->{PTYPE} !~ /^(?:VM)|(?:container)$/ ) { print "chvt 1\n"; print "\n%end\n\n" if ( ($c->{DIST} =~ /^[a-z-A-Z]+-(\d+)/) && ($1 >= 6) ); # # Post No chroot # sysInfo("Generating \%post NO chroot"); print "\n"; print "%post --nochroot\n"; print "\n"; print "chvt 3\n\n"; print "FLOG=$FLOG\n"; print "mkdir /mnt/sysimage/root/ks/\n"; print "LOG=/mnt/sysimage/root/ks/ks-post-nochrt-$FLOG\n\n"; print "\n"; print "/mnt/sysimage/usr/bin/logger -t KickStart[\$\$] -p $SyslogFacility.info Post NO chroot Starting\n\n"; if ( $c->{POSTNR} eq "y" ) { print "\n"; printConfig('N', $c->{PTYPE}, 'LOG'); } print "\n"; print "/mnt/sysimage/usr/bin/logger -t KickStart[\$\$] -p $SyslogFacility.info Post NO chroot Finished\n\n"; print "chvt 1\n"; print "\n%end\n\n" if ( ($c->{DIST} =~ /^[a-z-A-Z]+-(\d+)/) && ($1 >= 6) ); } sysInfo("Finished generating ks config"); exit; sub printConfig (@) { my $prefix = shift; my $type = shift; my $log = shift || 'LOG'; my %allow = (); my $use_allowlist = 0; if ( ($prefix) && ($type) ) { if ( defined($c->{KS_ALLOWLIST}) && $c->{KS_ALLOWLIST} ne '' ) { foreach my $entry ( split(/\s*,\s*/, $c->{KS_ALLOWLIST}) ) { next unless $entry; $allow{$entry} = 1; } $use_allowlist = scalar(keys %allow) ? 1 : 0; } print "\n"; if ( open(P,"$KDIR/ks.d/functions") ) { while (

) { print; } close P; print "\n"; } else { Warn("Could not open $KDIR/ks.d/functions"); } if ( opendir(D, "$KDIR/ks.d") ) { foreach my $file ( sort grep !/^\./, readdir(D) ) { my $printConfig = 0; if ( $type eq 'VM' ) { if ( $file =~ /^${prefix}\d+V\-/ ) { $printConfig = 2; } } elsif ( $type eq 'container' ) { if ( $file =~ /^${prefix}\d+C\-/ ) { $printConfig = 3; } } elsif ( $file =~ /^${prefix}\d\d[^\d]/ ) { # Old way compat $printConfig = 1; } elsif ( $file =~ /^${prefix}\d+A\-/ ) { $printConfig = 1; } elsif ( ($type eq 'probe') && ($file =~ /^${prefix}\d+P\-/) ) { $printConfig = 1; } elsif ( ($type eq 'server') && ($file =~ /^${prefix}\d+S\-/) ) { $printConfig = 1; } elsif ( ($type eq 'listener') && ($file =~ /^${prefix}\d+L\-/) ) { $printConfig = 1; } elsif ( ($type eq 'ds') && ($file =~ /^${prefix}\d+D\-/) ) { $printConfig = 1; } if ( $printConfig ) { next if ( $use_allowlist && !$allow{$file} ); print "####\n"; print "#\n"; print "# $file\n"; print "#\n"; print "####\n"; my $logger; if ( $type eq 'VM' ) { print "echo\nread -p 'Proceed with $file? [Y] ' OK\n"; print qq|if [ "\$OK" = "" -o "\$OK" = "y" -o "\$OK" = "Y" ]; then\n\n|; $logger = 'cat'; } elsif ( $prefix eq 'P' ) { if ( $c->{DIST} =~ /^[a-z-A-Z]+\-(?:8|9|10)/ ) { $logger = "logger -s -t KickStart[\$\$] -p $SyslogFacility.debug -n 10.1.1.1 --rfc3164"; } else { $logger = "python \/tmp\/syslog.py"; } } else { $logger = "logger -s -t KickStart[\$\$] -p $SyslogFacility.debug"; } if ( open(F, "$KDIR/ks.d/$file") ) { print "echo '-- Starting $file' | tee -a \$$log | $logger\n"; while ( ) { s/\#LOG/2\>\&1 \| tee \-a \$$log \| $logger/; print; } close F; print "echo '-- Done with $file' | tee -a \$$log | $logger\n"; print "\n"; } else { Warn("Could not read $file"); } if ( $type eq 'VM' ) { print "\nelse\n"; print " echo\n echo Skipping $file\n"; print "fi\n"; } } } closedir D; } else { Warn("Could not open $KDIR/ks.d"); } } else { Warn("Config script prefix and server type must be supplied for printConfig"); } } sub Log (@) { my $priority = shift; my $message = shift; if ( !(defined $syslog) ) { $syslog = new Net::Syslog( Name=>"KickStart", SyslogHost=>"$c->{KSRV}", Facility=>"$SyslogFacility" ); } $syslog->send( "$message", Name=>"KickStart", Priority=>"$priority"); } sub Debug (@) { my $message = shift; if ( $c->{DEBUG} >= 1 ) { print "# $message\n"; Log("debug", "$message"); } } sub Break (@) { print "#\n"; } sub Info (@) { my $message = shift; print "# $message\n"; Log("info", "$message"); } sub sysInfo (@) { my $message = shift; Log("info", "$message"); } sub Warn (@) { my $message = shift; print "# WARNING: $message\n"; warn "$message\n"; Log("warn", "$message"); } 1