summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-08-20 11:56:11 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2018-08-20 11:56:11 -0400
commitc7e1be058db00addddadcca191d87cba48647e40 (patch)
treeec534c612950b14667c057d50c21ec7a9adbf244
parent87ea82b6fa74a69b782e962125a42dedec2dfd87 (diff)
add openrc support for osi-shell, build an openrc base imageHEADmaster
-rw-r--r--osi-mk.d/openrc-osi-shell.sh35
-rw-r--r--osi-mk.d/systemd-osi-shell.sh1
-rwxr-xr-xruntests12
3 files changed, 48 insertions, 0 deletions
diff --git a/osi-mk.d/openrc-osi-shell.sh b/osi-mk.d/openrc-osi-shell.sh
new file mode 100644
index 0000000..654cc31
--- /dev/null
+++ b/osi-mk.d/openrc-osi-shell.sh
@@ -0,0 +1,35 @@
+#!/hint/bash -euE
+# Copyright (C) 2018 Luke Shumaker
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+post_install+=(10:openrc-osi-shell:post_install)
+openrc-osi-shell:post_install() {
+ local arg_mountpoint=$1
+
+ install -Dm755 /dev/stdin "${arg_mountpoint}/etc/osi-shell" <<-'EOT'
+ #!/bin/sh
+ # We can't use login(1) because it masks the exit status of the shell,
+ # but we want this to be a real local login with PAM, so use su(1),
+ # but trick in in to using login(1)'s PAM config. We undo this trick by
+ # using nsenter(1) to reset the mount namespace after we've done the PAM stuff.
+ # This hardcodes the shell as /bin/bash, which is the default for root.
+ unshare --mount -- sh -c 'mount --bind /etc/pam.d/login /etc/pam.d/su && exec -- su -c "exec nsenter --mount --target=1 -- setsid bash -l"' <>/dev/ttyS0 >&0 2>&0
+ echo $? >/dev/ttyS1
+ openrc-shutdown --poweroff
+ sleep infinity
+ EOT
+
+ install -Dm755 /dev/stdin "${arg_mountpoint}/etc/init.d/osi-shell" <<-'EOT'
+ #!/usr/bin/openrc-run
+
+ description="osi-shell service"
+ supervisor=supervise-daemon
+ command=/etc/osi-shell
+ pidfile="/run/${RC_SVCNAME}.pid"
+
+ depend() {
+ after network-online
+ }
+ EOT
+ arch-chroot -- "$arg_mountpoint" rc-update add osi-shell default
+}
diff --git a/osi-mk.d/systemd-osi-shell.sh b/osi-mk.d/systemd-osi-shell.sh
index dc161dc..abba7f9 100644
--- a/osi-mk.d/systemd-osi-shell.sh
+++ b/osi-mk.d/systemd-osi-shell.sh
@@ -31,6 +31,7 @@ systemd-osi-shell:post_install() {
# but we want this to be a real local login with PAM, so use su(1),
# but trick in in to using login(1)'s PAM config. We undo this trick by
# using nsenter(1) to reset the mount namespace after we've done the PAM stuff.
+ # This hardcodes the shell as /bin/bash, which is the default for root.
ExecStart=/bin/unshare --mount -- sh -c 'mount --bind /etc/pam.d/login /etc/pam.d/su && exec -- su -c "exec nsenter --mount --target=1 -- bash -l"'
StandardInput=tty
TTYPath=/dev/ttyS0
diff --git a/runtests b/runtests
index bf5d1cf..6d2d440 100755
--- a/runtests
+++ b/runtests
@@ -57,6 +57,18 @@ ${WORKDIR}/base.raw:
'$@.tmp'
mv -T -- '$@.tmp' '$@'
+${WORKDIR}/base-openrc.raw: osi-mk.d/openrc-osi-shell.sh
+${WORKDIR}/base-openrc.raw: osi-mk.d/utf8.sh
+${WORKDIR}/base-openrc.raw:
+ rm -f -- '$@' '$@.tmp'
+ mkdir -p -- '$(@D)'
+ ./osi-mk \
+ --size=2G \
+ --package='base-openrc' \
+ $(addprefix --module=,$(filter osi-mk.d/%.sh,$^)) \
+ '$@.tmp'
+ mv -T -- '$@.tmp' '$@'
+
${WORKDIR}/build.raw: ${WORKDIR}/base.raw
${WORKDIR}/build.raw: osi-mk.d/libretools.sh
${WORKDIR}/build.raw: osi-mk.d/builddeps.sh