mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-11-03 21:02:34 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			324 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			324 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#"
 | 
						|
 | 
						|
case "$XCATDEBUGMODE" in
 | 
						|
"1"|"2")
 | 
						|
    set -x
 | 
						|
    ;;
 | 
						|
esac
 | 
						|
export MASTER_IP="#ENV:MASTER_IP#"
 | 
						|
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib#
 | 
						|
log_label="xcat.deployment"
 | 
						|
msgutil_r "$MASTER_IP" "info" "============deployment starting============" "/var/log/xcat/xcat.log" "$log_label"
 | 
						|
msgutil_r "$MASTER_IP" "info" "Running Anaconda Pre-Installation script..." "/var/log/xcat/xcat.log" "$log_label"
 | 
						|
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/libexec/platform-python
 | 
						|
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 == b"ready\n"):
 | 
						|
        sock.send((sys.argv[1]+"\n").encode())
 | 
						|
        response = sock.recv(100)
 | 
						|
 | 
						|
sock.close()
 | 
						|
EOF
 | 
						|
 | 
						|
cat >/tmp/foo.py <<'EOF'
 | 
						|
#!/usr/libexec/platform-python
 | 
						|
 | 
						|
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 == b"ready\n"):
 | 
						|
	sock.send("installmonitor\n".encode())
 | 
						|
	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(b'\s+',received)
 | 
						|
			if(command[0] == b"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.encode())
 | 
						|
				break
 | 
						|
#UNCOMMENTOENABLEDEBUGPORT#			if(command[0] == b"sh"): #DEBUG purposes only, wide open root priv command here.
 | 
						|
#UNCOMMENTOENABLEDEBUGPORT#				newcommand = b""
 | 
						|
#UNCOMMENTOENABLEDEBUGPORT#				for i in command[1:]:
 | 
						|
#UNCOMMENTOENABLEDEBUGPORT#					newcommand = newcommand + i + b" "
 | 
						|
#UNCOMMENTOENABLEDEBUGPORT#				output = os.popen(newcommand.decode('utf-8')).read().encode()
 | 
						|
#UNCOMMENTOENABLEDEBUGPORT#				newSocket.send(output)
 | 
						|
#UNCOMMENTOENABLEDEBUGPORT#				break
 | 
						|
			if(command[0] == b"screendump"):
 | 
						|
				newcommand = "cat /dev/vcs"
 | 
						|
				for i in command[1:]:
 | 
						|
					newcommand = newcommand + i
 | 
						|
				output = os.popen(newcommand).read()
 | 
						|
				newSocket.send(output.encode())
 | 
						|
				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 &
 | 
						|
 | 
						|
base64decode()
 | 
						|
{
 | 
						|
    h0="0";  h1="1";  h2="2";  h3="3";  h4="4";  h5="5";  h6="6";  h7="7";
 | 
						|
    h8="8";  h9="9"; h10="A"; h11="B"; h12="C"; h13="D"; h14="E"; h15="F";
 | 
						|
 | 
						|
    while :
 | 
						|
    do
 | 
						|
        i=0
 | 
						|
        while [ "$i" -lt 4 ]
 | 
						|
        do
 | 
						|
            read -n 1 c || return
 | 
						|
 | 
						|
            case "${c}" in
 | 
						|
            "A") d=0  ;; "B") d=1  ;; "C") d=2  ;; "D") d=3  ;;
 | 
						|
            "E") d=4  ;; "F") d=5  ;; "G") d=6  ;; "H") d=7  ;;
 | 
						|
            "I") d=8  ;; "J") d=9  ;; "K") d=10 ;; "L") d=11 ;;
 | 
						|
            "M") d=12 ;; "N") d=13 ;; "O") d=14 ;; "P") d=15 ;;
 | 
						|
            "Q") d=16 ;; "R") d=17 ;; "S") d=18 ;; "T") d=19 ;;
 | 
						|
            "U") d=20 ;; "V") d=21 ;; "W") d=22 ;; "X") d=23 ;;
 | 
						|
            "Y") d=24 ;; "Z") d=25 ;; "a") d=26 ;; "b") d=27 ;;
 | 
						|
            "c") d=28 ;; "d") d=29 ;; "e") d=30 ;; "f") d=31 ;;
 | 
						|
            "g") d=32 ;; "h") d=33 ;; "i") d=34 ;; "j") d=35 ;;
 | 
						|
            "k") d=36 ;; "l") d=37 ;; "m") d=38 ;; "n") d=39 ;;
 | 
						|
            "o") d=40 ;; "p") d=41 ;; "q") d=42 ;; "r") d=43 ;;
 | 
						|
            "s") d=44 ;; "t") d=45 ;; "u") d=46 ;; "v") d=47 ;;
 | 
						|
            "w") d=48 ;; "x") d=49 ;; "y") d=50 ;; "z") d=51 ;;
 | 
						|
            "0") d=52 ;; "1") d=53 ;; "2") d=54 ;; "3") d=55 ;;
 | 
						|
            "4") d=56 ;; "5") d=57 ;; "6") d=58 ;; "7") d=59 ;;
 | 
						|
            "8") d=60 ;; "9") d=61 ;; "+") d=62 ;; "/") d=63 ;;
 | 
						|
            "=") d=0  ;;
 | 
						|
            *) continue ;;
 | 
						|
            esac
 | 
						|
 | 
						|
            eval "a${i}=${c}"
 | 
						|
            eval "b${i}=${d}"
 | 
						|
 | 
						|
            i=$(( i + 1 ))
 | 
						|
        done
 | 
						|
 | 
						|
        o0=$(( ((b0 << 2) | (b1 >> 4)) & 0xff ))
 | 
						|
        o1=$(( ((b1 << 4) | (b2 >> 2)) & 0xff ))
 | 
						|
        o2=$(( ((b2 << 6) | b3) & 0xff ))
 | 
						|
 | 
						|
        [ "${a2}" == "=" ] &&
 | 
						|
            eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16
 | 
						|
                ))}\"" &&
 | 
						|
            return
 | 
						|
        [ "${a3}" == "=" ] &&
 | 
						|
            eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16
 | 
						|
                ))}\\x\${h$(( o1 / 16 ))}\${h$(( o1 % 16
 | 
						|
                ))}\"" &&
 | 
						|
            return
 | 
						|
        eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16
 | 
						|
            ))}\\x\${h$(( o1 / 16 ))}\${h$(( o1 % 16
 | 
						|
            ))}\\x\${h$(( o2 / 16 ))}\${h$(( o2 % 16 ))}\""
 | 
						|
    done
 | 
						|
}
 | 
						|
 | 
						|
# $1 - The device name, eg., sda
 | 
						|
# Returns the device size, unit is KB.
 | 
						|
getdisksize()
 | 
						|
{
 | 
						|
	local disk="$1"
 | 
						|
 | 
						|
	disk="${disk#/dev/}"
 | 
						|
 | 
						|
	[ -z "${disk}" ] && echo "0" && return
 | 
						|
 | 
						|
	local blah
 | 
						|
	local blocks
 | 
						|
	local name
 | 
						|
 | 
						|
	while read -r blah blah blocks name
 | 
						|
	do
 | 
						|
		if [ "${name}" = "${disk}" ]
 | 
						|
		then
 | 
						|
			echo "${blocks}"
 | 
						|
			return
 | 
						|
		fi
 | 
						|
	done </proc/partitions
 | 
						|
 | 
						|
	echo "0"
 | 
						|
	return
 | 
						|
}
 | 
						|
 | 
						|
# 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
 | 
						|
msgutil_r "$MASTER_IP" "info" "Detecting install disk..." "/var/log/xcat/xcat.log" "$log_label"
 | 
						|
#
 | 
						|
# 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=xfs
 | 
						|
FSTYPE=xfs
 | 
						|
EFIFSTYPE=efi
 | 
						|
 | 
						|
#remove any exiting "xcatvg" VG to avoid fatal error
 | 
						|
vgs > /tmp/vgs 2>&1
 | 
						|
vgchange -a n xcatvg
 | 
						|
vgremove -f xcatvg
 | 
						|
 | 
						|
msgutil_r "$MASTER_IP" "info" "Found $instdisk, generate partition file..." "/var/log/xcat/xcat.log" "$log_label"
 | 
						|
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=256" >>/tmp/partitionfile
 | 
						|
fi
 | 
						|
 | 
						|
DISKSIZE="$(getdisksize "${instdisk}")"
 | 
						|
 | 
						|
# 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=1024" >>/tmp/partitionfile
 | 
						|
echo "part pv.000997 --grow --asprimary --ondisk=$instdisk --size=1024" >>/tmp/partitionfile
 | 
						|
echo "volgroup xcatvg --pesize=4096 pv.000997" >>/tmp/partitionfile
 | 
						|
echo "logvol swap --name=swap --vgname=xcatvg --recommended" >>/tmp/partitionfile
 | 
						|
 | 
						|
echo "logvol / --fstype=$FSTYPE --name=root --vgname=xcatvg --size=1024 --grow " >>/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 "====================================================="
 | 
						|
msgutil_r "$MASTER_IP" "info" "Generate the repository for the installation" "/var/log/xcat/xcat.log" "$log_label"
 | 
						|
# 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
 |