[packages] /etc/functions.sh => /lib/functions.sh
[packages.git] / net / dudders / files / dudders.hotplug
1 #!/bin/sh
2
3 . /lib/functions.sh
4
5 config_cb() {
6        local cfg="$CONFIG_SECTION"
7        local cfgtype
8        config_get cfgtype "$cfg" TYPE
9        dudders=/usr/bin/dudders
10
11        case "$cfgtype" in
12                dudders)
13                        config_get enabled  $cfg enabled
14                        [ "$enabled" = "yes" ] || return 0
15
16                        config_get tcp      $cfg tcp
17                        config_get keyname  $cfg keyname
18                        config_get mname    $cfg mname
19                        config_get zone     $cfg zone
20                        config_get keyfile  $cfg keyfile
21                        config_get hostname $cfg hostname
22                        config_get ttl      $cfg ttl
23
24                        [ -r "$keyfile" ] || return 1
25                        sleep 1
26                        interface=$(route -n 2>&- \
27                          |grep '^0.0.0.0' \
28                          |sed -e 's/.* \([^ ]\+\)$/\1/')
29                        [ -z "$interface" ] && return 0
30                        [ "$DEVICE" = "$interface" -o \
31                          "$IFNAME" = "$interface" -o \
32                          "$PPP_IFACE" = "$interface" ] || return 0
33                        ipaddr=${PPP_LOCAL:-${IPLOCAL:-$(ifconfig "$interface" \
34                            |grep -o 'addr:[^ ]\+' \
35                            |sed -e 's/addr://')}}
36                        OPTS=${keyname:+" -k '$keyname'"}
37                        [ "$tcp" = "yes" ] && OPTS=$OPTS" -T"
38                        OPTS=$OPTS${mname:+" -m '$mname'"}
39                        OPTS=$OPTS${zone:+" -z '$zone'"}
40                        eval $dudders -k $keyfile $OPTS $hostname $ttl $ipaddr
41                ;;
42        esac
43 }
44 case "${ACTION:-ifup}" in
45        ifup) config_load dudders ;;
46 esac