2019-03-06 19:14:04 +00:00
|
|
|
#!/bin/bash
|
2020-03-22 13:41:48 +00:00
|
|
|
# When wireless client AP or Bridge mode is enabled, this script handles starting
|
2019-03-07 10:17:16 +00:00
|
|
|
# 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
|
2020-03-21 23:37:05 +00:00
|
|
|
NAME=raspapd
|
2019-03-07 10:17:16 +00:00
|
|
|
DESC="Service control for RaspAP"
|
2019-04-30 18:30:26 +00:00
|
|
|
CONFIGFILE="/etc/raspap/hostapd.ini"
|
2020-03-22 13:41:48 +00:00
|
|
|
DAEMONPATH="/lib/systemd/system/raspapd.service"
|
2020-03-15 11:02:20 +00:00
|
|
|
OPENVPNENABLED=$(pidof openvpn | wc -l)
|
2019-03-07 10:17:16 +00: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"
|
2020-03-20 09:05:33 +00:00
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-a|--action)
|
|
|
|
action="$2"
|
|
|
|
shift
|
|
|
|
shift
|
2019-03-07 10:17:16 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
set -- "${positional[@]}"
|
2019-03-06 19:14:04 +00:00
|
|
|
|
|
|
|
echo "Stopping network services..."
|
2020-03-28 11:09:06 +00:00
|
|
|
if [ $OPENVPNENABLED -eq 1 ]; then
|
|
|
|
systemctl stop openvpn-client@client
|
|
|
|
fi
|
2020-03-22 13:41:48 +00:00
|
|
|
systemctl stop systemd-networkd
|
2019-03-06 19:14:04 +00:00
|
|
|
systemctl stop hostapd.service
|
|
|
|
systemctl stop dnsmasq.service
|
|
|
|
systemctl stop dhcpcd.service
|
|
|
|
|
2020-03-20 09:05:33 +00:00
|
|
|
if [ "${action}" = "stop" ]; then
|
|
|
|
echo "Services stopped. Exiting."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-03-29 14:14:12 +00:00
|
|
|
if [ -f "$DAEMONPATH" ] && [ ! -z "$interface" ]; then
|
2020-03-10 08:42:08 +00:00
|
|
|
echo "Changing RaspAP Daemon --interface to $interface"
|
|
|
|
sed -i "s/\(--interface \)[[:alnum:]]*/\1$interface/" "$DAEMONPATH"
|
|
|
|
fi
|
|
|
|
|
2019-04-30 18:30:26 +00:00
|
|
|
if [ -r "$CONFIGFILE" ]; then
|
|
|
|
declare -A config
|
2019-04-30 22:19:34 +00:00
|
|
|
while IFS=" = " read -r key value; do
|
2019-04-30 18:30:26 +00:00
|
|
|
config["$key"]="$value"
|
2019-04-30 22:19:34 +00:00
|
|
|
done < "$CONFIGFILE"
|
2019-04-30 18:30:26 +00:00
|
|
|
|
2020-03-10 08:42:08 +00:00
|
|
|
if [ "${config[BridgedEnable]}" = 1 ]; then
|
|
|
|
if [ "${interface}" = "br0" ]; then
|
2020-03-22 11:47:47 +00:00
|
|
|
echo "Stopping systemd-networkd"
|
|
|
|
systemctl stop systemd-networkd
|
|
|
|
|
2020-03-10 08:42:08 +00:00
|
|
|
echo "Restarting eth0 interface..."
|
|
|
|
ip link set down eth0
|
|
|
|
ip link set up eth0
|
|
|
|
|
2020-03-15 11:02:20 +00:00
|
|
|
echo "Removing uap0 interface..."
|
|
|
|
iw dev uap0 del
|
2020-03-22 13:41:48 +00:00
|
|
|
|
|
|
|
echo "Enabling systemd-networkd"
|
|
|
|
systemctl start systemd-networkd
|
|
|
|
systemctl enable systemd-networkd
|
2020-03-10 08:42:08 +00:00
|
|
|
fi
|
|
|
|
else
|
2020-03-22 13:41:48 +00:00
|
|
|
echo "Disabling systemd-networkd"
|
2020-03-29 14:14:12 +00:00
|
|
|
systemctl disable systemd-networkd
|
2020-03-22 13:41:48 +00:00
|
|
|
|
2020-03-29 14:14:12 +00:00
|
|
|
ip link ls up | grep -q 'br0' &> /dev/null
|
|
|
|
if [ $? == 0 ]; then
|
|
|
|
echo "Removing br0 interface..."
|
|
|
|
ip link set down br0
|
|
|
|
ip link del dev br0
|
|
|
|
fi
|
2020-03-10 08:42:08 +00:00
|
|
|
|
|
|
|
if [ "${config[WifiAPEnable]}" = 1 ]; then
|
|
|
|
if [ "${interface}" = "uap0" ]; then
|
2020-03-29 15:08:33 +00:00
|
|
|
|
|
|
|
ip link ls up | grep -q 'uap0' &> /dev/null
|
|
|
|
if [ $? == 0 ]; then
|
|
|
|
echo "Removing uap0 interface..."
|
|
|
|
iw dev uap0 del
|
|
|
|
fi
|
2020-03-10 08:42:08 +00:00
|
|
|
|
|
|
|
echo "Adding uap0 interface to ${config[WifiManaged]}"
|
|
|
|
iw dev ${config[WifiManaged]} interface add uap0 type __ap
|
|
|
|
# Bring up uap0 interface
|
|
|
|
ifconfig uap0 up
|
|
|
|
fi
|
2019-04-19 12:23:05 +00:00
|
|
|
fi
|
2019-04-19 11:35:03 +00:00
|
|
|
fi
|
|
|
|
fi
|
2019-03-06 19:14:04 +00:00
|
|
|
|
|
|
|
# Start services, mitigating race conditions
|
2019-04-19 12:23:05 +00:00
|
|
|
echo "Starting network services..."
|
2019-03-06 19:14:04 +00:00
|
|
|
systemctl start hostapd.service
|
2019-03-07 10:17:16 +00:00
|
|
|
sleep "${seconds}"
|
2019-03-06 19:14:04 +00:00
|
|
|
|
|
|
|
systemctl start dhcpcd.service
|
2019-03-07 10:17:16 +00:00
|
|
|
sleep "${seconds}"
|
2019-03-06 19:14:04 +00:00
|
|
|
|
|
|
|
systemctl start dnsmasq.service
|
|
|
|
|
2020-03-15 11:02:20 +00:00
|
|
|
if [ $OPENVPNENABLED -eq 1 ]; then
|
|
|
|
systemctl start openvpn-client@client
|
|
|
|
fi
|
|
|
|
|
2019-03-07 22:14:27 +00:00
|
|
|
echo "RaspAP service start DONE"
|
2019-03-06 19:14:04 +00:00
|
|
|
|