#!/bin/sh
# Compatibility entry for desktops which only scan the old directory.
root="${IPKG_INSTROOT:-}"
legacy="${root}/usr/share/linkeasefull/desktop-apps.d/00-kaiplus-plugin.json"
if [ ! -e "${legacy}" ] && [ ! -L "${legacy}" ]; then
	mkdir -p "${legacy%/*}" || printf '%s\n' 'kaiplus: unable to create compatibility app directory.' >&2
	ln -s /usr/share/kaiplus/kaiplus-plugin.json "${legacy}" 2>/dev/null || printf '%s\n' 'kaiplus: unable to create compatibility app entry.' >&2
fi
if [ -z "${IPKG_INSTROOT}" ]; then
	for option in port listen_mode external_port_enabled bind_addr; do
		uci -q delete "kaiplus.@kaiplus[0].${option}" || true
	done
	uci -q commit kaiplus || printf '%s\n' 'kaiplus: unable to save migrated settings.' >&2
	if pidof kaiplus kaiplus_bin >/dev/null 2>&1; then
		/etc/init.d/kaiplus restart || printf '%s\n' 'kaiplus: unable to restart service; restart it manually.' >&2
	fi
fi
exit 0
