43 lines
1.4 KiB
Plaintext
43 lines
1.4 KiB
Plaintext
|
#!/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 #
|
||
|
IFACE=`ifconfig | grep -P "^w" | awk '{print $1}'`;
|
||
|
|
||
|
# (2) Get nearest AP matching "SATS_*" and extract HASH #
|
||
|
AP_HASH=`sudo iwlist wlan0 scan | grep -P "^\s*ESSID:\"SATS_.+\"\s*$" | sed 's/^[ \t]*ESSID:"SATS_//' | sed 's/"[ \t]*$//'`;
|
||
|
|
||
|
# (3) Manage no AP found #
|
||
|
test `echo -ne $AP_HASH | wc -l` -eq 0 && slog "no AP found" && exit;
|
||
|
|
||
|
|
||
|
|
||
|
# [2] Calculate WIFI PASS from SSID hash
|
||
|
#========================================================#
|
||
|
PASS=`echo -ne "$HPEPPER$(echo -n "${HSALT}${AP_HASH}" | sha512sum | sed 's/[ \t]*-$//')" | sha512sum | sed 's/[ \t]*-//'`;
|
||
|
|
||
|
|
||
|
# [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;
|
||
|
|
||
|
slog "<<< Done";
|