8f924f154fce49fe093c8288c6ba0f9ba02fe539
[openwrt/svn-archive/archive.git] / net / ez-ipupdate / files / ez-ipupdate.hotplug
1 NAME=ez-ipupdate
2 COMMAND=/usr/sbin/$NAME
3
4 case "$ACTION" in
5 ifup|ifdown)
6 cleanup() {
7 [ -e $1 ] && {
8 kill -9 $(cat $1)
9 rm $1
10 }
11 }
12
13 ddns() {
14 local cfg="$1"
15 config_get program $cfg program
16 [ "$program" = "$NAME" ] && {
17 config_get interface $cfg interface
18 [ "$interface" = "$INTERFACE" ] && {
19 config_get dev "$INTERFACE" ifname
20
21 config_get enabled $cfg enabled
22 enabled=${enabled:-1}
23
24 config_get service $cfg service
25
26 config_get pidfile $cfg pidfile
27 pidfile=${pidfile:-/var/run/$NAME-$service-$dev.pid}
28
29 case "$ACTION" in
30 ifdown)
31 cleanup $pidfile
32 ;;
33 *)
34 case "$enabled" in
35 1|yes|true)
36 [ ! -e $pidfile ] && {
37 config_get cache $cfg cache
38 [ -z "$cache" ] && cache=/tmp/$NAME-$service-$dev.cache
39
40 config_get config $cfg config
41 [ -z "$config" ] && {
42 config=/var/run/$NAME-$service-$dev.conf
43 config_get username $cfg username
44 config_get password $cfg password
45 config_get hostname $cfg hostname
46 service=${service:-"dyndns"}
47 config_get server $cfg server
48 cat > $config <<EOF
49 service-type=$service
50 ${server:+server=$server}
51 user=$username:$password
52 host=$hostname
53 cache-file=$cache
54 pid-file=$pidfile
55 interface=$dev
56 quiet
57 EOF
58 }
59
60 $COMMAND -c $config 2>&1 | logger -t $NAME &
61 }
62 ;;
63 *)
64 cleanup $pidfile
65 ;;
66 esac
67 esac
68 }
69 }
70 }
71
72
73 include /lib/network
74 scan_interfaces
75 config_load ddns
76
77 config_foreach ddns ddns
78 ;;
79 esac