Skip to content

Instantly share code, notes, and snippets.

@backslash-f
Created December 10, 2021 20:40
Show Gist options
  • Select an option

  • Save backslash-f/fd0e4084fbed4fadda64ee28c7fc2b36 to your computer and use it in GitHub Desktop.

Select an option

Save backslash-f/fd0e4084fbed4fadda64ee28c7fc2b36 to your computer and use it in GitHub Desktop.

Revisions

  1. backslash-f created this gist Dec 10, 2021.
    28 changes: 28 additions & 0 deletions ddns-start
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/bin/sh

    # register a subdomain at https://www.duckdns.org/ to get your token
    # put 'hostname|token' in the 'Host Name' field under DDNS (custom)
    # e.g. myhost|abcdefgh-1234-5678-9876-f71b0ed7a7fe

    DDNS_HOSTNAME_FIELD=$(nvram get ddns_hostname_x)
    SUBDOMAIN=$(echo "$DDNS_HOSTNAME_FIELD" | awk -F'|' '{print $1}')
    TOKEN=$(echo "$DDNS_HOSTNAME_FIELD" | awk -F'|' '{print $2}')
    IP="$(curl -fs4 https://myip.dnsomatic.com/)"

    if [ -z "${IP}" ]
    then
    logger "The IP is empty! Not calling the update line..."
    else
    REQUEST_URL="https://www.duckdns.org/update?domains=${SUBDOMAIN}&token=${TOKEN}&ip=${IP}"
    logger "DDNS Request URL: ${REQUEST_URL}"

    RESULT=$(curl --silent "${REQUEST_URL}" 2>&1)
    logger "DDNS Request result: $RESULT"

    if [[ "$RESULT" == "OK" ]];
    then
    /sbin/ddns_custom_updated 1
    else
    /sbin/ddns_custom_updated 0
    fi
    fi