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
This commit is contained in:
ericagar 2011-08-22 01:08:40 +00:00
parent c573711051
commit 60d4077c14
2 changed files with 16 additions and 14 deletions

View File

@ -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"

View File

@ -10,7 +10,7 @@
#=cut
#-------------------------------------------------------------------------------
if [[ -z "$NODEROUTENAMES" ]]; then
if [ -z "$NODEROUTENAMES" ]; then
exit 0
fi