From 3b05e6d633737194b30027a2a25e388a049f240e Mon Sep 17 00:00:00 2001 From: Samveen Gulati Date: Tue, 3 Oct 2017 11:17:03 +0000 Subject: [PATCH 1/7] xHRM: modernize command substitution --- xCAT-server/share/xcat/scripts/xHRM | 56 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/xCAT-server/share/xcat/scripts/xHRM b/xCAT-server/share/xcat/scripts/xHRM index 9b8dc8576..5144e95e1 100755 --- a/xCAT-server/share/xcat/scripts/xHRM +++ b/xCAT-server/share/xcat/scripts/xHRM @@ -1,6 +1,6 @@ #!/bin/bash if [ "$(uname -s|tr 'A-Z' 'a-z')" = "linux" ];then - str_dir_name=`dirname $0` + str_dir_name=$(dirname $0) . $str_dir_name/xcatlib.sh fi #written in bash for fewest prerequisites @@ -9,17 +9,17 @@ function get_def_interface { #are in bash, the best alternative is to use ping to get at it #don't want to grep in /etc/hosts or presume DNS #we are, however, presuming ipv4 for the moment - retval=$(ping -c 1 `hostname`|head -n 1|cut -d\( -f 2|cut -d\) -f 1) + retval=$(ping -c 1 $(hostname)|head -n 1|cut -d\( -f 2|cut -d\) -f 1) if [ -z "$retval" -o "127.0.0.1" = "$retval" ]; then #ok, that didn't pan out, now we grab the first address that looks sane #retval=`ifconfig|grep inet" " |grep -v addr:127.0.0.1|grep -v 'addr:169.254'|head -n 1|cut -d: -f 2|cut -d' ' -f 1` - retval=`ip -4 -oneline addr show|grep -v "127.0.0.1"|grep -v '169.254'|head -n 1|awk -F 'inet ' '{print $2}'|awk -F '/' '{print $1}'` + retval=$(ip -4 -oneline addr show|grep -v "127.0.0.1"|grep -v '169.254'|head -n 1|awk -F 'inet ' '{print $2}'|awk -F '/' '{print $1}') fi if [ -z "$retval" ]; then echo "ERROR: Unable to reasonably guess the 'default' interface" >&2 exit 1 fi #iface=`ifconfig|grep -v inet6|egrep '(Link|inet)'|grep -B1 'addr:'$retval |head -n 1|awk '{print $1}'` - iface=`ip -4 -oneline addr show|grep -i $retval|awk -F ':' '{print $2}'|awk -F ' ' '{print $1}'|grep -o "[^ ]\+\( \+[^ ]\+\)*"` + iface=$(ip -4 -oneline addr show|grep -i $retval|awk -F ':' '{print $2}'|awk -F ' ' '{print $1}'|grep -o "[^ ]\+\( \+[^ ]\+\)*") if [ -z "$iface" ]; then echo "ERROR: Unable to reasonably guess the default interface" >&2 exit 1 @@ -36,8 +36,8 @@ function get_def_interface { INMATCH=0 fi if [ "$INMATCH" == 1 ]; then - if ! ethtool -i `echo $brline|awk '{print $NF}'`|grep "driver: tun" >& /dev/null; then - iface=`echo $brline|awk '{print $NF}'` + if ! ethtool -i $(echo $brline|awk '{print $NF}')|grep "driver: tun" >& /dev/null; then + iface=$(echo $brline|awk '{print $NF}') echo "$iface" IFS=$OFIS return @@ -60,7 +60,7 @@ function debianpreconf(){ mkdir -p "/etc/network/interfaces.d" fi #search xcat flag - XCATFLAG=`grep "#XCAT_CONFIG" /etc/network/interfaces` + XCATFLAG=$(grep "#XCAT_CONFIG" /etc/network/interfaces) if [ -n "$XCATFLAG" ];then return fi @@ -87,7 +87,7 @@ function debianpreconf(){ continue fi - CONFTYPE=`echo $LINE | cut -d" " -f1` + CONFTYPE=$(echo $LINE | cut -d" " -f1) if [ $CONFTYPE = 'auto' -o $CONFTYPE = 'allow-hotplug' ];then LINE=${LINE#$CONFTYPE} for NICNAME in $LINE; do @@ -95,7 +95,7 @@ function debianpreconf(){ done elif [ $CONFTYPE = 'iface' -o $CONFTYPE = 'mapping' ];then #find out the nic name, should think about the eth0:1 - NICNAME=`echo $LINE | cut -d" " -f 2 | cut -d":" -f 1` + NICNAME=$(echo $LINE | cut -d" " -f 2 | cut -d":" -f 1) CONFFILE="/etc/network/interfaces.d/$NICNAME" if [ ! -e $CONFFILE ];then echo "auto $NICNAME" > $CONFFILE @@ -112,8 +112,8 @@ function debianpreconf(){ if [ "storageprereq" = "$1" ]; then MOUNTURI="$2" - DIRNAME=`echo $MOUNTURI|sed -e 's!nfs://!nfs_!'` - MOUNTPATH=`echo $DIRNAME|sed -e 's!nfs_!!'|sed -e 's!/!:/!'` + DIRNAME=$(echo $MOUNTURI|sed -e 's!nfs://!nfs_!') + MOUNTPATH=$(echo $DIRNAME|sed -e 's!nfs_!!'|sed -e 's!/!:/!') if mount|grep $MOUNTPATH > /dev/null; then exit 0; fi @@ -141,7 +141,7 @@ elif [ "bridgeprereq" = "$1" ]; then fi if [[ "$INSPORT" =~ ^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$ ]] ; then - INSPORT=`ip -oneline link show|grep -i ether|grep -i $INSPORT |awk -F ':' '{print $2}'|grep -o "[^ ]\+\( \+[^ ]\+\)*"` + INSPORT=$(ip -oneline link show|grep -i ether|grep -i $INSPORT |awk -F ':' '{print $2}'|grep -o "[^ ]\+\( \+[^ ]\+\)*") fi if [ -z "$NETDESC" ]; then @@ -153,8 +153,8 @@ elif [ "bridgeprereq" = "$1" ]; then fi fi if echo "$NETDESC"|grep ':'> /dev/null; then - PORTS=`echo "$NETDESC"|cut -d: -f 1` - BNAME=`echo "$NETDESC"|cut -d: -f 2` + PORTS=$(echo "$NETDESC"|cut -d: -f 1) + BNAME=$(echo "$NETDESC"|cut -d: -f 2) else if [ -n "$INSTALLNIC" ]; then PORTS=$INSPORT @@ -181,7 +181,7 @@ elif [ "bridgeprereq" = "$1" ]; then fi #TO check whether the NIC had been attached to another bridge - bridgename=`brctl show |grep $PORTS` + bridgename=$(brctl show |grep $PORTS) if [ ! -z "$bridgename" ]; then echo "Device $PORTS is already a member of another bridge" exit 1 @@ -195,15 +195,15 @@ elif [ "bridgeprereq" = "$1" ]; then if echo "$PORTS"|grep '&'; then #we have bonding... fun to be had #To be slack, going to just support one bond for now.. modprobe bonding miimon=100 mode=4 - PORTS=`echo $PORTS |sed -e 's/&/ /'` + PORTS=$(echo $PORTS |sed -e 's/&/ /') ip link set bond0 up for p in $PORTS; do #TODO: we are only going to manage the default #route for now - saveroutes=`ip route | grep default| grep "dev $p"|grep via|sed -e 's/dev .*//'` + saveroutes=$(ip route | grep default| grep "dev $p"|grep via|sed -e 's/dev .*//') OIFS=$IFS IFS=$'\n' - saveip=`ip addr show dev $p scope global|grep inet|grep -v dynamic|sed -e 's/inet.//'|sed -e 's/[^ ]*$//'` + saveip=$(ip addr show dev $p scope global|grep inet|grep -v dynamic|sed -e 's/inet.//'|sed -e 's/[^ ]*$//') if [ ! -z "$saveip" ]; then for line in $saveip; do ip addr add dev bond0 $line @@ -235,14 +235,14 @@ elif [ "bridgeprereq" = "$1" ]; then brctl addbr $BNAME brctl setfd $BNAME 0 #fast forwarding ip link set $BNAME up - saveroutes=`ip route | grep default| grep "dev $PORTS"|grep via|sed -e 's/dev .*//'` + saveroutes=$(ip route | grep default| grep "dev $PORTS"|grep via|sed -e 's/dev .*//') OIFS=$IFS IFS=$'\n' - saveip=`ip addr show dev $PORTS scope global|grep inet|sed -e 's/inet.//'|sed -e 's/[^ ]*$//'` + saveip=$(ip addr show dev $PORTS scope global|grep inet|sed -e 's/inet.//'|sed -e 's/[^ ]*$//') if [ ! -z "$saveip" ]; then for line in $saveip; do IFS=$OIFS - newline=`echo $line|sed 's/dynamic//g'` + newline=$(echo $line|sed 's/dynamic//g') ip addr add dev $BNAME $newline done else @@ -256,7 +256,7 @@ elif [ "bridgeprereq" = "$1" ]; then IFS=$'\n' for line in $saveip; do IFS=$OIFS - newline=`echo $line|sed 's/dynamic//g'` + newline=$(echo $line|sed 's/dynamic//g') ip addr del dev $PORTS $newline done IFS=$OIFS @@ -289,7 +289,7 @@ DEVICE='$PORTS' ONBOOT='yes' BRIDGE='$BNAME' EOF - mac=`ip addr show dev $PORTS scope global|grep link|sed -e 's/link\/ether//'|sed -e 's/brd.*$//'|sed -e 's/[ ]*//'` + mac=$(ip addr show dev $PORTS scope global|grep link|sed -e 's/link\/ether//'|sed -e 's/brd.*$//'|sed -e 's/[ ]*//') if [ ! -z "$mac" ]; then echo "HWADDR='$mac'" >> $nwdir/ifcfg-$PORTS fi @@ -330,11 +330,11 @@ EOF echo " netmask 255.255.255.0" >> $nwdir/$BNAME fi else - my_subnet=`ip addr show dev $BNAME scope global|grep inet|grep -v dynamic|sed -e 's/inet.//'| awk '{print $1}'` + my_subnet=$(ip addr show dev $BNAME scope global|grep inet|grep -v dynamic|sed -e 's/inet.//'| awk '{print $1}') if [ ! -z "$my_subnet" ]; then - bridge_ip=`echo "$my_subnet"|cut -d\/ -f 1` - bridge_mask=`echo "$my_subnet"|cut -d\/ -f 2` - bridge_mask=`v4prefix2mask $bridge_mask` + bridge_ip=$(echo "$my_subnet"|cut -d\/ -f 1) + bridge_mask=$(echo "$my_subnet"|cut -d\/ -f 2) + bridge_mask=$(v4prefix2mask $bridge_mask) echo "iface $BNAME inet static" >> $nwdir/$BNAME echo " address $bridge_ip" >> $nwdir/$BNAME echo " netmask $bridge_mask" >> $nwdir/$BNAME @@ -352,7 +352,7 @@ DEVICE=$PORTS ONBOOT=yes BRIDGE=$BNAME EOF - mac=`ip addr show dev $PORTS scope global|grep link|sed -e 's/link\/ether//'|sed -e 's/brd.*$//'|sed -e 's/[ ]*//'` + mac=$(ip addr show dev $PORTS scope global|grep link|sed -e 's/link\/ether//'|sed -e 's/brd.*$//'|sed -e 's/[ ]*//') if [ ! -z "$mac" ]; then echo "HWADDR=$mac" >> $nwdir/ifcfg-$PORTS fi From 817009c21889ce70c792a71025f3f31ddd975143 Mon Sep 17 00:00:00 2001 From: Samveen Gulati Date: Fri, 27 Oct 2017 05:12:53 +0000 Subject: [PATCH 2/7] xHRM: improvments via ShellCheck --- xCAT-server/share/xcat/scripts/xHRM | 59 +++++++++++------------------ 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/xCAT-server/share/xcat/scripts/xHRM b/xCAT-server/share/xcat/scripts/xHRM index 5144e95e1..0485dae46 100755 --- a/xCAT-server/share/xcat/scripts/xHRM +++ b/xCAT-server/share/xcat/scripts/xHRM @@ -1,5 +1,5 @@ -#!/bin/bash -if [ "$(uname -s|tr 'A-Z' 'a-z')" = "linux" ];then +#!/bin/bash -u +if [ "$(uname -s|tr '[:upper:]' '[:lower:]')" = "linux" ];then str_dir_name=$(dirname $0) . $str_dir_name/xcatlib.sh fi @@ -9,7 +9,7 @@ function get_def_interface { #are in bash, the best alternative is to use ping to get at it #don't want to grep in /etc/hosts or presume DNS #we are, however, presuming ipv4 for the moment - retval=$(ping -c 1 $(hostname)|head -n 1|cut -d\( -f 2|cut -d\) -f 1) + retval=$(ping -c 1 "$(hostname)"|head -n 1|cut -d\( -f 2|cut -d\) -f 1) if [ -z "$retval" -o "127.0.0.1" = "$retval" ]; then #ok, that didn't pan out, now we grab the first address that looks sane #retval=`ifconfig|grep inet" " |grep -v addr:127.0.0.1|grep -v 'addr:169.254'|head -n 1|cut -d: -f 2|cut -d' ' -f 1` retval=$(ip -4 -oneline addr show|grep -v "127.0.0.1"|grep -v '169.254'|head -n 1|awk -F 'inet ' '{print $2}'|awk -F '/' '{print $1}') @@ -30,13 +30,13 @@ function get_def_interface { INMATCH=0 for brline in $(brctl show); do IFS=$OIFS - if [ $(expr match "$brline" $iface) == $(expr length $iface) ]; then + if [ "$(expr match "$brline" $iface)" == ${#iface} ]; then INMATCH=1 - elif [ $(expr match "$brline" " ") != 1 ]; then + elif [ "$(expr match "$brline" " ")" != 1 ]; then INMATCH=0 fi if [ "$INMATCH" == 1 ]; then - if ! ethtool -i $(echo $brline|awk '{print $NF}')|grep "driver: tun" >& /dev/null; then + if ! ethtool -i "$(echo $brline|awk '{print $NF}')"|grep "driver: tun" >& /dev/null; then iface=$(echo $brline|awk '{print $NF}') echo "$iface" IFS=$OFIS @@ -77,8 +77,7 @@ function debianpreconf(){ CONFFILE='' #read the backfile - cat /etc/network/interfaces.bak | while read LINE - do + while read LINE; do if [ ! "$LINE" ];then continue fi @@ -107,7 +106,7 @@ function debianpreconf(){ echo $LINE >> $CONFFILE fi - done + done > $nwdir/$BNAME - echo " address $bridge_ip" >> $nwdir/$BNAME - echo " netmask $bridge_mask" >> $nwdir/$BNAME + { echo "iface $BNAME inet static" + echo " address $bridge_ip" + echo " netmask $bridge_mask"; } >> $nwdir/$BNAME else echo "iface $BNAME inet dhcp" >> $nwdir/$BNAME fi fi - echo " bridge_ports $PORTS" >> $nwdir/$BNAME - echo " bridge_stp off" >> $nwdir/$BNAME - echo " bridge_fd 0" >> $nwdir/$BNAME - echo " bridge_maxwait 0" >> $nwdir/$BNAME + { echo " bridge_ports $PORTS" + echo " bridge_stp off" + echo " bridge_fd 0" + echo " bridge_maxwait 0"; } >> $nwdir/$BNAME else cat >$nwdir/ifcfg-$PORTS < Date: Fri, 27 Oct 2017 05:13:17 +0000 Subject: [PATCH 3/7] xHRM: more improvments via ShellCheck --- xCAT-server/share/xcat/scripts/xHRM | 64 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/xCAT-server/share/xcat/scripts/xHRM b/xCAT-server/share/xcat/scripts/xHRM index 0485dae46..200032c60 100755 --- a/xCAT-server/share/xcat/scripts/xHRM +++ b/xCAT-server/share/xcat/scripts/xHRM @@ -269,19 +269,19 @@ elif [ "bridgeprereq" = "$1" ]; then #write into the network configuration file if [[ $isSLES -eq 1 ]]; then - cat >$nwdir/ifcfg-$PORTS <> $nwdir/ifcfg-$PORTS + echo "HWADDR='$mac'" fi if [ ! -z "$vlan" ]; then - echo "VLAN='yes'" >> $nwdir/ifcfg-$PORTS - fi - cat >$nwdir/ifcfg-$BNAME <"$nwdir/ifcfg-$PORTS" + { cat <> $nwdir/ifcfg-$BNAME + echo "IPADDR='$3'" if [ ! -z "$4" ]; then - echo "NETMASK='$4'" >> $nwdir/ifcfg-$BNAME + echo "NETMASK='$4'" fi else - echo "BOOTPROTO=dhcp" >> $nwdir/ifcfg-$BNAME - fi + echo "BOOTPROTO=dhcp" + fi; } >$nwdir/ifcfg-$BNAME elif [ $isDebian ];then #ubuntu/debian echo "auto $PORTS" >$nwdir/$PORTS @@ -305,46 +305,46 @@ EOF echo " vlan-raw-device $PORTORG" fi - echo "auto $BNAME" > $nwdir/$BNAME + { echo "auto $BNAME" if [ ! -z "$3" ];then - echo "iface $BNAME inet static" >> $nwdir/$BNAME - echo " address $3" >> $nwdir/$BNAME + echo "iface $BNAME inet static" + echo " address $3" if [ ! -z "$4" ];then - echo " netmask $4" >> $nwdir/$BNAME + echo " netmask $4" else - echo " netmask 255.255.255.0" >> $nwdir/$BNAME + echo " netmask 255.255.255.0" fi else - my_subnet=$(ip addr show dev $BNAME scope global|grep inet|grep -v dynamic|sed -e 's/inet.//'| awk '{print $1}') + my_subnet=$(ip -4 -o addr show dev "$BNAME" scope global | awk '!/dynamic/{print $4}' ) if [ ! -z "$my_subnet" ]; then bridge_ip="${my_subnet//\/*}" bridge_mask="${my_subnet##*\/}" - bridge_mask=$(v4prefix2mask $bridge_mask) - { echo "iface $BNAME inet static" + bridge_mask=$(v4prefix2mask "$bridge_mask") + echo "iface $BNAME inet static" echo " address $bridge_ip" - echo " netmask $bridge_mask"; } >> $nwdir/$BNAME + echo " netmask $bridge_mask"; else - echo "iface $BNAME inet dhcp" >> $nwdir/$BNAME + echo "iface $BNAME inet dhcp" fi fi - { echo " bridge_ports $PORTS" + echo " bridge_ports $PORTS" echo " bridge_stp off" echo " bridge_fd 0" - echo " bridge_maxwait 0"; } >> $nwdir/$BNAME + echo " bridge_maxwait 0"; } > "$nwdir/$BNAME" else - cat >$nwdir/ifcfg-$PORTS <> $nwdir/ifcfg-$PORTS + echo "HWADDR=$mac" fi if [ ! -z "$vlan" ]; then - echo "VLAN=yes" >> $nwdir/ifcfg-$PORTS - fi - cat >$nwdir/ifcfg-$BNAME <"$nwdir/ifcfg-$PORTS" + { cat <> $nwdir/ifcfg-$BNAME + echo "IPADDR=$3" if [ ! -z "$4" ]; then - echo "NETMASK=$4" >> $nwdir/ifcfg-$BNAME + echo "NETMASK=$4" fi else - echo "BOOTPROTO=dhcp" >> $nwdir/ifcfg-$BNAME - fi + echo "BOOTPROTO=dhcp" + fi ; } > "$nwdir/ifcfg-$BNAME" fi - ifdown $BNAME;ifup $BNAME + ifdown "$BNAME"; ifup "$BNAME" fi #END bridge config. From c4f4760eb48277bf4e2ae34af25725f037572f33 Mon Sep 17 00:00:00 2001 From: Samveen Gulati Date: Fri, 27 Oct 2017 05:51:57 +0000 Subject: [PATCH 4/7] xHRM: migrate existing IP conf of $PORTS to bridge --- xCAT-server/share/xcat/scripts/xHRM | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xCAT-server/share/xcat/scripts/xHRM b/xCAT-server/share/xcat/scripts/xHRM index 200032c60..513a4dd92 100755 --- a/xCAT-server/share/xcat/scripts/xHRM +++ b/xCAT-server/share/xcat/scripts/xHRM @@ -1,4 +1,4 @@ -#!/bin/bash -u +#!/bin/bash if [ "$(uname -s|tr '[:upper:]' '[:lower:]')" = "linux" ];then str_dir_name=$(dirname $0) . $str_dir_name/xcatlib.sh @@ -235,7 +235,7 @@ elif [ "bridgeprereq" = "$1" ]; then brctl setfd $BNAME 0 #fast forwarding ip link set $BNAME up saveroutes="$(ip route | grep default| grep "dev $PORTS"|grep via|sed -e 's/dev .*//')" - saveip="$(ip -4 -o addr show dev enp0s3 scope global | sed 's/.*inet //'| sed 's/\( global \).*/\1/')" + saveip="$(ip -4 -o addr show dev $PORTS scope global | sed 's/.*inet //'| sed 's/\( global \).*/\1/')" if [ ! -z "$saveip" ]; then ip addr add dev $BNAME $newline else @@ -332,6 +332,8 @@ EOF echo " bridge_fd 0" echo " bridge_maxwait 0"; } > "$nwdir/$BNAME" else + # Migrate some PORTS configuration to Bridge: + ATTRS="$(egrep '^BOOTPROTO|^IPADDR|^NETMASK|^NETWORK|^GATEWAY' $nwdir/ifcfg-$PORTS)" { cat < "$nwdir/ifcfg-$BNAME" fi ifdown "$BNAME"; ifup "$BNAME" fi #END bridge config. - - From 5e93ea3b398e2d1875622fad4541e0749349e736 Mon Sep 17 00:00:00 2001 From: Samveen Gulati Date: Tue, 14 Nov 2017 07:56:10 +0000 Subject: [PATCH 5/7] Fix logic for bridgeprereq parameter parsing --- xCAT-server/share/xcat/scripts/xHRM | 58 ++++++++++++----------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/xCAT-server/share/xcat/scripts/xHRM b/xCAT-server/share/xcat/scripts/xHRM index 513a4dd92..d3f99e6a8 100755 --- a/xCAT-server/share/xcat/scripts/xHRM +++ b/xCAT-server/share/xcat/scripts/xHRM @@ -123,42 +123,35 @@ elif [ "bridgeprereq" = "$1" ]; then modprobe bridge NETDESC="$2" - # get the port for installation - if [ -n "$INSTALLNIC" ]; then - INSPORT=$INSTALLNIC - elif [ -n "$PRIMARYNIC" ]; then - INSPORT=$PRIMARYNIC - fi - if [ -z "$INSPORT" ] || [[ "$INSPORT" =~ ^(mac|MAC)$ ]]; then - if [ -n "$MACADDRESS" ] ; then - INSPORT=$MACADDRESS; - else - echo "should configure mac in $NODE definition." - exit 1 - fi - fi - - if [[ "$INSPORT" =~ ^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$ ]] ; then - INSPORT=$(ip -oneline link show|grep -i ether|grep -i $INSPORT |awk -F ':' '{print $2}'|grep -o "[^ ]\+\( \+[^ ]\+\)*") - fi - - if [ -z "$NETDESC" ]; then - if [ -n "$INSPORT" ]; then - NETDESC=$INSPORT:default - else - echo "Incorrect usage" - exit 1 - fi - fi if echo "$NETDESC"|grep ':'> /dev/null; then PORTS=$(echo "$NETDESC"|cut -d: -f 1) BNAME=$(echo "$NETDESC"|cut -d: -f 2) else - if [ -n "$INSTALLNIC" ]; then - PORTS=$INSPORT + if [ -n "$NETDESC" ]; then + BNAME=$NETDESC + else + BNAME=default fi - BNAME=$NETDESC + + # get the port for installation + if [ -n "$INSTALLNIC" ]; then + PORTS=$INSTALLNIC + elif [ -n "$PRIMARYNIC" ]; then + PORTS=$PRIMARYNIC + else + PORTS=$(get_def_interface) + fi + + if [ -z "$PORTS" ] || [[ "$PORTS" =~ ^(mac|MAC)$ ]]; then + if [ -n "$MACADDRESS" ] ; then + PORTS=$(ip -oneline link show|grep -i ether|grep -i $MACADDRESS |awk -F ':' '{print $2}'|grep -o "[^ ]\+\( \+[^ ]\+\)*") + else + echo "should configure mac in $NODE definition." + exit 1 + fi + fi + fi # To check whether the brctl have been installed @@ -171,10 +164,7 @@ elif [ "bridgeprereq" = "$1" ]; then echo "$BNAME" exit 0 fi - #Still here, that means we must build a bridge - if [ -z "$PORTS" ]; then #No ports specified, default to whatever looks up - PORTS=$(get_def_interface) - fi + if [ -z "$PORTS" ]; then #This has been checked many times before in theory, check again just in case exit 1 fi From 07add8e288412e75624e495ac5e8d25c4077ee6f Mon Sep 17 00:00:00 2001 From: Samveen Gulati Date: Tue, 14 Nov 2017 08:29:08 +0000 Subject: [PATCH 6/7] Fix back multi-ip transfer from port to bridge --- xCAT-server/share/xcat/scripts/xHRM | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xCAT-server/share/xcat/scripts/xHRM b/xCAT-server/share/xcat/scripts/xHRM index d3f99e6a8..3571d44bb 100755 --- a/xCAT-server/share/xcat/scripts/xHRM +++ b/xCAT-server/share/xcat/scripts/xHRM @@ -227,7 +227,9 @@ elif [ "bridgeprereq" = "$1" ]; then saveroutes="$(ip route | grep default| grep "dev $PORTS"|grep via|sed -e 's/dev .*//')" saveip="$(ip -4 -o addr show dev $PORTS scope global | sed 's/.*inet //'| sed 's/\( global \).*/\1/')" if [ ! -z "$saveip" ]; then - ip addr add dev $BNAME $newline + while read line; do + ip addr add dev $BNAME ${line//dynamic} + done <<<"$saveip" else if [ ! -z "$3" ]; then ip addr add dev $BNAME $3 @@ -235,7 +237,9 @@ elif [ "bridgeprereq" = "$1" ]; then fi brctl addif $BNAME $PORTS if [ ! -z "$saveip" ]; then - ip addr del dev $PORTS $newline + while read line; do + ip addr del dev $PORTS ${line//dynamic} + done <<<"$saveip" fi if [ ! -z "$saveroutes" ]; then ip route add $saveroutes From 76b477c39871842a6950c38a69bca9f14cf6f9bb Mon Sep 17 00:00:00 2001 From: Samveen Gulati Date: Tue, 14 Nov 2017 08:38:24 +0000 Subject: [PATCH 7/7] Error redirection for checks --- xCAT-server/share/xcat/scripts/xHRM | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xCAT-server/share/xcat/scripts/xHRM b/xCAT-server/share/xcat/scripts/xHRM index 3571d44bb..64d015911 100755 --- a/xCAT-server/share/xcat/scripts/xHRM +++ b/xCAT-server/share/xcat/scripts/xHRM @@ -24,7 +24,7 @@ function get_def_interface { echo "ERROR: Unable to reasonably guess the default interface" >&2 exit 1 fi - if brctl show | grep ^$iface >& /dev/null; then # + if brctl show | grep ^$iface &> /dev/null; then # OIFS=$IFS IFS=$'\n' INMATCH=0 @@ -155,13 +155,13 @@ elif [ "bridgeprereq" = "$1" ]; then fi # To check whether the brctl have been installed - if ! which brctl > /dev/null; then + if ! which brctl &> /dev/null; then echo "No bridge-utils installed, pls install it first" exit 1 fi - if brctl showstp "$BNAME" > /dev/null; then - echo "$BNAME" + if brctl showstp "$BNAME" &> /dev/null; then + echo "$BNAME already exists" exit 0 fi