summaryrefslogtreecommitdiff
path: root/osi-mk.d/openrc-osi-shell.sh
blob: 654cc3173c78ea8390442868e6525b2d9ec39577 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
}