d364659008f7d45c87d4b212407ad964a5c3064b
[packages.git] / net / updatedd / files / updatedd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
3 START=50
4
5 start_service () {
6         local section="$1"
7         config_get service  "$section" service
8         config_get username "$section" username
9         config_get password "$section" password
10         config_get host     "$section" host
11         config_get update   "$section" update
12
13         [ "$update" = 1 ] && {
14                 if [ "$service" = "dyndns" ]; then
15                         wget http://checkip.dyndns.org -O /tmp/updatedd_ip_check
16                         current_ip=`cat /tmp/updatedd_ip_check |cut -d':' -f2|cut -d'<' -f1 |cut -d' ' -f2`
17                         rm /tmp/updatedd_ip_check
18                         old_ip=`nslookup "$host" |grep "$host" -A 1 |grep Address |cut -d' ' -f3`
19                         if [ "$current_ip" = "$old_ip" ]; then
20                                 echo "Preventing abusive update"
21                                 abusive=1
22                         fi
23                 fi
24                 if [ "$abusive" != "1" ]; then
25                         /usr/bin/updatedd -Y $service -- $username:$password $host
26                 fi
27         }
28 }
29
30 start() {
31         config_load "updatedd"
32         config_foreach start_service updatedd
33 }
34
35 stop() {
36         killall updatedd
37 }