update network service examples
[oweals/busybox.git] / examples / var_service / zcip_if / zcip_handler
1 #!/bin/sh
2 # executed by zcip
3 # parameters: $1 and environment
4 # $1 is:
5 #
6 # init: zcip starts. Environment:
7 # interface=eth0
8 #
9 # config: Address is obtained.
10 # interface=eth0
11 # ip=169.254.a.b
12 #
13 # deconfig: Conflict or link went down.
14 # interface=eth0
15
16 service=${PWD##*/}
17 file_ipconf="$service.ipconf"
18 dir_ipconf="/var/run/service/fw"
19
20 exec >/dev/null
21 #exec >>"$0.out"  #debug
22 exec 2>&1
23
24 echo "`date`: Params: $*"
25
26 if test x"$1" != x"config"; then
27         # Reconfigure network with this interface disabled
28         echo "Deconfiguring"
29         rm "$file_ipconf"
30         rm "$dir_ipconf/$file_ipconf"
31         sv u /var/service/fw
32         exit
33 fi
34
35 # "config": we've got the address
36 # Record information for e.g. dhcp_$IF_pinger service
37 env >"env.out"
38
39 ./convert2ipconf "$file_ipconf"
40 # Reconfigure routing and firewall if needed
41 diff --brief "$file_ipconf" "$dir_ipconf/$file_ipconf" >/dev/null 2>&1
42 if test $? != 0; then
43         echo "Reconfiguring fw"
44         mkdir -p "$dir_ipconf" 2>/dev/null
45         cp "$file_ipconf" "$dir_ipconf/$file_ipconf"
46         sv u /var/service/fw
47 fi