Last active
May 1, 2019 00:30
-
-
Save nna774/9447e6336acb8e4d411e6c0e8d82f8f8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh -xe | |
IP=`curl https://ipinfo.io/ip 2> /dev/null` | |
EMAIL="hie@natto" | |
TOKEN="huehuehuehue" | |
LOG= | |
PTRS= | |
changed() { | |
DOMAIN=$1 | |
PTRS=`nslookup $1 | sed -ne 's/Address: //p'` | |
[ $IP != $PTRS ] | |
} | |
update() { | |
ZONE=$1 | |
RECORD=$2 | |
DOMAIN=$3 | |
if `changed $3`; then | |
echo "Address Changed! from $PTRS to $IP" >&2 | |
LOG=`curl -X PUT -H "Content-Type: application/json" -H "X-Auth-Email: ${EMAIL}" \ | |
-H "X-Auth-Key: ${TOKEN}" \ | |
https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records/${RECORD} \ | |
--data "{\"zone_id\": \"${ZONE}\", \"type\": \"A\", \"name\": \"${DOMAIN}\", \"content\": \"${IP}\"}"` | |
else | |
echo "Address not Changed." >&2 | |
fi | |
} | |
update "tatata" "sanukimiko" "mikan.nina.xxx" | |
if [ "x$LOG" != "x" ]; then | |
TEMP=`mktemp` | |
echo "From: Update DDNS log <[email protected]>" > "$TEMP" | |
echo "To: update-ddns@localhost" >> "$TEMP" | |
echo "Subject: Update DDNS log" >> "$TEMP" | |
echo >> "$TEMP" | |
echo "$LOG" | jq . >> "$TEMP" | |
sendmail "update-ddns@localhost" < "$TEMP" | |
rm -f "$TEMP" | |
fi |
This file contains hidden or 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
[Unit] | |
Description = update dns | |
[Service] | |
ExecStart = /home/nona/.dotfiles/bin/update-ddns.sh | |
Type = oneshot | |
User = nobody | |
[Install] | |
WantedBy = multi-user.target |
This file contains hidden or 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
[Unit] | |
Description=update dns | |
[Timer] | |
OnBootSec=5min | |
OnUnitActiveSec=1h | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment