|
|
@ -0,0 +1,171 @@ |
|
|
|
#!/bin/sh |
|
|
|
# |
|
|
|
# Copyright (C) 2020 TDT AG <development@tdt.de> |
|
|
|
# |
|
|
|
# This is free software, licensed under the GNU General Public License v2. |
|
|
|
# See https://www.gnu.org/licenses/gpl-2.0.txt for more information. |
|
|
|
# |
|
|
|
|
|
|
|
. /lib/functions.sh |
|
|
|
|
|
|
|
DDNS_PACKAGE_DIR="/usr/share/ddns" |
|
|
|
URL="https://raw.githubusercontent.com/openwrt/packages/master/net/ddns-scripts/files" |
|
|
|
|
|
|
|
usage() { |
|
|
|
local code="$1" |
|
|
|
local msg="$2" |
|
|
|
|
|
|
|
echo "$msg" |
|
|
|
echo "" |
|
|
|
echo "Usage: $(basename "$0") <command> <action> <service>" |
|
|
|
echo "" |
|
|
|
echo "Supported ddns <command>:" |
|
|
|
echo " service: Command for ddns service provider" |
|
|
|
echo "" |
|
|
|
echo "Supported ddns 'service' command <action>:" |
|
|
|
echo " update: Update local ddns service list" |
|
|
|
echo " list-available: List all available service providers" |
|
|
|
echo " list-installed: List all installed service providers" |
|
|
|
echo " install <service>: Install service provider" |
|
|
|
echo " remove <service>: Remove service provider" |
|
|
|
echo " purge: Remove local ddns serivces" |
|
|
|
|
|
|
|
exit "$code" |
|
|
|
} |
|
|
|
|
|
|
|
action_update() { |
|
|
|
local cacert |
|
|
|
|
|
|
|
config_load ddns |
|
|
|
config_get url global 'url' "${URL}${DDNS_PACKAGE_DIR}" |
|
|
|
config_get cacert global 'cacert' "IGNORE" |
|
|
|
url="${url}/list" |
|
|
|
|
|
|
|
mkdir -p "${DDNS_PACKAGE_DIR}" |
|
|
|
|
|
|
|
if [ "$cacert" = "IGNORE" ]; then |
|
|
|
uclient-fetch \ |
|
|
|
--no-check-certificate \ |
|
|
|
"$url" \ |
|
|
|
-O "${DDNS_PACKAGE_DIR}/list" |
|
|
|
elif [ -f "$cacert" ]; then |
|
|
|
uclient-fetch \ |
|
|
|
--ca-certificate="${cacert}" \ |
|
|
|
"$url" \ |
|
|
|
-O "${DDNS_PACKAGE_DIR}/list" |
|
|
|
elif [ -n "$cacert" ]; then |
|
|
|
echo "Certification file not found ($cacert)" |
|
|
|
exit 5 |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
action_list_available() { |
|
|
|
if [ -f "${DDNS_PACKAGE_DIR}/list" ]; then |
|
|
|
cat "${DDNS_PACKAGE_DIR}/list" |
|
|
|
else |
|
|
|
echo "No service file found please download first" |
|
|
|
exit 3 |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
action_list_installed() { |
|
|
|
if [ -d "${DDNS_PACKAGE_DIR}/services" ]; then |
|
|
|
ls "${DDNS_PACKAGE_DIR}/services" |
|
|
|
else |
|
|
|
echo "No services installed" |
|
|
|
exit 4 |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
action_install() { |
|
|
|
local service="$1" |
|
|
|
|
|
|
|
local url cacert |
|
|
|
|
|
|
|
config_load ddns |
|
|
|
config_get url global 'url' "${URL}${DDNS_PACKAGE_DIR}" |
|
|
|
config_get cacert global 'cacert' "IGNORE" |
|
|
|
url="${url}/services/${service}.json" |
|
|
|
|
|
|
|
if [ -z "$service" ]; then |
|
|
|
usage "4" "No service specified" |
|
|
|
fi |
|
|
|
|
|
|
|
mkdir -p "${DDNS_PACKAGE_DIR}/services" |
|
|
|
if [ "$cacert" = "IGNORE" ]; then |
|
|
|
uclient-fetch \ |
|
|
|
--no-check-certificate \ |
|
|
|
"${url}" \ |
|
|
|
-O "${DDNS_PACKAGE_DIR}/services/${service}.json" |
|
|
|
elif [ -f "$cacert" ]; then |
|
|
|
uclient-fetch \ |
|
|
|
--ca-certifcate="${cacert}" \ |
|
|
|
"${url}" \ |
|
|
|
-O "${DDNS_PACKAGE_DIR}/services/${service}.json" |
|
|
|
elif [ -n "$cacert" ]; then |
|
|
|
echo "Certification file not found ($cacert)" |
|
|
|
exit 5 |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
action_remove() { |
|
|
|
local service="$1" |
|
|
|
if [ -z "$service" ]; then |
|
|
|
usage "4" "No service specified" |
|
|
|
fi |
|
|
|
|
|
|
|
rm "${DDNS_PACKAGE_DIR}/services/${service}.json" |
|
|
|
} |
|
|
|
|
|
|
|
action_purge() { |
|
|
|
rm -rf "${DDNS_PACKAGE_DIR}/services" |
|
|
|
rm -rf "${DDNS_PACKAGE_DIR}/list" |
|
|
|
} |
|
|
|
|
|
|
|
sub_service() { |
|
|
|
local action="$1" |
|
|
|
local service="$2" |
|
|
|
|
|
|
|
case "$action" in |
|
|
|
update) |
|
|
|
action_update |
|
|
|
;; |
|
|
|
list-available) |
|
|
|
action_list_available |
|
|
|
;; |
|
|
|
list-installed) |
|
|
|
action_list_installed |
|
|
|
;; |
|
|
|
purge) |
|
|
|
action_purge |
|
|
|
;; |
|
|
|
install) |
|
|
|
action_install "$service" |
|
|
|
;; |
|
|
|
remove) |
|
|
|
action_remove "$service" |
|
|
|
;; |
|
|
|
*) |
|
|
|
usage "2" "Action not supported" |
|
|
|
;; |
|
|
|
esac |
|
|
|
} |
|
|
|
|
|
|
|
main() { |
|
|
|
local cmd="$1" |
|
|
|
local action="$2" |
|
|
|
local service="$3" |
|
|
|
|
|
|
|
[ "$#" -eq 0 ] && usage "1" |
|
|
|
|
|
|
|
case "${cmd}" in |
|
|
|
service) |
|
|
|
sub_service "${action}" "${service}" |
|
|
|
;; |
|
|
|
*) |
|
|
|
usage "1" "Command not supported" |
|
|
|
;; |
|
|
|
esac |
|
|
|
} |
|
|
|
|
|
|
|
main "$@" |