Skip to content

Instantly share code, notes, and snippets.

@Tymek
Last active March 8, 2021 20:21
Show Gist options
  • Save Tymek/4d262051a30f45217bb72913556b441b to your computer and use it in GitHub Desktop.
Save Tymek/4d262051a30f45217bb72913556b441b to your computer and use it in GitHub Desktop.
Headless Raspbian setup – WiFi and SSH
#!/bin/bash
clear
echo ""
echo -e "\e[44mHEADLESS RASPBIAN\e[0m"
echo "WiFi & SSH setup"
echo ""
echo "Available partitions:"
lsblk -e7
echo ""
DEFAULT_PATH=$(lsblk -e7 | grep /boot$ | awk '{print $NF}') # guess
DEFAULT_SSID=$(nmcli -t -f active,ssid dev wifi | grep ^yes | cut -d ':' -f2)
echo ""
read -p $'What directory should we use? \n> ' -i $DEFAULT_PATH -e BOOTPATH
echo ""
read -p $'Enter 2-letter country code \n> ' -i "PL" -e COUNTRY
echo ""
read -p $'Enter SSID \n> ' -i $DEFAULT_SSID -e SSID
echo ""
read -s -p $'Enter passphrase \n> ' -e PASS
echo ""
echo ""
echo -e "Writing \e[34m\e[1m$BOOTPATH/wpa_supplicant.conf\e[0m"
echo "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=$COUNTRY
network={
ssid=\"$SSID\"
psk=\"$PASS\"
}" > $BOOTPATH/wpa_supplicant.conf
echo -e "Creating \e[1m$BOOTPATH/ssh\e[0m"
echo "" > $BOOTPATH/ssh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment