#!/bin/sh
#Copyright: 2026 Aitor <aitor@genuen.org>
#License: CC0-1.0
#Comment: oneshot; invoke with: sv once mountkernfs.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; }

. /lib/init/vars.sh
. /lib/init/tmpfs.sh
. /lib/init/mount-functions.sh

mount_filesystems()
{
	MNTMODE="$1"
	mount_run "$MNTMODE"
	mount_lock "$MNTMODE"
	domount "$MNTMODE" proc "" /proc proc "-onodev,noexec,nosuid"
	if grep -E -qs "securityfs\$" /proc/filesystems; then
		domount "$MNTMODE" securityfs "" /sys/kernel/security securityfs
	fi
	if grep -E -qs "sysfs\$" /proc/filesystems; then
		domount "$MNTMODE" sysfs "" /sys sysfs "-onodev,noexec,nosuid"
	fi
	if [ -d /sys/fs/pstore ]; then
		domount "$MNTMODE" pstore "" /sys/fs/pstore pstore ""
	fi
	efivarsmnt=/sys/firmware/efi/efivars
	if test -d $efivarsmnt; then
		domount "$MNTMODE" efivarfs "" $efivarsmnt none ""
	fi
}

mount_filesystems mount_noupdate
exit 0
