#!/bin/sh
#Copyright: 2026 Aitor <aitor@genuen.org>
#License: CC0-1.0
#Comment: supervised vdevd (-f early; coldplug promotes same PID)

exec 2>&1

if [ -r /lib/vdev/vdev-env.sh ]; then
	# shellcheck disable=SC1091
	. /lib/vdev/vdev-env.sh
elif [ -r /usr/lib/runit-services/vdev-env.sh ]; then
	# shellcheck disable=SC1091
	. /usr/lib/runit-services/vdev-env.sh
fi

[ -x "${VDEV_BIN}" ] || exit 162

if [ -w /sys/kernel/uevent_helper ]; then
	echo > /sys/kernel/uevent_helper
fi
[ -x /sbin/restorecon ] && /sbin/restorecon -R "${VDEV_MOUNTPOINT}" || true

(
	/etc/s6-rc/sv/vdev-coldplug/shell_up 2>/dev/null ||
		/lib/vdev/vdev-coldplug-boot.sh
) >/dev/null 2>&1 &

export VDEV_JSON_STATE=early
exec "${VDEV_BIN}" -f -c "${VDEV_CONFIG_DIR}/${VDEV_EARLY}" "${VDEV_MOUNTPOINT}"
