Last active
January 4, 2016 03:59
-
-
Save floriangosse/8565889 to your computer and use it in GitHub Desktop.
Create a QR code for wifi
This file contains 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 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