Script: multipsk for OpenWrt 23+ snapshots

Hey!,

Today I decided to write a script for multipsk also since OpenWrt doesn't have a luci option yet and I also liked the way of using it in a form of a batch command.

here it is
#!/bin/sh

while getopts k:i:v:r:h flag
do
    case "${flag}" in
        k) key=${OPTARG};;
        i) interface=${OPTARG};;
        v) vid=${OPTARG};;
        r) radio=${OPTARG};;
        h)
          echo "makepsk: command help"
          echo "-k: wpa2 password"    
          echo "-i: interface/name where the vlan gets tagged to"
          echo "-v: the tagged vid"                              
          echo "-r: the defined radio"
          exit 1                      
          ;;    
    esac    
done    

if [ $OPTIND -eq 1 ]; 
then
	echo "No options were passed."
        exit 1
fi

echo "interface: $interface"
                            
uci add wireless wifi-station
uci set wireless.@wifi-station[-1].vid="$vid"
uci set wireless.@wifi-station[-1].iface="$radio"
uci set wireless.@wifi-station[-1].key="$key"    
                                             
uci add wireless wifi-vlan
uci set wireless.@wifi-vlan[-1].vid="$vid"
uci set wireless.@wifi-vlan[-1].name="$interface"
uci set wireless.@wifi-vlan[-1].network="$interface"
uci set wireless.@wifi-vlan[-1].iface="$radio"      
                                              
uci commit wireless

to make it executable use chmod +x makepsk.sh

a command looks like:
./makepsk.sh -k "yourpassword" -i "aya" -v "90" -r "default_radio1"

this means clients with yourpassword gets redirected to interface aya the default_radio1 is either 5ghz or 2.4ghz you can check this inside the wireless config in /etc/config/wireless you have to restart wifi manually with the wifi command.

I decided to make this since this creates 2 uci nodes each time which can be confusing + there isn't much documentation than maybe only about wpa_psk_file on the OpenWrt wiki, you need to use WPA2 otherwise it will not work.

there is a chance this doesn't work, then your OpenWrt version might be too old and you have to resort to wpa_psk_file, but this should work on the latest MT3000/MT6000 OpenWrt 24 snapshots, so I thought why not post it :smiley:

update 02-07-2024:

  • add check against null arguments.
2 Likes