summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2020-07-14 09:47:00 +0200
committerPeter Palfrader <peter@palfrader.org>2020-07-14 09:47:00 +0200
commit7460a97b0b9e549f012b030912e2ccf22f569825 (patch)
treea9ee47ba67e47be2fe842d19228323aff17e6b7f
parent159b3dc59b30df3e62d1bcadd088bf97642586e7 (diff)
Add qr wifi generation
-rwxr-xr-xqr21
1 files changed, 17 insertions, 4 deletions
diff --git a/qr b/qr
index 287c852..f736178 100755
--- a/qr
+++ b/qr
@@ -27,18 +27,21 @@ usage()
{
cat << EOF
usage: $0 -m <MSG>
+ $0 -w <essid> <password>
$0 [options] [<file>]
OPTIONS:
-m <MSG> Use MSG instead of reading input from file/stdin.
-M Add a/Include the trailing newline for single-line data.
+ -w <essid> <password> Create a wifi qr code.
EOF
}
msg=""
have_msg=0
multi_line=0
-while getopts "hm:M" OPTION
+wifi=0
+while getopts "hm:Mw" OPTION
do
case $OPTION in
h)
@@ -52,6 +55,9 @@ do
have_msg=1
msg="$OPTARG"
;;
+ w)
+ wifi=1
+ ;;
*)
usage >&2
exit 1
@@ -65,7 +71,15 @@ img="$(tempfile --suffix .png)"
trap "rm -f '$img'" EXIT
-if [ "$have_msg" -eq 0 ]; then
+if [ "$wifi" -gt 0 ]; then
+ if [ "$#" -ne 2 ]; then
+ usage >&2
+ exit 1
+ fi
+ essid="$1"; shift
+ password="$1"; shift
+ echo "WIFI:T:WPA;S:${essid};P:${password};;" | qrencode -s 5 -l H -o "$img"
+elif [ "$have_msg" -eq 0 ]; then
if [ "$#" -gt 1 ]; then
usage >&2
exit 1
@@ -75,8 +89,7 @@ if [ "$have_msg" -eq 0 ]; then
stdin="$(tempfile)"
trap "rm -f '$img' '$stdin'" EXIT
cat > "$stdin"
- set dummy "$stdin"
- shift
+ set -- "$stdin"
fi
fn="$1"; shift