#!/bin/sh

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

# Move dhcpcd.duid and dhcpcd.secret to new location when upgrading
# to dhcpcd 7.x.
# See https://roy.marples.name/blog/dhcpcd-7-finally-enters-beta.
if [ "$(apk version -t "$ver_old" '7.0.0-r0')" = '<' ]; then
	dbdir='/var/lib/dhcpcd'
	duid_old='/etc/dhcpcd.duid'
	secret_old='/etc/dhcpcd.secret'

	if [ -f $duid_old ] && [ ! -f $dbdir/duid ]; then
		echo "* Moving $duid_old to $dbdir/duid" >&2
		mv $duid_old $dbdir/duid
	fi
	if [ -f $secret_old ] && [ ! -f $dbdir/secret ]; then
		echo "* Moving $secret_old to $dbdir/secret" >&2
		mv $secret_old $dbdir/secret
	fi
fi

exit 0