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