Last Updated on March 7, 2021.
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))"
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
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-