#!/bin/sh
[ -n "${IPKG_INSTROOT}" ] && exit 0
case "${1:-remove}" in
    remove|deinstall|purge)
        if [ -x /etc/init.d/tachyon ]; then
            /etc/init.d/tachyon stop >/dev/null 2>&1 || true
            /etc/init.d/tachyon disable >/dev/null 2>&1 || true
        fi
        rm -f /etc/nftables.d/10-tachyon.nft /usr/share/nftables.d/ruleset-post/90-tachyon-kill-switch.nft /etc/sysctl.d/99-tachyon-bbr.conf /www/cgi-bin/tachyon-sub /tmp/luci-indexcache* 2>/dev/null || true
        if command -v nft >/dev/null 2>&1; then
            nft delete table inet TachyonTable >/dev/null 2>&1 || true
            nft delete table inet TachyonKillSwitch >/dev/null 2>&1 || true
            nft delete table inet tachyon >/dev/null 2>&1 || true
        fi
        if command -v ip >/dev/null 2>&1; then
            for _p in 9499 9500 9501; do
                for _fam in -4 -6; do
                    while ip "$_fam" rule del pref "$_p" >/dev/null 2>&1; do :; done
                done
            done
        fi
        ;;
esac
exit 0
