2019-03-06 20:14:04 +01:00
|
|
|
#!/bin/bash
|
2019-03-07 11:17:16 +01:00
|
|
|
# When wireless client AP mode is enabled, this script handles starting
|
|
|
|
# up network services in a specific order and timing to avoid race conditions.
|
|
|
|
|
|
|
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
|
|
|
NAME=raspap
|
|
|
|
DESC="Service control for RaspAP"
|
2019-04-30 20:30:26 +02:00
|
|
|
CONFIGFILE="/etc/raspap/hostapd.ini"
|
2019-03-07 11:17:16 +01:00
|
|
|
|
|
|
|
positional=()
|
|
|
|
while [[ $# -gt 0 ]]
|
|
|
|
do
|
|
|
|
key="$1"
|
|
|
|
|
|
|
|
case $key in
|
|
|
|
-i|--interface)
|
|
|
|
interface="$2"
|
|
|
|
shift # past argument
|
|
|
|
shift # past value
|
|
|
|
;;
|
|
|
|
-s|--seconds)
|
|
|
|
seconds="$2"
|
|
|
|
shift # past argument
|
|
|
|
shift # past value
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
set -- "${positional[@]}"
|
2019-03-06 20:14:04 +01:00
|
|
|
|
|
|
|
echo "Stopping network services..."
|
|
|
|
systemctl stop hostapd.service
|
|
|
|
systemctl stop dnsmasq.service
|
|
|
|
systemctl stop dhcpcd.service
|
|
|
|
|
2019-04-30 20:30:26 +02:00
|
|
|
if [ -r "$CONFIGFILE" ]; then
|
|
|
|
declare -A config
|
2019-05-01 00:19:34 +02:00
|
|
|
while IFS=" = " read -r key value; do
|
2019-04-30 20:30:26 +02:00
|
|
|
config["$key"]="$value"
|
2019-05-01 00:19:34 +02:00
|
|
|
done < "$CONFIGFILE"
|
2019-04-30 20:30:26 +02:00
|
|
|
|
2019-05-01 00:19:34 +02:00
|
|
|
if [ "${config[WifiAPEnable]}" = 1 ]; then
|
2019-04-19 14:23:05 +02:00
|
|
|
if [ "${interface}" = "uap0" ]; then
|
|
|
|
echo "Removing uap0 interface..."
|
|
|
|
iw dev uap0 del
|
2019-03-06 20:14:04 +01:00
|
|
|
|
2019-04-30 20:30:26 +02:00
|
|
|
echo "Adding uap0 interface to ${config[WifiManaged]}"
|
2019-05-01 00:19:34 +02:00
|
|
|
iw dev ${config[WifiManaged]} interface add uap0 type __ap
|
2019-04-19 14:23:05 +02:00
|
|
|
# Bring up uap0 interface
|
|
|
|
ifconfig uap0 up
|
|
|
|
fi
|
2019-04-19 13:35:03 +02:00
|
|
|
fi
|
|
|
|
fi
|
2019-03-06 20:14:04 +01:00
|
|
|
|
|
|
|
# Start services, mitigating race conditions
|
2019-04-19 14:23:05 +02:00
|
|
|
echo "Starting network services..."
|
2019-03-06 20:14:04 +01:00
|
|
|
systemctl start hostapd.service
|
2019-03-07 11:17:16 +01:00
|
|
|
sleep "${seconds}"
|
2019-03-06 20:14:04 +01:00
|
|
|
|
|
|
|
systemctl start dhcpcd.service
|
2019-03-07 11:17:16 +01:00
|
|
|
sleep "${seconds}"
|
2019-03-06 20:14:04 +01:00
|
|
|
|
|
|
|
systemctl start dnsmasq.service
|
|
|
|
|
2019-03-07 23:14:27 +01:00
|
|
|
echo "RaspAP service start DONE"
|
2019-03-06 20:14:04 +01:00
|
|
|
|