Browse Source

Add initswitch program and hook for pacman

nohooks-patch 0.3
M. Herdiansyah 4 years ago
parent
commit
a7fb08db7a
  1. 3
      Makefile
  2. 4
      README
  3. 18
      halt.8
  4. 50
      initswitch
  5. 21
      initswitch-hook

3
Makefile

@ -5,10 +5,13 @@ all:
install:
install -d $(DESTDIR)$(PREFIX)/bin
install -d $(DESTDIR)$(PREFIX)/share/libalpm/scripts
install -m755 halt $(DESTDIR)$(PREFIX)/bin/halt
ln -sf halt $(DESTDIR)$(PREFIX)/bin/shutdown
ln -sf halt $(DESTDIR)$(PREFIX)/bin/poweroff
ln -sf halt $(DESTDIR)$(PREFIX)/bin/reboot
install -m755 initswitch $(DESTDIR)$(PREFIX)/bin/initswitch
install -m755 initswitch-hook $(DESTDIR)$(PREFIX)/share/libalpm/scripts/initswitch
install -d $(DESTDIR)$(PREFIX)/share/man/man8
install -m644 halt.8 $(DESTDIR)$(PREFIX)/share/man/man8/halt.8
ln -sf halt.8 $(DESTDIR)$(PREFIX)/share/man/man8/shutdown.8

4
README

@ -1 +1,3 @@
This is a wrapper program for OpenRC and runit's shutdown scheme.
halt(8) is a wrapper program for OpenRC and runit's shutdown scheme.
Because halt(8) interacts directly with init(8), the initswitch program
is also included for easy init switching system.

18
halt.8

@ -16,11 +16,16 @@
\fBshutdown\fR [\-nfdw]
.
.SH "DESCRIPTION"
\fBhalt\fR/\fBreboot\fR/\fBpoweroff\fR/\fBshutdown\fR is a (mostly) sysvinit\-compatible binary\. It tells init(8)/openrc\-shutdown(8) to bring down, reboot, or power off the system\. Without \fB\-f\fR, it is a shortcut to \fBinit 0\fR/\fBinit 6\fR (runit) or \fBopenrc\-shutdown\fR (openrc)\.
\fBhalt\fR/\fBreboot\fR/\fBpoweroff\fR/\fBshutdown\fR is a (mostly)
sysvinit\-compatible binary\. It tells init(8)/openrc\-shutdown(8) to
bring down, reboot, or power off the system\. Without \fB\-f\fR, it is
a shortcut to \fBinit 0\fR/\fBinit 6\fR (runit) or \fBopenrc\-shutdown\fR
(openrc)\.
.
.TP
\fB\-n\fR
Don\'t sync before reboot or halt\. Note that the kernel and storage drivers may still sync\.
Don\'t sync before reboot or halt\. Note that the kernel and storage
drivers may still sync\.
.
.TP
\fB\-f\fR
@ -35,16 +40,19 @@ Do not write to the wtmp record\.
Do not stop the system but write to the wtmp record\.
.
.SH "NOTES"
This program tries to be as sysvinit\-compatible as possible, but due to limitations by the init system, some functions may not be available yet\.
This program tries to be as sysvinit\-compatible as possible, but due to
limitations by the init system, some functions may not be available yet\.
.
.P
Currently, the \fBshutdown\fR program behaves like the \fBpoweroff\fR program\.
Currently, the \fBshutdown\fR program behaves like the \fBpoweroff\fR
program\.
.
.P
Options \fB\-h\fR and \fB\-i\fR are fully ignored\.
.
.P
When you are using runit(8), the options \fB\-d\fR and \fB\-w\fR are ignored\.
When you are using runit(8), the options \fB\-d\fR and \fB\-w\fR are
ignored\.
.
.SH "SEE ALSO"
openrc\-init(8), runit(8)

50
initswitch

@ -0,0 +1,50 @@
#!/bin/sh
# This file is part of the halt program.
# To see the licensing terms, see the COPYING file.
check_current_init()
{
if [ "$(ps -o comm= 1)" = "runit" ]; then
selected2="*"
elif [ "$(ps -o comm= 1)" = "init" ]; then
selected1="*"
else
printf "\\033[1;31mError:\\033[m Current init is not supported!\\n"
exit 1
fi
}
available_init()
{
printf "Currently available init system(s): \\n"
[ -x "/sbin/openrc-init" ] && printf " - [\\033[1;32m%s\\033[0m] openrc\\n" "$selected1"
[ -x "/sbin/runit-init" ] && printf " - [\\033[1;32m%s\\033[0m] runit\\n" "$selected2"
}
select_init()
{
printf "Select your chosen init: "
read -r NEXTINIT
case $NEXTINIT in
"openrc") ln -s "openrc-init" "/usr/bin/init" ;;
"runit") ln -s "runit-init" "/usr/bin/init" ;;
*) printf "Init does not exist/is not supported!\\n"; exit 1 ;;
esac
}
main()
{
if [ "$(id -u)" != "0" ]; then
printf "\\033[1;31mError:\\033[m User must be root to run this program!\\n"
exit 1
fi
check_current_init
available_init
if [ -x "/usr/bin/openrc-init" ] && [ -x "/usr/bin/runit-init" ]; then
select_init
fi
}
main "$@"

21
initswitch-hook

@ -0,0 +1,21 @@
#!/bin/sh
if [ ! -L "/usr/bin/init" ]; then
case $1 in
"openrc") ln -sf "openrc-init" "/usr/bin/init" ;;
"runit") ln -sf "runit-init" "/usr/bin/init" ;;
esac
else
if [ -x "/usr/bin/openrc-init" ] && [ -x "/usr/bin/runit-init" ]; then
echo " We detected two init systems are installed in your system."
echo " Use 'initswitch' to choose your init."
elif [ -x "/usr/bin/openrc-init" ]; then
ln -sf "openrc-init" "/usr/bin/init"
echo " Activated OpenRC as your init system."
elif [ -x "/usr/bin/runit-init" ]; then
ln -sf "runit-init" "/usr/bin/init"
echo " Activated runit as your init system."
else
echo " You have no init systems installed."
echo " Install either openrc or runit-artix."
fi
fi