Blame SOURCES/daemon-scl-helper.sh

28a3cc
#!/bin/sh
28a3cc
28a3cc
# This helper script is necessary for having proper SELinux context of daemon
28a3cc
# process run in SCL environment via systemd unit file.
28a3cc
# Without this script the process looses SELinux type because /usr/bin/scl
28a3cc
# has context bin_t and unit_t -> bin_t results in unconfined process running.
28a3cc
# If this helper script has the same SELinux context as the original binary,
28a3cc
# the process will have proper SELinux context.
28a3cc
#
28a3cc
# This script was designed to be usable the same as the scl command is used,
28a3cc
# including the collections given as more arguments, separated from binary
28a3cc
# itself by -- separator.
28a3cc
# So it is possible to use the list of collections to be enabled via
28a3cc
# environment file.
28a3cc
# Thus, instead of:
28a3cc
#   /usr/bin/scl enable scl1 scl2 -- /path/to/bin arg1 arg2
28a3cc
# you can use:
28a3cc
#   /usr/bin/this-script enable scl1 scl2 -- /path/to/bin arg1 arg2
28a3cc
#
28a3cc
# Notice: do not forget to set proper SELinux context for this file.
28a3cc
# The context should be the same as the binary running has.
28a3cc
28a3cc
action="$1"
28a3cc
shift
28a3cc
28a3cc
while [ -n "$1" ] && [ "$1" != "--" ] ; do
28a3cc
  source scl_source "$action" "$1"
28a3cc
  shift
28a3cc
done
28a3cc
28a3cc
if [ $# -le 2 ] ; then
28a3cc
  echo "Usage `basename $0` enable sclname [sclname ...] -- /path/to/bin [arg ...]" >&2
28a3cc
  exit 1
28a3cc
fi
28a3cc
28a3cc
shift
28a3cc
28a3cc
exec "$@"
28a3cc
28a3cc
28a3cc