Skip to content

Instantly share code, notes, and snippets.

@nicholasadamou
Created April 22, 2018 13:58
Show Gist options
  • Save nicholasadamou/9b508c63dbb37df83ac2fde690c0a309 to your computer and use it in GitHub Desktop.
Save nicholasadamou/9b508c63dbb37df83ac2fde690c0a309 to your computer and use it in GitHub Desktop.
Configure the WiFi interface on Raspberry Pi 2/3.
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
exec sudo "$0" "$@"
fi
ssid="" # Enter SSID of WiFi
passwd="" # Enter Password of Given WiFi SSID
interface="wlan0"
wpa_conf="/etc/wpa_supplicant/wpa_supplicant.conf"
systemctl stop network-manager && systemctl disable network-manager
ifconfig "$interface" up
wpa_passphrase "$ssid" "$passwd" > "$wpa_conf"
x="/etc/network/interfaces"
if ! [ -f "$x".bak ]; then
cp "$x" "$x".bak
fi
cat > "$x" <<EOF
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
allow-hotplug "$interface"
iface "$interface" inet dhcp
wpa-conf "$wpa_conf"
EOF
wpa_supplicant -D wext -i "$interface" -c "$wpa_conf" &
dhclient -v "$interface"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment