setup/clone/utility/wlan0.dwc

53 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/bin/bash
LOGFILE="/home/sats/satsd/log/dwc.log";
slog(){
echo -e "$1" | sudo -u sats tee -a $LOGFILE > /dev/null;
}
test ! -f $LOGFILE && sudo -u sats touch $LOGFILE;
HSALT="***SALT***";
HPEPPER="***PEPPER***";
slog ">>> Dynamic Wireless Credentials";
# [1] Wifi scan for "SATS_*" APs
#========================================================#
# (1) Get interface name #
slog " * 1. Looking for wireless interface";
IFACE=`sudo ifconfig -a | grep -P "^w" | awk '{print $1}' | head -n 1`;
sudo ifconfig $IFACE up;
# (2) Manage no IFACE found #
test -z "$IFACE" && slog " > no wireless IFACE found" && exit;
slog " > got '$IFACE'";
# (3) Get nearest AP matching "SATS_*" and extract HASH #
slog " * 2. Looking for nearest AP matching 'SATS_.+'";
AP_HASH=`sudo iwlist $IFACE scan | grep -P "^\s*ESSID:\"SATS_.+\"\s*$" | sed 's/^[ \t]*ESSID:"SATS_//' | sed 's/"[ \t]*$//' | head -n 1`;
# (4) Manage no AP found #
test -z "$AP_HASH" && slog " > no AP found" && exit;
slog " > got 'SATS_$AP_HASH'";
# [2] Calculate WIFI PASS from SSID hash
#========================================================#
slog " * 3. Processing WPA2 passphrase"
PASS=`echo -ne "$HPEPPER$(echo -ne "${HSALT}${AP_HASH}" | sha512sum | sed 's/[ \t]*-$//')" | sha512sum | sed 's/[ \t]*-//' | cut -b 1-63`;
slog " > done";
# [3] Update 'wpa_supplicant' configuration
#========================================================#
echo -e "network={\n\tssid=\"SATS_$AP_HASH\"\n\tpsk=\"$PASS\"\n}" | sudo tee /etc/wpa_supplicant/$IFACE.conf;
slog "<<< Done\n";