2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-05-17 11:54:16 +00:00

genesis-scripts: improve shell quoting and syntax hygiene

Replace backtick command substitutions with $(), quote variable
expansions to prevent word splitting, replace useless cat pipes with
redirections, use grep -q instead of redirecting to /dev/null, and use
bash parameter expansion for case conversion.

Based on the work from PR #6366, rebased and adapted to current master.
Shebangs already merged separately via df64bf8fe are excluded.

Co-Authored-By: Samveen <samveen@yahoo.com>
This commit is contained in:
Vinícius Ferrão
2026-05-07 18:17:00 -03:00
parent 96b0b0b551
commit e239e04843
11 changed files with 107 additions and 109 deletions
+4 -4
View File
@@ -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
+6 -7
View File
@@ -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 </sys/devices/virtual/dmi/id/sys_vendor
read -r n </sys/devices/virtual/dmi/id/product_name
MTM="$m:$n"
fi
fi
@@ -128,7 +127,7 @@ elif [ -r /proc/device-tree/model ]; then #POWER
fi
# The MEMORY will look like this: 32868920
MEMORY=`cat /proc/meminfo |grep MemTotal|awk '{printf "%.0fMB\n", $2/1024}'`
MEMORY="$(awk '/MemTotal/{printf "%.0fMB\n", $2/1024}' /proc/meminfo)"
# The DISKSIZE will look like this: sda:960GB,sdb:960GB,sdc:480GB,sdd:480GB (sorted by major,minor)
DISKSIZE="$(grep -v name /proc/partitions |sort -g -k 1,2 |awk 'BEGIN{sep=""} /[^0-9]$/{printf("%s%s:%.0fGB", sep, $4, $3/1024^2) ; sep=","}')"
@@ -191,7 +190,7 @@ if [ -f "/usr/sbin/dmidecode" ]; then
if [ ${onboard#*.} = 0 ]; then
truncslot=${onboard%.*}
for obslot in `grep $truncslot /sys/class/net/*/device/uevent|sed -e s/.*=//`; do
if ! dmidecode -t 41|grep $obslot > /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 "</nic>" >> /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>$UUID</uuid>" >> /tmp/discopacket
fi
echo "<xcatpubkey>$PUBKEY</xcatpubkey>" >> /tmp/discopacket #this is not secure to use by itself, switch sourced pubkey for security
+1 -1
View File
@@ -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
+30 -31
View File
@@ -1,5 +1,4 @@
#!/bin/bash
#set -x
XCATPORT=3001
export XCATPORT
@@ -18,35 +17,35 @@ echo "<xcatrequest>
<command>getadapter</command>
<action>update</action>" >> "$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 '<nic>' >> "$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 "<interface>$tmp</interface>" >> "$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 "<predictablename>$tmp</predictablename>" >> "$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 "<pcilocation>${tmp%/net*}</pcilocation>" >> "$ADAPTERFILE"
fi
echo "<mac>`cat /sys/class/net/$nic/address`</mac>" >> "$ADAPTERFILE"
tmp=`udevadm info /sys/class/net/"$nic" | grep ID_VENDOR_FROM_DATABASE | awk -F '=' '{print $2}' | tr -s "\n" "/" | sed "s/\/$//g"`
echo "<mac>$(cat "/sys/class/net/$nic/address")</mac>" >> "$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 "<vendor>$tmp</vendor>" >> "$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 "<model>$tmp</model>" >> "$ADAPTERFILE"
fi
tmp=`ip link show $nic`
tmp="$(ip link show "$nic")"
if [ -n "$tmp" ]; then
tmp=${tmp#*state }
echo "<linkstate>${tmp% mode*}</linkstate>" >> "$ADAPTERFILE"
@@ -55,34 +54,34 @@ 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 '<nic>' >> "$ADAPTERFILE"
echo "<pcilocation>$pci</pcilocation>" >> "$ADAPTERFILE"
echo "<model>${tmp##*:}</model>" >> "$ADAPTERFILE"
echo '</nic>' >> "$ADAPTERFILE"
fi
tmp="$(lspci |grep "$pci")"
echo "<nic>
<pcilocation>$pci</pcilocation>
<model>${tmp##*:}</model>
</nic>" >> "$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 '<nic>' >> "$ADAPTERFILE"
echo "<pcilocation>$pci</pcilocation>" >> "$ADAPTERFILE"
echo "<model>${tmp##*: }</model>" >> "$ADAPTERFILE"
echo '</nic>' >> "$ADAPTERFILE"
fi
tmp="$(lspci |grep "$pci")"
echo "<nic>
<pcilocation>$pci</pcilocation>
<model>${tmp##*: }</model>
</nic>" >> "$ADAPTERFILE"
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 '<nic>' >> "$ADAPTERFILE"
echo "<pcilocation>$pci</pcilocation>" >> "$ADAPTERFILE"
echo "<model>${tmp##*: }</model>" >> "$ADAPTERFILE"
echo '</nic>' >> "$ADAPTERFILE"
fi
tmp="$(lspci |grep "$pci")"
echo "<nic>
<pcilocation>$pci</pcilocation>
<model>${tmp##*: }</model>
</nic>" >> "$ADAPTERFILE"
fi
done
echo "</xcatrequest>" >> "$ADAPTERFILE"
@@ -98,7 +97,7 @@ if [ -n "$XCATMASTER" ]; then
openssl s_client -connect $XCATMASTER:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1
fi
else
dhcps=`awk -F ' |;' '/dhcp-server/ { print $(NF-1) }' /var/lib/dhclient/dhclient.leases | tail -n 1`
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"
+7 -7
View File
@@ -5,7 +5,7 @@ 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 "<xcatrequest>
@@ -20,20 +20,20 @@ echo "</csr>
</xcatrequest>" >> /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
while read -r line; do
if [ "$line" = "</sha512sig>" ]; then
cat /tmp/certreq.b64sig >> /tmp/certreq.xml.new
fi
echo $line >> /tmp/certreq.xml.new
done
echo "$line" >> /tmp/certreq.xml.new
done < /tmp/certreq.xml
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
openssl s_client -connect "$XCATDEST" -quiet 2> /dev/null < /tmp/certreq.xml > /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
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
fi
rm /tmp/certreq.xml
+4 -4
View File
@@ -18,13 +18,13 @@ while [ ! -f /tmp/destiny.xml ] || grep error /tmp/destiny.xml; do
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
openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect "$XCATDEST" -quiet 2> /dev/null < /tmp/destreq.xml > /tmp/destiny.xml
else
cat /tmp/destreq.xml | openssl s_client -connect $XCATDEST -quiet 2> /dev/null > /tmp/destiny.xml
openssl s_client -connect "$XCATDEST" -quiet 2> /dev/null < /tmp/destreq.xml > /tmp/destiny.xml
fi
done
rm /tmp/destreq.xml
DESTINY=`grep '<destiny>' /tmp/destiny.xml | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'`
DESTINY="$(grep '<destiny>' /tmp/destiny.xml | awk -F'>' '{print $2}'|awk -F'<' '{print $1}')"
rm /tmp/destiny.xml
echo $DESTINY
echo "$DESTINY"
+8 -8
View File
@@ -10,9 +10,9 @@ 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}'`
for parm in $(cat /proc/cmdline); do
if echo "$parm" |grep -q xcatd=; then
XCATDEST="$(echo "$parm" |awk -F= '{print $2}')"
fi
done
fi
@@ -27,10 +27,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"|grep ^MAC|awk '{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 |grep "^Manufacturer ID"|awk '{print $4}')"
XPROD="$(ipmitool mc info | grep "^Product ID"|awk '{print $4}')"
if [ "$IPMIMFG" == "42817" -a "$XPROD" == "16975" ]; then
ISOPENBMC=1 # AC922
elif [ "$IPMIMFG" == "42817" -a "$XPROD" == "1" ]; then
@@ -57,9 +57,9 @@ while [ ! -f /tmp/ipmicfg.xml ] || grep error /tmp/ipmicfg.xml; do
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
openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect "$XCATDEST" -quiet 2> /dev/null < /tmp/bmcreq.xml > /tmp/ipmicfg.xml
else
cat /tmp/bmcreq.xml | openssl s_client -connect $XCATDEST -quiet 2> /dev/null > /tmp/ipmicfg.xml
openssl s_client -connect "$XCATDEST" -quiet 2> /dev/null < /tmp/bmcreq.xml > /tmp/ipmicfg.xml
fi
done
rm /tmp/bmcreq.xml
+5 -5
View File
@@ -16,16 +16,16 @@ while [ ! -f /tmp/destiny.xml ]; do
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
openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect "$XCATDEST" -quiet 2> /dev/null < /tmp/destreq.xml > /tmp/destiny.xml
else
cat /tmp/destreq.xml | openssl s_client -connect $XCATDEST -quiet 2> /dev/null > /tmp/destiny.xml
openssl s_client -connect "$XCATDEST" -quiet 2> /dev/null < /tmp/destreq.xml > /tmp/destiny.xml
fi
timer=60
done
rm /tmp/destreq.xml
DESTINY=`grep '<destiny>' /tmp/destiny.xml | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'`
DESTINY="$(grep '<destiny>' /tmp/destiny.xml | awk -F'>' '{print $2}'|awk -F'<' '{print $1}')"
if [ -z "$DESTINY" ]; then
ERROR=`grep '<error>' /tmp/destiny.xml | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'`
ERROR="$(grep '<error>' /tmp/destiny.xml | awk -F'>' '{print $2}'|awk -F'<' '{print $1}')"
if [ ! -z "$ERROR" ]; then
DESTINY="error=$ERROR"
else
@@ -33,4 +33,4 @@ if [ -z "$DESTINY" ]; then
fi
fi
rm /tmp/destiny.xml
echo $DESTINY
echo "$DESTINY"
+11 -11
View File
@@ -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)"
}
+6 -6
View File
@@ -4,9 +4,9 @@ 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}'`
for parm in $(cat /proc/cmdline); do
if echo "$parm" |grep -q xcatd=; then
XCATDEST="$(echo "$parm" |awk -F= '{print $2}')"
fi
done
fi
@@ -15,7 +15,7 @@ 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"|grep ^MAC|awk '{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 "<xcatrequest>
@@ -35,9 +35,9 @@ while [ ! -f /tmp/remsetup.xml ] || grep error /tmp/remsetup.xml; do
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
openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect "$XCATDEST" -quiet 2> /dev/null < /tmp/bmcreq.xml > /tmp/remsetup.xml
else
cat /tmp/bmcreq.xml | openssl s_client -connect $XCATDEST -quiet 2> /dev/null > /tmp/remsetup.xml
openssl s_client -connect "$XCATDEST" -quiet 2> /dev/null < /tmp/bmcreq.xml > /tmp/remsetup.xml
fi
done
rm /tmp/bmcreq.xml
+25 -25
View File
@@ -1,41 +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 -qv "$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 -qv "$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"
@@ -46,14 +46,14 @@ while [ $WAITING -gt 0 ]; do
# restart rsyslog after dhclient
if [ -f /var/run/syslogd.pid ]; then
kill -TERM `cat /var/run/syslogd.pid`
kill -TERM "$(cat /var/run/syslogd.pid)"
fi
if [ -f /var/run/rsyslogd.pid ]; then
kill -TERM `cat /var/run/rsyslogd.pid`
kill -TERM "$(cat /var/run/rsyslogd.pid)"
fi
sleep 3
RSYSLOGD_VERSION=`rsyslogd -v | grep -m1 "rsyslogd" | tr -s ' ' | cut -d" " -f2 | cut -d"." -f1`
RSYSLOGD_VERSION="$(rsyslogd -v | grep -m1 "rsyslogd" | tr -s ' ' | cut -d" " -f2 | cut -d"." -f1)"
if [ $RSYSLOGD_VERSION -ge 8 ]; then
# Newer versions of rsyslogd do not support -c flag anymore
/sbin/rsyslogd
@@ -64,9 +64,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 |grep -i ether |awk -F ':' '{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 -qi inet; then
WAITING=1
fi
done