#!/bin/sh

_root="${IPKG_INSTROOT:-}"
_map_live="$_root/lib/netifd/proto/map.sh"
_map_backup="${_map_live}.old"

[ -f "$_map_backup" ] && [ ! -L "$_map_backup" ] || {
	echo "error: no safe platform MAP backup is available to restore" >&2
	exit 1
}

mv -f "$_map_backup" "$_map_live" || {
	echo "error: could not restore the platform MAP protocol" >&2
	exit 1
}

if [ -z "$IPKG_INSTROOT" ]; then
	rm -rf /tmp/luci-* 2>/dev/null || true
fi

exit 0
