Skip to content

Instantly share code, notes, and snippets.

@0neday
Created October 2, 2021 14:31
Show Gist options
  • Select an option

  • Save 0neday/f6d87b2c472a3945eaabe598987d8515 to your computer and use it in GitHub Desktop.

Select an option

Save 0neday/f6d87b2c472a3945eaabe598987d8515 to your computer and use it in GitHub Desktop.

Revisions

  1. 0neday created this gist Oct 2, 2021.
    18 changes: 18 additions & 0 deletions vultr_ddns.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/bin/bash

    BIN_DIR=/mnt/jffs2/plug/app/busybox
    export PATH=$BIN_DIR/bin:$BIN_DIR/sbin:$BIN_DIR/usr/bin:$BIN_DIR/usr/sbin

    DOMAIN=''
    NAME=''
    APIKEY=''
    CAFILE="/mnt/jffs2/hw/etc/ssl/certs/ca-certificates.crt"
    CURL_BIN="/mnt/jffs2/plug/app/bin/curl"

    IPV4=$(ifconfig ppp257 | grep 'inet addr' | awk '{print $2}' | awk -F ':' '{print $2}')

    record_response_json=$($CURL_BIN --cacert $CAFILE -s -X GET -H "Authorization: Bearer ${APIKEY}" "https://api.vultr.com/v2/domains/$DOMAIN/records")

    records_id=$(echo $record_response_json | sed -E "s/.+\,\{\"id\":\"([a-f0-9-]+)\".+\"$NAME\".+/\1/g")

    $CURL_BIN --cacert $CAFILE -s -X PATCH -H "Authorization: Bearer ${APIKEY}" "https://api.vultr.com/v2/domains/$DOMAIN/records/$records_id" -H "Content-Type: application/json" --data "{\"name\":\"$NAME\",\"type\":\"A\",\"data\":\"$IPV4\",\"ttl\":120, \"priority\":0}"