#!/bin/sh
[ -n "${IPKG_INSTROOT}" ] && exit 0   # offline image build: defer to first boot
/etc/init.d/relayway-cored enable 2>/dev/null
# `restart` (NOT `start`): on an OVER-INSTALL the old cored may still be running and
# procd's `start` is a NO-OP (it diffs the declarative instance config — command +
# args + env — not the binary content on disk), so the freshly-unpacked binary
# would never actually run; the box keeps executing the OLD version. restart
# re-execs it. The preinst already stopped it, so on an upgrade this is the
# fresh start; the `|| start` covers any box where restart is unavailable.
# (Parity with install.sh step 6, line 318.)
/etc/init.d/relayway-cored restart 2>/dev/null || /etc/init.d/relayway-cored start 2>/dev/null
# Tell the operator where the admin dashboard is (parity with install.sh step 7).
_p="$(uci -q get relayway.cored.port 2>/dev/null)"; [ -n "$_p" ] || _p=7654
_ip="$(uci -q get network.lan.ipaddr 2>/dev/null)"
[ -n "$_ip" ] || _ip="$(ip -4 route get 1 2>/dev/null | sed -n 's/.*src \([0-9.]*\).*/\1/p' | head -1)"
[ -n "$_ip" ] || _ip="<router-lan-ip>"
echo "relayway: admin dashboard -> http://$_ip:$_p/"
echo "relayway: (standalone engine, optional) edit /etc/relayway/config.json then /etc/init.d/relayway enable && start"
exit 0
