1 #!/bin/sh /etc/rc.common
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
12 facters_dir
="/etc/alfred"
17 local ifce
="$1" dir
="$2"
19 if ! [ -d "$dir" ] ; then
21 echo "waiting $timeout secs for $ifce interface..."
22 for i
in $
(seq $timeout); do
24 [ -d "$dir" ] && break
25 if [ $i = $timeout ] ; then
26 echo "$ifce not detected, alfred not starting."
33 wait_for_ll_address
() {
37 echo "waiting $timeout secs for $iface address..."
38 for i
in $
(seq $timeout); do
40 # - the link-local address (starts with fe80)
41 # - without tentative flag (bit 0x40 in the flags field; the first char of the fifth field is evaluated)
42 # - on interface $iface
45 $1 ~ /^fe80/ && $5 ~ /^[012389ab]/ && $6 == "'"$iface"'" { RET=0 }
47 ' /proc
/net
/if_inet6
; then
53 echo "$iface address not detected, alfred not starting."
59 append
"interfaces" "$1" ","
60 wait_for_ll_address
"$1"
66 local disabled interface mode
69 # check if section is disabled
70 config_get_bool disabled
"$section" disabled
0
71 [ $disabled = 0 ] ||
return 1
75 config_list_foreach
"$section" "interface" append_interface
76 if [ -z "$interfaces" ]; then
77 config_get interface
"$section" interface
78 append_interface
"$interface"
80 append args
"-i $interfaces"
82 config_get mode
"$section" mode
83 [ "$mode" = "master" ] && append args
"-m"
85 config_get batmanif
"$section" batmanif
86 append args
"-b $batmanif"
88 if [ "$batmanif" != "none" ]; then
89 wait_for_dir
"$batmanif" "/sys/devices/virtual/net/$batmanif"
92 append alfred_args
"$args"
95 config_get_bool start_vis
"$section" start_vis
0
96 if [ "$start_vis" = 1 ] && [ -x /usr
/sbin
/batadv-vis
]; then
98 append vis_args
"-i $batmanif -s"
101 config_get_bool run_facters
"$section" run_facters
0
108 config_foreach alfred_start alfred
110 [ "$enable" = "0" ] && exit 0
112 procd_open_instance
"alfred"
113 procd_set_param
command /usr
/sbin
/alfred
114 procd_append_param
command ${alfred_args}
117 [ "$vis_enable" = "1" ] && {
118 procd_open_instance
"batadv-vis"
119 procd_set_param
command /usr
/sbin
/batadv-vis
120 procd_append_param
command ${vis_args}
124 [ "$run_facters" = "1" ] && {
125 ( for file in $facters_dir/* ; do [ -x $file ] && $file ; done )
126 if ! ( grep -q "for file in $facters_dir/\* ; do " /etc
/crontabs
/root
2>/dev
/null
) ; then
127 echo "*/5 * * * * ( for file in $facters_dir/* ; do [ -x \$file ] && \$file ; done )" >> /etc
/crontabs
/root
128 /etc
/init.d
/cron
enable
129 /etc
/init.d
/cron restart
135 procd_add_reload_trigger
"alfred"
139 [ -e /etc
/crontabs
/root
] && {
140 sed "\|for file in $facters_dir/\* ; do |d" -i /etc
/crontabs
/root
141 /etc
/init.d
/cron restart