fixed sats-wpa script [todo/include it in /etc/network/interfaces pre-up script]

This commit is contained in:
xdrm-brackets 2017-07-20 15:46:11 +02:00
parent 154d1e5b7b
commit bda1088125
3 changed files with 23 additions and 27 deletions

View File

@ -281,11 +281,6 @@ step7(){
echo " - /lib/systemd/system";
sudo cp ./utility/sats-update.service /mnt/lib/systemd/system/sats-update.service;
# (4) Install sats-pre-update service #
echo " (.) Create sats-pre-update service";
echo " - /lib/systemd/system";
sudo cp ./utility/sats-pre-update.service /mnt/lib/systemd/system/sats-pre-update.service;
# (5) Install sats-loop service #
echo " (.) Create sats-loop service";
echo " - /lib/systemd/system";
@ -304,9 +299,9 @@ step7(){
echo " (.) Create sats-update script";
cat ./utility/sats-update | sudo tee /mnt/service/sats-update > /dev/null;
# (9) Create sats-pre-update script #
echo " (.) Create sats-pre-update script";
cat ./utility/sats-pre-update | sed "s/\*\*\*SALT\*\*\*/$WIFI_SALT/" | sed "s/\*\*\*PEPPER\*\*\*/$WIFI_PEPPER/" | sudo tee /mnt/service/sats-pre-update > /dev/null;
# (9) Create sats-wpa script #
echo " (.) Create sats-wpa script";
cat ./utility/sats-wpa | sed "s/\*\*\*SALT\*\*\*/$WIFI_SALT/" | sed "s/\*\*\*PEPPER\*\*\*/$WIFI_PEPPER/" | sudo tee /mnt/service/sats-wpa > /dev/null;
# (10) Create sats-loop script #
echo " (.) Create sats-loop script";
@ -327,9 +322,9 @@ step7(){
echo " - sats-update @sats";
sudo chown 666:666 /mnt/service/sats-update;
sudo chmod 770 /mnt/service/sats-update;
echo " - sats-pre-update @pi";
sudo chown 1000:1000 /mnt/service/sats-pre-update;
sudo chmod 770 /mnt/service/sats-pre-update;
echo " - sats-wpa @pi";
sudo chown 1000:1000 /mnt/service/sats-wpa;
sudo chmod 770 /mnt/service/sats-wpa;
echo " - sats-loop @sats";
sudo chown 666:666 /mnt/service/sats-loop;
sudo chmod 770 /mnt/service/sats-loop;

View File

@ -13,19 +13,26 @@ slog ">>> Dynamic Wireless Credentials";
#========================================================#
# (1) Get interface name #
IFACE=`ifconfig | grep -P "^w" | awk '{print $1}'`;
slog "(1) Looking for wireless interface";
IFACE=`sudo ifconfig -a | grep -P "^w" | awk '{print $1}' | head -n 1`;
sudo ifconfig $IFACE up;
slog " > got '$IFACE'";
# (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]*$//'`;
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`;
slog " > got 'SATS_$AP_HASH'";
# (3) Manage no AP found #
test `echo -ne $AP_HASH | wc -l` -eq 0 && slog "no AP found" && exit;
test -z "$AP_HASH" && 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]*-//'`;
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.conf'
@ -40,4 +47,9 @@ sudo cat /etc/wpa_supplicant/wpa_supplicant.tmp | sed "s/^[ \t]*psk=.*$/\tpsk=\
# (3) Remove tmp file #
sudo rm /etc/wpa_supplicant/wpa_supplicant.tmp;
slog "(4) Trying to connect";
sudo wpa_supplicant -B -Dwext -i$IFACE -c/etc/wpa_supplicant/wpa_supplicant.conf;
sudo dhclient $IFACE;
slog "<<< Done";

View File

@ -1,11 +0,0 @@
[Unit]
Description=SATS DWC (Dynamic Wireless Credentials) Process
[Service]
Type=oneshot
User=pi
Group=pi
ExecStart=/bin/bash /service/sats-wpa
[Install]
WantedBy=network.target