45 lines
1.2 KiB
Bash
45 lines
1.2 KiB
Bash
|
#!/hint/bash
|
||
|
|
||
|
post_install+=(10:systemd-osi-shell:post_install)
|
||
|
systemd-osi-shell:post_install() {
|
||
|
local arg_mountpoint=$1
|
||
|
|
||
|
cat <<-'EOT' > "${arg_mountpoint}/etc/systemd/system/osi-shell.target"
|
||
|
[Unit]
|
||
|
Description=osi-shell target
|
||
|
Requires=multi-user.target
|
||
|
After=multi-user.target
|
||
|
Conflicts=rescue.target
|
||
|
AllowIsolate=yes
|
||
|
EOT
|
||
|
ln -sT -- osi-shell.target "${arg_mountpoint}/etc/systemd/system/default.target"
|
||
|
|
||
|
cat <<-'EOT' > "${arg_mountpoint}/etc/systemd/system/osi-shell.service"
|
||
|
[Unit]
|
||
|
Description=osi-shell service
|
||
|
Wants=network-online.target
|
||
|
After=network-online.target
|
||
|
|
||
|
[Service]
|
||
|
KillSignal=SIGHUP
|
||
|
KillMode=process
|
||
|
IgnoreSIGPIPE=no
|
||
|
|
||
|
ExecStart=/bin/sh
|
||
|
StandardInput=tty
|
||
|
TTYPath=/dev/ttyS0
|
||
|
TTYReset=yes
|
||
|
TTYVHangup=yes
|
||
|
|
||
|
# Write the exit status to ttyS1 and poweroff
|
||
|
# Bash sets exit status to 128+SIGNAL if we get killed by a signal,
|
||
|
# but there's not a good one-liner way to get from signal name to number,
|
||
|
# so just use 128.
|
||
|
ExecStopPost=/bin/sh -c 'if [ "$EXIT_CODE" = exited ]; then echo $EXIT_STATUS; else echo 128; fi > /dev/ttyS1; systemctl poweroff --no-block'
|
||
|
|
||
|
[Install]
|
||
|
WantedBy=osi-shell.target
|
||
|
EOT
|
||
|
systemctl --root="$arg_mountpoint" enable osi-shell.service
|
||
|
}
|