diff mbox

Remove bash'isms/zsh'isms in tcl and shell scripts

Message ID alpine.BSF.2.00.1211111105470.70593@toaster.local (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Garrett Cooper Nov. 11, 2012, 7:07 p.m. UTC
Signed-off-by: Garrett Cooper <yanegomi@gmail.com>
From 2d35f859094a8a34b2a22100f35dcd1b4148d29e Mon Sep 17 00:00:00 2001
From: Garrett Cooper <yanegomi@gmail.com>

Date: Mon, 5 Nov 2012 19:43:32 -0800
Subject: [PATCH] Remove bash'isms/zsh'isms in tcl and shell scripts

Signed-off-by: Garrett Cooper <yanegomi@gmail.com>

---
 autogen.sh                         |  4 ++--
 ibdiag/autogen.sh                  |  8 ++++----
 ibdm/autogen.sh                    |  8 ++++----
 ibis/autogen.sh                    | 10 +++++-----
 ibmgtsim/autogen.sh                |  4 ++--
 ibmgtsim/tests/OsmTest.check.tcl   |  4 ++--
 ibmgtsim/tests/osmStress.check.tcl |  2 +-
 ibmgtsim/tests/pkey.check.tcl      |  2 +-
 ibmgtsim/utils/fprogbar.sh         | 32 ++++++++++++++++----------------
 ibmgtsim/utils/install.sh          |  8 ++++----
 ibmgtsim/utils/mkSimNodeDir        |  6 +++---
 ibmgtsim/utils/uninstall.sh        | 15 ++++++---------
 12 files changed, 50 insertions(+), 53 deletions(-)

-- 
1.7.11.5
diff mbox

Patch

diff --git a/autogen.sh b/autogen.sh
index dda3137..4b6a990 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,8 +1,8 @@ 
-#!/bin/bash
+#!/bin/sh
 cd ${0%*/*}
 # get two strings of version numbers
 # parse the two strings and compare
-function compare_versions() {
+compare_versions() {
    cat <<EOF > /tmp/$$.awk
 /[0-9]+\.[0-9]+(\.[0-9]+)?[    ]+[0-9]+\.[0-9]+(\.[0-9]+)?/{
   vb = "$2";
diff --git a/ibdiag/autogen.sh b/ibdiag/autogen.sh
index 642cdc8..fb0f46f 100755
--- a/ibdiag/autogen.sh
+++ b/ibdiag/autogen.sh
@@ -1,8 +1,8 @@ 
-#!/bin/bash
+#!/bin/sh
 
 # get two strings of version numbers
 # parse the two strings and compare
-function compare_versions() {
+compare_versions() {
    cat <<EOF > /tmp/$$.awk
 /[0-9]+\.[0-9]+(\.[0-9]+)?[    ]+[0-9]+\.[0-9]+(\.[0-9]+)?/{
   vb = "$2";
@@ -41,8 +41,8 @@  EOF
 # We change dir since the later utilities assume to work in the project dir
 cd ${0%*/*}
 # remove previous
-\rm -rf autom4te.cache
-\rm -rf aclocal.m4
+rm -rf autom4te.cache
+rm -rf aclocal.m4
 # make sure autoconf is up-to-date
 ac_ver=`autoconf --version | head -n 1 | awk '{print $NF}'`
 compare_versions 2.59 $ac_ver
diff --git a/ibdm/autogen.sh b/ibdm/autogen.sh
index 927526f..5eceb89 100755
--- a/ibdm/autogen.sh
+++ b/ibdm/autogen.sh
@@ -1,8 +1,8 @@ 
-#!/bin/bash
+#!/bin/sh
 
 # get two strings of version numbers
 # parse the two strings and compare
-function compare_versions() {
+compare_versions() {
    cat <<EOF > /tmp/$$.awk
 /[0-9]+\.[0-9]+(\.[0-9]+)?[    ]+[0-9]+\.[0-9]+(\.[0-9]+)?/{
   vb = "$2";
@@ -40,8 +40,8 @@  EOF
 # We change dir since the later utilities assume to work in the project dir
 cd ${0%*/*}
 # remove previous
-\rm -rf autom4te.cache
-\rm -rf aclocal.m4
+rm -rf autom4te.cache
+rm -rf aclocal.m4
 # make sure autoconf is up-to-date
 ac_ver=`autoconf --version | head -n 1 | awk '{print $NF}'`
 compare_versions 2.59 $ac_ver
diff --git a/ibis/autogen.sh b/ibis/autogen.sh
index c0536a9..6adf391 100755
--- a/ibis/autogen.sh
+++ b/ibis/autogen.sh
@@ -1,8 +1,8 @@ 
-#!/bin/bash
+#!/bin/sh
 
 # get two strings of version numbers
 # parse the two strings and compare
-function compare_versions() {
+compare_versions() {
    cat <<EOF > /tmp/$$.awk
 /[0-9]+\.[0-9]+(\.[0-9]+)?[    ]+[0-9]+\.[0-9]+(\.[0-9]+)?/{
   vb = "$2";
@@ -38,9 +38,9 @@  EOF
 }
 
 cd ${0%*/*}
-\rm -rf autom4te.cache
-\rm -rf aclocal.m4
-\rm -f config/missing config/install-sh config/depcomp config/mkinstalldirs config/ltmain.sh config/config.sub config/config.guess
+rm -rf autom4te.cache
+rm -rf aclocal.m4
+rm -f config/missing config/install-sh config/depcomp config/mkinstalldirs config/ltmain.sh config/config.sub config/config.guess
 # make sure autoconf is up-to-date
 ac_ver=`autoconf --version | head -n 1 | awk '{print $NF}'`
 compare_versions 2.59 $ac_ver
diff --git a/ibmgtsim/autogen.sh b/ibmgtsim/autogen.sh
index a780e64..42c7ed0 100755
--- a/ibmgtsim/autogen.sh
+++ b/ibmgtsim/autogen.sh
@@ -1,8 +1,8 @@ 
-#!/bin/bash
+#!/bin/sh
 
 # get two strings of version numbers
 # parse the two strings and compare
-function compare_versions() {
+compare_versions() {
    cat <<EOF > /tmp/$$.awk
 /[0-9]+\.[0-9]+(\.[0-9]+)?[    ]+[0-9]+\.[0-9]+(\.[0-9]+)?/{
   vb = "$2";
diff --git a/ibmgtsim/tests/OsmTest.check.tcl b/ibmgtsim/tests/OsmTest.check.tcl
index 7121d21..ff4c462 100644
--- a/ibmgtsim/tests/OsmTest.check.tcl
+++ b/ibmgtsim/tests/OsmTest.check.tcl
@@ -49,7 +49,7 @@  proc checker {simDir osmPath osmPortGuid} {
    set osmTestCmd1 "$osmTestPath -v -t 1000 -g $osmPortGuid -l $osmTestLog -f c -i $osmTestInventory"
    puts "-I- Invoking: $osmTestCmd1 ..."
    # HACK: we currently ignore osmtest craches on exit flow:
-   catch {set res [eval "exec $osmTestCmd1 >& $osmTestStdOutLog"]}
+   catch {set res [eval "exec $osmTestCmd1 > $osmTestStdOutLog 2>&1"]}
 
    if {[catch {exec grep "OSMTEST: TEST \"Create Inventory\" PASS" $osmTestStdOutLog}]} {
       puts "-E- osmtest Create Inventory failed"
@@ -62,7 +62,7 @@  proc checker {simDir osmPath osmPortGuid} {
    set osmTestCmd2 "$osmTestPath -v -t 1000 -g $osmPortGuid -l $osmTestLog -f a -i $osmTestInventory"
    puts "-I- Invoking: $osmTestCmd2 ..."
    # HACK: we currently ignore osmtest craches on exit flow:
-   catch {set res [eval "exec $osmTestCmd2 >& $osmTestStdOutLog"]}
+   catch {set res [eval "exec $osmTestCmd2 > $osmTestStdOutLog 2>&1"]}
    if {[catch {exec grep "OSMTEST: TEST \"All Validations\" PASS" $osmTestStdOutLog}]} {
       puts "-E- osmtest All Validations failed"
       return 1
diff --git a/ibmgtsim/tests/osmStress.check.tcl b/ibmgtsim/tests/osmStress.check.tcl
index 2c741cb..f6e9d75 100755
--- a/ibmgtsim/tests/osmStress.check.tcl
+++ b/ibmgtsim/tests/osmStress.check.tcl
@@ -205,7 +205,7 @@  proc checker {simDir osmPath osmPortGuid} {
       set cmd "ibdiagnet -v -r -t $topologyFile -o $simDir"
       set ibdiagnetLog [file join $simDir ibdiagnet.stdout.log]
       puts "-I- Invoking $cmd "
-      if {[catch {set res [eval "exec $cmd >& $ibdiagnetLog"]} e]} {
+      if {[catch {set res [eval "exec $cmd > $ibdiagnetLog 2>&1"]} e]} {
          puts "-E- ibdiagnet failed"
          puts "-I- Result value $res"
          puts "-I- Error: $e"
diff --git a/ibmgtsim/tests/pkey.check.tcl b/ibmgtsim/tests/pkey.check.tcl
index 7083808..ecfdbee 100644
--- a/ibmgtsim/tests/pkey.check.tcl
+++ b/ibmgtsim/tests/pkey.check.tcl
@@ -310,7 +310,7 @@  proc checker {simDir osmPath osmPortGuid} {
       puts "-I- Invoking: $osmTestCmd1 ..."
 
       # HACK: we currently ignore osmtest craches on exit flow:
-      catch {set res [eval "exec $osmTestCmd1 >& $osmTestStdOutLog"]}
+      catch {set res [eval "exec $osmTestCmd1 > $osmTestStdOutLog 2>&1"]}
 
       if {[catch {exec grep "OSMTEST: TEST \"Create Inventory\" PASS" $osmTestStdOutLog}]} {
          puts "-E- osmtest Create Inventory failed"
diff --git a/ibmgtsim/utils/fprogbar.sh b/ibmgtsim/utils/fprogbar.sh
index 7805ff0..0a5f28c 100755
--- a/ibmgtsim/utils/fprogbar.sh
+++ b/ibmgtsim/utils/fprogbar.sh
@@ -1,4 +1,4 @@ 
-#!/bin/bash
+#!/bin/sh
 # fprogbar: File PROGress BAR
 #   This script output a progress bar in the terminal width which monitors
 #   file size relative to final expected size.
@@ -10,7 +10,7 @@ 
 # Note: It is recommended to provide final size which is a bit less than
 #       expected size, since this size is the termination point
 
-function usage()
+usage()
 {
   echo "usage: fprogbar <filename> <final size in bytes> [<process ID to sync with>]"
   exit 1
@@ -32,29 +32,29 @@  fi
 
 # prepare progress bar of style [        ] to be [+++     ]
 echo -n "[]"
-let num_of_dots=`tput cols`-12
-#for (( i= 0 ; i < $num_of_dots ;  )) ; do echo -n -e '\267' ; let i++ ;done
+num_of_dots=`tput cols`-12
+#i=0; while [ $i -lt $num_of_dots ] ; do echo -n -e '\267' ; : $(( i += 1 )); done
 #echo -n -e \]'\r'\[
-let bytes_per_dot=$final_sz/$num_of_dots
-let cur_bars=0
-let percent=0
+bytes_per_dot=$(( $final_sz / $num_of_dots ))
+cur_bars=0
+percent=0
 
 # Update dots until final size is reached
-while ((1)); do
-  lead_proc_cnt=`ps -eo "%p" | awk '$1 == '$pid2track' {print}' | wc -l`
+while : ; do
+  lead_proc_cnt=`ps -eo "%p" | awk '$1 == '$pid2track | wc -l`
   current_sz=`ls -l $file | awk '{print $5}'`
-  let req_bars=$current_sz/$bytes_per_dot
+  req_bars=$(( $current_sz / $bytes_per_dot ))
   if [ $req_bars -ge $num_of_dots ]; then
-    let req_bars=$num_of_dots
+    req_bars=$num_of_dots
   fi
-  for ((  ; $cur_bars < $req_bars ; )); do
-    let percent=($current_sz*100)/$final_sz
+  while [ $cur_bars -lt $req_bars ]; do
+    percent=$(( $(( $current_sz * 100 )) / $final_sz ))
     printf "\b+] %3d%%\b\b\b\b\b" $percent
-    let cur_bars++
+    : $(( cur_bars += 1 ))
   done
 
   # Check if reached expected file size
-  if [ \( $cur_bars -eq $num_of_dots \) -o \( $percent -ge 100 \)  ]; then
+  if [ $cur_bars -eq $num_of_dots -o $percent -ge 100 ]; then
     echo " 100%"
     exit 0
   fi
@@ -65,5 +65,5 @@  while ((1)); do
     exit 2
   fi
 
- usleep 200000
+  sleep 0.2
 done
diff --git a/ibmgtsim/utils/install.sh b/ibmgtsim/utils/install.sh
index 1d892d5..e0a0958 100755
--- a/ibmgtsim/utils/install.sh
+++ b/ibmgtsim/utils/install.sh
@@ -1,4 +1,4 @@ 
-#!/bin/bash
+#!/bin/sh
 #
 # This software is available to you under a choice of one of two
 # licenses.  You may choose to be licensed under the terms of the GNU
@@ -41,13 +41,13 @@  cd $PACKAGE_DIR
 #
 
 #Report: if config failed
-function config_failed() {
+config_failed() {
 	echo "Config failed ! (see $CFGLOG for details)"
 	exit 1
 }
 
 #Report: if make failed
-function make_failed() {
+make_failed() {
 	echo "Make failed ! (see $MAKELOG for details)"
 	exit 1
 }
@@ -59,7 +59,7 @@  PREFIX=/usr
 NO_BAR=0
 
 # parse parameters
-while [ "$1" ]; do
+while [ $# -gt 0 ]; do
 #  echo "Current parsed param is : $1"
   case $1 in
     "--prefix")
diff --git a/ibmgtsim/utils/mkSimNodeDir b/ibmgtsim/utils/mkSimNodeDir
index dcab4b3..d7322df 100755
--- a/ibmgtsim/utils/mkSimNodeDir
+++ b/ibmgtsim/utils/mkSimNodeDir
@@ -1,7 +1,7 @@ 
-#!/bin/bash
+#!/bin/sh
 
 usage="$0 -n node-name [-g sim-guids-file]"
-function help () {
+help() {
 cat <<EOF
 $usage
 
@@ -22,7 +22,7 @@  exit 0
 
 guids_file=ibmgtsim.guids.txt
 
-while getopts ":n:gh" options; do
+while getopts "n:g:h" options; do
   case $options in
     n ) node_name=$OPTARG;;
     g ) guids_file=$OPTARG;;
diff --git a/ibmgtsim/utils/uninstall.sh b/ibmgtsim/utils/uninstall.sh
index a65c273..9af3f71 100755
--- a/ibmgtsim/utils/uninstall.sh
+++ b/ibmgtsim/utils/uninstall.sh
@@ -1,4 +1,4 @@ 
-#!/bin/bash
+#!/bin/sh
 #
 # This software is available to you under a choice of one of two
 # licenses.  You may choose to be licensed under the terms of the GNU
@@ -19,22 +19,20 @@ 
 # Copyright (c) 2004 Mellanox Technologies Ltd.  All rights reserved.
 #
 
-function cleanup_ibmgtsim_files() {
+cleanup_ibmgtsim_files() {
     local PREFIX=$1
     # Clean old distribution
     binApps="IBMgtSim  ibmsquit  ibmssh  mkSimNodeDir  RunSimTest"
 
     echo "Removing Executables from : .......... $PREFIX/bin."
     for f in $binApps; do
-        rm -f ${PREFIX}/bin/$f 2&>1 > /dev/null;
-        if [ $? == 0 ]; then
+        if rm -f ${PREFIX}/bin/$f 2>&1 >/dev/null; then
             echo " Removed : ${PREFIX}/bin/$f"
         fi
     done
 
     echo "Removing Include Files from : ........ $PREFIX/include."
-    rm -rf ${PREFIX}/include/ibmgtsim 2&>1 > /dev/null
-    if [ $? == 0 ]; then
+    if rm -rf ${PREFIX}/include/ibmgtsim 2>&1 >/dev/null; then
         echo " Removed : ${PREFIX}/include/ibmgtsim"
     fi
 
@@ -42,8 +40,7 @@  function cleanup_ibmgtsim_files() {
     libs="libibmscli.a libibmscli.la libibmscli.so libibmscli.so.1
           libibmscli.so.1.0.0"
     for f in $libs; do
-        rm -rf ${PREFIX}/lib/$f 2&>1 > /dev/null;
-        if [ $? == 0 ]; then
+        if rm -rf ${PREFIX}/lib/$f 2>&1 >/dev/null; then
             echo " Removed : ${PREFIX}/lib/$f"
         fi
     done
@@ -52,7 +49,7 @@  function cleanup_ibmgtsim_files() {
 NO_BAR=0
 
 # parse parameters
-while [ "$1" ]; do
+while [ $# -gt 0 ]; do
 #  echo "Current parsed param is : $1"
   case $1 in
     "--prefix")