Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspberry Pi OS Bookworm + Pep 668 #13

Merged
merged 22 commits into from
May 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8ebf5b3
Enforce use of a virtual environment.
Gadgetoid Oct 16, 2023
fc12d7d
Add option to manage venv if it's not detected.
Gadgetoid Oct 16, 2023
c8b2011
QA: Drop --format argument from ruff.
Gadgetoid Oct 17, 2023
d9710f7
Drop an auto venv script into ~/Pimoroni, update venv prompt
Gadgetoid Oct 19, 2023
896b3b5
Switch venv location to virtualenvwrapper default.
Gadgetoid Oct 23, 2023
bd3bf8b
Tweaks to install and tool.pimoroni
Gadgetoid Oct 23, 2023
6e4dabc
CI: Set term in check.sh for GitHub Actions.
Gadgetoid Nov 6, 2023
b74d0c6
Better handling of /boot/config.txt and /boot/firmware/config.txt
Gadgetoid Nov 15, 2023
66f69e3
Fix VENV_DIR path.
Gadgetoid Nov 21, 2023
a9db28c
Fix auto_venv.sh creation.
Gadgetoid Nov 22, 2023
5a2228e
install.sh: normalise whitespace.
Gadgetoid Nov 22, 2023
fceeafb
install.sh: rework for better error reporting and fix some bugs.
Gadgetoid Nov 23, 2023
e8f9443
README.md: Correct coveralls badge branch.
Gadgetoid Dec 5, 2023
39d73f7
CI: Update GitHub Actions versions.
damacus Jan 8, 2024
5e294af
QA: Add shellcheck and fix/ignore all issues.
Gadgetoid Jan 9, 2024
f0e3f93
install.sh: slightly better feedback for setup commands.
Gadgetoid Jan 10, 2024
d6a2c6d
install.sh: fix quoting bug in do_config_backup.
Gadgetoid Jan 10, 2024
3c9d88a
install.sh: don't output printf commands.
Gadgetoid Jan 10, 2024
367cd22
install.sh: drop symlink warning for /boot/config.txt.
Gadgetoid Mar 11, 2024
31b961c
install.sh: drop quotes around apt packages.
Gadgetoid Apr 17, 2024
6bb337c
Makefile: fail make tag if dev tools not installed.
Gadgetoid Apr 29, 2024
c2d4193
tox.ini: update ruff invocation to avoid deprecation warning.
Gadgetoid May 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
LIBRARY_NAME=`grep -m 1 name pyproject.toml | awk -F" = " '{print substr($2,2,length($2)-2)}'`
CONFIG=/boot/config.txt
CONFIG_FILE=config.txt
CONFIG_DIR="/boot/firmware"
DATESTAMP=`date "+%Y-%m-%d-%H-%M-%S"`
CONFIG_BACKUP=false
APT_HAS_UPDATED=false
Expand Down Expand Up @@ -56,6 +57,22 @@ warning() {
echo -e "$(tput setaf 1)$1$(tput sgr0)"
}

find_config() {
if [ ! -f "$CONFIG_DIR/$CONFIG_FILE" ]; then
CONFIG_DIR="/boot"
if [ ! -f "$CONFIG_DIR/$CONFIG_FILE"]; then
warning "Could not find $CONFIG_FILE!"
exit 1
fi
else
if [ -f "/boot/$CONFIG_FILE" ] && [ ! -L "/boot/$CONFIG_FILE" ]; then
warning "Oops! It looks like /boot/$CONFIG_FILE is not a link to $CONFIG_DIR/$CONFIG_FILE"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My latest Pi OS install has a non-link file for /boot/config.txt with the contents:

DO NOT EDIT THIS FILE

The file you are looking for has moved to /boot/firmware/config.txt

Need to check if this is now standard across all Pi OS installs and, in any case, check for this text and avoid emitting this warning.

A simpler path might be to avoid all this kerfuffle and always prefer /boot/firmware/config.txt if it exists, without any efforts to warn about other config files.

Or maybe even fail outright if /boot/firmware/config.txt does not exist...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I found the change: RPi-Distro/pi-gen@a125344

It will be standard, but a quick test of 64bit Pi OS lite suggests it currently is not. Therefore the symlink warning is obsolete.

Copy link

@bsimmo bsimmo Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried growhat on RiOS bookworn 32bit, and it blew up at me, this was one of the problems. It doesn't have anything in /boot/firmware/ at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grow should have a fallback to /boot/config.txt- do you have a full output of the install script?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try again, but nothing was added to the normal config.txt.

For now to get it working I've moved to legacy 'bullseye' and the install was ok.

I'll have another go with bookworm when I get the time. (Then for fun I'll try the EnviroHat and the WeatherHat and the led matrix pi zero sized thing if forget the name of... obviously not as much fun as you're having rewriting all of this for all the devices.

But the venv never seemed to go right either, it didn't boot to one. and then when I manually enabled it none of the modules seemed to be there when running the examples. I'll check what it actually contains properly, it might be a few days though.

(Pi Zero, so has to be the 32bit lite version).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently I'm not enabling the virtual environment by default, though it should install a script into ~/Pimoroni/auto_venv.sh which can be optionally added to ~/.bashrc.

source ~/.virtualenvs/pimoroni/bin/activate should activate the venv manually.

warning "You might want to fix this!"
fi
fi
inform "Using $CONFIG_FILE in $CONFIG_DIR"
}

venv_bash_snippet() {
if [ ! -f $VENV_BASH_SNIPPET ]; then
cat << EOF > $VENV_BASH_SNIPPET
Expand Down Expand Up @@ -100,12 +117,12 @@ function do_config_backup {
if [ ! $CONFIG_BACKUP == true ]; then
CONFIG_BACKUP=true
FILENAME="config.preinstall-$LIBRARY_NAME-$DATESTAMP.txt"
inform "Backing up $CONFIG to /boot/$FILENAME\n"
sudo cp $CONFIG /boot/$FILENAME
inform "Backing up $CONFIG_DIR/$CONFIG_FILE to $CONFIG_DIR/$FILENAME\n"
sudo cp $CONFIG_DIR/$CONFIG_FILE $CONFIG_DIR/$FILENAME
mkdir -p $RESOURCES_TOP_DIR/config-backups/
cp $CONFIG $RESOURCES_TOP_DIR/config-backups/$FILENAME
cp $CONFIG_DIR/$CONFIG_FILE $RESOURCES_TOP_DIR/config-backups/$FILENAME
if [ -f "$UNINSTALLER" ]; then
echo "cp $RESOURCES_TOP_DIR/config-backups/$FILENAME $CONFIG" >> $UNINSTALLER
echo "cp $RESOURCES_TOP_DIR/config-backups/$FILENAME $CONFIG_DIR/$CONFIG_FILE" >> $UNINSTALLER
fi
fi
}
Expand Down Expand Up @@ -245,10 +262,12 @@ fi

cd $WD

find_config

for ((i = 0; i < ${#SETUP_CMDS[@]}; i++)); do
CMD="${SETUP_CMDS[$i]}"
# Attempt to catch anything that touches /boot/config.txt and trigger a backup
if [[ "$CMD" == *"raspi-config"* ]] || [[ "$CMD" == *"$CONFIG"* ]] || [[ "$CMD" == *"\$CONFIG"* ]]; then
# Attempt to catch anything that touches config.txt and trigger a backup
if [[ "$CMD" == *"raspi-config"* ]] || [[ "$CMD" == *"$CONFIG_DIR/$CONFIG_FILE"* ]] || [[ "$CMD" == *"\$CONFIG_DIR/\$CONFIG_FILE"* ]]; then
do_config_backup
fi
eval $CMD
Expand All @@ -258,10 +277,10 @@ for ((i = 0; i < ${#CONFIG_TXT[@]}; i++)); do
CONFIG_LINE="${CONFIG_TXT[$i]}"
if ! [ "$CONFIG_LINE" == "" ]; then
do_config_backup
inform "Adding $CONFIG_LINE to $CONFIG\n"
sudo sed -i "s/^#$CONFIG_LINE/$CONFIG_LINE/" $CONFIG
if ! grep -q "^$CONFIG_LINE" $CONFIG; then
printf "$CONFIG_LINE\n" | sudo tee --append $CONFIG
inform "Adding $CONFIG_LINE to $CONFIG_DIR/$CONFIG_FILE\n"
sudo sed -i "s/^#$CONFIG_LINE/$CONFIG_LINE/" $CONFIG_DIR/$CONFIG_FILE
if ! grep -q "^$CONFIG_LINE" $CONFIG_DIR/$CONFIG_FILE; then
printf "$CONFIG_LINE\n" | sudo tee --append $CONFIG_DIR/$CONFIG_FILE
fi
fi
done
Expand Down
Loading