#!/bin/sh
#Copyright: 2026 Aitor <aitor@genuen.org>
#License: CC0-1.0
#Comment: oneshot; invoke with: sv once bootmisc.sh

exec 2>&1

ebegin() { [ "${VERBOSE:-}" = no ] || echo "$@"; }
eend() { r=${1:-0}; shift || true; [ "$r" -eq 0 ] || [ "${VERBOSE:-}" = no ] || echo "$*" >&2; return "$r"; }
einfo() { [ "${VERBOSE:-}" = no ] || echo "$@"; }
ewarn() { echo "$@" >&2; }
eerror() { echo "$@" >&2; }

/usr/lib/runit-services/stage1/sv once mountnfs-bootclean.sh || exit 1
/usr/lib/runit-services/stage1/sv once checkroot-bootclean.sh || exit 1

[ "$DELAYLOGIN" ] || DELAYLOGIN=yes
. /lib/init/vars.sh

case "$DELAYLOGIN" in
  Y*|y*) echo "System bootup in progress - please wait" > /run/nologin ;;
esac
rm -f /tmp/.clean /run/.clean /run/lock/.clean
rm -f /tmp/.tmpfs /run/.tmpfs /run/lock/.tmpfs
utmp='/var/run/utmp'
if > "${utmp}" ; then
	chgrp utmp "${utmp}" || ewarn "failed to chgrp ${utmp}"
	chmod 664  "${utmp}" || ewarn "failed to chmod ${utmp}"
	[ -x /sbin/restorecon ] && /sbin/restorecon "${utmp}"
	exit 0
else
	eerror "failed to truncate ${utmp}"
	exit 1
fi
