#!/bin/bash IFACE={{ discovered_wireless_iface }} NETPLAN=0 SSID="" # 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/\"//` fi # covers raspbian if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ]; then SSID=`grep ssid /etc/wpa_supplicant/wpa_supplicant.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` fi # 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/\"//` sed 's|ctrl_interface=/run/wpa_supplicant|&\ncountry={{ host_country_code }}|' /run/netplan/wpa-$IFACE.conf fi # IIAB hint for NetworkManager if [ -f /etc/iiab/iiab.env ]; then source /etc/iiab/iiab.env if [ ! -z $CLIENT_SSID ]; then SSID=$CLIENT_SSID fi fi sleep 2 wpa_cli -i $IFACE scan > /dev/null sleep 1 FREQ=`wpa_cli -i $IFACE scan_results | grep $SSID | awk '{print $2}'` for result in $FREQ; do echo "frequency is $result for $SSID" if [ $result -lt 2485 ]; then FREQ2=$result fi done echo "Using $FREQ2 for $SSID" CHAN=$(($FREQ2 - 2407 )) CHAN=$(($CHAN / 5 )) echo "channel is $CHAN for $SSID" 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 if [ $NETPLAN -eq 1 ]; then systemctl restart netplan-wpa-wlan0.service fi systemctl stop dnsmasq.service systemctl start dnsmasq.service exit 0