2017-07-18 13:34:07 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
slog(){
|
|
|
|
echo "$1" | sudo -u sats tee -a /home/sats/satsd/log/update.log > /dev/null;
|
|
|
|
}
|
|
|
|
|
|
|
|
HSALT="***SALT***";
|
|
|
|
HPEPPER="***PEPPER***";
|
|
|
|
|
|
|
|
slog ">>> Dynamic Wireless Credentials";
|
|
|
|
|
|
|
|
# [1] Wifi scan for "SATS_*" APs
|
|
|
|
#========================================================#
|
|
|
|
|
|
|
|
# (1) Get interface name #
|
2017-07-20 13:46:11 +00:00
|
|
|
slog "(1) Looking for wireless interface";
|
|
|
|
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-20 13:46:11 +00:00
|
|
|
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`;
|
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-20 13:46:11 +00:00
|
|
|
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";
|
2017-07-18 13:34:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
# [3] Update 'wpa_supplicant.conf'
|
|
|
|
#========================================================#
|
|
|
|
|
|
|
|
# (1) Update SSID #
|
|
|
|
sudo cat /etc/wpa_supplicant/wpa_supplicant.conf | sed "s/^[ \t]*ssid=.*$/\tssid=\"SATS_$AP_HASH\"/" | sudo tee /etc/wpa_supplicant/wpa_supplicant.tmp;
|
|
|
|
|
|
|
|
# (2) Update PASS #
|
|
|
|
sudo cat /etc/wpa_supplicant/wpa_supplicant.tmp | sed "s/^[ \t]*psk=.*$/\tpsk=\"$PASS\"/" | sudo tee /etc/wpa_supplicant/wpa_supplicant.conf;
|
|
|
|
|
|
|
|
# (3) Remove tmp file #
|
|
|
|
sudo rm /etc/wpa_supplicant/wpa_supplicant.tmp;
|
|
|
|
|
2017-07-20 13:46:11 +00:00
|
|
|
|
|
|
|
slog "(4) Trying to connect";
|
|
|
|
sudo wpa_supplicant -B -Dwext -i$IFACE -c/etc/wpa_supplicant/wpa_supplicant.conf;
|
|
|
|
sudo dhclient $IFACE;
|
|
|
|
|
|
|
|
slog "<<< Done";
|