diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels8.pkglist b/xCAT-server/share/xcat/install/rh/compute.rhels8.pkglist new file mode 100644 index 000000000..527ec9825 --- /dev/null +++ b/xCAT-server/share/xcat/install/rh/compute.rhels8.pkglist @@ -0,0 +1,7 @@ +@^minimal-environment +chrony +net-tools +nfs-utils +openssh-server +rsync +util-linux diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl new file mode 100644 index 000000000..55edc48e6 --- /dev/null +++ b/xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl @@ -0,0 +1,61 @@ +#version=DEVEL +# System authorization information +auth --enableshadow --passalgo=sha512 +# Use text install +text +# Use network installation +%include /tmp/repos +# Not run the Setup Agent on first boot +firstboot --disable +# Keyboard layouts +keyboard --vckeymap=us --xlayouts='us' +# System language +lang en_US.UTF-8 + +# Network information +#KICKSTARTNET# +# Root password +rootpw --iscrypted #CRYPT:passwd:key=system,username=root:password# +# System services +services --disabled="NetworkManager" +# System timezone +timezone #TABLE:site:key=timezone:value# --isUtc +# Partition clearing information +zerombr +clearpart --all --initlabel +#XCAT_PARTITION_START# +%include /tmp/partitionfile +#XCAT_PARTITION_END# + +install +skipx +# Do not configure any iptables rules +firewall --disable +selinux --disable +reboot + +%packages +#INCLUDE_DEFAULT_PKGLIST# + +%end + +%anaconda +pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --emptyok +pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok +pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --emptyok +%end +%pre +{ +echo "Running Kickstart Pre-installation script..." +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8# +} &>>/tmp/pre-install.log +%end +%post --interpreter=/bin/bash +mkdir -p /var/log/xcat/ +cat /tmp/pre-install.log >>/var/log/xcat/xcat.log +{ +echo "Running Kickstart Post-installation script..." +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng# +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.rhels8# +} &>>/var/log/xcat/xcat.log +%end diff --git a/xCAT-server/share/xcat/install/scripts/post.rhels8 b/xCAT-server/share/xcat/install/scripts/post.rhels8 new file mode 100644 index 000000000..5d06b9df0 --- /dev/null +++ b/xCAT-server/share/xcat/install/scripts/post.rhels8 @@ -0,0 +1,20 @@ +# The nic name might change between the installation and 1st boot +# Active all the nics with network link during system boot + +[ "$XCATDEBUGMODE" ] || export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#" +[ "$MASTER_IP" ] || export MASTER_IP="#ENV:MASTER_IP#" +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib# + +for i in $(ls /etc/sysconfig/network-scripts/ifcfg-* | grep -v ifcfg-lo) +do + nicname="${i##*-}" + if ethtool $nicname | grep -E -i -q "Link detected.*yes" >/dev/null 2>&1 + then + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "info" "set NIC $nicname to be activated on system boot" "/var/log/xcat/xcat.log" + ;; + esac + sed -i 's/ONBOOT=no/ONBOOT=yes/' "$i" + fi +done diff --git a/xCAT-server/share/xcat/install/scripts/post.xcat.ng b/xCAT-server/share/xcat/install/scripts/post.xcat.ng new file mode 100644 index 000000000..c068ed882 --- /dev/null +++ b/xCAT-server/share/xcat/install/scripts/post.xcat.ng @@ -0,0 +1,438 @@ +# +# Run xCAT post install +# +export MASTER_IP="#ENV:MASTER_IP#" +export MASTER="#XCATVAR:XCATMASTER#" +export NODESTATUS="#XCATVAR:NODESTATUS#" +export XCATIPORT="#TABLE:site:key=xcatiport:value#" +export INSTALLDIR="#TABLE:site:key=installdir:value#" +export TFTPDIR="#TABLE:site:key=tftpdir:value#" +export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#" + +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib# + +umask 0022 + +case "$XCATDEBUGMODE" in +"1"|"2") + set -x + ;; +esac + +if [ -z "$XCATIPORT" ]; then + XCATIPORT="3002" +fi +if [ -z "$INSTALLDIR" ]; then + INSTALLDIR="/install" +fi +if [ -z "$TFTPDIR" ]; then + TFTPDIR="/tftpboot" +fi +if [[ "${TFTPDIR:0:1}" != "/" ]]; then + TFTPDIR="/$TFTPDIR" +fi + +NODESTATUS="$(echo "$NODESTATUS"| tr -d \'\" | tr A-Z a-z)" + +( +cat <<'EOF' +#INCLUDE:#TABLE:site:key=installdir:value#/postscripts/updateflag.awk# +EOF +) >/tmp/updateflag + +chmod 0755 /tmp/updateflag + +cd /tmp +log_label="xcat.deployment" +msgutil_r "$MASTER_IP" "info" "Executing post.xcat to prepare for firstbooting ..." "/var/log/xcat/xcat.log" "$log_label" + +RAND="$(perl -e 'print int(rand(50)). "\n"')" +case "$XCATDEBUGMODE" in +"1"|"2") + msgutil_r "$MASTER_IP" "debug" "sleep $RAND" "/var/log/xcat/xcat.log" "$log_label" + ;; +esac +sleep "$RAND" + +# Stop if no openssl to help the next bit +if ! type openssl >/dev/null 2>&1 +then + msgutil_r "$MASTER_IP" "error" "/usr/bin/openssl does not exist, halt ..." "/var/log/xcat/xcat.log" "$log_label" + /tmp/updateflag $MASTER $XCATIPORT "installstatus failed" + sleep infinity +fi + +# Save to /opt/xcat/xcatinfo file +mkdir -p /opt/xcat +touch /opt/xcat/xcatinfo + +grep -q 'XCATSERVER=' /opt/xcat/xcatinfo >/dev/null 2>&1 +if [ "$?" -eq "0" ] +then + sed -i "s/XCATSERVER=.*/XCATSERVER=$MASTER_IP/" /opt/xcat/xcatinfo +else + echo "XCATSERVER=$MASTER_IP" >>/opt/xcat/xcatinfo +fi + +grep -q 'INSTALLDIR' /opt/xcat/xcatinfo >/dev/null 2>&1 +if [ "$?" -eq "0" ] +then + sed -i "s/INSTALLDIR=.*/INSTALLDIR=$INSTALLDIR/" /opt/xcat/xcatinfo +else + echo "INSTALLDIR=$INSTALLDIR" >>/opt/xcat/xcatinfo +fi + +case "$XCATDEBUGMODE" in +"1"|"2") + msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatinfo generated" "/var/log/xcat/xcat.log" "$log_label" + ;; +esac + +# Download the postscripts +msgutil_r "$MASTER_IP" "info" "trying to download postscripts from $MASTER_IP..." "/var/log/xcat/xcat.log" "$log_label" + +# Stop if no curl to help the next bit +if ! type curl >/dev/null 2>&1 +then + msgutil_r "$MASTER_IP" "error" "Command curl not found, halt ..." "/var/log/xcat/xcat.log" "$log_label" + /tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed" + sleep infinity +fi + +# $1 URL +# $2 Destination directory +function download_recursive() +{ + local url="$1" + local dest_dir="$2" + local f + + [ "${url: -1}" = "/" ] && url="${url:0:-1}" + [ "${dest_dir: -1}" = "/" ] && dest_dir="${dest_dir:0:-1}" + mkdir -p "${dest_dir}" + + while read -r f + do + case "$f" in + *"/") + download_recursive "${url}/${f}" "${dest_dir}/${f:0:-1}" + [ "$?" -ne "0" ] && return 1 + ;; + *) + curl --retry 20 --max-time 60 "${url}/${f}" -o "${dest_dir}/${f}" + [ "$?" -ne "0" ] && return 1 + ;; + esac + done < <(curl --retry 20 --max-time 60 "${url}/" | grep -o '\1' | cut -d '"' -f 2) + return 0 +} + +download_recursive "http://$MASTER_IP$INSTALLDIR/postscripts/" "/xcatpost" 2>/tmp/download.log +if [ "$?" -ne "0" ] +then + msgutil_r "$MASTER_IP" "error" "failed to download postscripts from http://$MASTER_IP$INSTALLDIR/postscripts/, check /tmp/download.log on the node, halt ..." "/var/log/xcat/xcat.log" "$log_label" + /tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed" + sleep infinity +fi +find /xcatpost -type f -maxdepth 1 -exec chmod 0755 {} + +msgutil_r "$MASTER_IP" "info" "postscripts downloaded successfully" "/var/log/xcat/xcat.log" "$log_label" + +# Get the precreated mypostscript file +rm -rf /xcatpost/mypostscript +export NODE="#TABLE:nodelist:THISNODE:node#" + +msgutil_r "$MASTER_IP" "info" "trying to get mypostscript from $MASTER_IP..." "/var/log/xcat/xcat.log" "$log_label" + +curl --retry 20 --max-time 60 "http://$MASTER_IP$TFTPDIR/mypostscripts/mypostscript.$NODE" -o "/xcatpost/mypostscript.$NODE" 2> /tmp/download.log +if [ "$?" = "0" ] +then + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "precreated mypostscript downloaded successfully" "/var/log/xcat/xcat.log" "$log_label" + ;; + esac + mv /xcatpost/mypostscript.$NODE /xcatpost/mypostscript + chmod 700 /xcatpost/mypostscript +fi + +# Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images +USEOPENSSLFORXCAT=1 +export USEOPENSSLFORXCAT +XCATSERVER=$MASTER_IP:3001 +export XCATSERVER + +# If mypostscript doesn't exist, we will get it through getpostscript.awk +if [ ! -x /xcatpost/mypostscript ]; then + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "no pre-generated mypostscript., trying to get it with getpostscript.awk..." "/var/log/xcat/xcat.log" "$log_label" + ;; + esac + + # To support the postscripts in the subdirectories under /install/postscripts + # chmod +x /xcatpost/* + # Stop if no getpostscript.awk to help the next bit + if [ ! -x /xcatpost/getpostscript.awk ]; then + msgutil_r "$MASTER_IP" "error" "/xcatpost/getpostscript.awk does not exist, halt ..." "/var/log/xcat/xcat.log" "$log_label" + /tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed" + sleep infinity + fi + /xcatpost/getpostscript.awk | egrep '' | sed -e 's/<[^>]*>//g' | egrep -v '^ *$' | sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" >/xcatpost/mypostscript + + MYCONT="$(grep '^MASTER=' /xcatpost/mypostscript)" + RETRY=0 + while [ -z "$MYCONT" ]; do + RETRY=$(($RETRY + 1)) + if [ "$RETRY" -eq "10" ]; then + break + fi + + let SLI=$RANDOM%10+10 + sleep $SLI + /xcatpost/getpostscript.awk |egrep ''|sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /xcatpost/mypostscript + + MYCONT="$(grep '^MASTER=' /xcatpost/mypostscript)" + done +fi + +TMP="$(sed "/^#\s*postscripts-start-here/,/^#\s*postscripts-end-here/ s/\(.*\)/run_ps postscript \1/;s/run_ps postscript\s*#/#/;s/run_ps postscript\s*$//" /xcatpost/mypostscript)" +echo "$TMP" >/xcatpost/mypostscript +TMP="$(sed "/^#\s*postbootscripts-start-here/,/^#\s*postbootscripts-end-here/ s/\(.*\)/run_ps postbootscript \1/;s/run_ps postbootscript\s*#/#/;s/run_ps postbootscript\s*$//" /xcatpost/mypostscript)" + +cd /xcatpost +# gunzip xcatpost.tar.gz +# tar -xvf xcatpost.tar +# /xcatpost/#TABLE:nodelist:THISNODE:node# +export PATH="$PATH:/xcatpost" + +# use the run_ps subroutine to run the postscripts + +case "$XCATDEBUGMODE" in +"1"|"2") + echo "set -x" >/xcatpost/mypostscript + ;; +*) + >/xcatpost/mypostscript + ;; +esac + +echo " +. /xcatpost/xcatlib.sh + +# global value to store the running status of the postbootscripts,the value is non-zero if one postbootscript failed +return_value=0 + +# subroutine used to run postscripts +# \$1 argument is the script type +# rest argument is the script name and arguments +run_ps () { + local ret_local=0 + mkdir -p "\"/var/log/xcat\"" + # On some Linux distro, the rsyslogd daemon write log files with permision + # other than root:root. And in some case, the directory /var/log/xcat was + # created by xCAT, and had root:root ownership. In this way, rsyslogd + # did not have enough permission to write to log files under this directory. + # As a dirty hack, change the ownership of directory /var/log/xcat to the + # same ownership of directory /var/log. + chown `ls -ld /var/log | awk '{ print \$3\":\"\$4 }'` "\"/var/log/xcat\"" + local logfile=\"/var/log/xcat/xcat.log\" + local scriptype=\$1 + shift; + + if [ -z \"\$scriptype\" ]; then + scriptype=\"postscript\" + fi + + if [ -f \$1 ]; then + msgutil_r \"\$MASTER_IP\" \"info\" "\"Running \$scriptype: \$1\"" \"\$logfile\" \"xcat.mypostscript\" + if [ \"\$XCATDEBUGMODE\" = \"1\" ] || [ \"\$XCATDEBUGMODE\" = \"2\" ]; then + local compt=\$(file \$1) + local reg=\"shell script\" + if [[ \"\$compt\" =~ \$reg ]]; then + bash -x ./\$@ 2>&1 + ret_local=\$? + else + ./\$@ 2>&1 | logger -t xcat -p debug + ret_local=\${PIPESTATUS[0]} + fi + else + ./\$@ 2>&1 + ret_local=\${PIPESTATUS[0]} + fi + + if [ \"\$ret_local\" -ne \"0\" ]; then + return_value=\$ret_local + fi + msgutil_r \"\$MASTER_IP\" \"info\" "\"\$scriptype \$1 return with \$ret_local\"" \"\$logfile\" \"xcat.mypostscript\" + else + msgutil_r \"\$MASTER_IP\" \"error\" "\"\$scriptype \$1 does NOT exist.\"" \"\$logfile\" \"xcat.mypostscript\" + return_value=-1 + fi + + + return 0 +} +# subroutine end + +" >>/xcatpost/mypostscript +echo "$TMP" >>/xcatpost/mypostscript + +case "$XCATDEBUGMODE" in +"1"|"2") + echo "set +x" >>/xcatpost/mypostscript + ;; +esac + +chmod 0755 /xcatpost/mypostscript +if [ ! -x /xcatpost/mypostscript ]; then + msgutil_r "$MASTER_IP" "error" "failed to generate mypostscript file, halt ..." "/var/log/xcat/xcat.log" "$log_label" + /tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed" + sleep infinity +else + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "generate mypostscript file successfully" "/var/log/xcat/xcat.log" "$log_label" + ;; + esac +fi + +# Save the postboot scripts to /xcatpost/mypostscript.post +TMP=`sed "/^#\s*postscripts-start-here/,/^#\s*postscripts-end-here/ d" /xcatpost/mypostscript` +echo "$TMP" >/xcatpost/mypostscript.post +chmod 0755 /xcatpost/mypostscript.post + +if [ ! -x /xcatpost/mypostscript.post ] +then + msgutil_r "$MASTER_IP" "error" "failed to generate /xcatpost/mypostscript.post" "/var/log/xcat/xcat.log" "$log_label" +else + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "generate mypostscript.post file successfully" "/var/log/xcat/xcat.log" "$log_label" + ;; + esac +fi + +export OSVER="#TABLE:nodetype:THISNODE:os#" +# Create the post init service as a hook to run PS and PBS, as well as status updating +cat >/etc/systemd/system/xcatpostinit1.service <<'EOF' +#INCLUDE:/install/postscripts/xcatpostinit1.service# +EOF + +case "$XCATDEBUGMODE" in +"1"|"2") + msgutil_r "$MASTER_IP" "debug" "/etc/systemd/system/xcatpostinit1.service generated" "/var/log/xcat/xcat.log" "$log_label" + ;; +esac + +ln -s /etc/systemd/system/xcatpostinit1.service /etc/systemd/system/multi-user.target.wants/xcatpostinit1.service + +case "$XCATDEBUGMODE" in +"1"|"2") + msgutil_r "$MASTER_IP" "debug" "xcatpostinit1.service enabled" "/var/log/xcat/xcat.log" "$log_label" + ;; +esac + +cat >/opt/xcat/xcatpostinit1 <<'EOF' +#INCLUDE:/install/postscripts/xcatpostinit1.install# +EOF +chmod 0755 /opt/xcat/xcatpostinit1 + +# Create the xcatinstallpost +mkdir -p /opt/xcat +cat >/opt/xcat/xcatinstallpost <<'EOF' +#INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatinstallpost# + +if [ -f /xcatpost/mypostscript.post ] +then + RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post | cut -d= -f2 | tr -d \'\" | tr A-Z a-z` +fi + +if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]] && [[ ! "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then + systemctl disable xcatpostinit1.service + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "systemctl disable xcatpostinit1.service" "/var/log/xcat/xcat.log" "xcat.xcatinstallpost" + ;; + esac +fi + +EOF + +chmod 0755 /opt/xcat/xcatinstallpost + +if [ ! -x /opt/xcat/xcatinstallpost ] +then + msgutil_r "$MASTER_IP" "error" "failed to generate /opt/xcat/xcatinstallpost" "/var/log/xcat/xcat.log" "$log_label" +else + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatinstallpost generated" "/var/log/xcat/xcat.log" "$log_label" + ;; + esac +fi + +# Create the dskls post +cat >/opt/xcat/xcatdsklspost <<'EOF' +#INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatdsklspost# +EOF +chmod 755 /opt/xcat/xcatdsklspost + +if [ ! -x /opt/xcat/xcatdsklspost ]; then + msgutil_r "$MASTER_IP" "error" "failed to generate /opt/xcat/xcatdsklspost" "/var/log/xcat/xcat.log" "$log_label" +else + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatdsklspost generated" "/var/log/xcat/xcat.log" "$log_label" + ;; + esac +fi + +#create the preboot script and run here +TMP="$(sed '/^#\s*postbootscripts-start-here/,/^#\s*postbootscripts-end-here/ d' /xcatpost/mypostscript)" +echo "$TMP" >/xcatpost/mypostscript + +echo " +# Save bad return code to /opt/xcat/xcatinfo +if [ \"\$return_value\" -ne \"0\" ]; then + grep 'POSTSCRIPTS_RC' /opt/xcat/xcatinfo > /dev/null 2>&1 + if [ \$? -eq 0 ]; then + sed -i \"s/POSTSCRIPTS_RC=.*/POSTSCRIPTS_RC=1/\" /opt/xcat/xcatinfo + else + echo \"POSTSCRIPTS_RC=1\" >>/opt/xcat/xcatinfo + fi +fi +" >>/xcatpost/mypostscript + +chmod 0700 /xcatpost/mypostscript + +export ARCH="#TABLE:nodetype:THISNODE:arch#" +export CONSOLEPORT="#TABLEBLANKOKAY:nodehm:THISNODE:serialport#" + +# For redhat: +# place-holder for the code to save the repo info on compute node,pointing to the "pkgdir" of the osimage +# so that the provisioned node has the repo pointed to the distro path on MN +#WRITEREPO# + +case "$XCATDEBUGMODE" in +"1"|"2") + msgutil_r "$MASTER_IP" "info" "running mypostscript" "/var/log/xcat/xcat.log" "$log_label" + ;; +esac +/xcatpost/mypostscript +case "$XCATDEBUGMODE" in +"1"|"2") + msgutil_r "$MASTER_IP" "info" "mypostscript returned" "/var/log/xcat/xcat.log" "$log_label" + ;; +esac + +msgutil_r "$MASTER_IP" "info" "finished firstboot preparation, sending request to $MASTER:3002 for changing status..." "/var/log/xcat/xcat.log" "$log_label" +# The following command should always be run to prevent infinite installation loops +updateflag.awk "$MASTER" 3002 + +cd / + +case "$XCATDEBUGMODE" in +"1"|"2") + set +x + ;; +esac diff --git a/xCAT-server/share/xcat/install/scripts/pre.rhels8 b/xCAT-server/share/xcat/install/scripts/pre.rhels8 new file mode 100644 index 000000000..4ea92263b --- /dev/null +++ b/xCAT-server/share/xcat/install/scripts/pre.rhels8 @@ -0,0 +1,225 @@ +export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#" + +case "$XCATDEBUGMODE" in +"1"|"2") + set -x + ;; +esac + +if grep -q n8r /proc/cmdline >/dev/null 2>&1 +then + stty crtscts +fi +for x in 0 1 2 3 4 5 6 7 8 +do + mknod /dev/vcs$x c 7 $x + mknod /dev/vcsa$x c 7 $[$x+128] +done +chmod 0644 /dev/vcs* +chown root.tty /dev/vcs* + +if [ -r /tmp/updates/etc/pki/tls/certs/ca-bundle.crt ] +then + cp -f /tmp/updates/etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ +fi + +cat >/tmp/baz.py <<'EOF' +#!/usr/bin/python3 +import socket +import sys + +sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +sock.connect(('#XCATVAR:XCATMASTER#',#TABLE:site:key=xcatiport:value#)) + +print sys.argv[1] +response = sock.recv(100) +if(response == "ready\n"): + sock.send(sys.argv[1]+"\n") + response = sock.recv(100) + +sock.close() +EOF + +cat >/tmp/foo.py <<'EOF' +#!/usr/bin/python3 + +import socket +import os +import linecache +import re + +sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +sock.connect(('#XCATVAR:XCATMASTER#',#TABLE:site:key=xcatiport:value#)) + +response = sock.recv(100) +if(response == "ready\n"): + sock.send("installmonitor\n") + response = sock.recv(100) + +sock.close() + +sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + +port = 3054 +sock.bind(('', port)) + +sock.listen(5) + +try: + while 1: + newSocket, address = sock.accept() + while 1: + received = newSocket.recv(200) + if not received: + break + command = re.split('\s+',received) + if(command[0] == "stat"): + ilog = "" + line = "" + post = 0 + percent = 0 + count = 0 + numpack = 0 + pre = 0 + if(os.path.isfile('/tmp/xcatpre.log')): + ilog = '/tmp/xcatpre.log' + pre = 1 + if(os.path.isfile('/tmp/packaging.log')): + ilog = '/tmp/packaging.log' + if(os.path.isfile('/mnt/sysimage/tmp/post.log')): + ilog = '/mnt/sysimage/tmp/post.log' + post = True + if(ilog): + count = len(open(ilog).readlines()) + line = linecache.getline(ilog,count) + linecache.clearcache() + if(line and not post and not pre): + r2 = re.compile("Installing ([^ ]*) \((\d+)/(\d+)\)") + m2 = r2.search(line) + if m2: + newline = "%s (%.2f%%)" % (m2.group(1), 100 * float(m2.group(2)) / float(m2.group(3))) + else: + newline = "post" + line = "installing " + newline + if(line and post and not pre): + line = "installing " + line + if(not line): + line = "installing prep" + newSocket.send(line) + break +#UNCOMMENTOENABLEDEBUGPORT# if(command[0] == "sh"): #DEBUG purposes only, wide open root priv command here. +#UNCOMMENTOENABLEDEBUGPORT# newcommand = "" +#UNCOMMENTOENABLEDEBUGPORT# for i in command[1:]: +#UNCOMMENTOENABLEDEBUGPORT# newcommand = newcommand + i + " " +#UNCOMMENTOENABLEDEBUGPORT# output = os.popen(newcommand).read() +#UNCOMMENTOENABLEDEBUGPORT# newSocket.send(output) +#UNCOMMENTOENABLEDEBUGPORT# break + if(command[0] == "screendump"): + newcommand = "cat /dev/vcs" + for i in command[1:]: + newcommand = newcommand + i + output = os.popen(newcommand).read() + newSocket.send(output) + break + + newSocket.close() + +finally: + sock.close() +EOF + +chmod 0755 /tmp/foo.py +chmod 0755 /tmp/baz.py + +NODESTATUS="#TABLEBLANKOKAY:site:key=nodestatus:value#" + +case "$NODESTATUS" in +"0"|"N"|"n") + ;; +*) + /tmp/baz.py "installstatus installing" & + ;; +esac + +/tmp/foo.py >/foo.log 2>&1 & + +# time to ascertain fstype and PReP/UEFI/legacy +# also, find first available block device (sda or vda likely) +# TODO: pick a likely non-SAN target if possible +shopt -s nullglob + +# +# The getinstdisk script is common for RHEL/SLES/PowerKVM/Ubuntu. +# It will attempt to select the install disk and write the selection to /tmp/xcat.install_disk +# +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/getinstdisk# +if [ -f "/tmp/xcat.install_disk" ] +then + instdisk="$(cat /tmp/xcat.install_disk)" +fi + +BOOTFSTYPE=ext4 +FSTYPE=ext4 +EFIFSTYPE=efi + +echo "ignoredisk --only-use=$instdisk" >>/tmp/partitionfile +case "$(uname -m)" in +"ppc64"|"ppc64le") + echo "part prepboot --fstype=prepboot --asprimary --ondisk=$instdisk --size=8" >>/tmp/partitionfile + ;; +esac +if [ -d /sys/firmware/efi ] +then + echo "part /boot/efi --fstype=$EFIFSTYPE --ondisk=$instdisk --size=250" >>/tmp/partitionfile +fi + +# TODO: Ondisk detection, /dev/disk/by-id/edd-int13_dev80 for legacy maybe, and no idea about efi. At least maybe blacklist SAN if mptsas/mpt2sas/megaraid_sas seen... +echo "part /boot --fstype=$BOOTFSTYPE --asprimary --ondisk=$instdisk --size=512" >>/tmp/partitionfile +echo "part pv.000997 --grow --asprimary --ondisk=$instdisk --size=8192" >>/tmp/partitionfile +echo "volgroup system --pesize=4096 pv.000997" >>/tmp/partitionfile +echo "logvol / --fstype=$FSTYPE --name=root --vgname=system --grow --size=1024" >>/tmp/partitionfile +echo "logvol swap --name=swap --vgname=system --recommended" >>/tmp/partitionfile + +# Specify "bootloader" configuration in "/tmp/partitionfile" if there is no user customized partition file +BOOTLOADER="bootloader" + +# Specifies which drive the boot loader should be written to +# and therefore which drive the computer will boot from. +[ -n "$instdisk" ] && BOOTLOADER="$BOOTLOADER --boot-drive=$(basename $instdisk)" + +echo "$BOOTLOADER" >>/tmp/partitionfile + +#XCA_PARTITION_SCRIPT# + +#specify the kernel options which will be persistent after installation +if [ -n "#ENV:PERSKCMDLINE#" ];then + #append the persistent kernel options to the lines including "bootloader --append" + sed -i -e /bootloader/s#\'#\"#g -e '/bootloader/s/--append=\([^"]\S*[^"]\)/--append="\1"/g' -e '/bootloader/s/--append="\(.*\)"/--append="\1 #ENV:PERSKCMDLINE#"/g' /tmp/partitionfile + #append the persistent kernel options to the lines including "bootloader" without "--append" + sed -i -e '/bootloader/{/append=/!s/$/& --append="#ENV:PERSKCMDLINE#" /}' /tmp/partitionfile + #append the persistent kernel options to /tmp/partitionfile if it does not include "bootloader" + grep -q bootloader /tmp/partitionfile >/dev/null 2>&1 || echo -e "bootloader --append=\"#ENV:PERSKCMDLINE#\"" >>/tmp/partitionfile +fi + +# save the content of /tmp/partitionfile in /var/log/xcat/xcat.log +# so that we can inspect the partition scheme after installation +echo "================ The Partition Scheme ===============" +cat /tmp/partitionfile +echo "=====================================================" + +# The following code is to generate the repository for the installation +cat /proc/cmdline + +NEXTSERVER="$(grep -m 1 http /proc/cmdline)" +NEXTSERVER="${NEXTSERVER#*http://}" +NEXTSERVER="${NEXTSERVER%%:*}" + +export nextserver="$NEXTSERVER" +#INSTALL_SOURCES_IN_PRE# + +case "$XCATDEBUGMODE" in +"1"|"2") + set +x + ;; +esac