From c4a058c6d523c50cf6a9a850b1cd37091856e83d Mon Sep 17 00:00:00 2001 From: immarvin Date: Sat, 19 Nov 2016 05:02:11 -0500 Subject: [PATCH] refine the conditional code logic on swith variables site table --- .../share/xcat/install/scripts/post.debian | 6 +++--- .../share/xcat/install/scripts/post.xcat | 7 ++++--- xCAT/postscripts/xcatdsklspost | 20 +++++++++---------- xCAT/postscripts/xcatinstallpost | 6 +++--- xCAT/postscripts/xcatpostinit1.install | 4 ++-- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/xCAT-server/share/xcat/install/scripts/post.debian b/xCAT-server/share/xcat/install/scripts/post.debian index ad7a32ed3..f11296a24 100644 --- a/xCAT-server/share/xcat/install/scripts/post.debian +++ b/xCAT-server/share/xcat/install/scripts/post.debian @@ -160,12 +160,12 @@ 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` + RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post |cut -d= -f2 | tr -d \'\" | tr A-Z a-z` fi -if [ "$RUNBOOTSCRIPTS" != "'yes'" ]; then +if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then chkconfig xcatpostinit1 off fi -echo "REBOOT=TRUE" >> /opt/xcat/xcatinf +echo "REBOOT=TRUE" >> /opt/xcat/xcatinfo EOF chmod 755 /opt/xcat/xcatinstallpost diff --git a/xCAT-server/share/xcat/install/scripts/post.xcat b/xCAT-server/share/xcat/install/scripts/post.xcat index f663f8161..2d6cffec7 100755 --- a/xCAT-server/share/xcat/install/scripts/post.xcat +++ b/xCAT-server/share/xcat/install/scripts/post.xcat @@ -28,6 +28,7 @@ if [[ $TFTPDIR != /* ]]; 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# @@ -337,18 +338,18 @@ 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` + RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post |cut -d= -f2 | tr -d \'\" | tr A-Z a-z` fi if [[ $OSVER == ubuntu* ]]; then - if [ "$RUNBOOTSCRIPTS" != "'yes'" ]; then + if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then update-rc.d -f xcatpostinit1 remove fi if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "update-rc.d -f xcatpostinit1 remove" "/var/log/xcat/xcat.log" fi else - if [ "$RUNBOOTSCRIPTS" != "'yes'" ] && [ "$NODESTATUS" = "'n'" ]; then + if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]] && [[ ! "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then chkconfig xcatpostinit1 off if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "service xcatpostinit1 disabled" "/var/log/xcat/xcat.log" diff --git a/xCAT/postscripts/xcatdsklspost b/xCAT/postscripts/xcatdsklspost index 45b021da9..79379c960 100755 --- a/xCAT/postscripts/xcatdsklspost +++ b/xCAT/postscripts/xcatdsklspost @@ -24,13 +24,13 @@ if [ -f /xcatpost/mypostscript.post ]; then - XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` + XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post | cut -d= -f2 | tr -d \'\" | tr A-Z a-z` MASTER_IP=`grep '^MASTER_IP=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` else for param in `cat /proc/cmdline`; do key=`echo $param|awk -F= '{print $1}'` if [ "$key" = "xcatdebugmode" ]; then - XCATDEBUGMODE=`echo $param|awk -F= '{print $2}'` + XCATDEBUGMODE=`echo $param|awk -F= '{print $2}'| tr -d \'\" | tr A-Z a-z` fi if [ "$key" = "LOGSERVER" ]; then @@ -654,7 +654,7 @@ fi #save the USEFLOWCONTROL into the xcatinfo file #for updatenode case, passwd in with the -f flag if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ]; then - useflowcontrol=`grep '^USEFLOWCONTROL' /$xcatpost/mypostscript |cut -d= -f2` + useflowcontrol=`grep '^USEFLOWCONTROL' /$xcatpost/mypostscript |cut -d= -f2 | tr -d \'\" | tr A-Z a-z` fi if [ ! -f /opt/xcat/xcatinfo ]; then mkdir -p /opt/xcat @@ -662,7 +662,7 @@ if [ ! -f /opt/xcat/xcatinfo ]; then fi if [ -n "$useflowcontrol" ]; then # lets just put YES or NO in xcatinfo - if [ "$useflowcontrol" = "1" ] || [ "$useflowcontrol" = "yes" ] || [ "$useflowcontrol" = "YES" ]; then + if [[ "$useflowcontrol" =~ ^(1|yes|y)$ ]]; then new_fc="YES" else new_fc="NO" @@ -711,11 +711,11 @@ if [ "$MODE" = "6" ]; then echo "$TMP" > /$xcatpost/mypostscript # get the RUNBOOTSCRIPTS site variable if [ -f /$xcatpost/mypostscript ]; then - RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /$xcatpost/mypostscript |cut -d= -f2` + RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /$xcatpost/mypostscript |cut -d= -f2 | tr -d \'\" | tr A-Z a-z ` fi # if admin did not requested running of post boot scripts - then remove PBS - if [ "$RUNBOOTSCRIPTS" != "'yes'" ]; then + if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then #remove all the postscripts TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript @@ -890,8 +890,8 @@ echo "$TMP" > /$xcatpost/mypostscript if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ] || [ "$MODE" = "6" ]; then #notify the server that we are done with netbooting - CNS=`grep NODESTATUS= /$xcatpost/mypostscript |awk -F = '{print $2}'` - if [ -z "$CNS" ] || [ "$CNS" != "'0'" -a "$CNS" != "'N'" -a "$CNS" != "'n'" ]; then + CNS=`grep NODESTATUS= /$xcatpost/mypostscript |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z` + if [ -z "$CNS" ] || [[ "$CNS" =~ ^(1|yes|y)$ ]]; then # TMP=`sed "/postscripts-start-here/ i\updateflag.awk \\$MASTER 3002 \\"installstatus configuring\\"" /$xcatpost/mypostscript` # echo "$TMP"> /$xcatpost/mypostscript if [ "$MODE" = "6" ]; then @@ -922,8 +922,8 @@ fi DHCP_TMP=`sed 's/\(DHCPINTERFACES=\)\(.*\)$/\1"\2"/' /$xcatpost/mypostscript` echo "$DHCP_TMP" > /$xcatpost/mypostscript -CLEANUPXCATPOST=`grep CLEANUPXCATPOST= /$xcatpost/mypostscript |awk -F = '{print $2}'` -if [ "$CLEANUPXCATPOST" = "'1'" ] || [ "$CLEANUPXCATPOST" = "'yes'" ]; then +CLEANUPXCATPOST=`grep CLEANUPXCATPOST= /$xcatpost/mypostscript |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z` +if [[ "$CLEANUPXCATPOST" =~ ^(1|yes|y)$ ]]; then echo "cd /" >> /$xcatpost/mypostscript # /xcatpost might be read-only for statelite nodes echo "rm -rf /$xcatpost/*" >> /$xcatpost/mypostscript diff --git a/xCAT/postscripts/xcatinstallpost b/xCAT/postscripts/xcatinstallpost index 21309a79d..15c2068e5 100755 --- a/xCAT/postscripts/xcatinstallpost +++ b/xCAT/postscripts/xcatinstallpost @@ -7,7 +7,7 @@ . /xcatpost/xcatlib.sh if [ -f /xcatpost/mypostscript.post ]; then - XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` + XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post |cut -d= -f2 | tr -d \'\" | tr A-Z a-z ` MASTER_IP=`grep '^MASTER_IP=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` OSVER=`grep '^OSVER=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` fi @@ -83,8 +83,8 @@ else fi -CNS=`grep NODESTATUS= /xcatpost/mypostscript.post |awk -F = '{print $2}'` -if [ -z "$CNS" ] || [ "$CNS" != "'0'" -a "$CNS" != "'N'" -a "$CNS" != "'n'" ]; then +CNS=`grep NODESTATUS= /xcatpost/mypostscript.post |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z` +if [ -z "$CNS" ] || [[ "$CNS" =~ ^(1|yes|y)$ ]]; then #update the node status during the postbootscript running #TMP=`sed "/postbootscripts-start-here/ i\updateflag.awk \\$MASTER 3002 \\"installstatus configuring\\"" /xcatpost/mypostscript.post` #echo "$TMP"> /xcatpost/mypostscript.post diff --git a/xCAT/postscripts/xcatpostinit1.install b/xCAT/postscripts/xcatpostinit1.install index 7bb736b84..4042b6699 100755 --- a/xCAT/postscripts/xcatpostinit1.install +++ b/xCAT/postscripts/xcatpostinit1.install @@ -23,9 +23,9 @@ start) REBOOT=`grep 'REBOOT' /opt/xcat/xcatinfo |cut -d= -f2 | tr -d \'\"` fi # if the xcatdsklspost file exists and this is a reboot - run xcatdsklspost with a mode of 6 - if [ "$REBOOT" = "TRUE" -a -r /opt/xcat/xcatdsklspost ] && [[ "$RUNBOOTSCRIPTS" =~ ^1|yes|y$ ]]; then + if [ "$REBOOT" = "TRUE" -a -r /opt/xcat/xcatdsklspost ] && [[ "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then /opt/xcat/xcatdsklspost 6 - elif [ "$REBOOT" = "TRUE" ] && [[ "$NODESTATUS" =~ ^1|yes|y$ ]]; then + elif [ "$REBOOT" = "TRUE" ] && [[ "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then /xcatpost/updateflag.awk $XCATSERVER 3002 "installstatus booted" else # run /opt/xcat/xcatinstallpost