Last active
April 12, 2021 04:37
-
-
Save musicin3d/e58a0b097e17ec13df054ac57ac0fc7e to your computer and use it in GitHub Desktop.
Raspberry PI setup
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/bash | |
# | |
# Opinionated configuration script for Raspberry Pi OS | |
# | |
# This will: | |
# - Secure and update | |
# - Install common tools | |
# - Setup headless operation | |
# - Set locale to US/Central | |
# - and more | |
# | |
# How To Use: | |
# curl https://gist.githubusercontent.com/musicin3d/e58a0b097e17ec13df054ac57ac0fc7e/raw | bash - | |
# | |
# Author: @musicin3d | |
# License: whatever / FOSS | |
# Guarantees: none | |
# | |
# Other useful resources: | |
# - Static IP: https://www.raspberrypi.org/documentation/configuration/tcpip/ | |
# | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
# update and install from apt | |
apt upgrade | |
apt install vim | |
# enable ssh | |
raspi-config nonint do_ssh 0 | |
# change password | |
echo '' | |
while : ; do | |
read -p "Please set a new password for pi user: " -s pw1 </dev/tty | |
echo '' | |
read -p "Confirm new password for pi user: " -s pw2 </dev/tty | |
echo '' | |
[[ $pw1 == $pw2 ]] && break | |
echo 'Error: Passwords did not match' | |
done | |
echo "pi:$pw1" | chpasswd | |
echo 'Password updated'; echo '' | |
pw1='' | |
pw2='' | |
# boot to console | |
raspi-config nonint do_boot_behaviour B1 2> /dev/null | |
# minimize gpu memory | |
raspi-config nonint do_memory_split 16 | |
# set location to US/Central | |
raspi-config nonint do_change_locale en_US | |
raspi-config nonint do_configure_keyboard us | |
timedatectl set-timezone America/Chicago | |
raspi-config nonint do_wifi_country US | |
# expand file system | |
raspi-config nonint do_expand_rootfs | |
# update and manual config/review | |
SUDO_USER=pi raspi-config nonint do_update | |
# recommend reboot | |
echo '' | |
echo 'Reboot is HIGHLY recommended to apply all settings' | |
echo '' | |
while : ; do | |
read -p "Reboot now? (y/n): " reboot </dev/tty | |
[[ $reboot == 'y' ]] && reboot && exit 0 | |
[[ $reboot == 'n' ]] && break | |
echo 'Error: Invalid option. Please enter "y" or "n"' | |
done | |
echo '' | |
echo 'Run `reboot` when you are ready' | |
echo '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment