Created
November 11, 2019 19:54
-
-
Save zorun/86c825c80599af244bcfce742b6b3ba2 to your computer and use it in GitHub Desktop.
uci-defaults script for OpenWrt that configures Wi-Fi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
WIFI_PASSWORD_FILE="/lib/rezine/wifi" | |
# 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' | |
do | |
# 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 | |
# "rezine.org". 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="rezine.org" | |
uci set wireless.default_"$radio".encryption="psk-mixed" | |
uci set wireless.default_"$radio".key="$wifi_password" | |
uci -q commit wireless | |
done | |
rm -f "$WIFI_PASSWORD_FILE" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment