Last active
December 27, 2022 20:01
-
-
Save cemkeylan/d6ca2385a79bbb005664d6f478cd986a to your computer and use it in GitHub Desktop.
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
More info on: https://cemkeylan.com/blog/20200828-wpa-add-script.html |
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
#!/bin/sh | |
# Script to add wpa_supplicant networks through dmenu | |
if [ "$1" ]; then | |
name=$1 | |
else | |
name=$(dmenu -p "Please enter network name, leave empty if you want to search" <&-) | |
fi | |
[ "$name" ] || { | |
wpa_cli scan | |
name=$( | |
wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do | |
# Hidden wifi are not to be returned | |
[ "$ssid" ] || continue | |
echo "$ssid" | |
done | sort -u | dmenu -l 10 -p "Please choose WiFi") | |
[ "$name" ] || exit 1 | |
} | |
pass=$(dmenu -P -p "Please enter your password, leave empty if the network has open access.") | |
if [ "$pass" ]; then | |
wpa_passphrase "$name" <<EOF>> /etc/wpa_supplicant.conf | |
$pass | |
EOF | |
else | |
printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" >> /etc/wpa_supplicant.conf | |
fi | |
wpa_cli reconfigure |
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
#!/bin/sh -e | |
# Same but on command line with fzf (only for wifi selection) | |
stty="$(stty -g)" | |
trap "stty $stty" EXIT INT TERM HUP | |
if [ "$1" ]; then | |
name=$1 | |
else | |
printf 'Network Name, leave empty if you want to search: ' | |
read -r name | |
fi | |
[ "$name" ] || { | |
wpa_cli scan >/dev/null 2>&1 | |
name=$( | |
wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do | |
# Hidden wifi are not to be returned | |
[ "$ssid" ] || continue | |
echo "$ssid" | |
done | sort -u | fzf --prompt "Please choose WiFi: ") | |
} | |
[ "$name" ] || exit 1 | |
stty -echo | |
printf 'Please enter your password, leave empty if the network has open access.\nPassword: ' | |
read -r pass | |
if [ "$pass" ]; then | |
wpa_passphrase "$name" <<EOF>> /etc/wpa_supplicant.conf | |
$pass | |
EOF | |
else | |
printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" >> /etc/wpa_supplicant.conf | |
fi | |
wpa_cli reconfigure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment