commit 72b5759ce7a532d4ccacae193adcd7657d422c76
parent 06a00562802f2f692d301f37b20e4ca5e286361b
Author: ccx <root@dorje.wpr.cz>
Date: Thu, 11 Mar 2021 17:14:14 +0100
Copy skeleton directory, generate rc.init and runlevel scripts to contain absolute paths.
Diffstat:
5 files changed, 136 insertions(+), 1 deletion(-)
diff --git a/install b/install
@@ -1,10 +1,51 @@
#!/bin/sh
set -x
+set -e
test -d "$1" || exit 1
dst=$1
-exec s6-linux-init-maker \
+test -d "$sm_dst_s6_rc" || exit 1
+test -d "$sm_dst_package" || exit 1
+
+q() {
+ "$sm_dst_package/command/s6-quote" "$@"
+}
+
+q_init=$(q "$dst") || exit $?
+q_s6_rc=$(q "$sm_dst_s6_rc") || exit $?
+q_package=$(q "$sm_dst_package") || exit $?
+qc=$q_package/command
+
+cat >skel/rc.init <<EOF
+#!/$sm_dst_package/command/execline -S1
+export TERM "linux"
+if { $qc/s6-rc-init -d -c $q_s6_rc/compiled /run/service }
+$q_init/scripts/runlevel \$1
+EOF
+
+cat >skel/runlevel <<EOF
+#!/$sm_dst_package/command/execline -S1
+export TERM "linux"
+
+# The requested runlevel is in "\$1" but currently ignored.
+
+# Run the service manager.
+# Call it twice because the first time may spuriously "timeout"
+# due to the clock jumping forward.
+
+ifelse -X {
+ $qc/s6-rc -v 2 -t 600000 -- change ok-all-but-tty
+} {
+ # no timeout, start ttys properly
+ $qc/s6-rc -v 2 -t 600000 -- change ok-all
+}
+# try again without tty and then with
+foreground { $qc/s6-rc -v 2 -t 600000 -- change ok-all-but-tty }
+$qc/s6-rc -v 2 -t 600000 -- change ok-all
+EOF
+
+exec "$sm_dst_package/command/s6-linux-init-maker" \
-p "/command:/usr/local/bin:/usr/bin:/bin" \
-G "/usr/bin/env TERM=linux /sbin/getty 38400 tty9" \
-t 1 \
diff --git a/skel/rc.init b/skel/rc.init
@@ -0,0 +1,49 @@
+#!/bin/sh -e
+
+rl="$1"
+shift
+
+### argv now contains the arguments of the kernel command line that are
+### not of the form key=value. (The key=value arguments were stored by
+### s6-linux-init into an envdir, if instructed so via the -s option.)
+### Normally this argv remains unused because programs that need the
+### kernel command line usually read it later on from /proc/cmdline -
+### but just in case, it's available here.
+
+
+### 1. Early preparation
+### This is done only once at boot time.
+### Ideally, this phase should just initialize the service manager.
+
+### If your services are managed by sysv-rc:
+# /etc/init.d/rcS
+
+### If your services are managed by OpenRC:
+# /sbin/openrc sysinit
+# /sbin/openrc boot
+
+### If your services are managed by s6-rc:
+### (replace /run/service with your scandir)
+# s6-rc-init /run/service
+
+
+### 2. Starting the wanted set of services
+### This is also called every time you change runlevels with telinit.
+### (edit the location to suit your installation)
+### By default, $rl is the string "default", unless you changed it
+### via the -D option to s6-linux-init-maker.
+### Numeric arguments from 1 to 5 on the kernel command line will
+### override the default.
+
+# exec /etc/s6-linux-init/current/scripts/runlevel "$rl"
+
+
+### If this script is run in a container, then 1. and 2. above do not
+### apply and you should just call your CMD, if any, or let your
+### services run.
+### Something like this:
+
+# if test -z "$*" ; then return 0 ; fi
+# $@
+# echo $? > /run/s6-linux-init-container-results/exitcode
+# halt
diff --git a/skel/rc.shutdown b/skel/rc.shutdown
@@ -0,0 +1,9 @@
+#!/command/execlineb -P
+
+### Things to do before hardware halt/reboot/poweroff.
+### Ideally, it should be a single call to the service manager,
+### telling it to bring all the services down.
+
+redirfd -w 1 /dev/console
+redirfd -w 2 /dev/console
+s6-rc -v2 -bDa change
diff --git a/skel/rc.shutdown.final b/skel/rc.shutdown.final
@@ -0,0 +1,18 @@
+#!/bin/sh -e
+
+### Things to do *right before* the machine gets rebooted or
+### powered off, at the very end of the shutdown sequence,
+### when all the filesystems are unmounted.
+
+### This is a last resort hook; normally nothing should be
+### done here (your rc.shutdown script should have taken care
+### of everything) and you should leave this script empty.
+
+### Some distributions, however, may need to perform some
+### actions after unmounting the filesystems: typically if
+### an additional teardown action is required on a filesystem
+### after unmounting it, or if the system needs to be
+### pivot_rooted before it can be shut down, etc.
+
+### Those are all exceptional cases. If you don't know for
+### certain that you need to do something here, you don't.
diff --git a/skel/runlevel b/skel/runlevel
@@ -0,0 +1,18 @@
+#!/bin/sh -e
+
+### This script is called once at boot time by rc.init, and is
+### also called by the runleveld service every time the user
+### requests a machine state change via telinit.
+### Ideally, it should just be a call to the service manager.
+
+test "$#" -gt 0 || { echo 'runlevel: fatal: too few arguments' 1>&2 ; exit 100 ; }
+
+
+### If your services are managed by sysv-rc:
+# exec /etc/init.d/rc "$1"
+
+### If your services are managed by OpenRC:
+# exec /sbin/openrc "$1"
+
+### If your services are managed by s6-rc:
+# exec s6-rc -v2 -up change "$1"