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