From d62a63c3841d3ef005bbf1494c7cdbfa7c25863f Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 14 Mar 2023 01:23:11 -0700 Subject: update for Hetzner instead of Linode --- linode-ddns.sh | 56 -------------------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100755 linode-ddns.sh (limited to 'linode-ddns.sh') diff --git a/linode-ddns.sh b/linode-ddns.sh deleted file mode 100755 index cd0cd76..0000000 --- a/linode-ddns.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright 2022 David Vazgenovich Shakaryan -# -# LINODE_TOKEN= linode-ddns.sh - -IP_RESOLVER='https://ifconfig.co' -TARGET="${1}" - -shopt -s extglob - -die() { - [[ -n "${@}" ]] && echo "${@}" >&2 - exit 1 -} - -lincurl() { - curl -sfH "Authorization: Bearer ${LINODE_TOKEN}" \ - "https://api.linode.com/v4/domains/${1}" \ - "${@:2}" -} - -ip="$(curl -sf4 "${IP_RESOLVER}")" || die 'IP lookup failed' - -dom_re="${TARGET}" -while [[ "${dom_re}" =~ ^([^\\]*)\.(.*)$ ]]; do - dom_re="(${BASH_REMATCH[1]}\\.)?${BASH_REMATCH[2]}" -done - -res="$(lincurl)" || die 'Domains lookup failed' -IFS='|' read dom_id dom_name < <(jq -er --arg re "${dom_re}" \ - '[.data[] | select(.domain | test("\\A" + $re + "\\z"))] | - if . == [] then (null | halt_error) else . end | - max_by(.domain | length) | [.id, .domain] | join("|")' \ - <<< "${res}") || die 'Domain not found' -rec_name="${TARGET%%?(.)${dom_name}}" - -res=$(lincurl "${dom_id}/records") || die 'Records lookup failed' -rec_id="$(jq -er --arg name "${rec_name}" \ - 'first(.data[] | select(.type == "A" and .name == $name)) | .id' \ - <<< "${res}")" || die 'Record not found' - -res="$(lincurl "${dom_id}/records/${rec_id}")" || die 'Record lookup failed' -old_ip="$(jq -r '.target' <<< "${res}")" - -if [[ "${old_ip}" == "${ip}" ]]; then - echo "IP unchanged from ${ip}" - exit -fi - -res="$(lincurl "${dom_id}/records/${rec_id}" \ - -H 'Content-Type: application/json' \ - -X PUT -d "{\"target\":\"${ip}\"}")" || die 'Record update failed' -new_ip="$(jq -r '.target' <<< "${res}")" - -echo "IP changed from ${old_ip} to ${new_ip}" -- cgit v1.2.3-70-g09d2