#!/usr/sbin/openrc-run

description="bootclean after checkroot."

depend()
{
	need checkroot.sh
	provide checkroot-bootclean
}

. /lib/init/bootclean.sh

# Stock Debian clean_all wipes non-directory files under /run. On OpenRC
# that deletes /run/openrc/softlevel and service state mid-boot, which
# yields "hostname.sh would not start" / "openrc did not boot" cascades.
clean_all()
{
	command -v find >/dev/null 2>&1 || return 0
	log_begin_msg "Cleaning up temporary files..."
	ES=0
	clean_tmp || ES=1
	# Do not clean /run itself — OpenRC state lives there (/run/openrc).
	clean /run/lock "! -type d" || ES=1
	[ -d /run/shm ] && clean /run/shm "! -type d" || true
	log_end_msg $ES
	return $ES
}

start()
{
	# Force re-clean of dirs that later mounts may mask (Debian SysV).
	rm -f /tmp/.clean /run/lock/.clean
	# Keep /run/.clean alone; we no longer wipe /run.

	if ! clean_all; then
		ewarn "checkroot-bootclean: clean_all failed (continuing boot)"
	fi
	return 0
}

stop()
{
	return 0
}
