forked from artix/alpm-hooks
		
	Compare commits
	
		
			30 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| faca7dbca1 | |||
| 1f78e5fa1c | |||
| e5e819e337 | |||
| 1729205a54 | |||
| bd83fd645d | |||
| c9518dae35 | |||
| 51cf1104bd | |||
| 89b170310d | |||
| 4937e1ee11 | |||
| b6e6922998 | |||
| 48b9a2a9ec | |||
| e14878b49c | |||
| 31f3dda786 | |||
| 09ef3fc619 | |||
| 9442565f14 | |||
| c17eb2ad37 | |||
| 70445d2177 | |||
| 5d3cd01ffe | |||
| fccd8fcdd9 | |||
| 0126b86bf7 | |||
| 1487bf4089 | |||
| cf66dd76c5 | |||
| d68ed909c4 | |||
|   | 3ada9e391e | ||
| 3d142ebda7 | |||
| 7a5877342a | |||
| 6a1c2c55d9 | |||
| 09bc2d021b | |||
| 8396101929 | |||
| 1344532759 | 
							
								
								
									
										13
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								Makefile
									
									
									
									
									
								
							| @@ -2,6 +2,7 @@ PREFIX ?= /usr | ||||
| ALPMDIR = $(PREFIX)/share/libalpm | ||||
| SCRIPTSDIR = $(ALPMDIR)/scripts | ||||
| HOOKSDIR = $(ALPMDIR)/hooks | ||||
| BINDIR = $(PREFIX)/bin | ||||
|  | ||||
| OPENRCSCRIPTS = $(wildcard openrc/scripts/*) | ||||
| OPENRCHOOKS = $(wildcard openrc/hooks/*) | ||||
| @@ -33,9 +34,11 @@ UDEVHOOKS = $(wildcard udev/hooks/*) | ||||
| BASESCRIPTS = $(wildcard base/scripts/*) | ||||
| BASEHOOKS = $(wildcard base/hooks/*) | ||||
|  | ||||
| TMPFILESHOOKS = $(wildcard tmpfiles/hooks/*) | ||||
| TMPFILESHOOKS = $(wildcard etmpfiles/hooks/*) | ||||
|  | ||||
| SYSUSERSHOOKS = $(wildcard sysusers/hooks/*) | ||||
| SYSUSERSHOOKS = $(wildcard esysusers/hooks/*) | ||||
|  | ||||
| WRAPPER = $(wildcard wrapper/*) | ||||
|  | ||||
| DMODE = -dm0755 | ||||
| MODE = -m0644 | ||||
| @@ -105,4 +108,8 @@ install_dinit_at: install_hook_common | ||||
| install_dinit_dbus: install_hook_common | ||||
| 	install $(MODE) $(DINITDBUSHOOKS) $(DESTDIR)$(HOOKSDIR) | ||||
|  | ||||
| .PHONY: install install_base install_s6 install_openrc install_runit install_dinit | ||||
| install_wrapper: | ||||
| 	install $(DMODE) $(DESTDIR)$(BINDIR) | ||||
| 	install $(EMODE) $(WRAPPER) $(DESTDIR)$(BINDIR) | ||||
|  | ||||
| .PHONY: install install_base install_s6 install_openrc install_runit install_dinit install_wrapper | ||||
|   | ||||
| @@ -7,5 +7,5 @@ Target = usr/lib/binfmt.d/*.conf | ||||
| [Action] | ||||
| Description = Registering binary formats... | ||||
| When = PostTransaction | ||||
| Exec = /usr/share/libalpm/scripts/dinit-hook binfmt | ||||
| Exec = /usr/lib/artix/binfmt.sh | ||||
| NeedsTargets | ||||
| @@ -33,7 +33,7 @@ init_detect(){ | ||||
| s6_init_remake(){ | ||||
|     # we need to ensure that s6-linux-init-maker is run on every machine | ||||
|     rm -rf /tmp/current | ||||
|     s6-linux-init-maker -1 -G "/usr/bin/agetty -L -8 tty7 115200" -c /etc/s6/current /tmp/current | ||||
|     s6-linux-init-maker -1 -G "/usr/bin/agetty -L -8 tty12 115200" -c /etc/s6/current /tmp/current | ||||
|     mv /tmp/current/bin/init /tmp/current/bin/s6-init | ||||
|     cp -a /tmp/current/bin /usr | ||||
|     rm -rf /tmp/current/{bin,scripts} | ||||
|   | ||||
							
								
								
									
										11
									
								
								dinit/hooks/dinit-user-install.hook
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								dinit/hooks/dinit-user-install.hook
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| [Trigger] | ||||
| Type = Path | ||||
| Operation = Install | ||||
| Operation = Upgrade | ||||
| Target = etc/dinit.d/user/* | ||||
|  | ||||
| [Action] | ||||
| Description = Displaying dinit user service help ... | ||||
| When = PostTransaction | ||||
| Exec = /usr/share/libalpm/scripts/dinit-hook addU | ||||
| NeedsTargets | ||||
							
								
								
									
										10
									
								
								dinit/hooks/dinit-user-remove.hook
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								dinit/hooks/dinit-user-remove.hook
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| [Trigger] | ||||
| Type = Path | ||||
| Operation = Remove | ||||
| Target = etc/dinit.d/user/* | ||||
|  | ||||
| [Action] | ||||
| Description = Displaying dinit user service help ... | ||||
| When = PostTransaction | ||||
| Exec = /usr/share/libalpm/scripts/dinit-hook delU | ||||
| NeedsTargets | ||||
							
								
								
									
										11
									
								
								dinit/hooks/dinit-user-spawn-install.hook
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								dinit/hooks/dinit-user-spawn-install.hook
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| [Trigger] | ||||
| Type = Path | ||||
| Operation = Install | ||||
| # Operation = Upgrade | ||||
| Target = usr/lib/dinit.d/dinit-user-spawn | ||||
|  | ||||
| [Action] | ||||
| Description = Enabling dinit user spawn ... | ||||
| When = PostTransaction | ||||
| Exec = /usr/share/libalpm/scripts/dinit-hook userspawnE | ||||
| NeedsTargets | ||||
							
								
								
									
										10
									
								
								dinit/hooks/dinit-user-spawn-remove.hook
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								dinit/hooks/dinit-user-spawn-remove.hook
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| [Trigger] | ||||
| Type = Path | ||||
| Operation = Remove | ||||
| Target = usr/lib/dinit.d/dinit-user-spawn | ||||
|  | ||||
| [Action] | ||||
| Description = Disabling dinit user service help ... | ||||
| When = PostTransaction | ||||
| Exec = /usr/share/libalpm/scripts/dinit-hook userspawnD | ||||
| NeedsTargets | ||||
| @@ -14,13 +14,25 @@ svc_help(){ | ||||
|  | ||||
| svc_add_help(){ | ||||
|     echo "	==> Add a service:" | ||||
|     echo "	dinitctl enable <service>" | ||||
|     echo "	# dinitctl enable <service>" | ||||
|     svc_help | ||||
| } | ||||
|  | ||||
| svc_del_help(){ | ||||
|     echo "	==> Remove a service:" | ||||
|     echo "	dinitctl disable <service>" | ||||
|     echo "	# dinitctl disable <service>" | ||||
|     svc_help | ||||
| } | ||||
|  | ||||
| svc_user_add_help(){ | ||||
|     echo "	==> Add a user service:" | ||||
|     echo "	$ dinitctl enable <service>" | ||||
|     svc_help | ||||
| } | ||||
|  | ||||
| svc_user_del_help(){ | ||||
|     echo "	==> Remove a user service:" | ||||
|     echo "	$ dinitctl disable <service>" | ||||
|     svc_help | ||||
| } | ||||
|  | ||||
| @@ -42,17 +54,29 @@ restart_service() { | ||||
|     fi | ||||
| } | ||||
|  | ||||
| handle_user_spawn() { | ||||
|     if [ ! -S /run/dinitctl ]; then | ||||
|         echo >&2 "  Current root is not booted." | ||||
|         dinitctl "$1" -o dinit-user-spawn | ||||
|     else | ||||
|         dinitctl "$1" dinit-user-spawn | ||||
|     fi | ||||
| } | ||||
|  | ||||
| op="$1"; shift | ||||
|  | ||||
| case $op in | ||||
|   sysctl)   dinit_live; each_conf /usr/bin/sysctl -q -p ;; | ||||
|   binfmt)   dinit_live; /usr/bin/dinitctl restart binfmt ;; | ||||
|   dbus_reload) dinit_live; reload_dbus ;; | ||||
|     # For use by other packages | ||||
|   reload)   dinit_live; /usr/bin/dinitctl reload "$@"; /usr/bin/dinitctl restart "$@" ;; | ||||
|   restart)  dinit_live; restart_service "$1" ;; | ||||
|   add)      svc_add_help ;; | ||||
|   del)      svc_del_help ;; | ||||
|   addU)      svc_user_add_help ;; | ||||
|   delU)      svc_user_del_help ;; | ||||
|   userspawnE) handle_user_spawn enable ;; | ||||
|   userspawnD) handle_user_spawn disable ;; | ||||
|   *) echo >&2 "  Invalid operation '$op'"; exit 1 ;; | ||||
| esac | ||||
|  | ||||
|   | ||||
| @@ -7,4 +7,4 @@ Target = usr/lib/sysusers.d/*.conf | ||||
| [Action] | ||||
| Description = Creating system user accounts... | ||||
| When = PostTransaction | ||||
| Exec = /usr/bin/sysusers | ||||
| Exec = /usr/bin/esysusers | ||||
| @@ -7,4 +7,4 @@ Target = usr/lib/tmpfiles.d/*.conf | ||||
| [Action] | ||||
| Description = Creating temporary files... | ||||
| When = PostTransaction | ||||
| Exec = /usr/bin/tmpfiles --create | ||||
| Exec = /usr/bin/etmpfiles --create | ||||
| @@ -4,6 +4,6 @@ Operation = Upgrade | ||||
| Target = openrc | ||||
|  | ||||
| [Action] | ||||
| Description = Reexecuting init ... | ||||
| Description = Configuring user service & reexecuting init ... | ||||
| When = PostTransaction | ||||
| Exec = /usr/share/libalpm/scripts/openrc-hook reexec | ||||
|   | ||||
							
								
								
									
										11
									
								
								openrc/hooks/openrc-user-install.hook
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								openrc/hooks/openrc-user-install.hook
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| [Trigger] | ||||
| Type = Path | ||||
| Operation = Install | ||||
| Operation = Upgrade | ||||
| Target = etc/user/init.d/* | ||||
|  | ||||
| [Action] | ||||
| Description = Displaying openrc user service help ... | ||||
| When = PostTransaction | ||||
| Exec = /usr/share/libalpm/scripts/openrc-hook uadd | ||||
| NeedsTargets | ||||
							
								
								
									
										10
									
								
								openrc/hooks/openrc-user-remove.hook
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								openrc/hooks/openrc-user-remove.hook
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| [Trigger] | ||||
| Type = Path | ||||
| Operation = Remove | ||||
| Target = etc/user/init.d/* | ||||
|  | ||||
| [Action] | ||||
| Description = Displaying openrc user service help ... | ||||
| When = PostTransaction | ||||
| Exec = /usr/share/libalpm/scripts/openrc-hook udel | ||||
| NeedsTargets | ||||
| @@ -1,46 +1,80 @@ | ||||
| #!/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 <service> <start/stop/restart>" | ||||
| } | ||||
|  | ||||
| svc_add_help(){ | ||||
|     echo "	==> Add a service to runlevel:" | ||||
|     echo "	rc-update add <service> <runlevel>" | ||||
|     svc_help | ||||
| } | ||||
|  | ||||
| svc_del_help(){ | ||||
|     echo "	==> Remove a service from runlevel:" | ||||
|     echo "	rc-update del <service> <runlevel>" | ||||
|     svc_help | ||||
|     if [ ! -f /run/openrc/softlevel ]; then | ||||
|         echo >&2 "  Skipped: Current root is not booted." | ||||
|         exit 0 | ||||
|     fi | ||||
| } | ||||
|  | ||||
| each_conf() { | ||||
|   while read -r f; do | ||||
|     "$@" "/$f" | ||||
|   done | ||||
|     while read -r f; do | ||||
|         "$@" "/$f" | ||||
|     done | ||||
| } | ||||
|  | ||||
| svc_help(){ | ||||
|     arg="${1:-}" | ||||
|     str="${arg#--*}" | ||||
|     if [ -n "$str" ]; then | ||||
|         echo "	==> Start/stop/restart a $str service:" | ||||
|     else | ||||
|         echo "	==> Start/stop/restart a service:" | ||||
|     fi | ||||
|     echo "	rc-service <service> <start/stop/restart>" "$arg" | ||||
| } | ||||
|  | ||||
| svc_add_help(){ | ||||
|     arg="${1:-}" | ||||
|     str="${arg#--*}" | ||||
|     if [ -n "$str" ]; then | ||||
|         echo "	==> Add a $str service to runlevel:" | ||||
|     else | ||||
|         echo "	==> Add a service to runlevel:" | ||||
|     fi | ||||
|     echo "	rc-update add <service> <runlevel>" "$arg" | ||||
|     svc_help "$arg" | ||||
| } | ||||
|  | ||||
| svc_del_help(){ | ||||
|     arg="${1:-}" | ||||
|     str="${arg#--*}" | ||||
|     if [ -n "$str" ]; then | ||||
|         echo "	==> Remove a $str service from runlevel:" | ||||
|     else | ||||
|         echo "	==> Remove a service from runlevel:" | ||||
|     fi | ||||
|     echo "	rc-update del <service> <runlevel>" "$arg" | ||||
|     svc_help "$arg" | ||||
| } | ||||
|  | ||||
| svc_user_ln() { | ||||
|     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 | ||||
|   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 ;; | ||||
|     sysctl) openrc_live; each_conf /usr/bin/sysctl -q -p ;; | ||||
|     binfmt) openrc_live; each_conf /usr/lib/openrc/sh/binfmt.sh ;; | ||||
|     reexec) svc_user_ln; openrc_live; /usr/bin/openrc-shutdown -R ;; | ||||
|     # 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 ;; | ||||
|     reload) openrc_live; /usr/bin/rc-service "$@" reload ;; | ||||
|     add) svc_add_help ;; | ||||
|     del) svc_del_help ;; | ||||
|     uadd) svc_add_help "--user" ;; | ||||
|     udel) svc_del_help "--user" ;; | ||||
|     *) echo >&2 "  Invalid operation '$op'"; exit 1 ;; | ||||
| esac | ||||
|  | ||||
| exit 0 | ||||
|   | ||||
| @@ -1,11 +0,0 @@ | ||||
| [Trigger] | ||||
| Type = Path | ||||
| Operation = Install | ||||
| Operation = Upgrade | ||||
| Target = usr/lib/binfmt.d/*.conf | ||||
|  | ||||
| [Action] | ||||
| Description = Registering binary formats... | ||||
| When = PostTransaction | ||||
| Exec = /usr/share/libalpm/scripts/runit-hook binfmt | ||||
| NeedsTargets | ||||
| @@ -34,7 +34,6 @@ op="$1"; shift | ||||
|  | ||||
| case $op in | ||||
|   sysctl)   runit_live; each_conf /usr/bin/sysctl -q -p ;; | ||||
|   binfmt)   runit_live; each_conf /usr/lib/rc/sv.d/binfmt once ;; | ||||
|     # For use by other packages | ||||
|   reload)   runit_live; /usr/bin/sv "$@" reload ;; | ||||
|   add)      svc_add_help ;; | ||||
|   | ||||
| @@ -1,11 +0,0 @@ | ||||
| [Trigger] | ||||
| Type = Path | ||||
| Operation = Install | ||||
| Operation = Upgrade | ||||
| Target = usr/lib/binfmt.d/*.conf | ||||
|  | ||||
| [Action] | ||||
| Description = Registering binary formats... | ||||
| When = PostTransaction | ||||
| Exec = /usr/share/libalpm/scripts/s6-rc-hook binfmt | ||||
| NeedsTargets | ||||
| @@ -51,7 +51,6 @@ op="$1"; shift | ||||
|  | ||||
| case $op in | ||||
|   sysctl)   s6_live; each_conf /usr/bin/sysctl -q -p ;; | ||||
|   binfmt)   s6_live; sh /etc/s6/sv/binfmt/shell_up ;; | ||||
|   dbus_reload) s6_live; reload_dbus ;; | ||||
|     # For use by other packages | ||||
|   add)      svc_add_help ;; | ||||
|   | ||||
| @@ -16,7 +16,7 @@ case "$op" in | ||||
|     udev-reload) | ||||
|         udevd_live | ||||
|         /usr/bin/udevadm control --reload | ||||
|         /usr/bin/udevadm trigger | ||||
|         /usr/bin/udevadm trigger -c change | ||||
|         /usr/bin/udevadm settle | ||||
|     ;; | ||||
|     *) | ||||
|   | ||||
							
								
								
									
										86
									
								
								wrapper/artix-service
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								wrapper/artix-service
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,86 @@ | ||||
| #!/bin/bash | ||||
|  | ||||
| cmds_openrc() { | ||||
|     COMMANDS[enable]="rc-update add ${SV} default" | ||||
|     COMMANDS[disable]="rc-update del ${SV} default" | ||||
|     COMMANDS[start]="rc-service ${SV} start" | ||||
|     COMMANDS[stop]="rc-service ${SV} stop" | ||||
| } | ||||
|  | ||||
| cmds_s6() { | ||||
|     COMMANDS[start]="s6-rc -u change ${SV}" | ||||
|     COMMANDS[stop]="s6-rc -d change ${SV}" | ||||
|     COMMANDS[enable]="s6-service add default ${SV}" | ||||
|     COMMANDS[disable]="s6-service del default ${SV}" | ||||
| } | ||||
|  | ||||
| cmds_dinit() { | ||||
|     COMMANDS[start]="dinitctl start ${SV}" | ||||
|     COMMANDS[stop]="dinitctl stop ${SV}" | ||||
|     COMMANDS[enable]="dinitctl -o enable ${SV}" | ||||
|     COMMANDS[disable]="dinitctl -o disable ${SV}" | ||||
| } | ||||
|  | ||||
| cmds_runit() { | ||||
|     COMMANDS[start]="runsv /etc/runit/sv/${SV}" | ||||
|     COMMANDS[stop]="sv stop /etc/runit/sv/${SV}" | ||||
|     COMMANDS[enable]="ln -s /etc/runit/sv/${SV} /run/runit/service/" | ||||
|     COMMANDS[disable]="rm /run/runit/service/${SV}" | ||||
| } | ||||
|  | ||||
| is_live() { | ||||
|     if [[ ! -d /run/openrc && "${INIT}" == "openrc" ]]; then | ||||
|         echo >&2 "  Skipped: ${INIT} is not running." | ||||
|         exit 0 | ||||
|     elif [[ ! -d /run/s6-rc && "${INIT}" == "s6" ]]; then | ||||
|         echo >&2 "  Skipped: ${INIT} is not running." | ||||
|         exit 0 | ||||
|     elif [[ ! -S /run/dinitctl && "${INIT}" == "dinit" ]]; then | ||||
|         echo >&2 "  Skipped: ${INIT} is not running." | ||||
|         exit 0 | ||||
|     elif [[ ! -d /run/runit && "${INIT}" == "runit" ]]; then | ||||
|         echo >&2 "  Skipped: ${INIT} is not running." | ||||
|         exit 0 | ||||
|     fi | ||||
| } | ||||
|  | ||||
| detect() { | ||||
|     for i in "${SUPPORTED[@]}"; do | ||||
|         if [[ -f /usr/bin/"$i"-init ]]; then | ||||
|             INIT="$i" | ||||
|             cmds_"${INIT}" | ||||
|         fi | ||||
|     done | ||||
| } | ||||
|  | ||||
| usage() { | ||||
|     cat <<EOF | ||||
| usage: ${0##*/} [action] [service] | ||||
|  | ||||
|   actions: | ||||
|     enable | ||||
|     disable | ||||
|     start | ||||
|     stop | ||||
| EOF | ||||
| } | ||||
|  | ||||
| readonly SUPPORTED=(openrc s6 dinit runit) | ||||
| declare -A COMMANDS | ||||
|  | ||||
| INIT= | ||||
| ACTION="$1" | ||||
| SV="$2" | ||||
|  | ||||
| if [[ -z "${SV}" ]]; then | ||||
|     usage; exit 1 | ||||
| fi | ||||
|  | ||||
| detect | ||||
|  | ||||
| case "${ACTION}" in | ||||
|     start|stop)   is_live; ${COMMANDS["${ACTION}"]} ;; | ||||
|     enable|disable) ${COMMANDS["${ACTION}"]} ;; | ||||
|     help) usage; exit 0 ;; | ||||
|     *) usage; exit 1 ;; | ||||
| esac | ||||
		Reference in New Issue
	
	Block a user