#!/bin/bash

build() {
    declare -F add_busybox >/dev/null || . /usr/lib/initcpio/functions.d/systemd-extras

    add_busybox || return $?

    local service=(
        "[Unit]"
        "Description=Hold boot process"
        "DefaultDependencies=no"
	"Before=sysinit.target"
        ""
        "[Service]"
        "Type=forking"
        "ExecStart=sh -c 'touch /etc/hold; while [ -f /etc/hold ]; do sleep 2; done'"
        "TimeoutStartSec=infinity"
    )
    printf "%s\n" "${service[@]}" > ${BUILDROOT}/usr/lib/systemd/system/hold.service

    # enable hold service
    add_symlink /etc/systemd/system/sysinit.target.requires/hold.service /usr/lib/systemd/system/hold.service
}

help() {
    cat <<__EOF_HELP__
This hook delays the boot process until /etc/hold is deleted.

This may come in handy in case you want to perform some action on your root
file system (e.g. backup, encryption) without a running system already using
this root file system.

Mind that to proceed with the boot process you have to delete /etc/hold in your
initramfs, i.e. some kind of access to the initramfs is required. The
mkinitcpio hooks sd-tinyssh and sd-network enable access via SSH.

See https://github.com/wolegis/mkinitcpio-systemd-extras/wiki/Hold for details.
__EOF_HELP__
}
