From 8304f354132d9377c87d23348417bb72726895e4 Mon Sep 17 00:00:00 2001 From: Samveen Date: Thu, 4 Jul 2019 11:29:08 +0530 Subject: [PATCH] [genesis-scripts]Minor logic and piping improvements --- xCAT-genesis-scripts/usr/bin/bmcsetup | 1 + xCAT-genesis-scripts/usr/bin/diskdiscover | 8 +- xCAT-genesis-scripts/usr/bin/dodiscovery | 13 ++- xCAT-genesis-scripts/usr/bin/dosysclone | 2 +- xCAT-genesis-scripts/usr/bin/doxcat | 1 + xCAT-genesis-scripts/usr/bin/getadapter | 93 ++++++++++----------- xCAT-genesis-scripts/usr/bin/getcert | 54 ++++++------ xCAT-genesis-scripts/usr/bin/getdestiny | 33 ++++---- xCAT-genesis-scripts/usr/bin/getipmi | 23 ++--- xCAT-genesis-scripts/usr/bin/ifup | 1 + xCAT-genesis-scripts/usr/bin/nextdestiny | 36 ++++---- xCAT-genesis-scripts/usr/bin/raidcmd | 22 ++--- xCAT-genesis-scripts/usr/bin/remoteimmsetup | 17 ++-- xCAT-genesis-scripts/usr/bin/restart | 53 ++++++------ 14 files changed, 167 insertions(+), 190 deletions(-) diff --git a/xCAT-genesis-scripts/usr/bin/bmcsetup b/xCAT-genesis-scripts/usr/bin/bmcsetup index fa5955adbe..457875e881 100755 --- a/xCAT-genesis-scripts/usr/bin/bmcsetup +++ b/xCAT-genesis-scripts/usr/bin/bmcsetup @@ -1,3 +1,4 @@ +#!/bin/bash # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html # Lenovo (c) 2016 # diff --git a/xCAT-genesis-scripts/usr/bin/diskdiscover b/xCAT-genesis-scripts/usr/bin/diskdiscover index 7964d1c9ce..bf0ce3ab32 100755 --- a/xCAT-genesis-scripts/usr/bin/diskdiscover +++ b/xCAT-genesis-scripts/usr/bin/diskdiscover @@ -51,8 +51,8 @@ # source raidutils # ########################################### -str_dir_name=`dirname $0` -. $str_dir_name/raidutils +str_dir_name="$(dirname "$0")" +. "$str_dir_name/raidutils" ############################################ @@ -83,8 +83,8 @@ if [ "x$input" == "x--help" -o "x$input" == "x-h" ]; then usagesc exit 0 fi -if [ -z $input ]; then +if [ -z "$input" ]; then get_all_devices_for_raid else - get_devices_by_pciid $input + get_devices_by_pciid "$input" fi diff --git a/xCAT-genesis-scripts/usr/bin/dodiscovery b/xCAT-genesis-scripts/usr/bin/dodiscovery index 1afa958f0a..4861e86c3f 100755 --- a/xCAT-genesis-scripts/usr/bin/dodiscovery +++ b/xCAT-genesis-scripts/usr/bin/dodiscovery @@ -9,8 +9,7 @@ reqtime=0 maxresptime=180 minixcatd.awk & -PUBKEY=`openssl rsa -in /etc/xcat/privkey.pem -pubout 2> /dev/null|grep -v "PUBLIC KEY"` -PUBKEY=`echo $PUBKEY|sed -e 's/ //g'` +PUBKEY="$(openssl rsa -in /etc/xcat/privkey.pem -pubout 2> /dev/null|awk '!/ PUBLIC KEY/{printf $0}')" export PUBKEY logger -s -t $log_label -p local4.info "Beginning node discovery process..." @@ -98,8 +97,8 @@ if [ -r /sys/devices/virtual/dmi/id/product_name ]; then #x86 fi if [ -z "$MTM" -o "$MTM" == ":" ]; then logger -s -t $log_label -p local4.warning "Couldn't find MTM information in FRU, falling back to DMI (MTMS-based discovery may fail)" - m=`cat /sys/devices/virtual/dmi/id/sys_vendor` - n=`cat /sys/devices/virtual/dmi/id/product_name` + read -r m /dev/null; then + if ! dmidecode -t 41|grep -q $obslot; then obdevs=("${obdevs[@]}" $obslot) fi done @@ -271,7 +270,7 @@ for dev in `ip link|grep -B1 ether|grep UP|awk '{print $2}'|sed -e s/://|grep -v echo "" >> /tmp/discopacket done if [ "$UUID" == "unknown" ]; then - UUID=`echo $MTM-$SERIAL-$MAC_OF_FIRST_UP_NIC | tr /A-Z/ /a-z/` + UUID="${MTM,,}-${SERIAL,,}-${MAC_OF_FIRST_UP_NIC,,}" echo "$UUID" >> /tmp/discopacket fi echo "$PUBKEY" >> /tmp/discopacket #this is not secure to use by itself, switch sourced pubkey for security diff --git a/xCAT-genesis-scripts/usr/bin/dosysclone b/xCAT-genesis-scripts/usr/bin/dosysclone index ad1a7313b4..cd7b3b53e4 100755 --- a/xCAT-genesis-scripts/usr/bin/dosysclone +++ b/xCAT-genesis-scripts/usr/bin/dosysclone @@ -19,7 +19,7 @@ ping_test get_scripts_directory -if [ ! -z $HOSTNAME ]; then +if [ ! -z "$HOSTNAME" ]; then logmsg logmsg "This hosts name is: $HOSTNAME" fi diff --git a/xCAT-genesis-scripts/usr/bin/doxcat b/xCAT-genesis-scripts/usr/bin/doxcat index cfd1d48ca3..317e9cc70c 100755 --- a/xCAT-genesis-scripts/usr/bin/doxcat +++ b/xCAT-genesis-scripts/usr/bin/doxcat @@ -1,3 +1,4 @@ +#!/bin/bash # # 2013.02.07 Brian Elliott Finley # - Added slash in front of "var" in the NICSTOBRINGUP dhclient section. diff --git a/xCAT-genesis-scripts/usr/bin/getadapter b/xCAT-genesis-scripts/usr/bin/getadapter index 918d92b97f..dd3846d6e8 100755 --- a/xCAT-genesis-scripts/usr/bin/getadapter +++ b/xCAT-genesis-scripts/usr/bin/getadapter @@ -1,5 +1,4 @@ #!/bin/bash -#set -x XCATPORT=3001 export XCATPORT @@ -18,35 +17,35 @@ echo " getadapter update" >> "$ADAPTERFILE" -#scan adapters have recognized by operating system +# scan adapters that are recognized by operating system for n in /sys/class/net/*; do nic=${n##/sys/class/net/} if [ "$nic" == "lo" ]; then continue else echo '' >> "$ADAPTERFILE" - tmp=`udevadm info /sys/class/net/"$nic" | grep " INTERFACE" | awk -F '=' '{print $2}'` + tmp="$(udevadm info "/sys/class/net/$nic" | awk -F '=' '/ INTERFACE/{print $2}')" if [ -n "$tmp" ]; then echo "$tmp" >> "$ADAPTERFILE" fi - tmp=`udevadm info /sys/class/net/"$nic" | grep ID_NET_NAME | awk -F '=' '{print $2}'|sort -u| tr -s "\n" "/" | sed "s/\/$//g"` + tmp="$(udevadm info "/sys/class/net/$nic" | awk -F '=' '/ID_NET_NAME/{print $2}'|sort -u| tr -s "\n" "/" | sed 's#/$##g')" if [ -n "$tmp" ]; then echo "$tmp" >> "$ADAPTERFILE" fi - tmp=`udevadm info /sys/class/net/"$nic" | grep DEVPATH | awk -F 'devices' '{print $2}'` + tmp="$(udevadm info "/sys/class/net/$nic" | awk -F 'devices' '/DEVPATH/{print $2}')" if [ -n "$tmp" ]; then echo "${tmp%/net*}" >> "$ADAPTERFILE" fi - echo "`cat /sys/class/net/$nic/address`" >> "$ADAPTERFILE" - tmp=`udevadm info /sys/class/net/"$nic" | grep ID_VENDOR_FROM_DATABASE | awk -F '=' '{print $2}' | tr -s "\n" "/" | sed "s/\/$//g"` + echo "$(cat "/sys/class/net/$nic/address")" >> "$ADAPTERFILE" + tmp="$(udevadm info "/sys/class/net/$nic" | awk -F '=' '/ID_VENDOR_FROM_DATABASE/{print $2}' | tr -s "\n" "/" | sed 's#/$##g')" if [ -n "$tmp" ]; then echo "$tmp" >> "$ADAPTERFILE" fi - tmp=`udevadm info /sys/class/net/"$nic" | grep ID_MODEL_FROM_DATABASE | awk -F '=' '{print $2}'` + tmp="$(udevadm info /sys/class/net/"$nic" | awk -F '=' '/ID_MODEL_FROM_DATABASE/{print $2}')" if [ -n "$tmp" ]; then echo "$tmp" >> "$ADAPTERFILE" fi - tmp=`ip link show $nic` + tmp="$(ip link show "$nic")" if [ -n "$tmp" ]; then tmp=${tmp#*state } echo "${tmp% mode*}" >> "$ADAPTERFILE" @@ -55,57 +54,55 @@ for n in /sys/class/net/*; do fi done -for pci in `lspci |awk '/Ethernet/ {print $1}' `; do +for pci in $(lspci |awk '/Ethernet/ {print $1}'); do if ! grep -q "$pci" "$ADAPTERFILE" 2>/dev/null; then - tmp=`lspci |grep "$pci"` - echo '' >> "$ADAPTERFILE" - echo "$pci" >> "$ADAPTERFILE" - echo "${tmp##*:}" >> "$ADAPTERFILE" - echo '' >> "$ADAPTERFILE" - fi + tmp="$(lspci |grep "$pci")" + echo " +$pci +${tmp##*:} +" >> "$ADAPTERFILE" + fi done -for pci in `lspci |awk '/Network/ {print $1}' `; do +for pci in $(lspci |awk '/Network/ {print $1}'); do if ! grep -q "$pci" "$ADAPTERFILE" 2>/dev/null; then - tmp=`lspci |grep "$pci"` - echo '' >> "$ADAPTERFILE" - echo "$pci" >> "$ADAPTERFILE" - echo "${tmp##*: }" >> "$ADAPTERFILE" - echo '' >> "$ADAPTERFILE" - fi + tmp="$(lspci |grep "$pci")" + cat >> "$ADAPTERFILE" <<_END + +$pci +${tmp##*: } + +_END + fi done -for pci in `lspci |awk '/Mellanox/ {print $1}' `; do +for pci in $(lspci |awk '/Mellanox/ {print $1}'); do if ! grep -q "$pci" "$ADAPTERFILE" 2>/dev/null; then - tmp=`lspci |grep "$pci"` - echo '' >> "$ADAPTERFILE" - echo "$pci" >> "$ADAPTERFILE" - echo "${tmp##*: }" >> "$ADAPTERFILE" - echo '' >> "$ADAPTERFILE" - fi + tmp="$(lspci |grep "$pci")" + cat >> "$ADAPTERFILE" <<_END + +$pci +${tmp##*: } + +_END + fi done echo "" >> "$ADAPTERFILE" -#cat "$ADAPTERFILE" - +if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then # use client cert if available + SSL_CERT_OPTS=( -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem ) +fi if [ -n "$XCATMASTER" ]; then - if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available - echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $XCATMASTER" >> "$SCANNICLOG" - openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATMASTER:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1 - else - echo "transmit scan result without customer certificate to $XCATMASTER" >> "$SCANNICLOG" - openssl s_client -connect $XCATMASTER:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1 - fi + TARGET="$XCATMASTER" else - dhcps=`awk -F ' |;' '/dhcp-server/ { print $(NF-1) }' /var/lib/dhclient/dhclient.leases | tail -n 1` - if [ -n "$dhcps" ]; then - if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available - echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $dhcps" >> "$SCANNICLOG" - openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $dhcps:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1 - else - echo "transmit scan result without customer certificate to $dhcps" >> "$SCANNICLOG" - openssl s_client -connect $dhcps:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1 - fi + TARGET="$(awk -F ' |;' '/dhcp-server/ { print $(NF-1) }' /var/lib/dhclient/dhclient.leases | tail -n 1)" +fi +if [ -n "$TARGET" ]; then + if [[ "${#SSL_CERT_OPTS[@]}" -gt 0 ]]; then # using client cert + echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $TARGET" >> "$SCANNICLOG" + else + echo "transmit scan result without client certificate to $TARGET" >> "$SCANNICLOG" fi + openssl s_client "${SSL_CERT_OPTS[@]}" -connect "$TARGET:$XCATPORT" <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1 fi diff --git a/xCAT-genesis-scripts/usr/bin/getcert b/xCAT-genesis-scripts/usr/bin/getcert index 5cb40906d3..f3f6707836 100755 --- a/xCAT-genesis-scripts/usr/bin/getcert +++ b/xCAT-genesis-scripts/usr/bin/getcert @@ -5,37 +5,37 @@ if [ -z "$XCATDEST" ]; then XCATDEST=$1 fi #retry in case certkey.pem is not right, yet -while ! openssl req -new -key /etc/xcat/certkey.pem -out /tmp/tls.csr -subj "/CN=`hostname`" >& /dev/null; do +while ! openssl req -new -key /etc/xcat/certkey.pem -out /tmp/tls.csr -subj "/CN=$(hostname)" >& /dev/null; do sleep 1 done -echo " -getcredentials -x509cert -300 -" > /tmp/certreq.xml -cat /tmp/tls.csr >> /tmp/certreq.xml -echo " - - -" >> /tmp/certreq.xml +{ + cat <<__HEAD + + getcredentials + x509cert + 300 + +__HEAD + cat /tmp/tls.csr + cat <<__FOOT + + + + +__FOOT +} > /tmp/certreq.xml openssl dgst -sha512 -out /tmp/certreq.sha512 -sign /etc/xcat/privkey.pem /tmp/certreq.xml #chain off the switch published key openssl enc -e -a -in /tmp/certreq.sha512 > /tmp/certreq.b64sig -cat /tmp/certreq.xml |while read line; do - if [ "$line" = "" ]; then - cat /tmp/certreq.b64sig >> /tmp/certreq.xml.new - fi - echo $line >> /tmp/certreq.xml.new -done -mv /tmp/certreq.xml.new /tmp/certreq.xml -rm /tmp/certreq.b64sig /tmp/certreq.sha512 -cat /tmp/certreq.xml | openssl s_client -connect $XCATDEST -quiet 2> /dev/null > /tmp/certresp.xml -if grep 'BEGIN CERTIFICATE' /tmp/certresp.xml > /dev/null; then - awk '/BEGIN CERTIFICATE/,/END CERTIFICATE/' < /tmp/certresp.xml > /etc/xcat/cert.pem - #stop transmitting sysDesc, allowing the public key to age out of validity - for iface in `grep '^ e' /var/lib/lldpad/lldpad.conf|awk '{print $1}' `; do - lldptool -T -i $iface -V sysDesc enableTx=no >& /dev/null - done +sed -i "/^$/ r /tmp/certreq.b64sig" /tmp/certreq.xml +openssl s_client -connect "$XCATDEST" -quiet /dev/null >/tmp/certresp.xml +if grep -q 'BEGIN CERTIFICATE' /tmp/certresp.xml ; then + awk '/BEGIN CERTIFICATE/,/END CERTIFICATE/' < /tmp/certresp.xml > /etc/xcat/cert.pem + #stop transmitting sysDesc, allowing the public key to age out of validity + while read -r iface ; do + lldptool -T -i "$iface" -V sysDesc enableTx=no >& /dev/null + done < <(awk '/^ e/{print $1}' /var/lib/lldpad/lldpad.conf) fi +rm /tmp/certreq.b64sig /tmp/certreq.sha512 rm /tmp/certreq.xml rm /tmp/certresp.xml -kill $CREDPID +kill "$CREDPID" diff --git a/xCAT-genesis-scripts/usr/bin/getdestiny b/xCAT-genesis-scripts/usr/bin/getdestiny index 15cfc1baa5..96a89b28d2 100755 --- a/xCAT-genesis-scripts/usr/bin/getdestiny +++ b/xCAT-genesis-scripts/usr/bin/getdestiny @@ -1,30 +1,27 @@ #!/bin/bash if [ -z "$XCATDEST" ]; then - XCATDEST=$1 + XCATDEST="$1" fi echo " getdestiny 300 " > /tmp/destreq.xml if [ -f /tmp/destiny.xml ]; then rm /tmp/destiny.xml; fi -while [ ! -f /tmp/destiny.xml ] || grep error /tmp/destiny.xml; do - if [ -f /tmp/destiny.xml ]; then - timer=60 - while [ $timer -gt 0 ]; do - echo -en "Retrying in $timer seconds \r" >&2 - sleep 1 - timer=$(($timer-1)); - done - fi - echo " " >&2 - if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available - cat /tmp/destreq.xml | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATDEST -quiet 2> /dev/null > /tmp/destiny.xml - else - cat /tmp/destreq.xml | openssl s_client -connect $XCATDEST -quiet 2> /dev/null > /tmp/destiny.xml - fi +while [[ ! -f /tmp/destiny.xml ]] || grep error /tmp/destiny.xml; do + if [[ -f /tmp/destiny.xml ]]; then + for ((timer=60; timer>0; --timer)); do + echo -en "Retrying in $timer seconds \r" >&2 + sleep 1 + done + fi + echo " " >&2 + if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available + SSL_CERT_OPTS=( -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem ) + fi + openssl s_client "${SSL_CERT_OPTS[@]}" -connect "$XCATDEST" -quiet /dev/null > /tmp/destiny.xml done rm /tmp/destreq.xml -DESTINY=`grep '' /tmp/destiny.xml | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'` +DESTINY="$(awk -F'>' '//{print $2}' /tmp/destiny.xml|awk -F'<' '{print $1}')" rm /tmp/destiny.xml -echo $DESTINY +echo "$DESTINY" diff --git a/xCAT-genesis-scripts/usr/bin/getipmi b/xCAT-genesis-scripts/usr/bin/getipmi index fab0abb544..9b7a51bedd 100755 --- a/xCAT-genesis-scripts/usr/bin/getipmi +++ b/xCAT-genesis-scripts/usr/bin/getipmi @@ -10,11 +10,7 @@ fi # This section only works in genesis if [ -z "$XCATDEST" ]; then - for parm in `cat /proc/cmdline` ; do - if echo $parm |grep xcatd= > /dev/null; then - XCATDEST=`echo $parm |awk -F= '{print $2}'` - fi - done + read -r XCATDEST < <(grep xcatd= /proc/cmdline| sed 's/.*xcatd=\([^ ]*\).*/\1/') fi # This section works in diskless/diskful # The environment MASTER_IP and XCATDPORT is exported by mypostscript @@ -27,10 +23,10 @@ for LANCHAN in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do then break; fi; done -BMCMAC=`ipmitool lan print $LANCHAN|grep ^MAC|awk '{print $4}'` #bmcconfig may opt to use DHCP, if so we need to feed up the mac address +BMCMAC=$(ipmitool lan print $LANCHAN | awk '/^MAC/{print $4}') #bmcconfig may opt to use DHCP, if so we need to feed up the mac address #TODO: need a way to get the DUID the service processor may use, perhaps reserve that for 'ibmsetup' since spec doesn't touch ipv6? -IPMIMFG=`ipmitool mc info |grep "^Manufacturer ID"|awk '{print $4}'` -XPROD=`ipmitool mc info | grep "^Product ID"|awk '{print $4}'` +IPMIMFG=$(ipmitool mc info | awk '/^Manufacturer ID/{print $4}') +XPROD=$(ipmitool mc info | awk '/^Product ID/{print $4}') if [ "$IPMIMFG" == "42817" -a "$XPROD" == "16975" ]; then ISOPENBMC=1 else @@ -45,20 +41,17 @@ echo " rm -f /tmp/ipmicfg.xml while [ ! -f /tmp/ipmicfg.xml ] || grep error /tmp/ipmicfg.xml; do if [ -f /tmp/ipmicfg.xml ]; then - timer=60 - while [ $timer -gt 0 ]; do + for ((timer=60; timer > 0; --timer)); do sleep 1 echo -en "Retrying in $timer seconds \r" - timer=$(($timer-1)); done fi echo -en " \r"; if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available - cat /tmp/bmcreq.xml | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATDEST -quiet 2> /dev/null > /tmp/ipmicfg.xml - else - cat /tmp/bmcreq.xml | openssl s_client -connect $XCATDEST -quiet 2> /dev/null > /tmp/ipmicfg.xml + SSL_CERT_OPTS=( -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem ) fi + openssl s_client "${SSL_CERT_OPTS[@]}" -connect "$XCATDEST" -quiet /dev/null >/tmp/ipmicfg.xml done rm /tmp/bmcreq.xml -kill $CREDPID +kill "$CREDPID" diff --git a/xCAT-genesis-scripts/usr/bin/ifup b/xCAT-genesis-scripts/usr/bin/ifup index e5d7491e52..6a74b84db4 100755 --- a/xCAT-genesis-scripts/usr/bin/ifup +++ b/xCAT-genesis-scripts/usr/bin/ifup @@ -1,3 +1,4 @@ +#!/bin/bash if [ "${1%?}" = "usb" ]; then /sbin/setupimmnic fi diff --git a/xCAT-genesis-scripts/usr/bin/nextdestiny b/xCAT-genesis-scripts/usr/bin/nextdestiny index 086951c98c..d347edee37 100755 --- a/xCAT-genesis-scripts/usr/bin/nextdestiny +++ b/xCAT-genesis-scripts/usr/bin/nextdestiny @@ -1,6 +1,6 @@ #!/bin/bash if [ -z "$XCATDEST" ]; then - XCATDEST=$1 + XCATDEST=$1 fi echo " nextdestiny @@ -9,28 +9,22 @@ echo " if [ -f /tmp/destiny.xml ]; then rm /tmp/destiny.xml; fi timer=0 while [ ! -f /tmp/destiny.xml ]; do - while [ $timer -gt 0 ]; do - echo -en "No destiny command received, retrying in $timer seconds \r" >&2 - sleep 1 - timer=$(($timer-1)); - done - echo " " >&2; - if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available - cat /tmp/destreq.xml | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATDEST -quiet 2> /dev/null > /tmp/destiny.xml - else - cat /tmp/destreq.xml | openssl s_client -connect $XCATDEST -quiet 2> /dev/null > /tmp/destiny.xml - fi - timer=60 + for((; timer>0; --timer)); do + echo -en "No destiny command received, retrying in $timer seconds \r" >&2 + sleep 1 + done + echo " " >&2; + if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available + SSL_CERT_OPTS=( -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem ) + fi + openssl s_client "${SSL_CERT_OPTS[@]}" -connect "$XCATDEST" -quiet /dev/null >/tmp/destiny.xml + timer=60 done rm /tmp/destreq.xml -DESTINY=`grep '' /tmp/destiny.xml | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'` +DESTINY="$(awk -F'>' '//{print $2}' /tmp/destiny.xml | awk -F'<' '{print $1}')" if [ -z "$DESTINY" ]; then - ERROR=`grep '' /tmp/destiny.xml | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'` - if [ ! -z "$ERROR" ]; then - DESTINY="error=$ERROR" - else - DESTINY="error=No destiny command received" - fi + ERROR="$(awk -F'>' '//{print $2}' /tmp/destiny.xml |awk -F'<' '{print $1}')" + DESTINY="error=${ERROR:-No destiny command received}" fi rm /tmp/destiny.xml -echo $DESTINY +echo "$DESTINY" diff --git a/xCAT-genesis-scripts/usr/bin/raidcmd b/xCAT-genesis-scripts/usr/bin/raidcmd index 266c65727e..fb0a982b85 100755 --- a/xCAT-genesis-scripts/usr/bin/raidcmd +++ b/xCAT-genesis-scripts/usr/bin/raidcmd @@ -11,7 +11,7 @@ iprconfig="iprconfig" ######################################## function cmd_show_config { local lines="" - lines=`$iprconfig -c show-config` + lines="$($iprconfig -c show-config)" echo "$lines" } @@ -22,7 +22,7 @@ function cmd_show_config { ######################################## function cmd_show_ioas { local lines="" - lines=`$iprconfig -c show-ioas` + lines="$($iprconfig -c show-ioas)" echo "$lines" } @@ -34,7 +34,7 @@ function cmd_show_ioas { function cmd_show_details { local lines="" local dev=$* - lines=`$iprconfig -c show-details $dev` + lines="$($iprconfig -c show-details "$dev")" echo "$lines" } @@ -45,7 +45,7 @@ function cmd_show_details { ######################################## function cmd_show_arrays { local lines="" - lines=`$iprconfig -c show-arrays` + lines="$($iprconfig -c show-arrays)" echo "$lines" } @@ -60,7 +60,7 @@ function cmd_show_arrays { function is_array { local lines="" local dev=$* - lines=`$iprconfig -c show-details $dev | grep -sq "RAID Level"` + lines="$($iprconfig -c show-details "$dev" | grep -sq "RAID Level")" echo "$?" } @@ -72,7 +72,7 @@ function is_array { function cmd_alt_status { local lines="" local dev=$* - lines=`$iprconfig -c alt-status $dev` + lines="$($iprconfig -c alt-status "$dev")" echo "$lines" } @@ -84,7 +84,7 @@ function cmd_alt_status { function cmd_show_status { local lines="" local dev=$* - lines=`$iprconfig -c status $dev` + lines="$($iprconfig -c status "$dev")" echo "$lines" } @@ -96,7 +96,7 @@ function cmd_show_status { function cmd_show_alt_config { local lines="" local dev=$* - lines=`$iprconfig -c show-alt-config` + lines=$"($iprconfig -c show-alt-config)" echo "$lines" } @@ -108,7 +108,7 @@ function cmd_show_alt_config { function cmd_query_raid_delete { local lines="" local ioa=$* - lines=`$iprconfig -c query-raid-delete $ioa` + lines="$($iprconfig -c query-raid-delete "$ioa")" echo "$lines" } @@ -120,7 +120,7 @@ function cmd_query_raid_delete { function cmd__raid_delete { local lines="" local array=$* - lines=`$iprconfig -c raid-delete "$array"` + lines="$($iprconfig -c raid-delete "$array")" } ################################################################## @@ -131,6 +131,6 @@ function cmd__raid_delete { function cmd_raid_create { local iprconfig_args=$1 local member_sgs=$2 - lines=`$iprconfig -c raid-create $iprconfig_args $member_sgs` + lines="$($iprconfig -c raid-create "$iprconfig_args" "$member_sgs")" } diff --git a/xCAT-genesis-scripts/usr/bin/remoteimmsetup b/xCAT-genesis-scripts/usr/bin/remoteimmsetup index 027797e5cc..b3ee0bbfe9 100755 --- a/xCAT-genesis-scripts/usr/bin/remoteimmsetup +++ b/xCAT-genesis-scripts/usr/bin/remoteimmsetup @@ -4,18 +4,14 @@ if [ -z "$XCATDEST" ]; then XCATDEST=$1 fi if [ -z "$XCATDEST" ]; then - for parm in `cat /proc/cmdline` ; do - if echo $parm |grep xcatd= > /dev/null; then - XCATDEST=`echo $parm |awk -F= '{print $2}'` - fi - done + read -r XCATDEST < <(grep xcatd= /proc/cmdline| sed 's/.*xcatd=\([^ ]*\).*/\1/') fi for LANCHAN in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do if ipmitool channel info $LANCHAN 2> /dev/null | grep 802.3 > /dev/null 2>&1 && ipmitool raw 0xc 2 $LANCHAN 5 0 0 > /dev/null 2>&1; then break; fi; done -BMCMAC=`ipmitool lan print $LANCHAN|grep ^MAC|awk '{print $4}'` #bmcconfig may opt to use DHCP, if so we need to feed up the mac address +BMCMAC="$(ipmitool lan print $LANCHAN | awk '/^MAC/{print $4}')" #bmcconfig may opt to use DHCP, if so we need to feed up the mac address #TODO: need a way to get the DUID the service processor may use, perhaps reserve that for 'ibmsetup' since spec doesn't touch ipv6? echo " @@ -25,19 +21,16 @@ echo " rm /tmp/remsetup.xml while [ ! -f /tmp/remsetup.xml ] || grep error /tmp/remsetup.xml; do if [ -f /tmp/remsetup.xml ]; then - timer=60 - while [ $timer -gt 0 ]; do + for ((timer=60; timer > 0; --timer)); do sleep 1 echo -en "Retrying in $timer seconds \r" - timer=$(($timer-1)); done fi echo -en " \r"; if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available - cat /tmp/bmcreq.xml | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATDEST -quiet 2> /dev/null > /tmp/remsetup.xml - else - cat /tmp/bmcreq.xml | openssl s_client -connect $XCATDEST -quiet 2> /dev/null > /tmp/remsetup.xml + SSL_CERT_OPTS=( -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem ) fi + openssl s_client "${SSL_CERT_OPTS[@]}" -connect "$XCATDEST" -quiet /dev/null >/tmp/remsetup.xml done rm /tmp/bmcreq.xml diff --git a/xCAT-genesis-scripts/usr/bin/restart b/xCAT-genesis-scripts/usr/bin/restart index bb1ef0c84b..cf5ab783df 100755 --- a/xCAT-genesis-scripts/usr/bin/restart +++ b/xCAT-genesis-scripts/usr/bin/restart @@ -1,40 +1,41 @@ +#!/bin/bash # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html #Redhcp, do the xcat part again -FORCENICS=`cat /restart|awk '{print $2}'` +FORCENICS="$(awk '{print $2}' /restart)" rm /restart if [ ! -z "$FORCENICS" ]; then echo "Forcing down nics aside from $FORCENICS due to discoverynics setting" for pidfile in /var/run/dhclient.*.pid; do - NIC=`echo $pidfile|awk -F. '{print $2}'` - if [ ! -z "$NIC" ] && echo $NIC | egrep -v "$FORCENICS"; then - dhclient -r -1 -cf /etc/dhclient.conf -pf $pidfile $NIC - rm $pidfile - ip link set $NIC down + NIC="$(echo "$pidfile"|awk -F. '{print $2}')" + if [ ! -z "$NIC" ] && echo "$NIC" | egrep -v "$FORCENICS"; then + dhclient -r -1 -cf /etc/dhclient.conf -pf "$pidfile" "$NIC" + rm "$pidfile" + ip link set "$NIC" down fi done for pidfile in /var/run/dhclient6.*.pid; do - NIC=`echo $pidfile|awk -F. '{print $2}'` - if [ ! -z "$NIC" ] && echo $NIC | egrep -v "$FORCENICS"; then - dhclient -6 -r -1 -pf $pidfile -lf /var/lib/dhclient/dhclient6.leases $NIC - rm $pidfile - ip link set $NIC down + NIC="$(echo "$pidfile"|awk -F. '{print $2}')" + if [ ! -z "$NIC" ] && echo "$NIC" | egrep -v "$FORCENICS"; then + dhclient -6 -r -1 -pf "$pidfile" -lf /var/lib/dhclient/dhclient6.leases "$NIC" + rm "$pidfile" + ip link set "$NIC" down fi done fi WAITING=1 while [ $WAITING -gt 0 ]; do for pidfile in /var/run/dhclient.*.pid; do - NIC=`echo $pidfile|awk -F. '{print $2}'` - dhclient -r -1 -cf /etc/dhclient.conf -pf $pidfile $NIC - ip -4 addr flush dev $NIC - dhclient -cf /etc/dhclient.conf -nw -pf $pidfile $NIC + NIC="$(echo "$pidfile"|awk -F. '{print $2}')" + dhclient -r -1 -cf /etc/dhclient.conf -pf "$pidfile" "$NIC" + ip -4 addr flush dev "$NIC" + dhclient -cf /etc/dhclient.conf -nw -pf "$pidfile" "$NIC" done for pidfile in /var/run/dhclient6.*.pid; do - NIC=`echo $pidfile|awk -F. '{print $2}'` - dhclient -6 -r -1 -pf $pidfile -lf /var/lib/dhclient/dhclient6.leases $NIC - ip -6 addr flush dev $NIC scope global - ip -6 addr flush dev $NIC scope site - dhclient -6 -pf $pidfile -nw -lf /var/lib/dhclient/dhclient6.leases $NIC + NIC="$(echo "$pidfile"|awk -F. '{print $2}')" + dhclient -6 -r -1 -pf "$pidfile" -lf /var/lib/dhclient/dhclient6.leases "$NIC" + ip -6 addr flush dev "$NIC" scope global + ip -6 addr flush dev "$NIC" scope site + dhclient -6 -pf "$pidfile" -nw -lf /var/lib/dhclient/dhclient6.leases "$NIC" done echo -en "Waiting 10 seconds for DHCP changes to take effect \r" @@ -44,10 +45,10 @@ while [ $WAITING -gt 0 ]; do done # restart rsyslog after dhclient - kill -9 `cat /var/run/syslogd.pid` + kill -9 $(cat /var/run/syslogd.pid) sleep 3 - RSYSLOGD_VERSION=`rsyslogd -v | grep "rsyslogd" | cut -d" " -f2 | cut -d"." -f1` - if [ $RSYSLOGD_VERSION -ge 8 ]; then + RSYSLOGD_VERSION="$(rsyslogd -v | awk "/rsyslogd/{print $2}" | cut -d"." -f1)" + if [ "$RSYSLOGD_VERSION" -ge 8 ]; then # Newer versions of rsyslogd do not support -c flag anymore /sbin/rsyslogd else @@ -57,9 +58,9 @@ while [ $WAITING -gt 0 ]; do WAITING=0 if [ ! -z "$FORCENICS" ]; then #for nic in `ifconfig|grep HWaddr|awk '{print $1}'|egrep "$FORCENICS"`; do - for nic in `ip -oneline link show |grep -i ether |awk -F ':' '{print $2}'|grep -o "[^ ]\+\( \+[^ ]\+\)*"|egrep "$FORCENICS"`; do + for nic in $(ip -oneline link show |awk -v 'IGNORECASE=1' -F ':' '/ether/{print $2}'|grep -o "[^ ]\+\( \+[^ ]\+\)*"|egrep "$FORCENICS"); do # if ! ifconfig $nic|grep "inet addr" > /dev/null; then - if ! ip -4 -oneline addr show $nic|grep -i inet > /dev/null; then + if ! ip -4 -oneline addr show "$nic"|grep -iq inet; then WAITING=1 fi done @@ -68,7 +69,7 @@ while [ $WAITING -gt 0 ]; do while [ $delay -gt 0 ]; do echo -en "Not all of the nics $FORCENICS managed to acquire an address, retrying in $delay seconds... \r" done - echo " \r" + echo -en " \r" fi fi done