Created
April 13, 2023 20:05
-
-
Save isaac-ped/372bb69f0a7ce4fcbc3dddcba84a91e1 to your computer and use it in GitHub Desktop.
Create WIFI QRCode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env nix-shell | |
#! nix-shell -i bash -p qrencode | |
usage() { | |
echo "Usage: $0 <SSID> <PASSWORD> [-e ENCODING] [-o OUTPUT] -- Passthrough to qrencode" | |
echo "ENCODING defaults to WPA, but can also be WEP" | |
echo "OUTPUT defaults to <SSID>.png" | |
} | |
ssid="" | |
password="" | |
output="" | |
# Parse arguments | |
while [[ "$#" > 0 ]]; do | |
case $1 in | |
-e|--encoding) encoding="$2"; shift 2;; | |
-o|--output) output="$2"; shift 2 ;; | |
-h) usage; exit 0 ;; | |
--) shift; break ;; | |
*) | |
if [[ "$ssid" == "" ]]; then | |
ssid="$1"; | |
shift; continue; | |
fi | |
if [[ "$password" == "" ]]; then | |
password="$1"; | |
shift; continue; | |
fi | |
echo "Unexpected argument $1" | |
usage; exit 1 | |
;; | |
esac | |
done | |
if [[ "$password" == "" ]]; then | |
echo "Not enough arguments provided" | |
usage; exit 1 | |
fi | |
if [[ "$output" == "" ]]; then | |
output="${ssid}.png" | |
fi | |
# Format: WIFI:T:<encoding>;S:<ssid>;P:<password>;; | |
qrstring="WIFI:T:${encoding};S:${ssid};P:${password};;" | |
OPTS=("$@" -o "$output" -s 20 -m 5 ) | |
set -x | |
qrencode "${OPTS[@]}" "$qrstring" | |
annotate() { | |
convert "$output" \ | |
-gravity SouthWest \ | |
-pointsize 40 \ | |
-fill black \ | |
"$@" \ | |
"$output" | |
} | |
#convert \ | |
# $output \ | |
# -gravity north \ | |
# -pointsize 40 \ | |
# -fill black \ | |
# -weight bold \ | |
# -draw "text -10,20 'SSID:'" \ | |
# $output | |
set -e | |
annotate \ | |
-gravity North \ | |
-pointsize 60 \ | |
-draw "text 0,20 'WiFi Credentials'" | |
annotate \ | |
-draw "text 5,50 'SSID: '" | |
annotate \ | |
-stroke black \ | |
-family "courier" \ | |
-draw "text 150,52 '$ssid'" | |
annotate \ | |
-draw "text 5,1 'Pass: '" | |
annotate \ | |
-stroke black \ | |
-family "courier" \ | |
-draw "text 150,3 '$password'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment