#!/bin/sh
# Drop rc.d links left behind by a previous START priority.
#
# enable() in /etc/rc.common only does `ln -sf` for the current priority; it
# never removes the link a previous one created. This service moved from
# START=15 to START=02, and sysupgrade restores /etc/rc.d from the config
# backup over the new squashfs, so an upgraded unit ends up carrying both
# S15pcat2-display-mini and S02pcat2-display-mini.
#
# The stale one is harmless in effect -- by the time rcS reaches S15 the daemon
# is already running, so start-stop-daemon does nothing and it costs ~9 ms --
# but it makes the enable state ambiguous and would accumulate if the priority
# ever moved again.
#
# uci-defaults scripts are deleted once they exit 0, so this runs once per
# upgraded unit and then goes away.

for f in /etc/rc.d/S[0-9][0-9]pcat2-display-mini; do
	[ -e "$f" ] || continue
	case "$f" in
	/etc/rc.d/S02pcat2-display-mini) ;;
	*) rm -f "$f" ;;
	esac
done

exit 0
