osi-tools/osi-mk.d/systemd-osi-run.sh

36 lines
1005 B
Bash

#!/hint/bash
load_module "$(dirname -- "${BASH_SOURCE[0]}")/testuser.sh"
post_install+=(10:systemd-osi-run:post_install)
systemd-osi-run:post_install() {
local arg_mountpoint=$1
cat <<-'EOT' > "${arg_mountpoint}/etc/systemd/system/osi-run.target"
[Unit]
Description=osi-run target
Requires=multi-user.target
After=multi-user.target
Conflicts=rescue.target
AllowIsolate=yes
EOT
ln -sT osi-run.target "${arg_mountpoint}/etc/systemd/system/default.target"
cat <<-'EOT' > "${arg_mountpoint}/etc/systemd/system/osi-run.service"
[Unit]
Description=osi-run service
Wants=network-online.target
After=network-online.target
ConditionPathExists=/etc/osi-run
[Service]
Type=oneshot
StandardOutput=journal+console
ExecStart=/bin/bash -c '{ su testuser -c /etc/osi-run 2>&1; echo $? > /var/log/osi-run.status; } | tee /var/log/osi-run.out; systemctl poweroff --no-block'
[Install]
WantedBy=osi-run.target
EOT
systemctl --root="$arg_mountpoint" enable osi-run.service
}