#!/bin/sh
# Compatibility entry for desktops which only scan the old directory.
root="${IPKG_INSTROOT:-}"
legacy="${root}/usr/share/linkeasefull/desktop-apps.d/30-agentflow.json"
if [ ! -e "${legacy}" ] && [ ! -L "${legacy}" ]; then
	mkdir -p "${legacy%/*}" || printf '%s\n' 'agentflow: unable to create compatibility app directory.' >&2
	ln -s /usr/share/agentflow/agentflow-plugin.json "${legacy}" 2>/dev/null || printf '%s\n' 'agentflow: unable to create compatibility app entry.' >&2
fi
if [ -z "${IPKG_INSTROOT}" ]; then
	uci -q set agentflow.@agentflow[0].host='127.0.0.1' || printf '%s\n' 'agentflow: unable to migrate the listen address.' >&2
	uci -q commit agentflow || printf '%s\n' 'agentflow: unable to save migrated settings.' >&2
	if pidof agentflow >/dev/null 2>&1; then
		/etc/init.d/agentflow restart || printf '%s\n' 'agentflow: unable to restart service; restart it manually.' >&2
	fi
fi
exit 0
