#!/sbin/openrc-run
# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

extra_commands="mark_for_reboot"

STATEFILE=/force_reboot_shutdown

depend() {
	if [ -x /etc/init.d/root ]; then
		need root
	else
		need checkroot
	fi
}

start() {
	# check whether this time this is a reboot and I should shutdown

	if [ -e "${STATEFILE}" ]; then
		rm -f "${STATEFILE}"
		einfo "This is a reboot to write the wakeup-time into the bios."
		einfo "Shutting down now."
		init 0
	fi
}

stop() {
	:
}

mark_for_reboot() {
	touch "${STATEFILE}"
}

