auto-wifi-hotspot
#!/bin/bash
check_wifi_conn=$(nmcli conn show --active | grep wifi)
if [ ! -z "$check_wifi_conn" ]; then
echo "Wifi connection exists"
exit 0;
fi
source .env-hotspot
hotspot_info=$(nmcli -t conn show | grep "$CON_NAME")
if [ -z "$hotspot_info" ]; then
echo "Connection doesn't exist"
nmcli con add type wifi ifname $INTERFACE con-name $CON_NAME autoconnect yes ssid $HOTSPOT_SSID
nmcli con modify $CON_NAME 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
nmcli con modify $CON_NAME wifi-sec.key-mgmt wpa-psk
nmcli con modify $CON_NAME wifi-sec.psk $HOTSPOT_PASS
nmcli con modify $CON_NAME wifi-sec.pmf 1
hotspot_info=$(nmcli -t conn show | grep "$CON_NAME")
else
echo "Connection exists"
fi
IFS=':' read -ra hotspot_info_array <<< "$hotspot_info"
UUID=${hotspot_info_array[1]}
nmcli con up uuid $UUID
auto-wifi-hotspot.service
[Unit]
Description=Automatic create hotspot if wifi connection doesn't exist
After=NetworkManager.service
[Service]
Type=simple
User=q
ExecStart=/usr/bin/bash /home/q/bin/auto-wifi-hotspot
[Install]
WantedBy=multi-user.target
.env-hotspot
HOTSPOT_SSID="Hotspot"
HOTSPOT_PASS="qwerty123"
CON_NAME="Hotspot"
INTERFACE="wlo1"
May this bash script isn't best realisation. I always look forward your suggestions.
Create a Wi-Fi hotspot on Linux using nmcli
#OrangePi #RaspberryPi #Hotspot #Linux #nmcli