Raspberry Pi Setup Script

When I set up a Raspberry Pi, there are a few things that I have to do right out of the gate to make things easier on myself. They involve putting a few files on the sdcard to make the initial setup easier:

  • ssh
  • wpa_supplicant.conf
  • set_up.sh

The first file is just a blank file that triggers the pi to enable ssh. I set up most of my Raspberry Pis to be headless, so this combined with a reserved IP address in my router allows me to ssh to the Pi without having to first connect it to a monitor and keyboard.

The second file contains the connection information for my WiFi network. You can find more information about this on the Raspberry Pi website (wireless-cli).

The third file is a script that I made to make the initial configuration easier. I find myself doing a lot of things every time I set up a pi, and it was taking me 20-30 minutes to do everything. With this script, I can do it automatically in just a few minutes.

Here’s the script. I’ll break apart the different sections below:

#!/bin/bash

apt-get update
apt-get -y upgrade
apt-get -y install git screen
apt -y autoremove

ln -fs /usr/share/zoneinfo/US/Eastern /etc/localtime
dpkg-reconfigure -f noninteractive tzdata

adduser --disabled-password --gecos "Matt Himrod" matthimrod 
adduser matthimrod sudo
echo -e "password\npassword" | passwd matthimrod

echo matthimrod ALL=\(ALL:ALL\) ALL > /etc/sudoers.d/010_matthimrod

cat <<'__SET_UP_MATT__' > ~matthimrod/set_up.sh 
#!/bin/bash

echo ".cfg" >> .gitignore
git clone --bare "[email protected]:matthimrod/dotfiles.git" $HOME/.cfg
mv .bash_logout .bash_logout.orig
mv .bashrc .bashrc.orig
rm .ssh/authorized_keys
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME config --local status.showUntrackedFiles no
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME checkout

sudo rm -rf /boot/System\ Volume\ Information/
sudo rm /boot/set_up.sh
rm ~/set_up.sh

__SET_UP_MATT__
chown matthimrod:matthimrod -R ~matthimrod/set_up.sh
chmod 777 ~matthimrod/set_up.sh

/usr/bin/raspi-config

The first set of commands updates the software on the Pi, installs git and screen, and removes unneeded packages. This is the biggest timesaver since I don’t have to watch the process and run the next command when the previous one finishes.

Next, I set the time zone to US Eastern (or America/New York).

Then I add my user, add it to the sudo group, and set the password.

Now, the next lines drop another script in my home directory to do a few things as my own user. Specifically, I set up the dotfiles Github repository that I discussed in my last post. I also remove this script from /boot and the one from my home directory.

The last thing I do in the “root” script is run raspi-config so that I can change the hostname.

2025

Making PowerShell “Posh”

Back in the days when DOS and Windows were separate programs, the default Command Prompt didn’t look exactly the way that it does now. I can’t recall if it w...

Back to Top ↑

2024

PowerShell Short Scripts

As a Data Engineer using Mirth Connect, it’s often tricky to review my team’s merge requests because the merge request document contains the XML representati...

PowerShell Short Scripts

When dealing with Python dependencies, it’s sometimes necessary to determine if a given project is using a given version of a library. Since our team is usin...

Storing dotfiles in GitHub Revisited

A while ago, I wrote about using a bare git repository to manage my dotfiles. That worked somewhat well, but it had some shortcomings. Since, I’ve started us...

Python Context Managers

One of my current projects involves some improvements to code that I wrote last year – specifically enhancing the “Patient Identity Fixer”, which is my pet p...

PowerShell for Data Transformation: JSON

My team at work has a custom FHIR resource that we work with often called an Operation Outcome. We generate one of these for nearly every record we process, ...

Back to Top ↑

2021

Raspberry Pi Zero W “Busy Light”

COVID-19 has us many of us working from home. My husband and I are both fortunate enough to be in this group. However, as a teacher, his schedule is very pre...

Back to Top ↑

2020

Raspberry Pi Setup Script

When I set up a Raspberry Pi, there are a few things that I have to do right out of the gate to make things easier on myself. They involve putting a few file...

Storing dotfiles in GitHub

While I don’t use Linux as my primary operating system, I do use it a lot both at home and at work. It can be frustrating to try to sync up configurations be...

Nitro Cold Brew at Home!

Anyone who knows my husband or me knows that we really like our cold brew, and they also know that we make our own at home. Nitro cold brew has become a bit ...

OpenVPN On Raspberry Pi

So you want to run an OpenVPN Server on a Raspberry Pi? I did too, but it wasn’t easy to figure out the first time. If you want to skip all of this and do it...

Back to Top ↑