Skip to content

Instantly share code, notes, and snippets.

@mansouryaacoubi
Last active June 17, 2022 08:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mansouryaacoubi/d44ad218d87f941a58491b6e05b81dba to your computer and use it in GitHub Desktop.
Save mansouryaacoubi/d44ad218d87f941a58491b6e05b81dba to your computer and use it in GitHub Desktop.
Adds wifi to the wpa_supplicant file and reconfigures wpa_cli (Raspberry Pi Wifi)
#!/bin/bash
# @author Mansour Yaacoubi
# @filename addwifi.sh
# @usage sudo ./addwifi.sh "SSID" "WPA-Key"
# @task adds wifi to the wpa_supplicant file and reconfigures wpa_cli
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit 1
else
clear
echo
echo "Script is running with higher privileges as: $SUDO_USER -> $(whoami)"
echo
fi
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Missing operands"
echo "First arg: SSID; Second arg: Password"
exit
fi
wpa_passphrase "$1" "$2" >> /etc/wpa_supplicant/wpa_supplicant.conf
wpa_cli reconfigure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment