From: Florian Eckert Date: Thu, 17 Sep 2020 12:53:47 +0000 (+0200) Subject: ddns-scripts: add ddns script to manage the providers X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=f184fdf44c7e05659e9e62aa136571be572ba13d;p=feed%2Fpackages.git ddns-scripts: add ddns script to manage the providers Redmine-patch-id: 5298 Signed-off-by: Florian Eckert --- diff --git a/net/ddns-scripts/Makefile b/net/ddns-scripts/Makefile index 07c0425165..8c5d450f2b 100644 --- a/net/ddns-scripts/Makefile +++ b/net/ddns-scripts/Makefile @@ -199,6 +199,10 @@ define Package/ddns-scripts/install $(1)/usr/lib/ddns $(INSTALL_BIN) ./files/usr/lib/ddns/dynamic_dns_updater.sh \ $(1)/usr/lib/ddns + + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) ./files/usr/bin/ddns.sh \ + $(1)/usr/bin/ddns endef define Package/ddns-scripts/postinst diff --git a/net/ddns-scripts/files/usr/bin/ddns.sh b/net/ddns-scripts/files/usr/bin/ddns.sh new file mode 100644 index 0000000000..a2b93b0338 --- /dev/null +++ b/net/ddns-scripts/files/usr/bin/ddns.sh @@ -0,0 +1,171 @@ +#!/bin/sh +# +# Copyright (C) 2020 TDT AG +# +# 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") " + echo "" + echo "Supported ddns :" + echo " service: Command for ddns service provider" + echo "" + echo "Supported ddns 'service' command :" + 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 : Install service provider" + echo " remove : 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 "$@"