/etc/init.d/S33hostapd: enable AP interface if available

This commit is contained in:
Calin Crisan 2020-05-28 21:52:16 +03:00
parent 688388c3e7
commit c517c30230
2 changed files with 32 additions and 5 deletions

View File

@ -18,7 +18,6 @@ test -x ${PROG} || exit 0
test -n "${OS_VERSION}" || source /etc/init.d/base
prepare_conf ${CONF} ${SYS_CONF} ${BOOT_CONF}
test -s ${CONF} || exit 0
test -s ${WATCH_CONF} && source ${WATCH_CONF}
@ -38,7 +37,23 @@ watch() {
done
}
start() {
prepare_ap_iface() {
# Only prepare AP interfaces of format "apX"
if ! [[ "${OS_AP}" =~ ap([[:digit:]]) ]]; then
return
fi
wlan_iface=wlan${BASH_REMATCH[1]}
if ! iw dev ${wlan_iface} info &>/dev/null; then
return # No wlan interface
fi
msg_begin "Preparing AP interface"
iw dev ${wlan_interface} interface add ${OS_AP} type __ap &>/dev/null
test $? == 0 && msg_done || msg_fail
}
start_hostapd() {
msg_begin "Starting hostapd"
# wait up to 5 seconds for interface
@ -65,13 +80,27 @@ start() {
test -n "${module}" && msg_done "done (${module})"|| msg_done
}
stop() {
stop_hostapd() {
msg_begin "Stopping hostpad"
killall hostapd &>/dev/null
ps | grep hostapd | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill
msg_done
}
start() {
prepare_ap_iface
if [[ -s ${CONF} ]]; then
start_hostapd
fi
}
stop() {
if [[ -s ${CONF} ]]; then
stop_hostapd
fi
}
case "$1" in
start)
start
@ -90,4 +119,3 @@ case "$1" in
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

View File

@ -10,4 +10,3 @@ OS_FIRMWARE_METHOD="github"
OS_FIRMWARE_REPO="ccrisan/thingos"
OS_FIRMWARE_USERNAME=""
OS_FIRMWARE_PASSWORD=""