[packages] /etc/functions.sh => /lib/functions.sh
[packages.git] / net / freeswitch / files / freeswitch.hotplug
1 #!/bin/sh
2
3 . /lib/functions.sh
4 LOAD_STATE=1
5
6 if [ "$ACTION" = "ifup" ]; then
7         /etc/init.d/freeswitch enabled && {
8                 local not_all_up="$(sh -c '
9                         . /lib/functions.sh
10
11                         LOAD_STATE=1
12                         local if_is_down=0
13                         local network_ignore=""
14                         
15                         check_if_down () {
16                                 local cfg="$1"
17                                 local up
18                                 local proto
19                                 config_get_bool up "$1" up 0
20                                 config_get proto "$1" proto
21                                 if [ "$proto" != "none" ] && [ "$up" -ne 1 ]; then
22                                         local new_down=1
23                                         local oIFS="$IFS"
24                                         local ignore
25                                         IFS=" "
26                                         for ignore in $network_ignore; do
27                                                 [ "$cfg" = "$ignore" ] && new_down=0
28                                         done
29                                         IFS="$oIFS"
30                                         [ "$new_down" = "1" ] && if_is_down=1
31                                 fi
32                         }
33                         
34                         append_ignore() {
35                                 local cfg="$1"
36                                 local network
37                                 config_get network "$1" network
38                                 append network_ignore "$network"
39                         }       
40
41                         LOAD_STATE=1
42                         config_load freeswitch
43                         config_foreach append_ignore network_ignore
44                         config_load network
45                         config_foreach check_if_down interface
46                         
47                         echo "$if_is_down"
48                 ')"     
49                 [ "$not_all_up" = "0" ] && {
50                         local started
51                         {
52                                 mkdir -p /tmp/freeswitch
53                                 lock /tmp/freeswitch/.start.lck
54                                 config_load freeswitch
55                                 config_get started "state" started
56                                 [ "$started" != "1" ] && {
57                                         /etc/init.d/freeswitch start
58                                         uci_set_state freeswitch global state started 1
59                                 }
60                                 lock -u /tmp/freeswitch/.start.lck
61                         } &
62                 }
63         }
64 fi
65