Browse Source

added new shell script updatedns.sh
changend docker file and cron job

hmetzner 7 years ago
parent
commit
1eca228aac
3 changed files with 45 additions and 13 deletions
  1. 4 12
      Dockerfile
  2. 1 1
      cron
  3. 40 0
      updatedns.sh

+ 4 - 12
Dockerfile

@@ -1,19 +1,11 @@
 FROM alpine:3.6
 FROM alpine:3.6
 
 
-ADD cloudflare.sh /cloudflare.sh
+ADD updatedns.sh /updatedns.sh
 ADD cron /var/spool/cron/crontabs/root
 ADD cron /var/spool/cron/crontabs/root
 
 
-ENV ZONE=example.com \
-    HOST=example.com \
-    EMAIL=example@example.com \
-    API=1111111111111111 \
-    TTL=1 \
-    PROXY=true \
-    DEBUG=false
-
 RUN apk add --update curl && \
 RUN apk add --update curl && \
     rm -rf /var/cache/apk/* && \
     rm -rf /var/cache/apk/* && \
-    chmod +x /cloudflare.sh
+    chmod +x /updatedns.sh
 
 
-CMD /cloudflare.sh && \
-    crond -f
+CMD /updatedns.sh && \
+    crond -f

+ 1 - 1
cron

@@ -1 +1 @@
-*/5 * * * * /cloudflare.sh
+*/5 * * * * /updatedns.sh

+ 40 - 0
updatedns.sh

@@ -0,0 +1,40 @@
+#!/bin/sh
+
+echo "Current time: $(date "+%Y-%m-%d %H:%M:%S")"
+ip_file="ip"
+
+new_ip=$(curl -s http://ipecho.net/plain)
+
+# Fallbacks
+if [ -z "$new_ip" ]; then
+    new_ip=$(curl -s http://whatismyip.akamai.com)
+fi
+if [ -z "$new_ip" ]; then
+    new_ip=$(curl -s http://icanhazip.com/)
+fi
+if [ -z "$new_ip" ]; then
+    new_ip=$(curl -s https://tnx.nl/ip)
+fi
+
+if [ -z "$new_ip" ]; then
+    echo "Empty IP !"
+    exit 0
+fi
+
+if [ -f $ip_file ]; then
+  ip=$(cat $ip_file)
+  if [ "$ip" = "$new_ip" ]; then
+    echo "Same ip: $ip"
+    exit 0
+  fi
+fi
+
+update=$(curl -s -X GET "https://ip4.ddnss.de/upd.php?key=c1eed0f30eaa1a599570f18def222738&host=metzner.myhome-server.de")
+
+if echo "$update" | grep -q "Updated 1 hostname"; then
+    echo "DDNSS-IP changed to: $new_ip"
+  echo "$new_ip" > $ip_file
+else
+  printf "Update failed:\\n%s" "$update"
+  exit 1
+fi