Skip to content

Instantly share code, notes, and snippets.

@ecneladis
Forked from floriangosse/qrcode-wifi.sh
Created January 1, 2016 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecneladis/80d59ec3b05b5ced1661 to your computer and use it in GitHub Desktop.
Save ecneladis/80d59ec3b05b5ced1661 to your computer and use it in GitHub Desktop.
Create a QR code for wifi
#!/usr/bin/env bash
#
# Inspired by http://www.commandlinefu.com/commands/view/13028
#
# Author: Florian Goße <florian@essog.de>
# Date: 2014-01-22
#
# Check if executed in a terminal
if [[ -t 0 ]];
then
# Check if $DISPLAY exists
if [[ -z "$DISPLAY" ]];
then
echo "Cannot open display"
exit 1;
else
echo "Open on display $DISPLAY"
fi
fi
# Check if zenity and qrencode exists
hash zenity 2>/dev/null || { echo "Please install zenity"; exit 1; }
hash qrencode 2>/dev/null || { echo "Please install qrencode"; exit 1; }
# Enter network ssid
enter_network_name() {
zenity \
--entry \
--text="Network name (SSID)" \
--title="Create WiFi QR";
}
# Enter password
enter_password() {
zenity \
--password \
--title="Wifi Password";
}
# Select output file
select_file() {
zenity \
--file-selection \
--save \
--filename="${HOME}/qr-wifi.png" \
--confirm-overwrite \
--file-filter="*.png*" \
--title="Save as ...";
}
NETWORK_NAME=$(enter_network_name);
[[ -z "$NETWORK_NAME" ]] && exit 1;
PASSWORD=$(enter_password);
[[ -z "$PASSWORD" ]] && exit 1;
FILE=$(select_file);
[[ -z "$FILE" ]] && exit 1;
# Generate png
qrencode --level=H --size=7 --output="${FILE}" "WIFI:S:${NETWORK_NAME};T:WPA;P:${PASSWORD};;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment