#!/bin/sh
set -e

# Membership in boot is shipped by s6-bundle-boot (contents.d/mount).
# Never mkdir sv/boot here: that creates a real husk without type and
# blocks (or races) the packaging symlink sv/boot -> ../bundles/boot.
scrub_legacy_boot_atomics() {
	for s in mount-procfs mount-sysfs mount-devfs populate-run mount-tmpfs \
	         mount-cgroups mount-filesystems mount-rw mount-swap; do
		rm -f "/etc/s6-rc/sv/boot/contents.d/$s" \
		      "/etc/s6-rc/bundles/boot/contents.d/$s"
	done
}

case "$1" in
	configure)
		if ! id s6log >/dev/null 2>&1; then
			useradd -r -s /usr/sbin/nologin s6log
		fi
		scrub_legacy_boot_atomics
		# boot Depends on us, so we configure first; defer compile until
		# s6-bundle-boot is unpacked (type present) or its postinst runs.
		if [ -x /usr/lib/s6-helper/s6-helper ]; then
			/usr/lib/s6-helper/s6-helper recompile --when-ready
		elif [ -x /usr/sbin/s6-helper ]; then
			s6-helper recompile --when-ready
		else
			echo "warning: s6-bundle-mount: s6-helper missing; skip recompile" >&2
		fi
		;;
	abort-upgrade|abort-remove|abort-deconfigure) ;;
	*) echo "postinst called with unknown argument '$1'" >&2; exit 1 ;;
esac
#DEBHELPER#
exit 0
