From 6945528179abe39c589d546cd465d160992dcf7a Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Wed, 9 Sep 2020 17:21:04 +0200 Subject: ddns-scripts: update digitalocean.com-v2 to json Signed-off-by: Florian Eckert --- net/ddns-scripts/Makefile | 17 +++----- .../files/update_digitalocean_com_v2.sh | 51 ---------------------- .../usr/lib/ddns/update_digitalocean_com_v2.sh | 51 ++++++++++++++++++++++ .../share/ddns/services/digitalocean.com-v2.json | 9 ++++ 4 files changed, 67 insertions(+), 61 deletions(-) delete mode 100755 net/ddns-scripts/files/update_digitalocean_com_v2.sh create mode 100644 net/ddns-scripts/files/usr/lib/ddns/update_digitalocean_com_v2.sh create mode 100644 net/ddns-scripts/files/usr/share/ddns/services/digitalocean.com-v2.json diff --git a/net/ddns-scripts/Makefile b/net/ddns-scripts/Makefile index 56fb0ce38..ed055c92e 100755 --- a/net/ddns-scripts/Makefile +++ b/net/ddns-scripts/Makefile @@ -356,17 +356,17 @@ endef define Package/ddns-scripts_digitalocean.com-v2/install $(INSTALL_DIR) $(1)/etc/uci-defaults $(INSTALL_BIN) $(PKG_BUILD_DIR)/files/ddns.defaults $(1)/etc/uci-defaults/ddns_digtalocean.com-v2 + $(INSTALL_DIR) $(1)/usr/lib/ddns - $(INSTALL_BIN) $(PKG_BUILD_DIR)/files/update_digitalocean_com_v2.sh $(1)/usr/lib/ddns + $(INSTALL_BIN) ./files/usr/lib/ddns/update_digitalocean_com_v2.sh \ + $(1)/usr/lib/ddns + + $(INSTALL_DIR) $(1)/usr/share/ddns/services + $(INSTALL_DATA) ./files/usr/share/ddns/services/digitalocean.com-v2.json \ + $(1)/usr/share/ddns/services endef define Package/ddns-scripts_digitalocean.com-v2/postinst #!/bin/sh - # remove old services file entries - /bin/sed -i '/digitalocean\.com-v2/d' $${IPKG_INSTROOT}/etc/ddns/services >/dev/null 2>&1 - /bin/sed -i '/digitalocean\.com-v2/d' $${IPKG_INSTROOT}/etc/ddns/services_ipv6 >/dev/null 2>&1 - # and create new - printf "%s\\t%s\\n" '"digitalocean.com-v2"' '"update_digitalocean_com_v2.sh"' >> $${IPKG_INSTROOT}/etc/ddns/services - printf "%s\\t%s\\n" '"digitalocean.com-v2"' '"update_digitalocean_com_v2.sh"' >> $${IPKG_INSTROOT}/etc/ddns/services_ipv6 # on real system restart service if enabled [ -z "$${IPKG_INSTROOT}" ] && { [ -x /etc/uci-defaults/ddns_digitalocean.com-v2 ] && \ @@ -381,9 +381,6 @@ define Package/ddns-scripts_digitalocean.com-v2/prerm #!/bin/sh # if NOT run buildroot then stop service [ -z "$${IPKG_INSTROOT}" ] && /etc/init.d/ddns stop >/dev/null 2>&1 - # remove services file entries - /bin/sed -i '/digitalocean\.com-v2/d' $${IPKG_INSTROOT}/etc/ddns/services >/dev/null 2>&1 - /bin/sed -i '/digitalocean\.com-v2/d' $${IPKG_INSTROOT}/etc/ddns/services_ipv6 >/dev/null 2>&1 exit 0 # suppress errors endef diff --git a/net/ddns-scripts/files/update_digitalocean_com_v2.sh b/net/ddns-scripts/files/update_digitalocean_com_v2.sh deleted file mode 100755 index 0770ab270..000000000 --- a/net/ddns-scripts/files/update_digitalocean_com_v2.sh +++ /dev/null @@ -1,51 +0,0 @@ -# Script for sending user defined updates using DO API -# 2015 Artem Yakimenko -# -# activated inside /etc/config/ddns by setting -# -# option update_script '/usr/lib/ddns/update_do.sh' -# -# the script is parsed (not executed) inside send_update() function -# of /usr/lib/ddns/dynamic_dns_functions.sh -# so you can use all available functions and global variables inside this script -# already defined in dynamic_dns_updater.sh and dynamic_dns_functions.sh -# -# It make sence to define the update url ONLY inside this script -# because it's anyway unique to the update script -# otherwise it should work with the default scripts -# -# Options are passed from /etc/config/ddns: - -# Username - the record name DO Zone -# Password - API Token -# Domain - the domain managed by DO -# Parm_opt - The Record ID in the DO API structure - -local __URL="https://api.digitalocean.com/v2/domains/[DOMAIN]/records/[RECORD_ID]" -local __HEADER="Authorization: Bearer [PASSWORD]" -local __HEADER_CONTENT="Content-Type: application/json" -local __BODY='{"name":"[NAME]","data": "[IP]"}' -# inside url we need username and password - -[ -z "$domain" ] && write_log 14 "Service section not configured correctly! Missing 'domain'" -[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'Zone name in Username'" -[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'" -[ -z "$param_opt" ] && write_log 14 "Service section not configured correctly! Missing 'Zone ID in Optional Parameter'" - -# do replaces in URL, header and body: -__URL=$(echo $__URL | sed -e "s#\[RECORD_ID\]#$param_opt#g" \ - -e "s#\[DOMAIN\]#$domain#g") -__HEADER=$(echo $__HEADER| sed -e "s#\[PASSWORD\]#$password#g") -__HEADER_CONTENT=$(echo $__HEADER_CONTENT) -__BODY=$(echo $__BODY | sed -e "s#\[NAME\]#$username#g" -e "s#\[IP\]#$__IP#g") - -#Send PUT request - -curl -X PUT -H "$__HEADER_CONTENT" -H "$__HEADER" -d "$__BODY" "$__URL" - -write_log 7 "DDNS Provider answered:\n$(cat $DATFILE)" - -# analyse provider answers -# If IP is contained in the returned datastructure - API call was sucessful -grep -E "$__IP" $DATFILE >/dev/null 2>&1 -return $? # "0" if IP has been changed or no change is needed diff --git a/net/ddns-scripts/files/usr/lib/ddns/update_digitalocean_com_v2.sh b/net/ddns-scripts/files/usr/lib/ddns/update_digitalocean_com_v2.sh new file mode 100644 index 000000000..0770ab270 --- /dev/null +++ b/net/ddns-scripts/files/usr/lib/ddns/update_digitalocean_com_v2.sh @@ -0,0 +1,51 @@ +# Script for sending user defined updates using DO API +# 2015 Artem Yakimenko +# +# activated inside /etc/config/ddns by setting +# +# option update_script '/usr/lib/ddns/update_do.sh' +# +# the script is parsed (not executed) inside send_update() function +# of /usr/lib/ddns/dynamic_dns_functions.sh +# so you can use all available functions and global variables inside this script +# already defined in dynamic_dns_updater.sh and dynamic_dns_functions.sh +# +# It make sence to define the update url ONLY inside this script +# because it's anyway unique to the update script +# otherwise it should work with the default scripts +# +# Options are passed from /etc/config/ddns: + +# Username - the record name DO Zone +# Password - API Token +# Domain - the domain managed by DO +# Parm_opt - The Record ID in the DO API structure + +local __URL="https://api.digitalocean.com/v2/domains/[DOMAIN]/records/[RECORD_ID]" +local __HEADER="Authorization: Bearer [PASSWORD]" +local __HEADER_CONTENT="Content-Type: application/json" +local __BODY='{"name":"[NAME]","data": "[IP]"}' +# inside url we need username and password + +[ -z "$domain" ] && write_log 14 "Service section not configured correctly! Missing 'domain'" +[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'Zone name in Username'" +[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'" +[ -z "$param_opt" ] && write_log 14 "Service section not configured correctly! Missing 'Zone ID in Optional Parameter'" + +# do replaces in URL, header and body: +__URL=$(echo $__URL | sed -e "s#\[RECORD_ID\]#$param_opt#g" \ + -e "s#\[DOMAIN\]#$domain#g") +__HEADER=$(echo $__HEADER| sed -e "s#\[PASSWORD\]#$password#g") +__HEADER_CONTENT=$(echo $__HEADER_CONTENT) +__BODY=$(echo $__BODY | sed -e "s#\[NAME\]#$username#g" -e "s#\[IP\]#$__IP#g") + +#Send PUT request + +curl -X PUT -H "$__HEADER_CONTENT" -H "$__HEADER" -d "$__BODY" "$__URL" + +write_log 7 "DDNS Provider answered:\n$(cat $DATFILE)" + +# analyse provider answers +# If IP is contained in the returned datastructure - API call was sucessful +grep -E "$__IP" $DATFILE >/dev/null 2>&1 +return $? # "0" if IP has been changed or no change is needed diff --git a/net/ddns-scripts/files/usr/share/ddns/services/digitalocean.com-v2.json b/net/ddns-scripts/files/usr/share/ddns/services/digitalocean.com-v2.json new file mode 100644 index 000000000..abeac560f --- /dev/null +++ b/net/ddns-scripts/files/usr/share/ddns/services/digitalocean.com-v2.json @@ -0,0 +1,9 @@ +{ + "name": "digitalocean.com-v2", + "ipv4": { + "url": "update_digitalocean_com_v2.sh" + }, + "ipv6": { + "url": "update_digitalocean_com_v2.sh" + } +} -- cgit v1.2.3