-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shellcheck improvements for genesis-scripts #4923
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/bin/bash | ||
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html | ||
# Lenovo (c) 2016 | ||
# | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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..." | ||
|
@@ -90,36 +89,28 @@ if [ -r /sys/devices/virtual/dmi/id/product_name ]; then #x86 | |
IAMAVM=1 | ||
MTM=VMware | ||
else | ||
MTM=`cat /sys/devices/virtual/dmi/id/product_name|awk -F'[' '{print $2}'|awk -F']' '{print $1}'` | ||
MTM="$(awk -F'[' '{print $2}' /sys/devices/virtual/dmi/id/product_name |awk -F']' '{print $1}')" | ||
if [ -z "$MTM" ]; then | ||
FRU=`ipmitool fru print 0` | ||
if [ $? -eq 0 ]; then | ||
MTM=`echo "$FRU" | awk -F': ' '/Product Manufacturer/ {m=$2} /Product Name|Product Part Number/ {if (n==""||n=="NONE") {n=$2}} END {print m":"n}'` | ||
MTM="$(echo "$FRU" | awk -F': ' '/Product Manufacturer/ {m=$2} /Product Name|Product Part Number/ {if (n==""||n=="NONE") {n=$2}} END {print m":"n}')" | ||
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 | ||
SERIAL=`cat /sys/devices/virtual/dmi/id/product_serial` | ||
fi | ||
CPUCOUNT=`cat /proc/cpuinfo |grep "model name"|wc -l` | ||
grep "model name" /proc/cpuinfo | while read line; do #to avoid pulling in tail, we do a goofy thing | ||
echo $line > /tmp/cpumod | ||
done | ||
CPUTYPE=`cat /tmp/cpumod|awk -F':' '{print $2}'|sed -e 's/^ //'` | ||
read -r CPUCOUNT CPUTYPE < <(awk -F: 'BEGIN{c=0; n=""} /model name/{c=c+1; n=$2} END{printf "%d %s",c,n}' /proc/cpuinfo) | ||
UUID=`sed -e 's/\(..\)\(..\)\(..\)\(..\)-\(..\)\(..\)-\(..\)\(..\)/\4\3\2\1-\6\5-\8\7/' /sys/devices/virtual/dmi/id/product_uuid` | ||
|
||
elif [ -r /proc/device-tree/model ]; then #POWER | ||
MTM=`cat /proc/device-tree/model -vT | sed -e 's/^.*,//' | sed -e 's/^[\t ]*//'| sed -e 's/[\t ]*\^@//'` | ||
CPUCOUNT=`cat /proc/cpuinfo |grep -e "^cpu\s*:"|wc -l` | ||
PLATFORM=`cat /proc/cpuinfo | grep -e "^platform\s*:" | awk '{print \$3}'` | ||
grep -e "^cpu\s*:" /proc/cpuinfo | while read line; do #to avoid pulling in tail, we do a goofy thing | ||
echo $line > /tmp/cpumod | ||
done | ||
CPUTYPE=`cat /tmp/cpumod|awk -F':' '{print $2}'|sed -e 's/^ //'` | ||
PLATFORM="$(awk '/^platform\s*:/{print $3}' /proc/cpuinfo)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, the file,
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @neo954 Can you confirm the output expected from the old code. I get
|
||
read CPUCOUNT CPUTYPE < <(awk -F':' 'BEGIN{c=0; n=""} /^cpu\s*:/{c=c+1; n=$2} END{printf "%d %s",c,n}' /proc/cpuinfo) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not going to work. Please see my test results below. On ppc64le RHEL 7.4
On ppc64 RHEL 7.4
On x86-64 RHEL 7.4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @neo954 Can you give me the output of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, the file,
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @neo954 Can you confirm the value of
|
||
SERIAL=`cat /proc/device-tree/system-id -vT | sed -e 's/^.*,//' | sed -e 's/^[\t ]*//'| sed -e 's/[\t ]*\^@//'` | ||
# For POWER servers, the /proc/sys/kernel/random/uuid is changing for each query, so use mtms + mac of first up nic as the UUID | ||
#UUID=`sed -e 's/\(..\)\(..\)\(..\)\(..\)-\(..\)\(..\)-\(..\)\(..\)/\4\3\2\1-\6\5-\8\7/' /proc/sys/kernel/random/uuid` | ||
|
@@ -128,36 +119,35 @@ 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=","}')" | ||
|
||
logger -s -t $log_label -p local4.info "Beginning echo information to discovery packet file..." | ||
echo '<xcatrequest>' > /tmp/discopacket | ||
echo "<command>findme</command>" >> /tmp/discopacket | ||
echo "<sequential>1</sequential>" >> /tmp/discopacket | ||
echo "<arch>$ARCH</arch>" >> /tmp/discopacket | ||
echo "<xcatrequest> | ||
<command>findme</command> | ||
<sequential>1</sequential> | ||
<arch>$ARCH</arch>" >/tmp/discopacket | ||
if [ "$IAMAVM" = 1 ]; then | ||
echo "<nodetype>virtual</nodetype>" >> /tmp/discopacket | ||
fi | ||
echo "<cpucount>$CPUCOUNT</cpucount>" >> /tmp/discopacket | ||
echo "<cputype>$CPUTYPE</cputype>" >> /tmp/discopacket | ||
echo "<memory>$MEMORY</memory>" >> /tmp/discopacket | ||
echo "<disksize>$DISKSIZE</disksize>" >> /tmp/discopacket | ||
echo "<cpucount>$CPUCOUNT</cpucount> | ||
<cputype>$CPUTYPE</cputype> | ||
<memory>$MEMORY</memory> | ||
<disksize>$DISKSIZE</disksize>" >>/tmp/discopacket | ||
if [ "$UUID" != "unknown" ]; then | ||
echo "<uuid>$UUID</uuid>" >> /tmp/discopacket | ||
fi | ||
|
||
flag_mtm=`echo "$MTM" | sed 's/0//g'` | ||
flag_mtm="${MTM//0}" | ||
if [ "$flag_mtm" ] && [ "$MTM" != "unknown" ]; then | ||
MTM=`echo $MTM | sed 's/\.//g'` | ||
echo "<mtm>$MTM</mtm>" >> /tmp/discopacket | ||
fi | ||
flag_serial=`echo "$SERIAL" | sed 's/0//g'` | ||
flag_serial="${SERIAL//0}" | ||
if [ "$flag_serial" ] && [ "$SERIAL" != "unknown" ]; then | ||
SERIAL=`echo $SERIAL | sed 's/\.//g'` | ||
echo "<serial>$SERIAL</serial>" >> /tmp/discopacket | ||
echo "<serial>${SERIAL//.}</serial>" >> /tmp/discopacket | ||
fi | ||
if [ "$PLATFORM" != "unknown" ]; then | ||
echo "<platform>$PLATFORM</platform>" >> /tmp/discopacket | ||
|
@@ -191,7 +181,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 | ||
|
@@ -208,7 +198,7 @@ for dev in `ip link|grep -B1 ether|grep UP|awk '{print $2}'|sed -e s/://|grep -v | |
ADDRESS=`ip -4 -o a show dev $dev|awk '/global/{print $4}'` | ||
MAC=`ip link show dev $dev|grep ether|awk '{print $2}'| tr /a-f/ /A-F/` | ||
if [ "$MAC_OF_FIRST_UP_NIC" == "unknown" ]; then | ||
MAC_OF_FIRST_UP_NIC=`echo $MAC | sed -e s/://g` | ||
MAC_OF_FIRST_UP_NIC=${MAC//:} | ||
fi | ||
if [[ ! -z "$PCI_SLOT" && -f "/usr/sbin/dmidecode" ]]; then | ||
SLOTNAME=`dmidecode -t 9|egrep '(Designation|Address)'|grep -B1 $PCI_SLOT|grep Designation|sed -e 's/.*Designation:[ ]*//'` | ||
|
@@ -231,26 +221,16 @@ for dev in `ip link|grep -B1 ether|grep UP|awk '{print $2}'|sed -e s/://|grep -v | |
fi | ||
fi | ||
fi | ||
echo "<mac>$DRIVER|$dev|$MAC|$ADDRESS</mac>" >> /tmp/discopacket | ||
echo "<nic>" >> /tmp/discopacket | ||
echo " <devname>$dev</devname>" >> /tmp/discopacket | ||
echo " <driver>$DRIVER</driver>" >> /tmp/discopacket | ||
if [ ! -z "$ADDRESS" ]; then | ||
echo " <ip4address>$ADDRESS</ip4address>" >> /tmp/discopacket | ||
fi | ||
echo " <hwaddr>$MAC</hwaddr>" >> /tmp/discopacket | ||
if [ ! -z "$PCI_SLOT" ]; then | ||
echo " <pcidev>$PCI_SLOT</pcidev>" >> /tmp/discopacket | ||
fi | ||
if [ ! -z "$SLOTNAME" ]; then | ||
echo " <location>$SLOTNAME</location>" >> /tmp/discopacket | ||
fi | ||
if [ ! -z "$ONBOARDINDEX" ]; then | ||
echo " <onboardeth>$ONBOARDINDEX</onboardeth>" >> /tmp/discopacket | ||
fi | ||
if [ ! -z "$FIRMDESC" ]; then | ||
echo " <firmdesc>$FIRMDESC</firmdesc>" >> /tmp/discopacket | ||
fi | ||
echo "<mac>$DRIVER|$dev|$MAC|$ADDRESS</mac> | ||
<nic> | ||
<devname>$dev</devname> | ||
<driver>$DRIVER</driver> | ||
${ADDRESS:+ <ip4address>$ADDRESS</ip4address>} | ||
<hwaddr>$MAC</hwaddr> | ||
${PCI_SLOT:+ <pcidev>$PCI_SLOT</pcidev>} | ||
${SLOTNAME:+ <location>$SLOTNAME</location>} | ||
${ONBOARDINDEX:+ <onboardeth>$ONBOARDINDEX</onboardeth>} | ||
${FIRMDESC:+ <firmdesc>$FIRMDESC</firmdesc>}" >>/tmp/discopacket | ||
myswitch=`lldptool -n -i $dev -t -V sysName|grep -v 'System Name TLV'|sed -e 's/^ *//'` | ||
if [ ! -z "$myswitch" -a "$myswitch" != "Agent instance for device not found" ]; then | ||
echo " <switchname>$myswitch</switchname>" >> /tmp/discopacket | ||
|
@@ -271,32 +251,27 @@ 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 | ||
echo "<sha512sig>" >> /tmp/discopacket | ||
echo "</sha512sig>" >> /tmp/discopacket | ||
echo "</xcatrequest>" >> /tmp/discopacket | ||
#this is not secure to use by itself, switch sourced pubkey for security | ||
echo "<xcatpubkey>$PUBKEY</xcatpubkey> | ||
<sha512sig> | ||
</sha512sig> | ||
</xcatrequest>" >>/tmp/discopacket | ||
openssl dgst -sha512 -out /tmp/discopacket.sha512 -sign /etc/xcat/privkey.pem /tmp/discopacket | ||
openssl enc -e -a -in /tmp/discopacket.sha512 > /tmp/discopacket.b64sig | ||
cat /tmp/discopacket |while read line; do | ||
if [ "$line" = "</sha512sig>" ]; then | ||
cat /tmp/discopacket.b64sig >> /tmp/discopacket.new | ||
fi | ||
echo $line >> /tmp/discopacket.new | ||
done | ||
mv /tmp/discopacket.new /tmp/discopacket | ||
sed -i "/^<sha512sig>$/ r /tmp/discopacket.b64sig" /tmp/discopacket | ||
logger -s -t $log_label -p local4.info "Discovery packet file is ready." | ||
rm -f /tmp/discopacket.gz | ||
gzip -9 /tmp/discopacket | ||
if [ ! -z "$XCATMASTER" ]; then | ||
logger -s -t $log_label -p local4.info "Sending the discovery packet to xCAT ($XCATMASTER:$XCATPORT)..." | ||
(cat /tmp/discopacket.gz | udpcat.awk $XCATMASTER $XCATPORT ) & | ||
logger -s -t $log_label -p local4.info "Sending the discovery packet to xCAT ($XCATMASTER:$XCATPORT)..." | ||
(udpcat.awk $XCATMASTER $XCATPORT </tmp/discopacket.gz) & | ||
fi | ||
for dhcps in `grep dhcp-server /var/lib/dhclient/dhclient.leases|awk '{print $4}'|sed -s 's/;//'`; do | ||
logger -s -t $log_label -p local4.info "Sending the discovery packet to xCAT ($dhcps:$XCATPORT)..." | ||
(cat /tmp/discopacket.gz | udpcat.awk $dhcps $XCATPORT ) & | ||
logger -s -t $log_label -p local4.info "Sending the discovery packet to xCAT ($dhcps:$XCATPORT)..." | ||
(udpcat.awk $dhcps $XCATPORT </tmp/discopacket.gz) & | ||
done | ||
|
||
#record the time when the "findme request is sent to master" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/bin/bash | ||
# | ||
# 2013.02.07 Brian Elliott Finley <[email protected]> | ||
# - Added slash in front of "var" in the NICSTOBRINGUP dhclient section. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, the file,
/proc/cpuinfo
from a Power 8 test machine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neo954 Can you confirm the value of
CPUTYPE
with the old code against the above? I get the same value with old code as with new code for thecpuinfo
contents for P8 as above: