e7a346
From 994f4d8922f45e298aa6c048614319f353994550 Mon Sep 17 00:00:00 2001
e7a346
From: Milan Zink <mzink@redhat.com>
e7a346
Date: Wed, 10 Jan 2018 13:04:42 +0100
e7a346
Subject: [PATCH 159/180] extras/hooks: Fix S10selinux-label-brick.sh hook
e7a346
 script
e7a346
e7a346
* script was failng due to syntax error
e7a346
* shellcheck issues fixed
e7a346
* improved performance: semanage & restorecon is being run on unique path
e7a346
e7a346
>upstream patch : https://review.gluster.org/#/c/19177/
e7a346
e7a346
Change-Id: I58b357d9fd37586004a2a518f7a5d1c5c9ddd7e3
e7a346
BUG: 1546075
e7a346
Signed-off-by: Milan Zink <zeten30@gmail.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/130591
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e7a346
---
e7a346
 .../create/post/S10selinux-label-brick.sh          | 57 +++++++++++-----------
e7a346
 1 file changed, 29 insertions(+), 28 deletions(-)
e7a346
e7a346
diff --git a/extras/hook-scripts/create/post/S10selinux-label-brick.sh b/extras/hook-scripts/create/post/S10selinux-label-brick.sh
e7a346
index 6be4072..de242d2 100755
e7a346
--- a/extras/hook-scripts/create/post/S10selinux-label-brick.sh
e7a346
+++ b/extras/hook-scripts/create/post/S10selinux-label-brick.sh
e7a346
@@ -14,48 +14,49 @@ OPTSPEC="volname:"
e7a346
 VOL=
e7a346
 
e7a346
 parse_args () {
e7a346
-        ARGS=$(getopt -o '' -l $OPTSPEC -n $PROGNAME -- "$@")
e7a346
-        eval set -- "$ARGS"
e7a346
-
e7a346
-        while true; do
e7a346
-        case $1 in
e7a346
-        --volname)
e7a346
-         shift
e7a346
-         VOL=$1
e7a346
-         ;;
e7a346
-        *)
e7a346
-         shift
e7a346
-         break
e7a346
-         ;;
e7a346
-        esac
e7a346
+  ARGS=$(getopt -o '' -l ${OPTSPEC} -n ${PROGNAME} -- "$@")
e7a346
+  eval set -- "${ARGS}"
e7a346
+
e7a346
+  while true; do
e7a346
+    case ${1} in
e7a346
+      --volname)
e7a346
+        shift
e7a346
+        VOL=${1}
e7a346
+      ;;
e7a346
+      *)
e7a346
         shift
e7a346
-        done
e7a346
+        break
e7a346
+      ;;
e7a346
+    esac
e7a346
+    shift
e7a346
+  done
e7a346
 }
e7a346
 
e7a346
 set_brick_labels()
e7a346
 {
e7a346
-        volname=$1
e7a346
+  volname=${1}
e7a346
 
e7a346
-        # grab the path for each local brick
e7a346
-        brickdirs=$(grep '^path=' /var/lib/glusterd/vols/${volname}/bricks/* | cut -d= -f 2)
e7a346
+  # grab the path for each local brick
e7a346
+  brickpath="/var/lib/glusterd/vols/${volname}/bricks/*"
e7a346
+  brickdirs=$(grep '^path=' "${brickpath}" | cut -d= -f 2 | sort -u)
e7a346
 
e7a346
-        for b in $brickdirs
e7a346
-        do
e7a346
-                # Add a file context for each brick path and associate with the
e7a346
-                # glusterd_brick_t SELinux type.
e7a346
-                semanage fcontext --add -t glusterd_brick_t -r s0 $b(/.*)?
e7a346
+  for b in ${brickdirs}; do
e7a346
+    # Add a file context for each brick path and associate with the
e7a346
+    # glusterd_brick_t SELinux type.
e7a346
+    pattern="${b}\(/.*\)?"
e7a346
+    semanage fcontext --add -t glusterd_brick_t -r s0 "${pattern}"
e7a346
 
e7a346
-                # Set the labels on the new brick path.
e7a346
-                restorecon -R $b
e7a346
-        done
e7a346
+    # Set the labels on the new brick path.
e7a346
+    restorecon -R "${b}"
e7a346
+  done
e7a346
 }
e7a346
 
e7a346
 SELINUX_STATE=$(which getenforce && getenforce)
e7a346
 [ "${SELINUX_STATE}" = 'Disabled' ] && exit 0
e7a346
 
e7a346
 parse_args "$@"
e7a346
-[ -z "$VOL" ] && exit 1
e7a346
+[ -z "${VOL}" ] && exit 1
e7a346
 
e7a346
-set_brick_labels $VOL
e7a346
+set_brick_labels "${VOL}"
e7a346
 
e7a346
 exit 0
e7a346
-- 
e7a346
1.8.3.1
e7a346