Skip to content

Instantly share code, notes, and snippets.

@cemkeylan

cemkeylan/README

Last active Aug 28, 2020
Embed
What would you like to do?
More info on: https://cemkeylan.com/blog/20200828-wpa-add-script.html
#!/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
#!/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
You can’t perform that action at this time.