Blame SOURCES/scl-register-helper.sh

fa51b1
#!/bin/sh
fa51b1
fa51b1
scl_reggen(){
fa51b1
fa51b1
  # helper function to save some chars
fa51b1
  add2file(){
fa51b1
    if ! [ -f "${2}" ] ; then
fa51b1
      mkdir -p $(dirname "${2}")
fa51b1
      echo "#!/bin/sh" >"${2}"
fa51b1
      chmod a+x "${2}"
fa51b1
    fi
fa51b1
    echo "${1}" >>"${2}"
fa51b1
  }
fa51b1
fa51b1
  package=$1
fa51b1
  [ -z "$package" ] && echo "No package specified." && return 1
fa51b1
  shift
fa51b1
fa51b1
  while [ -n "$1" ] ; do
fa51b1
    action="$1"
fa51b1
    shift
fa51b1
fa51b1
    case "$action" in
fa51b1
fa51b1
      --cpfile )
fa51b1
        file=$1
fa51b1
        shift
fa51b1
        [ -z "$file" ] && echo "No file specified for cpfile." && return 1
fa51b1
        # make dir and cp file
fa51b1
        mkdir -p $(dirname ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/register.content${file})
fa51b1
        cp ${_SR_BUILDROOT}${file} ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/register.content${file}
fa51b1
        # add command to script that handles copying file on register
fa51b1
        add2file "cp -n ${_SR_SCL_SCRIPTS}/register.content${file} ${file}" \
fa51b1
                 ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/register.d/50.${package}.content-create
fa51b1
        # add command to script that handles removing file on deregister
fa51b1
        add2file "rm -f ${file}" ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/deregister.d/50.${package}.content-remove
fa51b1
        ;;
fa51b1
fa51b1
      --selinux )
fa51b1
        dst=$1
fa51b1
        src=$2
fa51b1
        shift 2
fa51b1
        [ -z "$dst" ] && echo "No src or dst specified for selinux." && return 1
fa51b1
        # store rule for setting selinux
fa51b1
        add2file "semanage fcontext -a -e \"$src\" \"$dst\" >/dev/null 2>&1 || :" \
fa51b1
                 ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/register.d/20.${package}.selinux-set
fa51b1
        # store rule for restoring selinux
fa51b1
        add2file "restorecon -R \"$dst\" >/dev/null 2>&1 || :" \
fa51b1
                 ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/register.d/80.${package}.selinux-restore
fa51b1
        ;;
fa51b1
fa51b1
      --mkdir )
fa51b1
        dst=$1
fa51b1
        shift
fa51b1
        [ -z "$dst" ] && echo "No dst specified for mkdir." && return 1
fa51b1
        # store command for creating directory
fa51b1
        add2file "mkdir -p ${dst}" ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/register.d/40.${package}.content-create
fa51b1
        # store command for removing directory if empty, ignore errors
fa51b1
        add2file "rmdir --ignore-fail-on-non-empty -p ${dst}" \
fa51b1
                 ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/deregister.d/60.${package}.content-remove
fa51b1
        ;;
fa51b1
fa51b1
      --touch )
fa51b1
        file=$1
fa51b1
        shift
fa51b1
        [ -z "$file" ] && echo "No file specified for touch." && return 1
fa51b1
        # store command for creating file
fa51b1
        add2file "touch ${file}" ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/register.d/50.${package}.content-create
fa51b1
        # add command to script that handles removing file on deregister
fa51b1
        add2file "rm -f ${file}" ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/deregister.d/50.${package}.content-remove
fa51b1
        ;;
fa51b1
fa51b1
      --chmod )
fa51b1
        dst=$2
fa51b1
        args=$1
fa51b1
        shift 2
fa51b1
        [ -z "$args" ] && echo "No dst or args specified for chmod." && return 1
fa51b1
        # store command for chmod
fa51b1
        add2file "chmod $args ${dst}" ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/register.d/60.${package}.attrs
fa51b1
        ;;
fa51b1
fa51b1
      --chown )
fa51b1
        dst=$1
fa51b1
        args=$2
fa51b1
        shift 2
fa51b1
        [ -z "$args" ] && echo "No dst or args specified for chown." && return 1
fa51b1
        # store command for chown
fa51b1
        add2file "chown $args ${dst}" ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/register.d/60.${package}.attrs
fa51b1
        ;;
fa51b1
fa51b1
      --runafterregister )
fa51b1
        cmd=$1
fa51b1
        shift
fa51b1
        [ -z "$cmd" ] && echo "No cmd specified for run." && return 1
fa51b1
        # store command for running after
fa51b1
        add2file "$cmd" ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/register.d/90.${package}.run
fa51b1
        ;;
fa51b1
fa51b1
      --runafterderegister )
fa51b1
        cmd=$1
fa51b1
        shift
fa51b1
        [ -z "$cmd" ] && echo "No cmd specified for run." && return 1
fa51b1
        # store command for running after
fa51b1
        add2file "$cmd" ${_SR_BUILDROOT}${_SR_SCL_SCRIPTS}/deregister.d/90.${package}.run
fa51b1
        ;;
fa51b1
fa51b1
      *)
fa51b1
        echo "Wrong action $*"
fa51b1
        return 1
fa51b1
        ;;
fa51b1
    esac
fa51b1
  done
fa51b1
}