From aee9e3d27f56e4c0c2f981f20b15189eb7ffce51 Mon Sep 17 00:00:00 2001 From: Xavier Hernandez Date: Fri, 19 Jan 2018 12:18:13 +0100 Subject: tests: improve and fix some test scripts Change-Id: Iceefe22af754096c599dc570d4894d14fce4deae Updates: bz#1193929 Signed-off-by: Xavier Hernandez --- .../delete/pre/S10selinux-del-fcontext.sh | 30 ++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'extras') diff --git a/extras/hook-scripts/delete/pre/S10selinux-del-fcontext.sh b/extras/hook-scripts/delete/pre/S10selinux-del-fcontext.sh index e7f4e8f5d49..056b52afe76 100755 --- a/extras/hook-scripts/delete/pre/S10selinux-del-fcontext.sh +++ b/extras/hook-scripts/delete/pre/S10selinux-del-fcontext.sh @@ -35,26 +35,30 @@ function parse_args () { function delete_brick_fcontext() { - volname="${1}" + local volname=$1 + local fctx + local list=() + fctx="$(semanage fcontext --list -C)" # grab the path for each local brick brickpath="/var/lib/glusterd/vols/${volname}/bricks/" - brickdirs=$( - find "${brickpath}" -type f -exec grep '^path=' {} \; | \ - cut -d= -f 2 | \ - sort -u - ) - + brickdirs=$(find "${brickpath}" -type f -exec grep '^path=' {} \; | \ + cut -d= -f 2 | sort -u) for b in ${brickdirs} do - # remove the file context associated with the brick path pattern="${b}(/.*)?" - semanage fcontext --delete "${pattern}" - - # remove the labels on brick path. + echo "${fctx}" | grep "^${pattern}\s" >/dev/null + if [[ $? -eq 0 ]]; then + list+=("${pattern}") + fi + done + if [[ ${#list[@]} -gt 0 ]]; then + printf 'fcontext --delete %s\n' "${list[@]}" | semanage -i - + fi + for b in ${brickdirs} + do restorecon -R "${b}" - done - + done } SELINUX_STATE=$(which getenforce && getenforce) -- cgit