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

sv once checkfs.sh || exit 1
sv once checkroot-bootclean.sh || exit 1

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

if [ -r /etc/default/locale ]; then
	. /etc/default/locale
	export LANG
fi

mount_all_local() {
	if mountpoint -q /usr; then
		mount -o remount /usr
	fi
	mount -a -t nonfs,nfs4,smbfs,cifs,ncp,ncpfs,coda,ocfs2,gfs,gfs2,ceph \
		-O no_netdev
}
pre_mountall
ebegin "Mounting local filesystems"
mount_all_local
eend $?
post_mountall

mkdir -p /var/log/fsck

INITCTL="/run/initctl"
if [ ! -p "$INITCTL" ] && [ -f "/usr/share/sysvinit/update-rc.d" ]; then
	rm -f "$INITCTL"
	mknod -m 600 "$INITCTL" p
	PID="$(pidof -s /sbin/init || echo 1)"
	[ -n "$PID" ] && kill -s USR1 "$PID"
fi

if [ "$NOSWAP" = yes ]; then
	[ "$VERBOSE" = no ] || ewarn "Not activating swap as requested via bootoption noswap."
else
	ebegin "Activating swapfile swap, if any"
	swapon -a -e 2>/dev/null || :
	eend 0
fi

mount_run mount_noupdate
mount_lock mount_noupdate
mount_shm mount_noupdate
mount_tmp mount_noupdate
exit 0
