Skip to content

Instantly share code, notes, and snippets.



Created Nov 11, 2019
What would you like to do?
uci-defaults script for OpenWrt that configures Wi-Fi
# If no password is provided in the image, exit and remove this script
wifi_password="$(cat $WIFI_PASSWORD_FILE)" || exit 0
for radio in 'radio0' 'radio1'
# Radio doesn't exist.
uci -q get wireless."$radio" || continue
# SSID is different from the OpenWrt default!
# This happens during upgrade in two cases:
# 1) if the user had previously customized the SSID;
# 2) if the user was already using our custom image with SSID
# "". He/she may have changed the password and channel,
# and we have no way to check that.
# In both cases, we don't want to touch anything.
ssid="$(uci -q get wireless.default_${radio}.ssid)"
[ "$ssid" != "OpenWrt" ] && continue
# Set fixed channel
hwmode=$(uci -q get wireless."$radio".hwmode)
[ "$hwmode" = "11g" ] && channel=6
[ "$hwmode" = "11a" ] && channel=36
[ -n "$channel" ] && uci set wireless."$radio".channel="$channel"
# Set country
uci set wireless."$radio".country="FR"
# Enable radio
uci set wireless."$radio".disabled="0"
# Set SSID and password
uci set wireless.default_"$radio".ssid=""
uci set wireless.default_"$radio".encryption="psk-mixed"
uci set wireless.default_"$radio".key="$wifi_password"
uci -q commit wireless
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.