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