e7a346
From 121180edc218432a782a153e94b9f884d4c56a7c Mon Sep 17 00:00:00 2001
e7a346
From: Anoop C S <anoopcs@redhat.com>
e7a346
Date: Sun, 9 Sep 2018 11:39:47 +0530
e7a346
Subject: [PATCH 482/493] extras/hooks: General improvements to
e7a346
 S30samba-start.sh
e7a346
e7a346
Based on https://review.gluster.org/c/glusterfs/+/19204 from
e7a346
Milan Zink <mzink@redhat.com>
e7a346
e7a346
upstream ref: https://review.gluster.org/c/glusterfs/+/21124
e7a346
e7a346
Change-Id: I61f62407a62475a74a6cc046c24748a31c66e6cd
e7a346
BUG: 1541568
e7a346
Signed-off-by: Anoop C S <anoopcs@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/158496
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e7a346
---
e7a346
 extras/hook-scripts/start/post/S30samba-start.sh | 26 ++++++++++++------------
e7a346
 1 file changed, 13 insertions(+), 13 deletions(-)
e7a346
e7a346
diff --git a/extras/hook-scripts/start/post/S30samba-start.sh b/extras/hook-scripts/start/post/S30samba-start.sh
e7a346
index 5d586ee..dfd9c1b 100755
e7a346
--- a/extras/hook-scripts/start/post/S30samba-start.sh
e7a346
+++ b/extras/hook-scripts/start/post/S30samba-start.sh
e7a346
@@ -68,14 +68,14 @@ function parse_args () {
e7a346
 }
e7a346
 
e7a346
 function find_config_info () {
e7a346
-        cmdout=`smbd -b | grep smb.conf`
e7a346
-        if [ $? -ne 0 ];then
e7a346
+        cmdout=$(smbd -b 2> /dev/null)
e7a346
+        CONFIGFILE=$(echo "$cmdout" | grep CONFIGFILE | awk '{print $2}')
e7a346
+        if [ -z "$CONFIGFILE" ]; then
e7a346
                 echo "Samba is not installed"
e7a346
                 exit 1
e7a346
         fi
e7a346
-        CONFIGFILE=`echo $cmdout | awk '{print $2}'`
e7a346
-        PIDDIR=`smbd -b | grep PIDDIR | awk '{print $2}'`
e7a346
-        LOGFILEBASE=`smbd -b | grep 'LOGFILEBASE' | awk '{print $2}'`
e7a346
+        PIDDIR=$(echo "$cmdout" | grep PIDDIR | awk '{print $2}')
e7a346
+        LOGFILEBASE=$(echo "$cmdout" | grep 'LOGFILEBASE' | awk '{print $2}')
e7a346
 }
e7a346
 
e7a346
 function add_samba_share () {
e7a346
@@ -89,11 +89,11 @@ function add_samba_share () {
e7a346
         STRING+="path = /\n"
e7a346
         STRING+="read only = no\n"
e7a346
         STRING+="guest ok = yes\n"
e7a346
-        printf "$STRING"  >> ${CONFIGFILE}
e7a346
+        printf "$STRING"  >> "${CONFIGFILE}"
e7a346
 }
e7a346
 
e7a346
 function sighup_samba () {
e7a346
-        pid=`cat ${PIDDIR}/smbd.pid`
e7a346
+        pid=$(cat "${PIDDIR}/smbd.pid" 2> /dev/null)
e7a346
         if [ "x$pid" != "x" ]
e7a346
         then
e7a346
                 kill -HUP "$pid";
e7a346
@@ -106,12 +106,12 @@ function get_smb () {
e7a346
         volname=$1
e7a346
         uservalue=
e7a346
 
e7a346
-        usercifsvalue=$(grep user.cifs $GLUSTERD_WORKDIR/vols/"$volname"/info |\
e7a346
+        usercifsvalue=$(grep user.cifs "$GLUSTERD_WORKDIR"/vols/"$volname"/info |\
e7a346
                         cut -d"=" -f2)
e7a346
-        usersmbvalue=$(grep user.smb $GLUSTERD_WORKDIR/vols/"$volname"/info |\
e7a346
+        usersmbvalue=$(grep user.smb "$GLUSTERD_WORKDIR"/vols/"$volname"/info |\
e7a346
                        cut -d"=" -f2)
e7a346
 
e7a346
-        if [ $usercifsvalue = "disable" ] || [ $usersmbvalue = "disable" ]; then
e7a346
+        if [ "$usercifsvalue" = "disable" ] || [ "$usersmbvalue" = "disable" ]; then
e7a346
                 uservalue="disable"
e7a346
         fi
e7a346
         echo "$uservalue"
e7a346
@@ -125,9 +125,9 @@ fi
e7a346
 #Find smb.conf, smbd pid directory and smbd logfile path
e7a346
 find_config_info
e7a346
 
e7a346
-if ! grep --quiet "\[gluster-$VOL\]" ${CONFIGFILE} ; then
e7a346
-        add_samba_share $VOL
e7a346
+if ! grep --quiet "\[gluster-$VOL\]" "${CONFIGFILE}" ; then
e7a346
+        add_samba_share "$VOL"
e7a346
 else
e7a346
-        sed -i '/\[gluster-'"$VOL"'\]/,/^$/!b;/available = no/d' ${CONFIGFILE}
e7a346
+        sed -i '/\[gluster-'"$VOL"'\]/,/^$/!b;/available = no/d' "${CONFIGFILE}"
e7a346
 fi
e7a346
 sighup_samba
e7a346
-- 
e7a346
1.8.3.1
e7a346