2 Commits
1.8 ... 1.9

Author SHA1 Message Date
4937e1ee11 Merge pull request 'add openrc-user-hook' (#27) from openrc-user-sv into master
Reviewed-on: #27
2025-03-08 16:30:54 +01:00
b6e6922998 add openrc-user-hook 2025-03-08 16:28:30 +01:00
3 changed files with 65 additions and 10 deletions

View File

@@ -0,0 +1,11 @@
[Trigger]
Type = Path
Operation = Install
Operation = Upgrade
Target = etc/user/init.d/*
[Action]
Description = Configuring openrc user ...
When = PostTransaction
Exec = /usr/share/libalpm/scripts/openrc-user-hook create
NeedsTargets

View File

@@ -10,23 +10,17 @@ openrc_live() {
svc_help(){
echo " ==> Start/stop/restart a service:"
echo " rc-service <service> <start/stop/restart>"
echo " ==> Further info on user services:"
echo "https://wiki.artixlinux.org/Main/OpenRC#User_Services"
}
svc_add_help(){
echo " ==> Add a service to runlevel:"
echo " rc-update add <service> <runlevel>"
echo " ==> Add a user service to runlevel:"
echo " rc-update add <service> <runlevel> -U"
svc_help
}
svc_del_help(){
echo " ==> Remove a service from runlevel:"
echo " rc-update del <service> <runlevel>"
echo " ==> Remove a user service from runlevel:"
echo " rc-update del <service> <runlevel> -U"
svc_help
}
@@ -39,11 +33,11 @@ each_conf() {
op="$1"; shift
case $op in
sysctl) openrc_live; each_conf /usr/bin/sysctl -q -p ;;
binfmt) openrc_live; each_conf /usr/lib/openrc/sh/binfmt.sh ;;
sysctl) openrc_live; each_conf /usr/bin/sysctl -q -p ;;
binfmt) openrc_live; each_conf /usr/lib/openrc/sh/binfmt.sh ;;
reexec) openrc_live; /usr/bin/openrc-shutdown -R ;;
# For use by other packages
reload) openrc_live; /usr/bin/rc-service "$@" reload ;;
# For use by other packages
reload) openrc_live; /usr/bin/rc-service "$@" reload ;;
add) svc_add_help ;;
del) svc_del_help ;;
*) echo >&2 " Invalid operation '$op'"; exit 1 ;;

View File

@@ -0,0 +1,50 @@
#!/bin/sh -e
openrc_live() {
if [ ! -f /run/openrc/softlevel ]; then
echo >&2 " Skipped: Current root is not booted."
exit 0
fi
}
svc_help(){
echo " ==> Start/stop/restart a service:"
echo " rc-service -U <service> <start/stop/restart>"
}
svc_add_help(){
echo " ==> Add a user service to runlevel:"
echo " rc-update -U add <service> <runlevel>"
svc_help
}
svc_del_help(){
echo " ==> Remove a user service from runlevel:"
echo " rc-update -U del <service> <runlevel>"
svc_help
}
create_user_symlinks() {
umin=$(grep "^UID_MIN" /etc/login.defs)
umax=$(grep "^UID_MAX" /etc/login.defs)
users=$(awk -F':' -v "min=${umin##UID_MIN}" -v "max=${umax##UID_MAX}" \
'{ if ( $3 >= min && $3 <= max ) print $0 }' /etc/passwd \
| cut -d: -f1)
for u in $users; do
if [ ! -e /etc/init.d/user.$u ]; then
ln -sv /etc/init.d/user /etc/init.d/user.$u
fi
done
}
op="$1"; shift
case $op in
create) openrc_live; create_user_symlinks ;;
add) svc_add_help ;;
del) svc_del_help ;;
*) echo >&2 " Invalid operation '$op'"; exit 1 ;;
esac
exit 0