# $NetBSD: INSTALL,v 1.8 2023/05/10 19:22:33 schmonz Exp $

RCDBOOT_STYLE=@RCDBOOT_STYLE@
RCD_SCRIPTS_DIR=@RCD_SCRIPTS_DIR@
UNPRIVILEGED=@UNPRIVILEGED@
EGDIR=@EGDIR@

warning_filevault() {
	${CAT} <<EOF
===========================================================================

WARNING: With FileVault enabled, per-user supervision trees won't work.

===========================================================================
EOF
}

case "${STAGE}" in

POST-INSTALL)
	case "${RCDBOOT_STYLE}" in
	darwin-launchd)
		if [ "x${UNPRIVILEGED}" = "xyes" ] ; then
			${CP} ${EGDIR}/org.pkgsrc.rc.d-boot.plist \
			      $HOME/Library/LaunchAgents/org.pkgsrc.rc.d-boot.plist
			launchctl load -w $HOME/Library/LaunchAgents/org.pkgsrc.rc.d-boot.plist
		else
			launchctl load -w /Library/LaunchDaemons/org.pkgsrc.rc.d-boot.plist
		fi
		if fdesetup status | awk '{print $3}' | grep -q '^On\.$'; then
			warning_filevault
		fi
		;;
	freebsd-native)
		;;
	linux-systemd)
		systemctl enable --now /etc/systemd/system/pkgsrc-rc.d-boot.service
		;;
	linux-sysv-debian)
		update-rc.d pkgsrc-rc.d-boot defaults
		;;
	linux-sysv-redhat)
		chkconfig --add pkgsrc-rc.d-boot
		chkconfig pkgsrc-rc.d-boot on
		;;
	netbsd-native)
		;;
	openbsd-rcd)
		short_order=$(rc.d-boot list | ${SED} -e "s|^${RCD_SCRIPTS_DIR}/||" | ${GREP} -v '^[A-Z]*$')
		rcctl enable ${short_order}
		rcctl order ${short_order}
		${SED} -e 's|^pkg_scripts=\([a-z]*.*\)$|pkg_scripts="\1"|' \
			< /etc/rc.conf.local \
			> /etc/rc.conf.local.tmp \
			&& ${MV} /etc/rc.conf.local.tmp /etc/rc.conf.local
		;;
	esac

	;;

esac
