#!/bin/sh
[ -n "${IPKG_INSTROOT}" ] && exit 0
# Nested opkg cannot run under LuCI's rpcd opkg timeout — schedule via procd oneshot.
# Do not use a bare "(…) &" from postinst: rpcd may kill the process group.
rm -f /etc/bmsos-bundle.ok
printf '%s\n' 'state=installing' 'phase=scheduled' 'detail=Bundle accepted — installing in background. Open Services → bmsOS Gateway for progress.' "updated=" > /tmp/bmsos-install.status
/etc/init.d/bmsos-bundle-install enable 2>/dev/null || true
/etc/init.d/bmsos-bundle-install start 2>/dev/null || start-stop-daemon -S -b -x /usr/bin/bmsos-bundle-install
logger -t bmsos-bundle "nested install scheduled — see /tmp/bmsos-bundle-install.log + /tmp/bmsos-install.status"
echo "bmsos-bundle: installing in background. Open Services → bmsOS Gateway for live status (or /tmp/bmsos-install.status)."
exit 0
