From c57371105118e15ff896e0da79e84d9a29fb39c9 Mon Sep 17 00:00:00 2001 From: ericagar Date: Sat, 20 Aug 2011 03:38:17 +0000 Subject: [PATCH] Fix for defect 3394877: Fix bashisms in otherpkgs git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10331 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT/postscripts/otherpkgs | 182 ++++++++++++++++++++++++++++++++----- 1 file changed, 161 insertions(+), 21 deletions(-) diff --git a/xCAT/postscripts/otherpkgs b/xCAT/postscripts/otherpkgs index 2dd30028b..5f09670aa 100755 --- a/xCAT/postscripts/otherpkgs +++ b/xCAT/postscripts/otherpkgs @@ -22,9 +22,146 @@ #=cut #------------------------------------------------------------------------------- +# pmatch determines if 1st argument string is matched by 2nd argument pattern + +pmatch () +{ + case $1 in + $2) return 0;; # zero return code means string matched by pattern + esac + + return 1 # non-zero return code means string not matched by pattern +} + +## +## The following routines implement the notion of an array. +## The POSIX shell does not support arrays. +## With these routines, an array conceptually called "my_array" is implmented using the following series +## of variables: +## +## my_array__ARRAY_HIGH_INDEX - holds the highest index used in the array +## my_array__0 - value for element 0 of my_array: my_array[0] in standard array notation +## my_array__1 - value for element 1 of my_array: my_array[1] in standard array notation +## . . +## . . +## . . +## + +# +# array_empty - make the array whose name is given by $1 empty (with no elements). +# +# sample call: array_empty my_array +# + +array_empty () +{ + local array_name="$1" + local high_ndx_varname="${array_name}__ARRAY_HIGH_INDEX" + local elem_varname + local high_ndx + local ndx + + # Determine current element count + + eval "high_ndx=\$${high_ndx_varname}" + + if [ -z "$high_ndx" ]; then + return + fi + + # Unset all previously defined element variables and the high index variable + + ndx=0 + + while [ $ndx -le $high_ndx ]; do + elem_varname="${array_name}__${ndx}" + + eval "unset ${elem_varname}" + + ndx=$(expr $ndx + 1) + done + + eval "unset ${high_ndx_varname}" +} + +# +# array_get_size - return the size of the array whose name is given by $1. +# The size, which is the highest index plus one is written to standard output +# +# sample call: size=$(array_get_size my_array) +# + +array_get_size () +{ + local array_name="$1" + + local high_ndx_varname="${array_name}__ARRAY_HIGH_INDEX" + local high_ndx + + eval "high_ndx=\$${high_ndx_varname}" + + if [ -z "$high_ndx" ]; then + high_ndx=-1 + fi + + echo $(expr $high_ndx + 1) +} + +# +# array_set_element - set an element to a value. $1 is the array name, $2 is the element index, +# $3 is the element value. +# +# sample call: array_set_element my_array index "the new element value" +# + +array_set_element () +{ + local array_name="$1" + local ndx="$2" + local elem_value="$3" + local high_ndx_varname="${array_name}__ARRAY_HIGH_INDEX" + local elem_varname + local high_ndx + + # Set specified element to specified value + + elem_varname="${array_name}__${ndx}" + + eval "${elem_varname}=\"${elem_value}\"" + + # Adjust high index + + eval "high_ndx=\$${high_ndx_varname}" + + if [ -z "$high_ndx" ]; then + high_ndx=-1 + fi + + if [ $ndx -gt $high_ndx ]; then + eval "${high_ndx_varname}=${ndx}" + fi +} + +# +# array_get_element - get an element's value. $1 is the array name, $2 is the element index. +# +# sample call: value=$(array_get_element my_array index) +# + +array_get_element () +{ + local array_name="$1" + local ndx="$2" + + eval "echo \"\$${array_name}__${ndx}\"" +} + +## +## End of set routines. +## # do nothing for diskless deployment case because it is done in the image already -if [[ $UPDATENODE -ne 1 ]]; then +if [ -z "$UPDATENODE" ] || [ $UPDATENODE -ne 1 ]; then if [ "$NODESETSTATE" = "netboot" -o \ "$NODESETSTATE" = "statelite" -o \ "$NODESETSTATE" = "diskless" -o \ @@ -35,16 +172,16 @@ if [[ $UPDATENODE -ne 1 ]]; then fi fi -if [[ -z "$OTHERPKGS_INDEX" ]]; then +if [ -z "$OTHERPKGS_INDEX" ]; then echo "$0: no extra rpms to install" exit 0 fi -if [[ -z "$NFSSERVER" ]]; then +if [ -z "$NFSSERVER" ]; then NFSSERVER=$MASTER fi -if [[ -z "$INSTALLDIR" ]]; then +if [ -z "$INSTALLDIR" ]; then INSTALLDIR="/install" fi @@ -56,12 +193,15 @@ if [ $? -eq 0 ]; then mounted=1 fi -if [[ -z "$OTHERPKGDIR" ]]; then +if [ -z "$OTHERPKGDIR" ]; then OTHERPKGDIR="$NFSSERVER/post/otherpkgs/$OSVER/$ARCH" fi if [ $mounted -eq 0 ]; then - OTHERPKGDIR=${OTHERPKGDIR/#$INSTALLDIR/$NFSSERVER/} + otherpkg_subdir=${OTHERPKGDIR#$INSTALLDIR} + if [ "$otherpkg_subdir" != "$OTHERPKGDIR" ]; then + OTHERPKGDIR=${NFSSERVER}${otherpkg_subdir} + fi fi echo NFSSERVER=$NFSSERVER @@ -113,14 +253,14 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do repo_base="/tmp" fi - repo_path=() + array_empty repo_path repo_pkgs="" repo_pkgs_preremove="" repo_pkgs_postremove="" plain_pkgs="" plain_pkgs_preremove="" plain_pkgs_postremove="" - handled_path=() + array_empty handled_path for x in `echo "$pkglist" | tr "," "\n"` do #check if the file name starts with -- or -. @@ -164,26 +304,26 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do try_repo=1 rc=1 i=0 - while [ $i -lt ${#handled_path[*]} ]; do - if [ ${handled_path[$i]} = $path ]; then + while [ $i -lt $(array_get_size handled_path) ]; do + if [ $(array_get_element handled_path $i) = $path ]; then try_repo=0 j=0 - while [ $j -lt ${#repo_path[*]} ]; do - if [ ${repo_path[$j]} = $path ]; then + while [ $j -lt $(array_get_size repo_path) ]; do + if [ $(array_get_element repo_path $j) = $path ]; then rc=0 break fi - let j++ + j=$((j+1)) done break fi - let i++ + i=$((i+1)) done #try to add the path to the repo if [ $try_repo -eq 1 ]; then - index=${#repo_path[*]} + index=$(array_get_size repo_path) REPOFILE="$repo_base/xCAT-otherpkgs$index.repo" echo "[xcat-otherpkgs$index]" > $REPOFILE echo "name=xcat-otherpkgs$index" >> $REPOFILE @@ -200,13 +340,13 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do result=`yum list $fn 2>&1` if [ $? -eq 0 ]; then rc=0 - repo_path[${#repo_path[*]}]=$path + array_set_element repo_path $index $path else rm $REPOFILE fi elif [ $haszypper -eq 1 ]; then #use zypper - if [[ "$OSVER" = sles11* ]]; then + if ( pmatch "$OSVER" "sles11*" ); then result=`zypper ar -c $REPOFILE` else result=`zypper sa -c $REPOFILE` @@ -215,7 +355,7 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do result=`zypper --non-interactive refresh xcat-otherpkgs$index 2>&1` if [ $? -eq 0 ]; then rc=0 - repo_path[${#repo_path[*]}]=$path + array_set_element repo_path $index $path else result=`zypper sd xcat-otherpkgs$index` fi @@ -228,7 +368,7 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do #now no hope we have to use rpm command plain_pkgs="$plain_pkgs $x*" fi - handled_path[${#handled_path[*]}]=$path + array_set_element handled_path $(array_get_size handled_path) $path fi done @@ -348,7 +488,7 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do if [ $mounted -eq 0 ]; then cd /xcatpost dir_no_ftproot=${OTHERPKGDIR#$INSTALLDIR/} - dir_no_ftproot=${dir_no_ftproot/\/*/} + dir_no_ftproot=${dir_no_ftproot%%/*} rm -f -R $dir_no_ftproot fi fi @@ -384,7 +524,7 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do echo "$result" fi - let op_index=$op_index+1 + op_index=$((op_index+1)) done exit 0