#!/bin/sh

setup_color() {
    if [ -t 1 ]; then
        RED=$(printf '\033[31m')
        GREEN=$(printf '\033[32m')
        RESET=$(printf '\033[m')
    else
        RED=""
        GREEN=""
        RESET=""
    fi
}
setup_color

command_exists() {
    command -v "$@" >/dev/null 2>&1
}

error() {
    echo ${RED}"Error: $@"${RESET} >&2
}

command_exists opkg || {
    error "This script only supports OpenWrt."
    exit 1
}

if command_exists /etc/init.d/ddnsto; then
    /etc/init.d/ddnsto stop >/dev/null 2>&1 || true
fi

opkg remove app-meta-ddnsto luci-i18n-ddnsto-zh-cn luci-app-ddnsto ddnsto

rm -f /etc/config/ddnsto
rm -f /usr/bin/ddnsto
rm -f /etc/init.d/ddnsto
rm -f /tmp/ddnsto.ipk /tmp/luci-app-ddnsto.ipk /tmp/luci-i18n-ddnsto-zh-cn.ipk

printf "$GREEN"
echo "ddnsto is removed."
printf "$RESET"
