Last Updated on May 28, 2023.
I’m putting things here I often come back to with Raspberry Pi Setups but didn’t think they’d actually belong in their own article, at least as of yet.
Auto mount USB stick
See https://krystof.io/auto-mounting-a-usb-drive-in-a-raspberry-pi/
Login
Detecting SSH vs console
I’ve used this when wanting to start certain code when in console mode vs SSH logins. Edit ~/.profile and add commands as needed.
if [ "$SSH_CONNECTION" != "" ]; then
echo SSH being used, enabling ssh-session specific functionality
else
echo Enabling console-specific functionality
fi
Shell Scripting
Trapping program execution time in a wrapper shell script
I used this to time C64 demos when I was curating lists for my stream. I would play a demo until I was finished or it was over and when I would exit VICE the elapsed time would print out. First time I ever had to trap in a shell script.
#!/bin/bash
function ctrl_c() {
echo "** Trapped CTRL-C"
}
trap ctrl_c INT
start_time="$(date -u +%s)"
/home/pi/viceinstall/bin/x64 -autostart ./$1 > executionlog.txt
end_time="$(date -u +%s)"
echo "time elapsed: $(($end_time-$start_time))"
Another example that traps the exiting of a shell (since we set -e to turn on exit on error)
set -e
trap 'catch $? $LINENO' EXIT
catch() {
echo "catching!"
if [ "$1" != "0" ]; then
# error handling goes here
echo "Error $1 occurred on $2"
fi
}
Redirecting Nohup
Nohup redirects output and is often used for running programs in the background. If I don’t want the nohup.out and just want to redirect to null, I can do this:
nohup command </dev/null >/dev/null 2>&1 &
Networking
apt update/install/upgrade fails with ipV6 lookup
From Stack Overflow – ‘Just to get it to work’
Add -o Acquire::ForceIPv4=true
when running apt-get
.
If you want to make the setting persistent just create /etc/apt/apt.conf.d/99force-ipv4 and put Acquire::ForceIPv4 "true";
in it:
echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4
Ubuntu Wifi / Network Setup with netplan
I use these when I’m using Ubuntu server and need to get Wifi working.
List Network Devices – Wifi is generally wlXXXXXX
ls /sys/class/net
Edit the netplan config file (Ubuntu server was at /etc/netplan/00-installer-config.yaml
, and reworked accordingly. Sample:
network:
ethernets:
eth0:
dhcp4: true
optional: true
version: 2
wifis:
wlp3s0:
optional: true
access-points:
"SSID-NAME-HERE":
password: "PASSWORD-HERE"
dhcp4: true
Follow with sudo netplan apply
to finish up.
Peripheral Devices
Mouse Polling Rate
I used this to boost mouse polling rate when using a Raspberry Pi as a modern day Steamlink (since Steamlink is discontinued and who knows how long mine will live) using Parsec/Moonlight.
Add this to the end of /boot/cmdline.txt
:
usbhid.mousepoll=8
The lower you go the more CPU the Pi will use for this.
Reference: https://support.parsecgaming.com/hc/en-us/articles/115002699012-Setting-Up-On-Raspberry-Pi-Raspbian-
System Versions and Firmware
Check Firmware Version
sudo /opt/vc/bin/vcgencmd version
Update firmware – check version:
sudo rpi-eeprom-update
Update via normal update with full-upgrade switch:
sudo apt update
sudo apt full-upgrade
To ONLY update firmware:
sudo rpi-eeprom-update -d -a
Network Backup
This is a nice setup that I’ve used to take occasional snapshots of Raspberry Pi computers I’ve setup for internal network components. I generally shut down any docker or webmin services before running it.