Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong
GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/external/packages/extras-buildpkgs/hostapd/debian/ifupdown/hostapd.sh
13272 views
1
#!/bin/sh
2
3
# Copyright (C) 2006-2009 Debian hostapd maintainers
4
# Faidon Liambotis <[email protected]>
5
# Kel Modderman <[email protected]>
6
#
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License
9
# as published by the Free Software Foundation; either version 2
10
# of the License, or (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# On Debian GNU/Linux systems, the text of the GPL license,
18
# version 2, can be found in /usr/share/common-licenses/GPL-2.
19
20
# quit if we're called for lo
21
if [ "$IFACE" = lo ]; then
22
exit 0
23
fi
24
25
if [ -n "$IF_HOSTAPD" ]; then
26
HOSTAPD_CONF="$IF_HOSTAPD"
27
else
28
exit 0
29
fi
30
31
HOSTAPD_BIN="/usr/sbin/hostapd"
32
HOSTAPD_PNAME="hostapd"
33
HOSTAPD_PIDFILE="/run/hostapd.$IFACE.pid"
34
HOSTAPD_OMIT_PIDFILE="/run/sendsigs.omit.d/hostapd.$IFACE.pid"
35
36
if [ ! -x "$HOSTAPD_BIN" ]; then
37
exit 0
38
fi
39
40
if [ "$VERBOSITY" = "1" ]; then
41
TO_NULL="/dev/stdout"
42
else
43
TO_NULL="/dev/null"
44
fi
45
46
hostapd_msg () {
47
case "$1" in
48
verbose)
49
shift
50
echo "$HOSTAPD_PNAME: $@" > "$TO_NULL"
51
;;
52
stderr)
53
shift
54
echo "$HOSTAPD_PNAME: $@" > /dev/stderr
55
;;
56
*)
57
;;
58
esac
59
}
60
61
test_hostapd_pidfile () {
62
if [ -n "$1" ] && [ -f "$2" ]; then
63
if start-stop-daemon --stop --quiet --signal 0 \
64
--exec "$1" --pidfile "$2"; then
65
return 0
66
else
67
rm -f "$2"
68
return 1
69
fi
70
else
71
return 1
72
fi
73
}
74
75
init_hostapd () {
76
HOSTAPD_OPTIONS="-B -P $HOSTAPD_PIDFILE $HOSTAPD_CONF"
77
HOSTAPD_MESSAGE="$HOSTAPD_BIN $HOSTAPD_OPTIONS"
78
79
test_hostapd_pidfile "$HOSTAPD_BIN" "$HOSTAPD_PIDFILE" && return 0
80
81
hostapd_msg verbose "$HOSTAPD_MESSAGE"
82
start-stop-daemon --start --oknodo --quiet --exec "$HOSTAPD_BIN" \
83
--pidfile "$HOSTAPD_PIDFILE" -- $HOSTAPD_OPTIONS > "$TO_NULL"
84
85
if [ "$?" -ne 0 ]; then
86
return "$?"
87
fi
88
89
HOSTAPD_PIDFILE_WAIT=0
90
until [ -s "$HOSTAPD_PIDFILE" ]; do
91
if [ "$HOSTAPD_PIDFILE_WAIT" -ge 5 ]; then
92
hostapd_msg stderr \
93
"timeout waiting for pid file creation"
94
return 1
95
fi
96
97
HOSTAPD_PIDFILE_WAIT=$(($HOSTAPD_PIDFILE_WAIT + 1))
98
sleep 1
99
done
100
cat "$HOSTAPD_PIDFILE" > "$HOSTAPD_OMIT_PIDFILE"
101
102
return 0
103
}
104
105
kill_hostapd () {
106
HOSTAPD_MESSAGE="stopping $HOSTAPD_PNAME via pidfile: $HOSTAPD_PIDFILE"
107
108
test_hostapd_pidfile "$HOSTAPD_BIN" "$HOSTAPD_PIDFILE" || return 0
109
110
hostapd_msg verbose "$HOSTAPD_MESSAGE"
111
start-stop-daemon --stop --oknodo --quiet --exec "$HOSTAPD_BIN" \
112
--pidfile "$HOSTAPD_PIDFILE" > "$TO_NULL"
113
114
[ "$HOSTAPD_OMIT_PIDFILE" ] && rm -f "$HOSTAPD_OMIT_PIDFILE"
115
}
116
117
case "$MODE" in
118
start)
119
case "$PHASE" in
120
pre-up)
121
init_hostapd || exit 1
122
;;
123
*)
124
hostapd_msg stderr "unknown phase: \"$PHASE\""
125
exit 1
126
;;
127
esac
128
;;
129
stop)
130
case "$PHASE" in
131
post-down)
132
kill_hostapd
133
;;
134
*)
135
hostapd_msg stderr "unknown phase: \"$PHASE\""
136
exit 1
137
;;
138
esac
139
;;
140
*)
141
hostapd_msg stderr "unknown mode: \"$MODE\""
142
exit 1
143
;;
144
esac
145
146
exit 0
147
148