#!/bin/sh

if [ "x${1}" = 'xconfigure' ]; then
	while read link; do
		# 15 is a (temporary?) middle ground: alternatives that should
		# override busybox's have priority 20 (which should maybe be
		# increased to 30), and expect-doc provides a /usr/bin/mkpasswd
		# alternative with priority 10.
		update-alternatives --install "${link}" "${link##*/}" \
			"${link}.busybox" 15
	done </usr/share/busybox/alternatives
	if ! [ -f /etc/rc.policy ]; then
		if [ "x$(cat /etc/proteanos_plat)" = 'xdev' ]; then
			printf 'disabled\n' >/etc/rc.policy
		else
			printf 'enabled\n' >/etc/rc.policy
		fi
	fi
	if [ -f /usr/share/busybox/init-scripts ]; then
		while read -r script enabled; do
			if [ "x${enabled}" = 'xenabled' ]; then
				[ "x${2:+set}" != 'xset' ] && \
					"/etc/init.d/${script}" enable
				"/etc/init.d/${script}" start
			fi
		done </usr/share/busybox/init-scripts
	fi
fi