"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/extras/hook-scripts/create/post/S10selinux-label-brick.sh" (16 Sep 2020, 1345 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 #
    3 # Install to hooks/<HOOKS_VER>/create/post
    4 #
    5 # Add an SELinux file context for each brick using the glusterd_brick_t type.
    6 # This ensures that the brick is relabeled correctly on an SELinux restart or
    7 # restore. Subsequently, run a restore on the brick path to set the selinux
    8 # labels.
    9 #
   10 ###
   11 
   12 PROGNAME="Sselinux"
   13 OPTSPEC="volname:"
   14 VOL=
   15 
   16 parse_args () {
   17   ARGS=$(getopt -o '' -l ${OPTSPEC} -n ${PROGNAME} -- "$@")
   18   eval set -- "${ARGS}"
   19 
   20   while true; do
   21     case ${1} in
   22       --volname)
   23         shift
   24         VOL=${1}
   25       ;;
   26       *)
   27         shift
   28         break
   29       ;;
   30     esac
   31     shift
   32   done
   33 }
   34 
   35 set_brick_labels()
   36 {
   37   volname="${1}"
   38 
   39   # grab the path for each local brick
   40   brickpath="/var/lib/glusterd/vols/${volname}/bricks/"
   41   brickdirs=$(
   42     find "${brickpath}" -type f -exec grep '^path=' {} \; | \
   43     cut -d= -f 2 | \
   44     sort -u
   45   )
   46 
   47   for b in ${brickdirs}; do
   48     # Add a file context for each brick path and associate with the
   49     # glusterd_brick_t SELinux type.
   50     pattern="${b}(/.*)?"
   51     semanage fcontext --add -t glusterd_brick_t -r s0 "${pattern}"
   52     # Set the labels on the new brick path.
   53     restorecon -R "${b}"
   54   done
   55 }
   56 
   57 SELINUX_STATE=$(which getenforce && getenforce)
   58 [ "${SELINUX_STATE}" = 'Disabled' ] && exit 0
   59 
   60 parse_args "$@"
   61 [ -z "${VOL}" ] && exit 1
   62 
   63 set_brick_labels "${VOL}"
   64 
   65 exit 0