1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-13 19:52:06 +00:00
iiab/roles/network/templates/hostapd/test-wifi

79 lines
2.6 KiB
Text
Raw Normal View History

2020-04-22 20:59:50 +00:00
#!/bin/bash
2020-04-22 00:22:35 +00:00
IFACE={{ discovered_wireless_iface }}
2020-05-04 13:58:37 +00:00
RASPBIAN=0
2020-04-27 15:34:43 +00:00
NETPLAN=0
2020-04-22 00:22:35 +00:00
SSID=""
2020-05-04 13:58:37 +00:00
# when we get here br0 should be available and dbus wpa_supplicant was started if enabled. None
# of the backends that use wpa_supplicant should be active yet based on the Before= After= lines
# in the wifi-test.service unit file.
2020-04-27 15:34:43 +00:00
# covers systemd-networkd
if [ -f /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf ]; then
SSID=`grep ssid /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//`
2020-04-22 00:22:35 +00:00
fi
2020-04-27 15:34:43 +00:00
# covers raspbian
2020-04-22 00:22:35 +00:00
if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ]; then
2020-05-04 13:58:37 +00:00
RASPBIAN=1
2020-04-22 20:59:50 +00:00
SSID=`grep ssid /etc/wpa_supplicant/wpa_supplicant.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//`
2020-04-22 00:22:35 +00:00
fi
2020-04-27 15:34:43 +00:00
# covers netplan
if [ -f /run/netplan/wpa-$IFACE.conf ]; then
NETPLAN=1
SSID=`grep ssid /run/netplan/wpa-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//`
2020-04-29 17:47:43 +00:00
sed 's|ctrl_interface=/run/wpa_supplicant|&\ncountry={{ host_country_code }}|' /run/netplan/wpa-$IFACE.conf
2020-04-27 15:34:43 +00:00
fi
# IIAB hint for NetworkManager
2020-05-04 13:58:37 +00:00
# could scrape /etc/NetworkManager/system-connections/ looking for ssid
2020-04-22 00:22:35 +00:00
if [ -f /etc/iiab/iiab.env ]; then
source /etc/iiab/iiab.env
if [ ! -z $CLIENT_SSID ]; then
SSID=$CLIENT_SSID
fi
fi
2020-05-04 13:58:37 +00:00
# might need to start the dbus wpa_supplicant
#if [ $RASPBIAN -eq 1 ]; then
# systemctl start wpa_supplicant
#fi
2020-04-22 00:22:35 +00:00
sleep 2
2020-04-27 14:44:17 +00:00
wpa_cli -i $IFACE scan > /dev/null
sleep 1
2020-04-22 20:59:50 +00:00
FREQ=`wpa_cli -i $IFACE scan_results | grep $SSID | awk '{print $2}'`
for result in $FREQ; do
2020-04-27 14:44:17 +00:00
echo "frequency is $result for $SSID"
if [ $result -lt 2485 ]; then
FREQ2=$result
fi
done
echo "Using $FREQ2 for $SSID"
2020-04-27 14:44:17 +00:00
CHAN=$(($FREQ2 - 2407 ))
2020-04-22 20:59:50 +00:00
CHAN=$(($CHAN / 5 ))
2020-04-22 00:22:35 +00:00
echo "channel is $CHAN for $SSID"
2020-05-04 13:58:37 +00:00
HOSTAPD=`grep channel /etc/hostapd/hostapd.conf | awk -F = '{print $2}'`
echo "Hostapd set for $HOSTAPD"
if [ $CHAN -ne $HOSTAPD ]; then
echo "Editing Hostapd for channel $CHAN"
cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf
sed -i -e "s/^channel.*/channel=$CHAN/" /etc/hostapd/hostapd.conf
systemctl stop wpa_supplicant
systemctl start hostapd
systemctl start wpa_supplicant
# This is more of a netplan workaround should go away.
if [ $NETPLAN -eq 1 ]; then
systemctl restart netplan-wpa-$IFACE.service
fi
else
#we started it stop it now, dhcpcd should launch it's version anyway
# if [ $RASPBIAN -eq 1 ]; then
# systemctl stop wpa_supplicant
# fi
# firmware might force the need to restart anyway
# systemctl stop wpa_supplicant
systemctl start hostapd
# systemctl start wpa_supplicant
2020-04-27 15:34:43 +00:00
fi
2020-04-27 14:44:17 +00:00
systemctl start dnsmasq.service
exit 0