From 83c1fd88d8d925344167eea5250bb5e8f715d1ce Mon Sep 17 00:00:00 2001 From: Midgard <2885-Midgard@users.noreply.framagit.org> Date: Wed, 26 Jul 2023 15:47:29 +0200 Subject: [PATCH] [bin] Add qrwifi script --- bin/qrwifi | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 bin/qrwifi diff --git a/bin/qrwifi b/bin/qrwifi new file mode 100755 index 0000000..7e14950 --- /dev/null +++ b/bin/qrwifi @@ -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 [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 " 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