From 60d4077c1417eff0ad0f903b95bc0b201893e1e8 Mon Sep 17 00:00:00 2001 From: ericagar Date: Mon, 22 Aug 2011 01:08:40 +0000 Subject: [PATCH] Fix for defect 3396020: Fix bashisms in setroute and routeop git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10332 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT/postscripts/routeop | 28 +++++++++++++++------------- xCAT/postscripts/setroute | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/xCAT/postscripts/routeop b/xCAT/postscripts/routeop index 123309a65..4da49db6f 100755 --- a/xCAT/postscripts/routeop +++ b/xCAT/postscripts/routeop @@ -15,7 +15,7 @@ op=$1 net=$2 mask=$3 gw=$4 -if [[ -n "$5" ]]; then +if [ -n "$5" ]; then ifname=$5 fi @@ -27,19 +27,21 @@ route_exists() gw=$3 ret=0 - if [[ -n "$4" ]]; then + if [ -n "$4" ]; then ifname=$4 fi + os_type=$(uname -s) + result=`netstat -nr|grep $net`; if [ $? -eq 0 ] && [ -n "$result" ]; then for x in `echo "$result"|tr -s " " ","` do - if [[ $OSTYPE = linux* ]]; then + if [ "$os_type" = "Linux" ]; then net1=`echo $x|cut -d',' -f1` gw1=`echo $x|cut -d',' -f2` mask1=`echo $x|cut -d',' -f3` - if [[ "$net" == "$net1" ]] && [[ "$mask" == "$mask1" ]] && [[ "$gw" == "$gw1" ]]; then + if [ "$net" = "$net1" ] && [ "$mask" = "$mask1" ] && [ "$gw" = "$gw1" ]; then ret=1 break fi @@ -52,17 +54,17 @@ route_exists() n3=`echo $net |cut -d'.' -f3` n4=`echo $net |cut -d'.' -f4` - let "netnum = $(( $n1 << 24 )) + $(( $n2 << 16 )) + $(( $n3 << 8 )) + $n4" + netnum="$(( ($n1 << 24) + ($n2 << 16) + ($n3 << 8) + $n4 ))" bits=32 while [ `expr $netnum % 2` -eq 0 ] do - let "bits = $bits -1" - let "netnum = $netnum >> 1" + bits="$(( $bits - 1 ))" + netnum="$(( $netnum >> 1 ))" done tmp2="$net/$bits"; #echo "$tmp2=$tmp2" - if [[ "$tmp1" == "$tmp2" ]] && [[ "$gw" == "$gw1" ]]; then + if [ "$tmp1" = "$tmp2" ] && [ "$gw" = "$gw1" ]; then ret=1 break fi @@ -74,9 +76,9 @@ route_exists() } result=$(route_exists $net $mask $gw) -if [[ "$result" == "0" ]]; then - if [[ "$op" == "add" ]]; then - if [[ $OSTYPE = linux* ]]; then +if [ "$result" = "0" ]; then + if [ "$op" = "add" ]; then + if [ "$(uname -s)" = "Linux" ]; then cmd="route add -net $net netmask $mask gw $gw" else cmd="route add -net $net -netmask $mask $gw" @@ -93,8 +95,8 @@ if [[ "$result" == "0" ]]; then echo "The route ($net $mask $gw) does not exist." fi else - if [[ "$op" == "delete" ]]; then - if [[ $OSTYPE = linux* ]]; then + if [ "$op" = "delete" ]; then + if [ "$(uname -s)" = "Linux" ]; then cmd="route delete -net $net netmask $mask gw $gw" else cmd="route delete -net $net -netmask $mask $gw" diff --git a/xCAT/postscripts/setroute b/xCAT/postscripts/setroute index 256b204e4..2299827b8 100755 --- a/xCAT/postscripts/setroute +++ b/xCAT/postscripts/setroute @@ -10,7 +10,7 @@ #=cut #------------------------------------------------------------------------------- -if [[ -z "$NODEROUTENAMES" ]]; then +if [ -z "$NODEROUTENAMES" ]; then exit 0 fi