Przeglądaj źródła

Ticket #47511 - bashisms in 389-ds-base admin scripts

Description by mvocu (Thank you):
The shell scripts in 389-ds-base/ldap/admin/src/scripts use 'source'
to source common scripts; the 'source' keyword is bash-specific (or
c-shell, if memory serves). The interpreter is set to /bin/sh, which
is not guaranteed to be bash (and at least on Debian 7.1 it is dash).
The 'source' keyword can be replaced by '.', which should work.

Thanks to Rowan Thorpe ([email protected]) for providing us the
patch.

Note: The comment of commit 2ce7a7334bcb89e47c0f5c544144aec37010a5b9
had an incorrect credit, which is fixed by this commit.

https://fedorahosted.org/389/ticket/47511

Reviewed and tested by [email protected].

(cherry picked from commit 2ce7a7334bcb89e47c0f5c544144aec37010a5b9)
Noriko Hosoi 10 lat temu
rodzic
commit
b35286b78a

+ 2 - 2
ldap/admin/src/initconfig.in

@@ -2,11 +2,11 @@
 OS=`uname -s`
 # use the new mt slab memory allocator on Solaris
 # this requires Solaris 9 update 3 or later
-if [ "$OS" = "SunOS" -a -f /usr/lib/libumem.so ] ; then
+if [ "$OS" = "SunOS" ] && [ -f /usr/lib/libumem.so ] ; then
     LD_PRELOAD=/usr/lib/libumem.so
     export LD_PRELOAD
 fi
-if [ "$OS" = "SunOS" -a -f /usr/lib/64/libumem.so ] ; then
+if [ "$OS" = "SunOS" ] && [ -f /usr/lib/64/libumem.so ] ; then
     LD_PRELOAD_64=/usr/lib/64/libumem.so
     export LD_PRELOAD_64
 fi

+ 44 - 48
ldap/admin/src/scripts/DSSharedLib.in

@@ -98,13 +98,13 @@ get_init_file()
     do
         inst_count=`expr $inst_count + 1`
         id=`normalize_server_id $configfile`
-        if [ -n "$servid" -a "$id" = "$servid" ]
+        if [ -n "$servid" ] && [ "$id" = "$servid" ]
         then
             # found it
             echo $configfile
             exit 0
         fi
-        if  [ $first == "yes" ]
+        if  [ $first = "yes" ]
         then
             instances=$id
             first="no"
@@ -114,7 +114,7 @@ get_init_file()
     done
 
     # server id not provided, check if there is only one instance
-    if [ -z "$servid" -a $inst_count -eq 1 ]
+    if [ -z "$servid" ] && [ $inst_count -eq 1 ]
     then
         # return the file
         echo $configfile
@@ -135,48 +135,44 @@ process_dse ()
     configdir=$1
     pid=$2
     file="$configdir/dse.ldif"
-    shopt -s nocasematch
-    OLD_IFC=$IFC
+    OLD_IFS=$IFS
     IFS=""
     while read -r LINE
     do
-        if [[ $LINE !=  \ * ]] && [ "$output" != "" ]
+        case $LINE in
+            ' '*)
+                ;;
+            *)
+                if [ -n "$output" ]
+                then
+                    echo "$output" >> /tmp/DSSharedLib.$pid
+                    output=""
+                fi
+                ;;
+        esac
+        if [ -n "$output" ]
         then
-            echo "$output" >> /tmp/DSSharedLib.$pid
-            output=""
-        fi
-        if [ "$output" != "" ] && [[ $LINE == \ * ]]
-        then
-            # continuation line, strip the space and append it
-            LINE=`echo "$LINE" | sed -e 's/^ //'`
-            output=$output$LINE
-        elif [[ $LINE == nsslapd-port* ]]
-        then
-            output=$LINE;
-        elif [[ $LINE == nsslapd-localhost* ]]
-        then
-            output=$LINE;
-        elif [[ $LINE == nsslapd-securePort* ]]
-        then
-            output=$LINE;
-        elif [[ $LINE == nsslapd-security* ]]
-        then
-            output=$LINE;
-        elif [[ $LINE == nsslapd-ldapilisten* ]]
-        then
-            output=$LINE;
-        elif [[ $LINE == nsslapd-ldapifilepath* ]]
-        then
-            output=$LINE;
-        elif [[ $LINE == nsslapd-rootdn* ]]
-        then
-            output=$LINE;
-        elif [[ $LINE == nsslapd-ldapiautobind* ]]
-        then
-            output=$LINE;
-        elif [[ $LINE == nsslapd-certdir* ]]
-        then
-            output=$LINE;
+            case $LINE in
+                ' '*)
+                    # continuation line, strip the space and append it
+                    LINE=`echo "$LINE" | sed -e 's/^ //'`
+                    output=$output$LINE
+                    ;;
+            esac
+        else
+            case $LINE in
+                nsslapd-certdir*|\
+                nsslapd-ldapiautobind*|\
+                nsslapd-ldapilisten*|\
+                nsslapd-ldapifilepath*|\
+                nsslapd-localhost*|\
+                nsslapd-port*|\
+                nsslapd-rootdn*|\
+                nsslapd-securePort*|\
+                nsslapd-security*)
+                    output=$LINE
+                    ;;
+            esac
         fi
     
     done < $file
@@ -194,19 +190,19 @@ check_protocol ()
     ldapi=$3
     openldap=$4
        
-    if [ "$protocol" == "LDAPI" ] && [ "$openldap" != "yes" ]; then
+    if [ "$protocol" = "LDAPI" ] && [ "$openldap" != "yes" ]; then
         echo ""
         exit
-    elif [ "$protocol" == "LDAPI" ] && [ "$ldapi" == "off" ]; then
+    elif [ "$protocol" = "LDAPI" ] && [ "$ldapi" = "off" ]; then
         echo ""
         exit
-    elif [ "$protocol" == "STARTTLS" ]; then
-        if [ "$security" == "" ] || [ "$security" == "off" ]; then
+    elif [ "$protocol" = "STARTTLS" ]; then
+        if [ -z "$security" ] || [ "$security" = "off" ]; then
             echo ""
             exit
         fi
-    elif [ "$protocol" == "LDAPS" ]; then
-        if [ "$security" == "" ] || [ "$security" == "off" ]; then
+    elif [ "$protocol" = "LDAPS" ]; then
+        if [ -z "$security" ] || [ "$security" = "off" ]; then
             echo ""
             exit
         fi
@@ -224,4 +220,4 @@ check_protocol ()
     fi
 
     echo "$protocol"
-}
+}

+ 13 - 10
ldap/admin/src/scripts/bak2db.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
@@ -26,15 +26,18 @@ if [ $# -lt 1 ] || [ $# -gt 7 ]
 then
     usage
     exit 1
-elif [[ $1 == -* ]]
-then
-    usage
-    exit 1
-else
-    archivedir=$1
-    shift
 fi
-    
+case $1 in
+    -*)
+        usage
+        exit 1
+        ;;
+    *)
+        archivedir=$1
+        shift
+        ;;
+esac
+
 while getopts "hn:Z:qd:vi:a:SD:" flag
 do
     case $flag in
@@ -55,7 +58,7 @@ do
 done
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"

+ 3 - 4
ldap/admin/src/scripts/db2bak.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
@@ -26,7 +26,6 @@ then
     usage
     exit 1
 fi
-
 if [ "$#" -gt 0 ]
 then
     if [[ $1 != -* ]]
@@ -56,7 +55,7 @@ done
 
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
@@ -67,7 +66,7 @@ fi
 servid=`normalize_server_id $initfile`
 . $initfile
 
-if [ -z $bak_dir ]
+if [ -z "$bak_dir" ]
 then
     bak_dir=@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/$servid-`date +%Y_%m_%d_%H_%M_%S`
 fi

+ 2 - 2
ldap/admin/src/scripts/db2index.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
@@ -59,7 +59,7 @@ then
 fi
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"

+ 11 - 11
ldap/admin/src/scripts/db2ldif.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
@@ -39,7 +39,7 @@ make_ldiffile()
     be=""
     while [ "$1" != "" ]
     do
-        if [ "$1" = "-a" ]; then
+        if [ "x$1" = "x-a" ]; then
             shift
             if [ `expr "$1" : "/.*"` -gt 0 ]; then 
 	            if [ `expr "$1" : "/.*"` -gt 0 ]; then 
@@ -56,17 +56,17 @@ make_ldiffile()
                 shift 
                 return 0 
             fi
-        elif [ "$1" = "-n" ]; then
+        elif [ "x$1" = "x-n" ]; then
             shift
-            if [ "$be" = "" ]; then
+            if [ -z "$be" ]; then
                 be="$1"
             else
                 tmpbe="$be"
                 be="${tmpbe}-$1"
             fi
-        elif [ "$1" = "-s" ]; then
+        elif [ "x$1" = "x-s" ]; then
             shift
-            if [ "$1" != "" ]; then
+            if [ -n "$1" ]; then
                 rdn=`echo $1 | awk -F, '{print $1}'`
                 rdnval=`echo $rdn | awk -F= '{print $2}'`
                 if [ "$be" = "" ]; then
@@ -76,15 +76,15 @@ make_ldiffile()
                     be="${tmpbe}-$rdnval"
                 fi
             fi
-        elif [ "$1" = "-M" ]; then
+        elif [ "x$1" = "x-M" ]; then
             be=""
         fi
-        if [ "$1" != "" ]; then
+        if [ -n "$1" ]; then
             shift
         fi
     done
 
-    if [ "$be" = "" ]; then
+    if [ -z "$be" ]; then
         echo @localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/ldif/$servid-`date +%Y_%m_%d_%H%M%S`.ldif
     else
         echo @localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/ldif/$servid-${be}-`date +%Y_%m_%d_%H%M%S`.ldif
@@ -92,7 +92,7 @@ make_ldiffile()
     return 0
 }
 
-if [ "$#" -lt 2 ];
+if [ $# -lt 2 ];
 then
     usage
     exit 1
@@ -137,7 +137,7 @@ then
 fi
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"

+ 3 - 3
ldap/admin/src/scripts/dbverify.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
@@ -47,7 +47,7 @@ do
 done
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
@@ -58,7 +58,7 @@ fi
 . $initfile
 
 @sbindir@/ns-slapd dbverify -D $CONFIG_DIR $args
-if [ $display_version == "yes" ]; then
+if [ $display_version = "yes" ]; then
     exit 0
 fi
 if [ $? -eq 0 ]; then

+ 2 - 2
ldap/admin/src/scripts/dn2rdn.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
@@ -39,7 +39,7 @@ do
 done
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"

+ 2 - 2
ldap/admin/src/scripts/ldif2db.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
@@ -82,7 +82,7 @@ do
 done
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"

+ 23 - 23
ldap/admin/src/scripts/ldif2ldap.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@ldapsdk_libdir@"
 libpath_add "@libdir@"
@@ -40,14 +40,14 @@ do
     esac
 done
 
-if [ "$input_file" == "" ]
+if [ -z "$input_file" ]
 then 
     usage
     exit 1
 fi
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
@@ -67,13 +67,13 @@ ldapi=$(grep -i 'nsslapd-ldapilisten' $file | awk '{print $2}' )
 ldapiURL=$(grep -i 'nsslapd-ldapifilepath' $file | awk '{print $2}' )
 certdir=$(grep -i 'nsslapd-certdir' $file | awk '{print $2}' )
 autobind=$(grep -i 'nsslapd-ldapiautobind' $file | awk '{print $2}' )
-if [ "$rootdn" == "" ]; then
+if [ -z "$rootdn" ]; then
     value=$(grep -i 'nsslapd-rootdn' $file)
     rootdn=`echo "$value" | sed -e 's/nsslapd-rootdn: //i'`
 fi
 rm $file
 
-if [ "$ldapiURL" != "" ]; then
+if [ -n "$ldapiURL" ]; then
     ldapiURL=`echo "$ldapiURL" | sed -e 's/\//%2f/g'`
     ldapiURL="ldapi://"$ldapiURL
 fi
@@ -86,7 +86,7 @@ then
     export LDAPTLS_CACERTDIR=$certdir
 fi
 
-if [ -z $security ]; then
+if [ -z "$security" ]; then
     security="off"
 fi
 revised_protocol=$(check_protocol $protocol $security $ldapi $openldap)
@@ -99,12 +99,12 @@ protocol=$revised_protocol
 #
 # STARTTLS
 #
-if [ "$security" == "on" ]; then
-    if [ "$protocol" == "STARTTLS" ] || [ "$protocol" == "" ]; then
-        if [ "$error" == "yes" ]; then 
+if [ "$security" = "on" ]; then
+    if [ "$protocol" = "STARTTLS" ] || [ -z "$protocol" ]; then
+        if [ "$error" = "yes" ]; then
             echo "Using the next most secure protocol(STARTTLS)"
         fi
-        if [ "$openldap" == "yes" ]; then
+        if [ "$openldap" = "yes" ]; then
             ldapmodify -x -ZZ -p $port -h $host -D $rootdn -w $passwd -a -f $input_file
         else
             ldapmodify -ZZZ -P $certdir -p $port -h $host -D $rootdn -w $passwd -a -f $input_file
@@ -116,12 +116,12 @@ fi
 #
 # LDAPS
 #
-if [ "$security" == "on" ]; then
-    if [ "$protocol" == "LDAPS" ] || [ "$protocol" == "" ]; then
-        if [ "$error" == "yes" ]; then 
+if [ "$security" = "on" ]; then
+    if [ "$protocol" = "LDAPS" ] || [ -z "$protocol" ]; then
+        if [ "$error" = "yes" ]; then
             echo "Using the next most secure protocol(LDAPS)"
         fi
-        if [ "$openldap" == "yes" ]; then
+        if [ "$openldap" = "yes" ]; then
             ldapmodify -x -H "ldaps://$host:$secure_port" -D $rootdn -w $passwd -a -f $input_file
         else
             ldapmodify -Z -P $certdir -p $secure_port -h $host -D $rootdn -w $passwd -a -f $input_file 
@@ -133,21 +133,21 @@ fi
 #
 # LDAPI
 #
-if [ "$ldapi" == "on" ] && [ "$openldap" == "yes" ]; then
-    if [ "$protocol" == "LDAPI" ] || [ "$protocol" == "" ]; then
-        if [ "$(id -u)" == "0" ] && [ "$autobind" == "on" ]; then
-            if [ "$error" == "yes" ]; then 
+if [ "$ldapi" = "on" ] && [ "$openldap" = "yes" ]; then
+    if [ "$protocol" = "LDAPI" ] || [ -z "$protocol" ]; then
+        if [ $(id -u) -eq 0 ] && [ "$autobind" = "on" ]; then
+            if [ "$error" = "yes" ]; then
                 echo "Using the next most secure protocol(LDAPI/AUTOBIND)"
             fi
             ldapmodify -H $ldapiURL -Y EXTERNAL -a -f $input_file 2>/dev/null
         else
-            if [ "$error" == "yes" ]; then 
+            if [ "$error" = "yes" ]; then
                 echo "Using the next most secure protocol(LDAPI)"
             fi
             ldapmodify -x -H $ldapiURL -D $rootdn -w $passwd -a -f $input_file
         fi
         rc=$?
-        if [ $rc != 0 ]
+        if [ $rc -ne 0 ]
         then
             echo "Operation failed (error $rc)"
         fi
@@ -158,11 +158,11 @@ fi
 #
 # LDAP
 #
-if [ "$protocol" == "LDAP" ] || [ "$protocol" == "" ]; then
-    if [ "$error" == "yes" ]; then 
+if [ "$protocol" = "LDAP" ] || [ -z "$protocol" ]; then
+    if [ "$error" = "yes" ]; then
         echo "Using the next most secure protocol(LDAP)"
     fi
-    if [ "$openldap" == "yes" ]; then
+    if [ "$openldap" = "yes" ]; then
         ldapmodify -x -p $port -h $host -D $rootdn -w $passwd -a -f $input_file
     else
         ldapmodify -p $port -h $host -D $rootdn -w $passwd -a -f $input_file

+ 22 - 22
ldap/admin/src/scripts/monitor.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@ldapsdk_libdir@"
@@ -41,7 +41,7 @@ do
 done
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
@@ -66,17 +66,17 @@ ldapi=$(grep -i 'nsslapd-ldapilisten' $file | awk '{print $2}' )
 ldapiURL=$(grep -i 'nsslapd-ldapifilepath' $file | awk '{print $2}' )
 certdir=$(grep -i 'nsslapd-certdir' $file | awk '{print $2}' )
 autobind=$(grep -i 'nsslapd-ldapiautobind' $file | awk '{print $2}' )
-if [ "$rootdn" == "" ]; then
+if [ -z "$rootdn" ]; then
     value=$(grep -i 'nsslapd-rootdn' $file)
     rootdn=`echo "$value" | sed -e 's/nsslapd-rootdn: //i'`
 fi
 rm $file
 
-if [ "$passwd" != "" ]; then
+if [ -n "$passwd" ]; then
     dn="-D $rootdn"
     passwd="-w$passwd"
 fi
-if [ "$ldapiURL" != "" ]
+if [ -n "$ldapiURL" ]
 then
     ldapiURL=`echo "$ldapiURL" | sed -e 's/\//%2f/g'`
     ldapiURL="ldapi://"$ldapiURL
@@ -103,12 +103,12 @@ protocol=$revised_protocol
 #
 # STARTTLS
 #
-if [ "$security" == "on" ]; then
-    if [ "$protocol" == "STARTTLS" ] || [ "$protocol" == "" ]; then
-        if [ "$error" == "yes" ]; then 
+if [ "$security" = "on" ]; then
+    if [ "$protocol" = "STARTTLS" ] || [ -z "$protocol" ]; then
+        if [ "$error" = "yes" ]; then
             echo "Using the next most secure protocol(STARTTLS)"
         fi
-        if [ "$openldap" == "yes" ]; then
+        if [ "$openldap" = "yes" ]; then
             ldapsearch -x -LLL -ZZ -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
         else
             ldapsearch -ZZZ -P $certdir  -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
@@ -120,12 +120,12 @@ fi
 #
 # LDAPS
 #
-if [ "$security" == "on" ]; then
-    if [ "$protocol" == "LDAPS" ] || [ "$protocol" == "" ]; then
-        if [ "$error" == "yes" ]; then 
+if [ "$security" = "on" ]; then
+    if [ "$protocol" = "LDAPS" ] || [ -z "$protocol" ]; then
+        if [ "$error" = "yes" ]; then
             echo "Using the next most secure protocol(LDAPS)"
         fi
-        if [ "$openldap" == "yes" ]; then
+        if [ "$openldap" = "yes" ]; then
             ldapsearch -x -LLL -H "ldaps://$host:$secure_port" -b "$MDN" -s base $dn $passwd "objectClass=*"
         else 
             ldapsearch -Z -P $certdir -p $secure_port -b "$MDN" -s base $dn $passwd "objectClass=*"
@@ -137,15 +137,15 @@ fi
 #
 # LDAPI
 #
-if [ "$ldapi" == "on" ] && [ "$openldap" == "yes" ]; then
-    if [ "$protocol" == "LDAPI" ] || [ "$protocol" == "" ]; then
-        if [ "$(id -u)" == "0" ] && [ "$autobind" == "on" ]; then
-            if [ "$error" == "yes" ]; then 
+if [ "$ldapi" = "on" ] && [ "$openldap" = "yes" ]; then
+    if [ "$protocol" = "LDAPI" ] || [ -z "$protocol" ]; then
+        if [ $(id -u) -eq 0 ] && [ "$autobind" = "on" ]; then
+            if [ "$error" = "yes" ]; then
                 echo "Using the next most secure protocol(LDAPI/AUTOBIND)"
             fi
             ldapsearch -LLL -H "$ldapiURL" -b "$MDN" -s base -Y EXTERNAL "objectClass=*" 2>/dev/null
         else
-            if [ "$error" == "yes" ]; then 
+            if [ "$error" = "yes" ]; then
                 echo "Using the next most secure protocol(LDAPI)"
             fi
             ldapsearch -x -LLL -H "$ldapiURL" -b "$MDN" -s base $dn $passwd "objectClass=*"
@@ -157,14 +157,14 @@ fi
 #
 # LDAP
 #
-if [ "$protocol" == "LDAP" ] || [ "$protocol" == "" ]; then
-    if [ "$error" == "yes" ]; then 
+if [ "$protocol" = "LDAP" ] || [ "$protocol" = "" ]; then
+    if [ "$error" = "yes" ]; then
         echo "Using the next most secure protocol(LDAP)"
     fi
-    if [ "$openldap" == "yes" ]; then
+    if [ "$openldap" = "yes" ]; then
         ldapsearch -x -LLL -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
     else
         ldapsearch -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
-    fi   
+    fi
     exit $?
 fi

+ 1 - 1
ldap/admin/src/scripts/restart-dirsrv.in

@@ -7,7 +7,7 @@
 #       2: Server started successfully (was not running)
 #       3: Server could not be stopped
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 restart_instance() {
     SERV_ID=$1

+ 2 - 2
ldap/admin/src/scripts/restoreconfig.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@nss_libdir@"
@@ -31,7 +31,7 @@ do
 done
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"

+ 3 - 3
ldap/admin/src/scripts/saveconfig.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@libdir@"
@@ -31,7 +31,7 @@ do
 done
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
@@ -45,7 +45,7 @@ servid=`normalize_server_id $initfile`
 echo saving configuration...
 conf_ldif=@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/$servid-`date +%Y_%m_%d_%H%M%S`.ldif
 @sbindir@/ns-slapd db2ldif -N -D $CONFIG_DIR -s "o=NetscapeRoot" -a $conf_ldif -n NetscapeRoot 2>&1
-if [ "$?" -ge 1 ] 
+if [ $? -ge 1 ]
 then
     echo Error occurred while saving configuration
     exit 1

+ 8 - 8
ldap/admin/src/scripts/start-dirsrv.in

@@ -6,7 +6,7 @@
 #       1: Server could not be started
 #       2: Server already running
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 # Starts a single instance
 start_instance() {
@@ -44,7 +44,7 @@ start_instance() {
     STARTPIDFILE=$RUN_DIR/$PRODUCT_NAME-$SERV_ID.startpid
     if test -f $STARTPIDFILE ; then
         PID=`cat $STARTPIDFILE`
-        if kill -0 $PID > /dev/null 2>&1 ; then
+        if kill -s 0 $PID > /dev/null 2>&1 ; then
             echo There is an ns-slapd process already running: $PID
             return 2;
         else
@@ -53,7 +53,7 @@ start_instance() {
     fi
     if test -f $PIDFILE ; then
         PID=`cat $PIDFILE`
-        if kill -0 $PID > /dev/null 2>&1 ; then
+        if kill -s 0 $PID > /dev/null 2>&1 ; then
             echo There is an ns-slapd running: $PID
             return 2;
         else
@@ -64,7 +64,7 @@ start_instance() {
     # Use systemctl if available and running as root, 
     # otherwise start the instance the old way.
     #
-    if [ -d "@systemdsystemunitdir@" ] && [ "$(id -u)" == "0" ];then
+    if [ -d "@systemdsystemunitdir@" ] && [ $(id -u) -eq 0 ];then
         @bindir@/systemctl start @package_name@@$SERV_ID.service
         if [ $? -ne 0 ]; then
             return 1
@@ -96,7 +96,7 @@ start_instance() {
     while test $loop_counter -le $max_count; do
         loop_counter=`expr $loop_counter + 1`
         if test ! -f $PIDFILE ; then
-            if kill -0 $PID > /dev/null 2>&1 ; then
+            if kill -s 0 $PID > /dev/null 2>&1 ; then
                 sleep 1
         else
             echo Server failed to start !!! Please check errors log for problems
@@ -123,12 +123,12 @@ do
 done
 shift $(($OPTIND-1))
 
-if [ "$initconfig_dir" = "" ]; then
+if [ -z "$initconfig_dir" ]; then
     initconfig_dir=@initconfigdir@
 fi
 
 found=0
-if [ "$#" -eq 0 ]; then
+if [ $# -eq 0 ]; then
     # We're starting all instances.
     ret=0
     initfiles=`get_initconfig_files $initconfig_dir` || { echo No instances found in $initconfig_dir ; exit 1 ; }
@@ -137,7 +137,7 @@ if [ "$#" -eq 0 ]; then
         echo Starting instance \"$inst\"
         start_instance $inst
         rv=$?
-        if [ "$rv" -ne 0 ]; then
+        if [ $rv -ne 0 ]; then
             ret=$rv
         fi
     done

+ 7 - 7
ldap/admin/src/scripts/stop-dirsrv.in

@@ -6,7 +6,7 @@
 #       1: Server could not be stopped
 #       2: Server was not running
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 stop_instance() {
     SERV_ID=$1
@@ -28,7 +28,7 @@ stop_instance() {
     fi
     PID=`cat $PIDFILE`
     # see if the server is already stopped
-    kill -0 $PID > /dev/null 2>&1 || {
+    kill -s 0 $PID > /dev/null 2>&1 || {
         echo Server not running
         if test -f $PIDFILE ; then
             rm -f $PIDFILE
@@ -39,7 +39,7 @@ stop_instance() {
     #
     # use systemctl if running as root
     #
-    if [ -d "@systemdsystemunitdir@" ] && [ "$(id -u)" == "0" ];then
+    if [ -d "@systemdsystemunitdir@" ] && [ $(id -u) -eq 0 ];then
         # 
         # Now, check if systemctl is aware of this running instance
         #
@@ -65,7 +65,7 @@ stop_instance() {
     max_count=600
     while test $loop_counter -le $max_count; do
         loop_counter=`expr $loop_counter + 1`
-        if kill -0 $PID > /dev/null 2>&1 ; then
+        if kill -s 0 $PID > /dev/null 2>&1 ; then
             sleep 1;
         else
             if test -f $PIDFILE ; then
@@ -88,11 +88,11 @@ do
 done
 shift $(($OPTIND-1))
 
-if [ "$initconfig_dir" = "" ]; then
+if [ -z "$initconfig_dir" ]; then
     initconfig_dir=@initconfigdir@
 fi
 
-if [ "$#" -eq 0 ]; then
+if [ $# -eq 0 ]; then
     # We're stopping all instances.
     ret=0
     initfiles=`get_initconfig_files $initconfig_dir` || { echo No instances found in $initconfig_dir ; exit 1 ; }
@@ -105,7 +105,7 @@ if [ "$#" -eq 0 ]; then
         echo Stopping instance \"$inst\"
         stop_instance $inst
         rv=$?
-        if [ "$rv" -ne 0 ]; then
+        if [ $rv -ne 0 ]; then
             ret=$rv
         fi
     done

+ 3 - 3
ldap/admin/src/scripts/suffix2instance.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@libdir@"
@@ -32,14 +32,14 @@ do
     esac
 done
 
-if [ "$args" == "" ]
+if [ -z "$args" ]
 then
     usage
     exit 1
 fi
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"

+ 2 - 2
ldap/admin/src/scripts/upgradedb.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@libdir@"
@@ -39,7 +39,7 @@ do
 done
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
     echo "Available instances: $initfile"

+ 3 - 3
ldap/admin/src/scripts/upgradednformat.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 # upgradednformat -- upgrade DN format to the new style (RFC 4514)
 # Usgae: upgradednformat [-N] -n backend_instance -a db_instance_directory
@@ -49,13 +49,13 @@ do
     esac
 done
 
-if [ "$be" = "" ] || [ "$dir" = "" ]; then
+if [ -z "$be" ] || [ -z "$dir" ]; then
     usage
     exit 1
 fi
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"

+ 2 - 2
ldap/admin/src/scripts/vlvindex.in

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-source @datadir@/@package_name@/data/DSSharedLib
+. @datadir@/@package_name@/data/DSSharedLib
 
 libpath_add "@libdir@/@package_name@/"
 libpath_add "@libdir@"
@@ -45,7 +45,7 @@ do
 done
 
 initfile=$(get_init_file "@initconfigdir@" $servid)
-if [ $? == 1 ]
+if [ $? -eq 1 ]
 then
     usage
     echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"

+ 1 - 1
rpm/389-ds-base-git.sh

@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 DATE=`date +%Y%m%d`
 # use a real tag name here

+ 2 - 2
rpm/add_patches.sh

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-function usage()
+usage()
 {
     echo "Adds patches to a specfile"
     echo ""
@@ -51,5 +51,5 @@ for p in $patches; do
     sed -i -e "/${prefix}/a Patch${i}: ${p}" -e "/$prepprefix/a %patch${i} -p1" $specfile
     prefix="Patch${i}:"
     prepprefix="%patch${i}"
-    i=$(($i+1))
+    i=`expr $i + 1`
 done

+ 1 - 1
rpm/rpmverrel.sh

@@ -6,7 +6,7 @@ srcdir=`pwd`
 
 # Source VERSION.sh to set the version
 # and release environment variables.
-source ./VERSION.sh
+. ./VERSION.sh
 
 if [ "$1" = "version" ]; then
   echo $RPM_VERSION

+ 9 - 17
wrappers/initscript.in

@@ -32,28 +32,20 @@ then
     fi
 fi
 
-# figure out which echo we're using
-ECHO_N=`echo -n`
-
-# some shells echo cannot use -n - linux echo by default cannot use \c
 echo_n()
 {
-    if [ "$ECHO_N" = '-n' ] ; then
-        echo "$*\c"
-    else
-        echo -n "$*"
-    fi
+    printf '%s' "$*"
 }
 
 # failure and success are not defined on some platforms
-type failure > /dev/null 2>&1 || {
+which failure > /dev/null 2>&1 || {
 failure()
 {
     echo_n " FAILED"
 }
 }
 
-type success > /dev/null 2>&1 || {
+which success > /dev/null 2>&1 || {
 success()
 {
     echo_n " SUCCESS"
@@ -178,7 +170,7 @@ start() {
             pid=`cat $pidfile`
             instlockfile="@localstatedir@/lock/@package_name@/slapd-$instance/server/$pid"
             name=`ps -p $pid | tail -1 | awk '{ print $4 }'`
-            if kill -0 $pid && [ $name = "ns-slapd" ]; then
+            if kill -s 0 $pid && [ $name = "ns-slapd" ]; then
                 echo_n " already running"
                 success; echo
                 successes=`expr $successes + 1`
@@ -239,7 +231,7 @@ start() {
             while test $loop_counter -le $max_count ; do
                 loop_counter=`expr $loop_counter + 1`
                 if test ! -f $pidfile ; then
-                    if kill -0 $pid > /dev/null 2>&1 ; then
+                    if kill -s 0 $pid > /dev/null 2>&1 ; then
                         sleep 1
                     else
                         break
@@ -249,7 +241,7 @@ start() {
                     break
                 fi
             done
-            if kill -0 $pid > /dev/null 2>&1 && test -f $pidfile ; then
+            if kill -s 0 $pid > /dev/null 2>&1 && test -f $pidfile ; then
                 success; echo
                 successes=`expr $successes + 1`
             else
@@ -278,7 +270,7 @@ stop() {
         if [ -f $pidfile ]; then
             pid=`cat $pidfile`
             server_stopped=0
-            if kill -0 $pid > /dev/null 2>&1 ; then
+            if kill -s 0 $pid > /dev/null 2>&1 ; then
                 kill $pid
                 if [ $? -eq 0 ]; then
                     server_stopped=1
@@ -297,7 +289,7 @@ stop() {
                 max_count=600
                 while test $loop_counter -le $max_count; do
                     loop_counter=`expr $loop_counter + 1`
-                    if kill -0 $pid > /dev/null 2>&1 ; then
+                    if kill -s 0 $pid > /dev/null 2>&1 ; then
                         sleep 1
                     else
                         if test -f $pidfile ; then
@@ -339,7 +331,7 @@ status() {
      for instance in $INSTANCES; do
          if [ -f $piddir/slapd-$instance.pid ]; then
              pid=`cat $piddir/slapd-$instance.pid`
-             if kill -0 $pid > /dev/null 2>&1 ; then
+             if kill -s 0 $pid > /dev/null 2>&1 ; then
                  echo "$prog $instance (pid $pid) is running..."
              else
                 echo "$prog $instance dead but pid file exists"

+ 10 - 18
wrappers/ldap-agent-initscript.in

@@ -31,28 +31,20 @@ then
     fi
 fi
 
-# figure out which echo we're using
-ECHO_N=`echo -n`
-
-# some shells echo cannot use -n - linux echo by default cannot use \c
 echo_n()
 {
-    if [ "$ECHO_N" = '-n' ] ; then
-        echo "$*\c"
-    else
-        echo -n "$*"
-    fi
+    printf '%s' "$*"
 }
 
 # failure and success are not defined on some platforms
-type failure > /dev/null 2>&1 || {
+which failure > /dev/null 2>&1 || {
 failure()
 {
     echo_n " FAILED"
 }
 }
 
-type success > /dev/null 2>&1 || {
+which success > /dev/null 2>&1 || {
 success()
 {
     echo_n " SUCCESS"
@@ -92,7 +84,7 @@ start() {
     if [ -f $pidfile ]; then
         pid=`cat $pidfile`
         name=`ps -p $pid | tail -1 | awk '{ print $4 }'`
-        if kill -0 $pid && [ $name = "$processname" ]; then
+        if kill -s 0 $pid && [ $name = "$processname" ]; then
             echo_n " already running"
             success; echo
             subagent_running=1
@@ -121,7 +113,7 @@ start() {
         while test $loop_counter -le $max_count ; do
             loop_counter=`expr $loop_counter + 1`
             if test ! -f $pidfile ; then
-                if kill -0 $pid > /dev/null 2>&1 ; then
+                if kill -s 0 $pid > /dev/null 2>&1 ; then
                     sleep 1
                 else
                     break
@@ -131,7 +123,7 @@ start() {
                 break
             fi
         done
-        if kill -0 $pid > /dev/null 2>&1 && test -f $pidfile ; then
+        if kill -s 0 $pid > /dev/null 2>&1 && test -f $pidfile ; then
             success; echo
         else
             failure; echo
@@ -147,7 +139,7 @@ stop() {
     if [ -f $pidfile ]; then
         pid=`cat $pidfile`
         subagent_stopped=0
-        if kill -0 $pid > /dev/null 2>&1 ; then
+        if kill -s 0 $pid > /dev/null 2>&1 ; then
             kill $pid
             if [ $? -eq 0 ]; then
                 subagent_stopped=1
@@ -164,7 +156,7 @@ stop() {
             max_count=10
             while test $loop_counter -le $max_count; do
                 loop_counter=`expr $loop_counter + 1`
-                if kill -0 $pid > /dev/null 2>&1 ; then
+                if kill -s 0 $pid > /dev/null 2>&1 ; then
                     sleep 1
                 else
                     if test -f $pidfile ; then
@@ -200,7 +192,7 @@ condrestart() {
     if [ -f $pidfile ]; then
         pid=`cat $pidfile`
         name=`ps -p $pid | tail -1 | awk '{ print $4 }'`
-        if kill -0 $pid && [ $name = "$processname" ]; then
+        if kill -s 0 $pid && [ $name = "$processname" ]; then
             restart
         fi
     fi
@@ -210,7 +202,7 @@ status() {
      ret=0
      if [ -f $pidfile ]; then
          pid=`cat $pidfile`
-         if kill -0 $pid > /dev/null 2>&1 ; then
+         if kill -s 0 $pid > /dev/null 2>&1 ; then
              echo "$prog (pid $pid) is running..."
          else
             echo "$prog dead but pid file exists"