Blame SOURCES/scl-register-helper.sh

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