#!/bin/sh

ver_new="$1"
ver_old="$2"

if [ "$(apk version -t "$ver_old" "5.0.1-r0")" = "<" ]; then
	cat >&2 <<-EOF
	*
	* Service knot-resolver was renamed to kresd and it logs to syslog
	* instead of file by default. Fixing runlevels for you...
	*
	EOF

	for path in $(find /etc/runlevels -type l -name knot-resolver); do
		rm "$path"
		ln -s /etc/init.d/kresd "${path%/*}/kresd"
	done
	if [ -f /run/knot-resolver.pid ] && ! [ -f /run/kresd.pid ]; then
		mv /run/knot-resolver.pid /run/kresd.pid
	fi

	# We've already copied it to kresd in pre-upgrade script.
	rm -f /etc/conf.d/knot-resolver
fi
