2008-05-01 20:52:16 +00:00
|
|
|
#!/bin/sh
|
2008-04-14 12:20:34 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# Generic xCAT post script for diskless nodes
|
2010-03-24 12:05:58 +00:00
|
|
|
# The syntax of this script
|
|
|
|
# xcatdsklspost {mode} {-m|-M} [postscirpts]
|
2009-07-29 21:25:59 +00:00
|
|
|
# This script is called in the following different palces:
|
2010-03-21 13:11:47 +00:00
|
|
|
# updatenode -P ... --> xcatdsklspost 1 -m/-M ...
|
|
|
|
# updatenode -S --> xcatdsklspost 2 -m/-M otherpkgs
|
2009-07-29 21:25:59 +00:00
|
|
|
# moncfg rmcmon --> xcatdsklspost 3 configrmcnodes
|
|
|
|
# node deployment --> xcatdsklspost
|
2010-01-25 11:34:42 +00:00
|
|
|
# statelite mode --> xcatdsklspost 4
|
2010-03-21 13:11:47 +00:00
|
|
|
# update security --> xcatdsklspost 5 -m/-M ...
|
2008-04-14 12:20:34 +00:00
|
|
|
#
|
|
|
|
#####################################################
|
2009-12-04 21:22:07 +00:00
|
|
|
download_postscripts()
|
|
|
|
{
|
|
|
|
server=$1
|
|
|
|
if [ -z $server ]; then
|
|
|
|
return 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
max_retries=5
|
|
|
|
retry=0
|
|
|
|
rc=1
|
|
|
|
while [ 0 -eq 0 ]; do
|
2010-04-23 05:37:55 +00:00
|
|
|
wget -l inf -nH -N -r --waitretry=10 --random-wait -T 60 ftp://$server/postscripts -P /xcatpost --cut-dirs=1 2> /tmp/wget.log
|
2009-12-04 21:22:07 +00:00
|
|
|
rc=$?
|
|
|
|
|
|
|
|
if [ $rc -eq 0 ]; then
|
|
|
|
return 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
retry=$(($retry+1))
|
|
|
|
if [ $retry -eq $max_retries ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
let sli=$RANDOM%20
|
|
|
|
sleep $sli
|
|
|
|
done
|
|
|
|
return $rc
|
|
|
|
}
|
|
|
|
|
2010-03-21 13:11:47 +00:00
|
|
|
# parse the arguments
|
|
|
|
ARGNUM=$#;
|
|
|
|
if [ -z $1 ]; then
|
2010-03-24 12:05:58 +00:00
|
|
|
NODE_DEPLOYMENT=1
|
2010-03-21 13:11:47 +00:00
|
|
|
else
|
2010-03-24 12:05:58 +00:00
|
|
|
NODE_DEPLOYMENT=0
|
2010-03-21 13:11:47 +00:00
|
|
|
case $1 in
|
|
|
|
1|2|5)
|
|
|
|
MODE=$1
|
|
|
|
if [ $ARGNUM -gt 1 ]; then
|
|
|
|
if [ $2 == "-m" ]; then
|
|
|
|
P_SIP=$3
|
|
|
|
else
|
|
|
|
if [ $2 == "-M" ]; then
|
|
|
|
P_SIP=$3
|
|
|
|
new_ms=$P_SIP
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ $ARGNUM -gt 3 ]; then
|
|
|
|
POSTSCRIPTS=$4
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
3|4) MODE=$1;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2009-12-04 21:22:07 +00:00
|
|
|
|
2008-05-01 20:52:16 +00:00
|
|
|
if [ ! `uname` == Linux ]; then
|
|
|
|
MYDIR=`dirname $0`
|
|
|
|
exec $MYDIR/xcatdsklspost.aix
|
|
|
|
exit
|
|
|
|
fi
|
2008-05-13 23:33:16 +00:00
|
|
|
let SLI=$RANDOM%10
|
|
|
|
sleep $SLI
|
2008-05-01 20:52:16 +00:00
|
|
|
|
2010-01-25 11:34:42 +00:00
|
|
|
if [ ! -d /xcatpost ]; then
|
|
|
|
mkdir -p /xcatpost;
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d /tmp/postage ]; then
|
|
|
|
mkdir -p /tmp/postage
|
|
|
|
fi
|
2009-12-04 21:22:07 +00:00
|
|
|
rm -R -f /xcatpost/*
|
|
|
|
rm -R -f /tmp/postage/*
|
2008-05-27 18:21:23 +00:00
|
|
|
|
2009-12-04 21:22:07 +00:00
|
|
|
#here we get all the postscripts. Please do not change this behaviour because some scripts depend on others
|
|
|
|
cd /tmp/postage
|
2009-02-16 07:22:21 +00:00
|
|
|
|
2010-01-25 11:34:42 +00:00
|
|
|
|
2010-03-21 13:11:47 +00:00
|
|
|
if [ "$MODE" == "4" ]; then # for statelite mode
|
2010-01-25 11:34:42 +00:00
|
|
|
# We have written the xCATSERVER info into the kernel command line!!
|
|
|
|
for i in `cat /proc/cmdline`; do
|
|
|
|
KEY=`echo $i | awk -F= '{print $1}'`
|
|
|
|
if [ "$KEY" == "XCAT" ]; then
|
|
|
|
TMP=`echo $i | awk -F= '{print $2}'`
|
|
|
|
XCATSERVER=`echo $TMP | cut -d: -f1`
|
|
|
|
echo "XCATSERVER=$XCATSERVER" > /opt/xcat/xcatinfo
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -f /opt/xcat/xcatinfo ]; then
|
|
|
|
SIP=`cut -d= -f2 /opt/xcat/xcatinfo`;
|
2010-04-23 05:37:55 +00:00
|
|
|
if [ -n "$SIP" ]; then
|
|
|
|
download_postscripts $SIP
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
downloaded=1
|
|
|
|
fi
|
|
|
|
fi
|
2010-01-25 11:34:42 +00:00
|
|
|
else
|
|
|
|
echo "xCAT management server IP can't be determined.\nexiting...";
|
2010-02-23 15:15:32 +00:00
|
|
|
logger -t xCAT "xcatdsklspost:xCAT management server IP can't be determined.\nexiting...";
|
2010-01-25 11:34:42 +00:00
|
|
|
exit;
|
2009-12-04 21:22:07 +00:00
|
|
|
fi
|
2010-03-21 13:11:47 +00:00
|
|
|
else # for common mode
|
|
|
|
downloaded=0;
|
|
|
|
#open the xcatinfo file to look for the master if it is not set
|
|
|
|
if [ -f /opt/xcat/xcatinfo ]; then
|
|
|
|
SIP=`grep 'XCATSERVER' /opt/xcat/xcatinfo |cut -d= -f2`
|
|
|
|
if [ -n "$SIP" ]; then
|
|
|
|
download_postscripts $SIP
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
downloaded=1
|
|
|
|
fi
|
|
|
|
fi
|
2009-12-04 21:22:07 +00:00
|
|
|
fi
|
|
|
|
|
2010-03-21 13:11:47 +00:00
|
|
|
#try the -m if it is specified, -m is passed in the updatenode command
|
|
|
|
if [ $downloaded -eq 0 ]; then
|
|
|
|
if [ "XX$P_SIP" != "XX" ]; then
|
2010-04-15 13:04:33 +00:00
|
|
|
SIP=$P_SIP
|
2010-03-21 13:11:47 +00:00
|
|
|
download_postscripts $SIP
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
downloaded=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#try the dhcp server, this is used for initial boot for the node.
|
|
|
|
if [ $downloaded -eq 0 ]; then
|
|
|
|
#setup $OSVER ,for SLES11
|
|
|
|
if [ -e '/etc/SuSE-release' ]; then
|
|
|
|
OSVER=`grep -h VERSION /etc/SuSE-release |awk '{print $3}'`
|
|
|
|
fi
|
|
|
|
SIPS=`grep -h dhcp-server-identifier /var/lib/dhclient/dhclient*.leases 2> /dev/null|awk '{print $3}'|sed -e 's/;//'`
|
|
|
|
if [ -z "$SIPS" ]; then
|
|
|
|
SIPS=`grep -h DHCPSID /var/lib/dhcpcd/*.info 2> /dev/null|awk -F= '{print $2}'|sed -e s/\'//g`
|
|
|
|
fi
|
|
|
|
SIP=`echo $SIPS|awk '{printf $NF}' | tail -n 1` #Pick one for wget
|
|
|
|
if [ -n "$SIP" ]; then
|
|
|
|
download_postscripts $SIP
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
downloaded=1
|
|
|
|
fi
|
|
|
|
elif [ -x "/sbin/dhcpcd" ]; then
|
|
|
|
# New dhcpcd doesn't creates *.info files.
|
|
|
|
for lease in $(ls "/var/lib/dhcpcd/"); do
|
|
|
|
iface="$(echo "$lease" | sed -n -e 's/^dhcpcd-\(.*\)\.lease$/\1/p')"
|
|
|
|
if [ -n "$iface" ]; then
|
|
|
|
SIP="$(dhcpcd -q -T "$iface" | sed -n -e '/new_dhcp_server_identifier/ s/.*=//p')"
|
|
|
|
if [ -n "$SIP" ]; then
|
|
|
|
download_postscripts $SIP
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
downloaded=1
|
|
|
|
break
|
|
|
|
fi
|
2010-02-24 09:44:42 +00:00
|
|
|
fi
|
|
|
|
fi
|
2010-03-21 13:11:47 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#no hope, now let's get out of here.
|
|
|
|
if [ $downloaded -eq 0 ]; then
|
|
|
|
hn=`hostname`
|
|
|
|
echo "Cannot download the postscripts from the xCAT server for node $hn"
|
|
|
|
logger -t xCAT "xcatdsklspost:Cannot download the postscripts from the xCAT server for node $hn"
|
|
|
|
exit
|
2009-12-04 21:22:07 +00:00
|
|
|
fi
|
2009-09-09 20:36:53 +00:00
|
|
|
|
2010-03-21 13:11:47 +00:00
|
|
|
fi # finish the postscripts download
|
2010-01-25 11:34:42 +00:00
|
|
|
|
2008-05-09 17:20:04 +00:00
|
|
|
if grep 'rw /rw tmpfs ' /proc/mounts >& /dev/null; then
|
|
|
|
touch /var/lock/subsys/xcatmounts
|
|
|
|
echo '#!/bin/bash' > /etc/rc6.d/K10xcatmounts
|
|
|
|
echo umount -l /ro >> /etc/rc6.d/K10xcatmounts
|
|
|
|
echo umount -l /rw >> /etc/rc6.d/K10xcatmounts
|
|
|
|
chmod 755 /etc/rc6.d/K10xcatmounts
|
|
|
|
ln -sf /etc/rc6.d/K10xcatmounts /etc/rc0.d/K10xcatmounts
|
|
|
|
fi
|
|
|
|
|
2010-04-20 03:29:10 +00:00
|
|
|
chmod +x /xcatpost/*;
|
2008-09-08 18:54:30 +00:00
|
|
|
|
2010-04-22 07:16:11 +00:00
|
|
|
cd /xcatpost;
|
2008-05-01 20:52:16 +00:00
|
|
|
PATH=/xcatpost:$PATH
|
|
|
|
export PATH
|
2009-12-04 21:22:07 +00:00
|
|
|
|
|
|
|
if [ -x /usr/bin/openssl ]; then
|
|
|
|
XCATSERVER="$SIP:3001"
|
|
|
|
export XCATSERVER
|
|
|
|
USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images
|
|
|
|
export USEOPENSSLFORXCAT
|
|
|
|
fi
|
|
|
|
|
2008-05-01 20:52:16 +00:00
|
|
|
/xcatpost/getpostscript.awk | sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' > /tmp/mypostscript;
|
2009-06-19 18:44:02 +00:00
|
|
|
MYCONT=`grep MASTER /tmp/mypostscript`
|
2008-09-08 18:54:30 +00:00
|
|
|
#echo "MYCONT=$MYCONT"
|
2009-09-16 08:28:04 +00:00
|
|
|
#if getpostscript.awk fails, the postscript will fall into infinit loop
|
|
|
|
#so one retry_number is added to avoid sunc a condition
|
|
|
|
MAX_RETRIES=10
|
|
|
|
RETRY=0
|
2008-05-13 23:33:16 +00:00
|
|
|
while [ -z "$MYCONT" ]; do
|
2009-09-16 08:28:04 +00:00
|
|
|
RETRY=$(($RETRY+1))
|
|
|
|
if [ $RETRY -eq $MAX_RETRIES ]
|
|
|
|
then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
2008-05-13 23:33:16 +00:00
|
|
|
let SLI=$RANDOM%10
|
|
|
|
let SLI=10+$SLI
|
|
|
|
sleep $SLI
|
2010-03-21 13:11:47 +00:00
|
|
|
|
|
|
|
/xcatpost/getpostscript.awk | sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' > /tmp/mypostscript;
|
|
|
|
MYCONT=`grep MASTER /tmp/mypostscript`
|
|
|
|
if [ ! -z "$MYCONT" ]; then
|
|
|
|
break;
|
2010-01-25 11:34:42 +00:00
|
|
|
fi
|
2008-05-13 23:33:16 +00:00
|
|
|
done
|
2009-06-04 15:33:44 +00:00
|
|
|
|
2009-12-04 21:22:07 +00:00
|
|
|
#save the MASTER into the xcatinfo file for node deployment case,
|
|
|
|
#for updatenode case, only save it when -M is specified
|
2010-03-21 13:11:47 +00:00
|
|
|
if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" == "4" ]; then
|
2009-12-04 21:22:07 +00:00
|
|
|
new_ms=`grep '^MASTER' /tmp/mypostscript |cut -d= -f2`
|
|
|
|
fi
|
|
|
|
if [ -n "$new_ms" ]; then
|
2009-09-21 14:12:48 +00:00
|
|
|
if [ ! -f /opt/xcat/xcatinfo ]; then
|
|
|
|
mkdir -p /opt/xcat
|
2009-12-04 21:22:07 +00:00
|
|
|
touch /opt/xcat/xcatinfo
|
2009-09-21 14:12:48 +00:00
|
|
|
fi
|
|
|
|
grep 'XCATSERVER' /opt/xcat/xcatinfo 2>&1 > /dev/null
|
|
|
|
if [ $? -eq 0 ]; then
|
2009-12-04 21:22:07 +00:00
|
|
|
sed -i "s/XCATSERVER=.*/XCATSERVER=$new_ms/" /opt/xcat/xcatinfo
|
2009-09-21 14:12:48 +00:00
|
|
|
else
|
2009-12-04 21:22:07 +00:00
|
|
|
echo "XCATSERVER=$new_ms" >> /opt/xcat/xcatinfo
|
2009-09-21 14:12:48 +00:00
|
|
|
fi
|
2009-12-04 21:22:07 +00:00
|
|
|
fi
|
|
|
|
|
2009-09-21 14:12:48 +00:00
|
|
|
|
2009-07-29 21:25:59 +00:00
|
|
|
# when called by the updatenode command
|
|
|
|
#modify the UPDATENODE flag to 1
|
2010-03-21 13:11:47 +00:00
|
|
|
if [ "$MODE" == "1" ] || [ "$MODE" == "2" ]; then
|
2009-06-04 15:33:44 +00:00
|
|
|
TMP=`sed -e 's/UPDATENODE=0/UPDATENODE=1/g' /tmp/mypostscript`;
|
|
|
|
echo "$TMP" > /tmp/mypostscript;
|
|
|
|
fi
|
2010-03-21 13:11:47 +00:00
|
|
|
if [ "$MODE" == "5" ]; then
|
|
|
|
TMP=`sed -e 's/UPDATENODE=0/UPDATENODE=1\nUPDATESECURITY=1\nexport UPDATESECURITY/g' /tmp/mypostscript`;
|
|
|
|
echo "$TMP" > /tmp/mypostscript;
|
|
|
|
fi
|
2009-06-04 15:33:44 +00:00
|
|
|
|
2009-12-22 04:34:29 +00:00
|
|
|
# postscript name is specified with the updatenode
|
2010-03-21 13:11:47 +00:00
|
|
|
if [ "XX$POSTSCRIPTS" != "XX" ]; then
|
2009-12-22 04:34:29 +00:00
|
|
|
#remove all the postbootscripts
|
|
|
|
TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ d" /tmp/mypostscript`
|
|
|
|
echo "$TMP" > /tmp/mypostscript
|
2008-09-08 18:54:30 +00:00
|
|
|
#remove all the postscripts
|
|
|
|
TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ d" /tmp/mypostscript`
|
|
|
|
echo "$TMP" > /tmp/mypostscript
|
2009-09-18 11:28:34 +00:00
|
|
|
echo "# postscripts-start-here\n" >> /tmp/mypostscript
|
2008-09-08 18:54:30 +00:00
|
|
|
#add requested postscripts in
|
2010-03-21 13:11:47 +00:00
|
|
|
echo "$POSTSCRIPTS" | tr "," "\n" >> /tmp/mypostscript
|
2009-09-18 11:28:34 +00:00
|
|
|
echo "# postscripts-end-here\n" >> /tmp/mypostscript
|
2008-09-08 18:54:30 +00:00
|
|
|
fi
|
2009-07-23 20:56:57 +00:00
|
|
|
|
|
|
|
#ADDSITEYUM is set by post.rh and post.rh.iscsi for full installtion
|
2009-12-15 14:25:36 +00:00
|
|
|
#if [[ "$ADDSITEYUM" = "1" ]]; then
|
|
|
|
# TMP=`sed "/postscripts-start-here/ a addsiteyum" /tmp/mypostscript`
|
|
|
|
# echo "$TMP" > /tmp/mypostscript
|
|
|
|
#fi
|
2009-07-23 20:56:57 +00:00
|
|
|
|
2008-09-08 18:54:30 +00:00
|
|
|
#MYCONT=`cat /tmp/mypostscript`
|
|
|
|
#echo "$MYCONT"
|
|
|
|
|
2009-09-18 11:28:34 +00:00
|
|
|
# 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*$//" /tmp/mypostscript`
|
|
|
|
echo "
|
|
|
|
# subroutine used to run postscripts
|
2010-04-09 06:12:40 +00:00
|
|
|
run_ps () {
|
2010-04-27 05:52:26 +00:00
|
|
|
logdir=\"/var/log/xcat\"
|
2010-04-13 03:48:29 +00:00
|
|
|
mkdir -p \$logdir
|
2010-04-27 05:52:26 +00:00
|
|
|
logfile=\"/var/log/xcat/xcat.log\"
|
2010-04-09 06:12:40 +00:00
|
|
|
|
2009-09-18 11:28:34 +00:00
|
|
|
if [[ -f \$1 ]]; then
|
2010-04-12 09:22:55 +00:00
|
|
|
echo \"Running postscript: \$1\" | tee -a \$logfile
|
2010-04-13 03:48:29 +00:00
|
|
|
./\$1 2>&1 | tee -a \$logfile
|
2009-09-18 11:28:34 +00:00
|
|
|
else
|
2010-04-12 09:22:55 +00:00
|
|
|
echo \"Postscript \$1 does NOT exist.\" | tee -a \$logfile
|
2009-09-18 11:28:34 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
# subroutine end
|
|
|
|
|
|
|
|
" > /tmp/mypostscript
|
|
|
|
echo "$TMP" >> /tmp/mypostscript
|
2009-12-15 14:25:36 +00:00
|
|
|
TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /tmp/mypostscript`
|
|
|
|
echo "$TMP" > /tmp/mypostscript
|
2009-09-18 11:28:34 +00:00
|
|
|
|
2010-03-21 13:11:47 +00:00
|
|
|
if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" == "4" ]; then
|
2008-09-26 23:07:45 +00:00
|
|
|
#notify the server that we are done with netbooting
|
2009-03-24 19:44:23 +00:00
|
|
|
CNS=`grep NODESTATUS= /tmp/mypostscript |awk -F = '{print $2}'`
|
2009-03-25 03:25:59 +00:00
|
|
|
if [ -z "$CNS" ] || [ "$CNS" != "'0'" -a "$CNS" != "'N'" -a "$CNS" != "'n'" ]; then
|
2009-03-24 03:12:03 +00:00
|
|
|
echo "updateflag.awk \$MASTER 3002 \"installstatus booted\"" >> /tmp/mypostscript
|
|
|
|
fi
|
2008-09-26 23:07:45 +00:00
|
|
|
fi
|
|
|
|
|
2009-02-19 08:45:16 +00:00
|
|
|
DHCP_TMP=`sed 's/\(DHCPINTERFACES=\)\(.*\)$/\1"\2"/' /tmp/mypostscript`
|
|
|
|
echo "$DHCP_TMP" > /tmp/mypostscript
|
2009-02-16 07:22:21 +00:00
|
|
|
|
2008-05-01 20:52:16 +00:00
|
|
|
chmod +x /tmp/mypostscript
|
|
|
|
if [ -x /tmp/mypostscript ];then
|
|
|
|
/tmp/mypostscript
|
|
|
|
fi
|
2009-07-23 20:56:57 +00:00
|
|
|
#rm -f /tmp/mypostscript
|
2008-09-25 03:04:56 +00:00
|
|
|
|
2008-11-09 03:20:21 +00:00
|
|
|
#tell user it is done when this is called by updatenode command
|
2010-03-21 13:11:47 +00:00
|
|
|
if [ "$MODE" == "1" ] || [ "$MODE" == "2" ] || [ "$MODE" == "5" ]; then
|
2009-08-03 11:41:16 +00:00
|
|
|
echo "returned from postscript"
|
2008-11-09 03:20:21 +00:00
|
|
|
fi
|
2008-09-08 18:54:30 +00:00
|
|
|
|