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