nnwifi.sh (1705B)
1 #!/bin/sh 2 # Universal wifi setup for lightweight Linux systems 3 # depends on wpa_supplicant and udhcpc 4 # the script must be run as root 5 # (can configure in /etc/doas.conf to run without password) 6 # Created by Luxferre in 2023, released into public domain 7 8 # config file place 9 CFG="$HOME/nnwifi.conf" 10 SSID_HIDDEN=1 11 12 [ -f "$CFG" ] && . $CFG # source it 13 14 # if "conf", run the interactive prompt 15 # otherwise use the preconfigured values 16 if [ "$1" == "conf" ]; then 17 printf "Interface[%s]: " "$IFACE" 18 read -r INP_IFACE 19 printf "Access point[%s]: " "$SSID" 20 read -r INP_SSID 21 printf "Password[unchanged]: " 22 read -r INP_PSK 23 printf "Primary DNS[%s]: " "$DNS_PRIMARY" 24 read -r INP_DNS_PRIMARY 25 printf "Secondary DNS[%s]: " "$DNS_SECONDARY" 26 read -r INP_DNS_SECONDARY 27 [ -n "$INP_IFACE" ] && IFACE="$INP_IFACE" 28 [ -n "$INP_SSID" ] && SSID="$INP_SSID" 29 [ -n "$INP_PSK" ] && PSK="$INP_PSK" 30 [ -n "$INP_DNS_PRIMARY" ] && DNS_PRIMARY="$INP_DNS_PRIMARY" 31 [ -n "$INP_DNS_SECONDARY" ] && DNS_SECONDARY="$INP_DNS_SECONDARY" 32 # update the config 33 cat << ENDCFG > $CFG 34 IFACE=$IFACE 35 SSID="$SSID" 36 PSK="$PSK" 37 DNS_PRIMARY="$DNS_PRIMARY" 38 DNS_SECONDARY="$DNS_SECONDARY" 39 ENDCFG 40 fi 41 42 # most probably you don't need to change these two 43 44 SUPFILE="/etc/wpa_supplicant.conf" 45 SUPCTL="/var/run/wpa_supplicant" 46 47 # first template $SUPFILE 48 49 cat << ENDSUP > $SUPFILE 50 ctrl_interface=$SUPCTL 51 update_config=1 52 network={ 53 ssid="$SSID" 54 scan_ssid=$SSID_HIDDEN 55 psk="$PSK" 56 } 57 ENDSUP 58 59 # then setup the interface 60 killall udhcpc 61 killall wpa_supplicant 62 63 ip link set $IFACE up 64 wpa_supplicant -B -i $IFACE -c $SUPFILE 65 udhcpc -i $IFACE 66 echo "nameserver $DNS_PRIMARY" > /etc/resolv.conf 67 echo "nameserver $DNS_SECONDARY" >> /etc/resolv.conf