openwrt/wifi: add minimal script for setting up a wifi+ssh accessible device

This commit is contained in:
Nico Schottelius 2025-10-30 10:56:29 +01:00
commit d9c0ea5009

View file

@ -0,0 +1,55 @@
#!/bin/sh
# 2025-10-30, Nico Schottelius
# Configure a device with a WAN port to allow ssh access and be IPv6 client
if [ $# -ne 2 ]; then
echo "$0 ip-address ssid wifi-psk"
echo " ip-address: where to find the OpenWRT device"
echo " hostname: which hostname to set"
echo " ssid for the wifi"
echo " psk for the wifi"
exit 1
fi
my_ip=$1; shift
new_hostname=$1; shift
ssid=$1; shift
psk=$1; shift
cat <<EOF | ssh -t "root@${my_ip}"
set -x
# Allow SSH in
if ! uci show firewall | grep "name='Allow-SSH'"; then
uci add firewall rule
uci set firewall.@rule[-1].name='Allow-SSH-in'
uci set firewall.@rule[-1].src='wan'
uci set firewall.@rule[-1].proto='tcp'
uci set firewall.@rule[-1].dest_port='22'
uci set firewall.@rule[-1].target='ACCEPT'
fi
uci set system.@system[0].hostname="${new_hostname}"
# Wifi configuration
uci set wireless.radio0=wifi-device
uci set wireless.radio0.htmode='HT40'
uci set wireless.radio0.channel='6'
uci set wireless.radio0.country='CH'
uci set wireless.default_radio0.encryption='psk2'
uci set wireless.default_radio0.key='${psk}'
uci set wireless.default_radio0.ssid='${ssid}'
uci set wireless.radio1.country='CH'
uci set wireless.default_radio1.encryption='psk2'
uci set wireless.default_radio1.key='${psk}'
uci set wireless.default_radio1.ssid='${ssid}'
# Ensure it is not disabled
uci delete wireless.radio0.disabled
uci delete wireless.radio1.disabled
uci commit
EOF