#!/bin/sh

# Stop services before removal
if [ -x /etc/init.d/xtna-service ]; then
    /etc/init.d/xtna-service stop 2>/dev/null || true
    /etc/init.d/xtna-service disable 2>/dev/null || true
fi

if [ -x /etc/init.d/xtna-updater ]; then
    /etc/init.d/xtna-updater stop 2>/dev/null || true
    /etc/init.d/xtna-updater disable 2>/dev/null || true
fi

# Ensure processes are terminated (opkg runs in its own session, safe to kill updater)
killall xtna-service 2>/dev/null || true
killall xtna-updater 2>/dev/null || true
sleep 1

# Backup XplicitTrust directory for upgrades
if [ -d /etc/XplicitTrust ]; then
    rm -rf /tmp/xtna-config-backup
    cp -a /etc/XplicitTrust /tmp/xtna-config-backup
fi

exit 0
