Skip to content

Commit 901dc94

Browse files
committed
Improve wifi QR code generator
1 parent 826d2b5 commit 901dc94

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

qr/wifi-qr.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
# {{{
4+
35
set -uo pipefail
46

57
stderr() {
@@ -19,15 +21,31 @@ if [[ $# -lt 2 ]]; then
1921
exit 0
2022
fi
2123

24+
missing_dependencies=false
25+
declare -r dependencies=(
26+
qrencode
27+
)
28+
for dep in "${dependencies[@]}"; do
29+
if ! command -v "${dep}" &> /dev/null; then
30+
stderr "❌ ERROR: Missing dependency ${dep}"
31+
missing_dependencies=true
32+
fi
33+
done
34+
if ${missing_dependencies}; then
35+
fail 'Please install the missing dependencies!'
36+
fi
37+
38+
# }}}
39+
2240
declare -r SSID="${1}"
2341
declare -r PASSWORD="${2//;/\\;}" # Sanitize the password from bad characters
2442
declare -r ENC_TYPE=WPA
2543

2644

2745
if [[ $# -eq 3 ]]; then
28-
declare -r QR_CMD="qrencode --output=${3}"
46+
declare -ar FLAGS=("--output=${3}")
2947
else
30-
declare -r QR_CMD='qrencode -t utf8 -o -'
48+
declare -ar FLAGS=('-t' 'utf8' '-o' '-')
3149
fi
3250

33-
echo -n "WIFI:S:${SSID};T:${ENC_TYPE};P:${PASSWORD};;" | ${QR_CMD}
51+
echo -n "WIFI:S:${SSID};T:${ENC_TYPE};P:${PASSWORD};;" | qrencode "${FLAGS[@]}"

0 commit comments

Comments
 (0)