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