#!/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 -o pipefail -c 'su testuser -c /etc/osi-run 2>&1 | tee /var/log/osi-run.out; r=$? echo $r > /var/log/osi-run.status; rm -f /etc/osi-run; systemctl poweroff --no-block; exit $r' [Install] WantedBy=osi-run.target EOT systemctl --root="$arg_mountpoint" enable osi-run.service }