Skip to content

Instantly share code, notes, and snippets.

@elbosso
Created March 31, 2018 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbosso/359e79620b6535242758f7955637cd66 to your computer and use it in GitHub Desktop.
Save elbosso/359e79620b6535242758f7955637cd66 to your computer and use it in GitHub Desktop.
#!/bin/bash
ssid=$1
mac=$2
RAWPSK=$(pwgen -1Bv |tr '/' '$')
ENCODEDPSK=$(wpa_passphrase "${ssid}" "${RAWPSK}" |grep psk|tail -n 1|cut -d '=' -f 2)
echo $mac $ssid $RAWPSK $ENCODEDPSK
# Generate QR code pictures for Android and Windows
qrencode -t PNG -o /tmp/android_${mac}.png -s 4 "WIFI:T:WPA;S:${ssid};P:${RAWPSK};H:${hidden};"
./terminalqr.py "WIFI:T:WPA;S:${ssid};P:${RAWPSK};H:${hidden};" >/tmp/android_${mac}.txt
qrencode -t PNG -o /tmp/windows_${mac}.png -s 4 "WIFI;T:WPA;S:${ssid};P:${RAWPSK};H:${hidden};"
./terminalqr.py "WIFI:T:WPA;S:${ssid};P:${RAWPSK};H:${hidden};" >/tmp/windows_${mac}.txt
# IOS requires a hosted webpage which I do not want to host
# Use the copy to clipboard function for the password and manually connect instead.
qrencode -t PNG -o /tmp/ios_${mac}.png -s 4 "${RAWPSK}"
./terminalqr.py "${RAWPSK}" >/tmp/ios_${mac}.txt
alreadythere=$(grep ${mac} /etc/hostapd-psk|wc -l)
if [ ${alreadythere} -eq 0 ]; then
echo habs noch nicht
echo $mac $ENCODEDPSK >> /etc/hostapd-psk
else
sed -ie "s/${mac} .*/${mac} ${ENCODEDPSK}/" /etc/hostapd-psk
echo habs schon
fi
service hostapd reload
echo "New WLAN password was generated and hostapd reloaded."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment