-
Notifications
You must be signed in to change notification settings - Fork 47
/
S42connman
executable file
·84 lines (68 loc) · 1.79 KB
/
S42connman
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
CONF="/etc/connman/main.conf"
PROG="/usr/sbin/connmand"
PROG_WO="/usr/sbin/connmand-wait-online"
LOG="/var/log/connman.log"
LIB_DIR="/var/lib/connman"
RUN_DIR="/var/run/connman"
ONLINE_TIMEOUT=20
ONLINE_TIMEOUT_INITIAL=20
ONLINE_TIMEOUT_CHECK=5
ONLINE_HANDLER_SCRIPT="/usr/libexec/connman-online-handler"
test -x ${PROG} || exit 0
test -s ${CONF} || exit 0
test -n "${OS_VERSION}" || source /etc/init.d/base
watch_online() {
is_online=false
while true; do
${PROG_WO} --timeout=${ONLINE_TIMEOUT_CHECK} &>/dev/null
if [[ $? == 0 ]]; then
if [[ ${is_online} == false ]]; then
${ONLINE_HANDLER_SCRIPT} true
is_online=true
fi
else
if [[ ${is_online} == true ]]; then
${ONLINE_HANDLER_SCRIPT} false
is_online=false
fi
fi
sleep 1
done
}
start() {
msg_begin "Starting connman"
mkdir -p ${RUN_DIR}
ln -sf ${RUN_DIR}/resolv.conf /tmp/resolv.conf
ifconfig lo up
${PROG} -n -r &> ${LOG} &
if grep -qE '(Favorite)|(AutoConnect)=true' ${LIB_DIR}/*/settings 2>/dev/null; then
timeout=${ONLINE_TIMEOUT}
else
timeout=${ONLINE_TIMEOUT_INITIAL}
fi
test -x ${ONLINE_HANDLER_SCRIPT} && watch_online &> /var/log/online-handler.log &
${PROG_WO} --timeout=${timeout}
test $? == 0 && msg_done || msg_fail
}
stop() {
msg_begin "Stopping connman"
ps | grep connman | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill
msg_done
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 2
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac