mirror of
https://git.valherun.com/valherun/pxe_boot_alma.git
synced 2026-10-15 21:22:03 -04:00
- restructure boot/kickstarts/scripts/docs into homelab/ - docs: alma9->10 breaking changes, CIS hardening, kickstart changes - add find_cron_entries.sh helper and codex running memory notes Co-Authored-By: Claude Fable 5 <[email protected]>
509 lines
13 KiB
Perl
509 lines
13 KiB
Perl
#!/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;
|
|
$c->{DIST} = "default";
|
|
$c->{DEBUG} = 0;
|
|
$c->{TYPE} = "probe";
|
|
$c->{PRE} = 'y';
|
|
$c->{POST} = 'y';
|
|
$c->{POSTNR} = 'y';
|
|
$c->{IG_HOME} = "/opt/iglass";
|
|
$c->{IG_ETC} = "/etc/iglass";
|
|
$c->{KSRV} = "10.1.1.1";
|
|
|
|
# Load QUERY_STRING variables cuz I need to see if DIST is defined
|
|
foreach my $pair ( split(/\&/,$ENV{QUERY_STRING}) ) {
|
|
if ( $pair =~ /(\S+)\=(\S+)/ ) {
|
|
eval "\$c->{$1} = '$2'";
|
|
Debug("$1 = '$c->{$1}'");
|
|
} else {
|
|
$c->{DIST} = $ENV{QUERY_STRING};
|
|
last;
|
|
}
|
|
}
|
|
print "\n";
|
|
|
|
# Find who is Asking
|
|
my $MAC;
|
|
if ( $ENV{REMOTE_ADDR} ) {
|
|
`/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\./ ) {
|
|
$c->{KSRV} = "192.168.177.14";
|
|
}
|
|
}
|
|
|
|
my $KDIR = "/export/KickStart/cfg";
|
|
|
|
# Load custom config file variables
|
|
if ( open(C, "$KDIR/stag.d/$MAC.cfg") ) {
|
|
#print "\n";
|
|
Debug("$KDIR/stag.d/$MAC.cfg:");
|
|
while ( <C> ) {
|
|
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");
|
|
}
|
|
|
|
$KDIR .= "/$c->{DIST}";
|
|
my $URL = "http://$c->{KSRV}/KickStart/$c->{DIST}";
|
|
|
|
if ( -d "$KDIR" ) {
|
|
Info("Using config directory $KDIR");
|
|
} else {
|
|
Warn("KS directory '$KDIR' for $c->{DIST}/ does not exist!");
|
|
}
|
|
|
|
# Load config file variables
|
|
if ( open(C, "$KDIR/ks.config") ) {
|
|
#print "\n";
|
|
Debug("$KDIR/ks.config:");
|
|
while ( <C> ) {
|
|
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+)/ ) {
|
|
eval "\$c->{$1} = '$2'";
|
|
Debug("Reset $1 = '$2'");
|
|
} else {
|
|
$c->{DIST} = $ENV{QUERY_STRING};
|
|
last;
|
|
}
|
|
}
|
|
|
|
if ( open(C, "$KDIR/../stag.d/$MAC.cfg") ) {
|
|
#print "\n";
|
|
Debug("$KDIR/../stag.d/$MAC.cfg:");
|
|
while ( <C> ) {
|
|
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}");
|
|
}
|
|
|
|
# Find iGlass release version
|
|
my $IGRELEASE=`cd /export/KickStart/iglass-releases; ls -v probe*rpm | tail -1`;
|
|
chomp $IGRELEASE;
|
|
|
|
Break();
|
|
Info("IP=$ENV{REMOTE_ADDR}");
|
|
Info("MAC=$MAC");
|
|
Info("IGRELEASE=$IGRELEASE");
|
|
Break();
|
|
|
|
print "\n";
|
|
print "install\n";
|
|
print "\n";
|
|
|
|
if ( $INTERACTIVE eq "y" ) {
|
|
print "interactive\n";
|
|
}
|
|
|
|
print "text\n";
|
|
print "keyboard us\n";
|
|
|
|
if ( $c->{DIST} eq "CentOS-3.7" ) {
|
|
print "mouse genericps/2 --device psaux --emulthree\n";
|
|
}
|
|
|
|
print "\n";
|
|
print "lang en_US\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";
|
|
print "network --device eth0 --bootproto dhcp --nodns --noipv6\n";
|
|
print "\n";
|
|
|
|
print "url --url $URL\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-5\./ ) {
|
|
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=sda --append=\"rhgb quiet\"";
|
|
} else {
|
|
print "langsupport --default en_US en_US\n";
|
|
print "bootloader --location=mbr";
|
|
}
|
|
print " --md5pass=$c->{MD5PASS}" if ( $c->{MD5PASS} );
|
|
print "\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";
|
|
}
|
|
|
|
print "authconfig --enableshadow --enablemd5\n";
|
|
|
|
if ( $TZ ) {
|
|
print "timezone $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 "ssd" ) {
|
|
|
|
# Created in %pre
|
|
sysInfo("Solid State Disk partition config handled with sfdisk in \%pre");
|
|
|
|
print "partition /boot --fstype ext3 --onpart=sda1\n";
|
|
# /opt/iglass will be sda2
|
|
print "partition swap --onpart=sda3\n";
|
|
print "partition / --fstype ext4 --onpart=sda4 --noformat\n";
|
|
|
|
} else {
|
|
|
|
# Created in %pre
|
|
sysInfo("Disk partition info will be included from \%pre");
|
|
print "%include /tmp/diskpart.cfg\n";
|
|
|
|
}
|
|
|
|
print "\n";
|
|
|
|
# List of packages to install
|
|
print "%packages\n";
|
|
sysInfo("Generating package list from $KDIR/KS_Packages[-$c->{TYPE}].cfg");
|
|
print "# Packages from $KDIR/KS_Packages.cfg\n";
|
|
|
|
if ( open(P,"$KDIR/KS_Packages.cfg") ) {
|
|
while ( <P> ) {
|
|
print;
|
|
}
|
|
close P;
|
|
} else {
|
|
Warn("No packages found");
|
|
}
|
|
if ( open(P,"$KDIR/KS_Packages-$c->{TYPE}.cfg") ) {
|
|
while ( <P> ) {
|
|
print;
|
|
}
|
|
close P;
|
|
}
|
|
|
|
my $FLOG = `date +custom-%F.log`;
|
|
chomp $FLOG;
|
|
|
|
#
|
|
# Pre
|
|
#
|
|
print "\n";
|
|
print "%pre\n";
|
|
print "\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 "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/pre-$FLOG";
|
|
print "\n";
|
|
|
|
printConfig('P', $c->{TYPE}, 'PRELOG');
|
|
|
|
print "chvt 1\n";
|
|
}
|
|
|
|
#
|
|
# Install happens here
|
|
#
|
|
|
|
#
|
|
# Post chroot to /mnt/sysimage
|
|
#
|
|
sysInfo("Generating \%post with chroot");
|
|
print "\n";
|
|
print "%post\n";
|
|
print "\n";
|
|
print "chvt 3\n\n";
|
|
print "FLOG=$FLOG\n";
|
|
print "LOG=/root/post-chrt-$FLOG\n";
|
|
print "\n";
|
|
print "\nlogger -t KickStart[\$\$] -p $SyslogFacility.info Post chroot Starting\n\n";
|
|
if ( $c->{POST} eq "y" ) {
|
|
print "MAC=$MAC\n";
|
|
print "DIST=$c->{DIST}\n";
|
|
print "TYPE=$c->{TYPE}\n";
|
|
print "IGRELEASE=$IGRELEASE\n";
|
|
print "KSRV=$c->{KSRV}\n";
|
|
print "IG_HOME=$c->{IG_HOME}\n";
|
|
print "IG_ETC=$c->{IG_ETC}\n";
|
|
print "IG_ETC=$c->{IG_ETC}\n";
|
|
print "\n";
|
|
print "echo \"MAC=\$MAC\" | tee -a \$LOG | logger -s -t KickStart[\$\$] -p $SyslogFacility.info\n";
|
|
print "echo \"DIST=\$DIST\" | tee -a \$LOG | logger -s -t KickStart[\$\$] -p $SyslogFacility.info\n";
|
|
print "echo \"TYPE=\$TYPE\" | tee -a \$LOG | logger -s -t KickStart[\$\$] -p $SyslogFacility.info\n";
|
|
print "echo \"IGRELEASE=\$IGRELEASE\" | tee -a \$LOG | logger -s -t KickStart[\$\$] -p $SyslogFacility.info\n";
|
|
print "echo \"KSRV=\$KSRV\" | tee -a \$LOG | logger -s -t KickStart[\$\$] -p $SyslogFacility.info\n";
|
|
print "echo \"IG_HOME=\$IG_HOME\" | tee -a \$LOG | logger -s -t KickStart[\$\$] -p $SyslogFacility.info\n";
|
|
print "echo \"IG_ETC=\$IG_ETC\" | tee -a \$LOG | logger -s -t KickStart[\$\$] -p $SyslogFacility.info\n";
|
|
print "\n";
|
|
|
|
printConfig('S', $c->{TYPE}, 'LOG');
|
|
}
|
|
|
|
print "\nlogger -t KickStart[\$\$] -p $SyslogFacility.info Post chroot Finished\n\n";
|
|
print "chvt 1\n";
|
|
|
|
#
|
|
# 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 "LOG=/mnt/sysimage/root/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->{TYPE}, 'LOG');
|
|
}
|
|
|
|
print "\n";
|
|
|
|
print "/mnt/sysimage/usr/bin/logger -t KickStart[\$\$] -p $SyslogFacility.info Post NO chroot Finished\n\n";
|
|
print "chvt 1\n";
|
|
|
|
sysInfo("Finished generating ks config");
|
|
exit;
|
|
|
|
|
|
sub printConfig (@) {
|
|
my $prefix = shift;
|
|
my $type = shift;
|
|
my $log = shift || 'LOG';
|
|
|
|
if ( ($prefix) && ($type) ) {
|
|
|
|
print "\n";
|
|
if ( opendir(D, "$KDIR/ks.d") ) {
|
|
foreach my $file ( sort readdir(D) ) {
|
|
|
|
if ( ($file =~ /^${prefix}\d\d[^\d]/) # Old way compat
|
|
|| ($file =~ /^${prefix}\d+A\-/)
|
|
|| ( ($type eq 'probe') && ($file =~ /^${prefix}\d+P\-/) )
|
|
|| ( ($type eq 'server') && ($file =~ /^${prefix}\d+S\-/) )
|
|
|| ( ($type eq 'listener') && ($file =~ /^${prefix}\d+L\-/) )
|
|
|| ( ($type eq 'ds') && ($file =~ /^${prefix}\d+D\-/) )
|
|
) {
|
|
|
|
print "####\n";
|
|
print "#\n";
|
|
print "# $file\n";
|
|
print "#\n";
|
|
print "####\n";
|
|
|
|
my $logger = ( $prefix eq 'P' ) ? "python \/tmp\/syslog.py" : "logger -s -t KickStart[\$\$] -p $SyslogFacility.debug";
|
|
if ( open(F, "$KDIR/ks.d/$file") ) {
|
|
print "echo '-- Starting $file' | tee -a \$$log | $logger\n";
|
|
while ( <F> ) {
|
|
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");
|
|
}
|
|
}
|
|
}
|
|
closedir D;
|
|
} else {
|
|
Warn("Could not open 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
|