#!/usr/bin/execlineb -P
# Supervised hotplug listener. shell_run starts early, or long-running
# if coldplug has already promoted (service restart).
# Real sh lives in shell_run (execlineb cannot quote multiline sh -c).

fdmove -c 2 1

s6-envdir /run/vdev/env

multisubstitute
{
	importas -i VDEV_EARLY_STAMP VDEV_EARLY_STAMP
	importas -i VDEV_STAMP_DIR VDEV_STAMP_DIR
	importas -i VDEV_TERMINAL_STAMP VDEV_TERMINAL_STAMP
	importas -i VDEV_BIN VDEV_BIN
	importas -i VDEV_CONFIG_DIR VDEV_CONFIG_DIR
	importas -i VDEV_LONG_RUNNING VDEV_LONG_RUNNING
	importas -i VDEV_EARLY VDEV_EARLY
	importas -i VDEV_MOUNTPOINT VDEV_MOUNTPOINT
}

ifte
{
	${VDEV_BIN} -f -c ${VDEV_CONFIG_DIR}/${VDEV_LONG_RUNNING} ${VDEV_MOUNTPOINT}
}
{
	${VDEV_BIN} -f -c ${VDEV_CONFIG_DIR}/${VDEV_EARLY} ${VDEV_MOUNTPOINT}
}
eltest -e ${VDEV_EARLY_STAMP} -o -e ${VDEV_STAMP_DIR}/promoted.conf -o -e ${VDEV_TERMINAL_STAMP}
