Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # interface going down
- if [ "${0#*ip-down.d/}" = "${0##*/}" ]; then
- exec killall -w "${0##*/}"
- fi
- [ "$PPP_IFACE" = 'pppoe-data' ] || exec logger -p daemon.info -t dyndns "Not applying DNS to iface '$PPP_IFACE'"
- read domain </proc/sys/kernel/hostname
- domain=$domain.example.com
- email=
- key=
- zone=
- api=https://api.cloudflare.com/client/v4/zones/$zone/dns_records
- auth="-H X-Auth-Email:$email -H X-Auth-Key:$key"
- updatedns() {
- ret=0
- if ! id=$(curl -s $auth $api |jq -er ".result[] | select(.name == \"$domain\") | .id"); then
- return 1
- fi
- uri="$api/$id"
- json=/tmp/dyndns-$$.json
- curl -sS -XPUT $uri $auth \
- -H 'Content-Type: application/json' \
- -d "{\"type\":\"A\", \"name\":\"$domain\", \"content\":\"$IPLOCAL\"}" >$json
- if jq -ec '.success == false' <$json >/dev/null; then
- logger -p daemon.warning -t dyndns "server returned '$(jq -c .errors <$json)'"
- ret=1
- fi
- rm -f $json
- return $ret
- }
- i=60
- while [ $i -ge 0 ]; do
- updatedns && exec logger -p daemon.info -t dyndns "DNS for $domain set to $IPLOCAL"
- sleep 5
- logger -p daemon.notice -t dyndns "Retry setting DNS for $domain ($i more tries)"
- i=$((i - 1))
- done &
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement