#!/bin/bash # # Setup hostname # echo "post scripts" >/root/post.log [ $XCATDEBUGMODE ] || export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#" [ $MASTER_IP ] || export MASTER_IP="#ENV:MASTER_IP#" #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib# export PRINIC=#TABLEBLANKOKAY:noderes:THISNODE:primarynic# if [ "$PRINIC" == "mac" ] then export PRINIC='#GETPRINICMAC:THISNODE#' fi if [ -z "$PRINIC" ] then export PRINIC=eth0 elif [[ `echo "$PRINIC" | grep -sqE ^[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+$ ;echo $?` == "0" ]]; then #export PRINIC=`ifconfig -a | grep -i "HWaddr $PRINIC" | awk '{print $1}'` export PRINIC=`ip -o link|grep -i "$PRINIC" |awk '{print $2}'|sed s/://` fi #IP=$(ifconfig $PRINIC | grep inet | awk '{print $2}' | awk -F: '{print $2}') IP=$(ip addr show dev $PRINIC | grep inet | grep -v inet6 | awk '{print $2}' | head -n 1 | awk -F '/' '{print $1}') if [ -z $IP ] then dhclient $PRINIC #IP=$(ifconfig $PRINIC | grep inet | awk '{print $2}' | awk -F: '{print $2}') IP=$(ip addr show dev $PRINIC | grep inet | grep -v inet6 | awk '{print $2}' | head -n 1 | awk -F '/' '{print $1}') fi if [ "$XCATDEBUGMODE" > "0" ]; then msgutil_r "$MASTER_IP" "debug" "PRINIC=$PRINIC,IP=$IP" "/var/log/xcat/xcat.log" fi if [ "$XCATDEBUGMODE" > "0" ]; then msgutil_r "$MASTER_IP" "debug" "generating /etc/resolv.conf" "/var/log/xcat/xcat.log" fi echo "search #TABLE:site:key=domain:value#" >/etc/resolv.conf for i in $(echo #TABLE:site:key=nameservers:value# | tr ',' ' ') do echo "nameserver $i" done >>/etc/resolv.conf #change the soft link /bin/sh to /bin/bash ln -sf /bin/bash /bin/sh # #delete the useless apt repo #sed -i 's/^deb.*updates.*$/#&/g' /etc/apt/sources.list # Run xCAT post install # export MASTER_IP="#ENV:MASTER_IP#" export MASTER_IPS="#XCATVAR:XCATMASTER#" export MASTER="#XCATVAR:XCATMASTER#" export INSTALLDIR=#TABLE:site:key=installdir:value# if [ -z "$INSTALLDIR" ]; then INSTALLDIR="/install" fi cd /tmp RAND=$(perl -e 'print int(rand(50)). "\n"') sleep $RAND for j in $(seq 1 20) do GOTIT=0 for i in $MASTER_IPS do if [ "$XCATDEBUGMODE" > "0" ]; then msgutil_r "$MASTER_IP" "debug" "downloading postscripts from http://$i$INSTALLDIR/postscripts/" "/var/log/xcat/xcat.log" fi wget -l inf -N -r --waitretry=10 --random-wait --retry-connrefused -e robots=off -nH --cut-dirs=2 --reject "index.html*" --no-parent -t 0 -T 60 http://$i$INSTALLDIR/postscripts/ -P /xcatpost #wget --wait=10 --random-wait --waitretry=10 --retry-connrefused -t 0 -T 60 http://$i/install/autoinst/xcatpost.tar.gz if [ "$?" = "0" ] then if [ ! -x /usr/bin/openssl ]; then #Stop if no openssl to help the next bit if [ "$XCATDEBUGMODE" > "0" ]; then msgutil_r "$MASTER_IP" "debug" "/usr/bin/openssl does not exist,exit..." "/var/log/xcat/xcat.log" fi exit 1 fi USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images export USEOPENSSLFORXCAT XCATSERVER=$i:3001 export XCATSERVER mv $i/postscripts /xcatpost rm -rf $i # To support the postscripts in the subdirectories under /install/postscripts #chmod +x /xcatpost/* chmod -R +x `find /xcatpost/ -maxdepth 1 -print | grep -E -v '^(/xcatpost/|/xcatpost/_xcat|/xcatpost/_ssh|/xcatpost/ca|/xcatpost/hostkeys)$'` if [ "$XCATDEBUGMODE" > "0" ]; then msgutil_r "$MASTER_IP" "debug" "trying to get mypostscript with getpostscript.awk" "/var/log/xcat/xcat.log" fi /xcatpost/getpostscript.awk |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` MAX_RETRIES=10 RETRY=0 while [ -z "$MYCONT" ]; do RETRY=$(($RETRY+1)) if [ $RETRY -eq $MAX_RETRIES ] then break fi let SLI=$RANDOM%10+10 sleep $SLI /xcatpost/getpostscript.awk |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 chmod +x /xcatpost/mypostscript GOTIT=1 break fi done if [ "$GOTIT" = "1" ] then #save the master to /opt/xcat/xcatinfo file if [ ! -f /opt/xcat/xcatinfo ]; then mkdir -p /opt/xcat touch /opt/xcat/xcatinfo fi echo "XCATSERVER=$i" > /opt/xcat/xcatinfo break fi RAND=$(perl -e 'print int(rand(5)). "\n"') sleep $RAND done cd /xcatpost #gunzip xcatpost.tar.gz #tar -xvf xcatpost.tar #/xcatpost/#TABLE:nodelist:THISNODE:node# export PATH=$PATH:/xcatpost #save the postboot scripts to /var/tmp/mypostscript.post # # mypostscript.post must survive a reboot. Traditionally, xCAT has put mypostscript.post in /tmp. # However, Ubuntu cleans /tmp on reboot. So, for Ubuntu, /var/tmp is used instead. # use the run_ps subroutine to run the postscripts TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /xcatpost/mypostscript` 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 run_ps () { local ret_local=0 mkdir -p "\"/var/log/xcat\"" local logfile=\"/var/log/xcat/xcat.log\" if [ -f \$1 ]; then echo \"\`date\` Running postscript: \$*\" msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Running postscript: \$*\"" \"\$logfile\" if [ \"\$XCATDEBUGMODE\" = \"1\" ]; then bash -x ./\$@ 2>&1 | tee -a \$logfile ret_local=\${PIPESTATUS[0]} else ./\$@ 2>&1 | tee -a \$logfile ret_local=\${PIPESTATUS[0]} fi if [ \"\$ret_local\" -ne \"0\" ]; then return_value=\$ret_local fi echo \"Postscript: \$* exited with code \$ret_local\" msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` postscript \$* return with \$ret_local\"" \"\$logfile\" else echo \"\`date\` Postscript \$1 does NOT exist.\" msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Postscript \$1 does NOT exist.\"" \"\$logfile\" return_value=-1 fi return 0 } # subroutine end " > /xcatpost/mypostscript echo "$TMP" >> /xcatpost/mypostscript TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ d" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript.post chmod 755 /xcatpost/mypostscript.post #create the post init cat >/etc/init.d/xcatpostinit1 << 'EOF' #INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatpostinit1# EOF chmod 755 /etc/init.d/xcatpostinit1 ln -s /etc/init.d/xcatpostinit1 /etc/rc2.d/S84xcatpostinit1 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` fi if [ "$RUNBOOTSCRIPTS" != "'yes'" ]; then msgutil_r "$MASTER_IP" "debug" "update-rc.d -f xcatpostinit1 remove" "/var/log/xcat/xcat.log" update-rc.d -f xcatpostinit1 remove fi echo "REBOOT=TRUE" >> /opt/xcat/xcatinfo EOF chmod 755 /opt/xcat/xcatinstallpost update-rc.d xcatpostinit1 defaults #create the dskls post cat >/opt/xcat/xcatdsklspost << 'EOF' #INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatdsklspost# EOF chmod 755 /opt/xcat/xcatdsklspost #only run the prebooot scripts here TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ d" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript if [ "$XCATDEBUGMODE" > "0" ]; then msgutil_r "$MASTER_IP" "debug" "running mypostscript" "/var/log/xcat/xcat.log" fi /xcatpost/mypostscript if [ "$XCATDEBUGMODE" > "0" ]; then msgutil_r "$MASTER_IP" "debug" "mypostscript return" "/var/log/xcat/xcat.log" fi export NODE=#TABLE:nodelist:THISNODE:node# export OSVER=#TABLE:nodetype:THISNODE:os# export ARCH=#TABLE:nodetype:THISNODE:arch# export CONSOLEPORT=#TABLEBLANKOKAY:nodehm:THISNODE:serialport# #addsiteyum if [[ -r /boot/grub/menu.lst ]]; then sed -i 's/^serial/#serial/' /boot/grub/menu.lst sed -i 's/^terminal/#terminal/' /boot/grub/menu.lst elif [[ -r /boot/grub/grub.cfg ]] ; then update-grub fi if echo "$ARCH" | grep -i 'ppc64'; then if [ -z "$CONSOLEPORT" ] ; then export CONSOLEPORT=0 fi CONSOLE="hvc$CONSOLEPORT" if [[ -r /etc/default/grub ]] ; then sed -i "s/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"console=$CONSOLE\"/" /etc/default/grub else echo "GRUB_CMDLINE_LINUX_DEFAULT=\"console=$CONSOLE\"" > /etc/default/grub fi update-grub cat >/etc/init/$CONSOLE\.conf << 'EOF' start on stopped rc RUNLEVEL=[2345] and ( not-container or container CONTAINER=lxc or container CONTAINER=lxc-libvirt) stop on runlevel [!2345] respawn #exec /sbin/getty -L 115200 hvc0 vt102 script for i in `cat /proc/cmdline`; do KEY=`echo $i|cut -d= -f 1` if [ "$KEY" == "console" -a "$i" != "console=tty0" ]; then VALUE=`echo $i | awk -F= '{print $2}'` COTTY=`echo $VALUE|awk -F, '{print $1}'` COSPEED=`echo $VALUE|awk -F, '{print $2}'|awk -Fn '{print $1}'` break fi done exec /sbin/getty -L $COSPEED $COTTY vt102 end script EOF fi #sed -i 's/\(deb.*security.*\)/#\1/' /etc/apt/sources.list #iso does not contains source deb packages #sed -i 's/^\(\s*deb-src.*install.*\)$/#\1/g' /etc/apt/sources.list #delete the 127.0.1.1 line from /etc/hosts sed -i '/127.0.1.1/d' /etc/hosts if [ "$XCATDEBUGMODE" > "0" ]; then msgutil_r "$MASTER_IP" "debug" "installation finished, reporting status..." "/var/log/xcat/xcat.log" fi updateflag.awk $MASTER 3002 cd / #rm -Rf /xcatpost #rm -f /tmp/mypostscript exit 0