[bin] Add qrwifi script
This commit is contained in:
parent
c4653b40e1
commit
83c1fd88d8
1 changed files with 35 additions and 0 deletions
35
bin/qrwifi
Executable file
35
bin/qrwifi
Executable file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/sh
|
||||||
|
ssid="${1:-}"
|
||||||
|
if [ -z "$ssid" ]; then
|
||||||
|
ssid="$(wpa_cli status | rg -o --replace='$1' '^ssid=(.*)$')"
|
||||||
|
fi
|
||||||
|
if [ -z "$ssid" ]; then
|
||||||
|
echo "Not connected to a WiFi network via wpa_supplicant"
|
||||||
|
echo "Use $0 <ssid> [password]" to share another WiFi network
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
pw="${2:-}"
|
||||||
|
if [ -z "$pw" ]; then
|
||||||
|
pw="$(sudo cat /etc/wpa_supplicant/wpa_supplicant.conf | sed -n '/^[\t ]*ssid="'"$ssid"'"$/{:findpsk;N;/\n[\t ]*psk=/!b findpsk;s/^\(\n\|.\)*[\t ]*psk="\(.*\)"$/\2/p; }')"
|
||||||
|
fi
|
||||||
|
if [ -z "$pw" ]; then
|
||||||
|
echo "Couldn't find password for network \`$ssid\`"
|
||||||
|
echo "Use $0 <ssid> <password>" to share a specific SSID and password
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Sharing network \`$ssid\`"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$ssid" ] || [ -z "$pw" ]; then
|
||||||
|
echo "Missing SSID or password"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if printf '%s' "$pw" | grep -qF ';'; then
|
||||||
|
echo "Password contains ;, I didn't look up how to handle that case"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f /tmp/qr.png
|
||||||
|
printf '%s' "WIFI:T:WPA;S:$ssid;P:$pw;;" | qrencode -s 10 -o /tmp/qr.png
|
||||||
|
nsxiv /tmp/qr.png
|
Loading…
Reference in a new issue