Created
October 2, 2021 14:31
-
-
Save 0neday/f6d87b2c472a3945eaabe598987d8515 to your computer and use it in GitHub Desktop.
vultr api v2 ddns shell scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment