From 6475eebf5363abcc8d3ee795edf43aca4f46d6f3 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 19 Dec 2023 08:38:30 +0100 Subject: [PATCH 01/55] Add components folder to installation and docs. First component is hifiberry sound card --- documentation/builders/components/Readme.md | 3 ++ .../builders/components/hifiberry.md | 41 +++++++++++++++++++ installation/components/setup_hifiberry.sh | 38 +++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 documentation/builders/components/Readme.md create mode 100644 documentation/builders/components/hifiberry.md create mode 100644 installation/components/setup_hifiberry.sh diff --git a/documentation/builders/components/Readme.md b/documentation/builders/components/Readme.md new file mode 100644 index 000000000..f4d109032 --- /dev/null +++ b/documentation/builders/components/Readme.md @@ -0,0 +1,3 @@ +# Phoniebox components directory + +* [Hifberry](./hifiberry.md) \ No newline at end of file diff --git a/documentation/builders/components/hifiberry.md b/documentation/builders/components/hifiberry.md new file mode 100644 index 000000000..9aa3966f3 --- /dev/null +++ b/documentation/builders/components/hifiberry.md @@ -0,0 +1,41 @@ +# HiFiBerry + +## Automatic setup + +Use this install script to enable your HiFiBerry board. + +``` +$ cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup-hifiberry.sh && sudo ./setup_hifiberry.sh +``` + +## Manual steps to enable sound through HiFiBerry board + +1. Make sure your onboard sound of your Raspberry Pi is disabled. Check `/boot/config.txt`. The installation + + ``` + dtparam=audio=off + ``` + +2. Run the following command to enable HiFiBerry boards. + + ``` + echo "dtoverlay=hifiberry-dac" | sudo tee -a /boot/config.txt + ``` + +3. Enable volume control. Create or edit the following file: `sudo vi /etc/asound.conf` + + ``` + pcm.hifiberry { + type softvol + slave.pcm "plughw:0" + control.name "HifiBerry" + control.card 0 + } + + pcm.!default { + type plug + slave.pcm "hifiberry" + } + ``` + +4. Restart your device. diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh new file mode 100644 index 000000000..305d2d23d --- /dev/null +++ b/installation/components/setup_hifiberry.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Check if the script is run as root +if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" 1>&2 + exit 1 +fi + +# Disable onboard sound of Raspberry Pi +echo "Disabling onboard sound..." +sed -i '/dtparam=audio=on/c\dtparam=audio=off' /boot/config.txt + +# Enable HiFiBerry board +echo "Enabling HiFiBerry board..." +grep -qxF 'dtoverlay=hifiberry-dac' /boot/config.txt || echo 'dtoverlay=hifiberry-dac' >> /boot/config.txt + +# Backup asound.conf +if [ -f /etc/asound.conf ]; then + echo "Backing up existing asound.conf..." + cp /etc/asound.conf "/etc/asound.conf.backup.$(date +%Y%m%d%H%M%S)" +fi + +echo "Configuring sound settings..." +cat > /etc/asound.conf << EOF +pcm.hifiberry { + type softvol + slave.pcm "plughw:0" + control.name "HifiBerry" + control.card 0 +} + +pcm.!default { + type plug + slave.pcm "hifiberry" +} +EOF + +echo "Configuration complete. Please restart your device." From 66390159d7cd493ea5241fb3c96177f77e3ca0b9 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 19 Dec 2023 21:36:48 +0100 Subject: [PATCH 02/55] Allow for all hifiberry boards --- installation/components/setup_hifiberry.sh | 49 +++++++++++++++++++--- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 305d2d23d..da6fa4bad 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -1,20 +1,59 @@ #!/bin/bash +# This script follows the official HiFiBerry documentation +# https://www.hifiberry.com/docs/software/configuring-linux-3-18-x/ + # Check if the script is run as root if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" 1>&2 exit 1 fi -# Disable onboard sound of Raspberry Pi +# List of HiFiBerry boards +echo -m "\n +Select your HiFiBerry board: +1) DAC for Raspberry Pi 1/DAC+ Light/DAC Zero/MiniAmp/Beocreate/DAC+ DSP/DAC+ RTC +2) DAC+ Standard/Pro/Amp2 +3) DAC2 HD +4) DAC+ ADC +5) DAC+ ADC Pro +6) Digi+ +7) Digi+ Pro +8) Amp+ (not Amp2) +9) Amp3" +read -p "Enter your choice (1-9): " choice + +enable_hifiberry() { + echo "Enabling HiFiBerry board..." + grep -qxF "dtoverlay=$1" /boot/config.txt || echo "dtoverlay=$1" >> /boot/config.txt +} + +case $choice in + 1) enable_hifiberry "hifiberry-dac";; + 2) enable_hifiberry "hifiberry-dacplus";; + 3) enable_hifiberry "hifiberry-dacplushd";; + 4) enable_hifiberry "hifiberry-dacplusadc";; + 5) enable_hifiberry "hifiberry-dacplusadcpro";; + 6) enable_hifiberry "hifiberry-digi";; + 7) enable_hifiberry "hifiberry-digi-pro";; + 8) enable_hifiberry "hifiberry-amp";; + 9) enable_hifiberry "hifiberry-amp3";; + *) echo "Invalid selection. Exiting."; exit 1;; +esac + echo "Disabling onboard sound..." sed -i '/dtparam=audio=on/c\dtparam=audio=off' /boot/config.txt -# Enable HiFiBerry board -echo "Enabling HiFiBerry board..." -grep -qxF 'dtoverlay=hifiberry-dac' /boot/config.txt || echo 'dtoverlay=hifiberry-dac' >> /boot/config.txt +if grep -q 'dtoverlay=vc4-fkms-v3d' /boot/config.txt; then + echo "Disabling audio in vc4-fkms-v3d overlay..." + sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' /boot/config.txt +fi + +if grep -q 'dtoverlay=vc4-kms-v3d' /boot/config.txt; then + echo "Disabling audio in vc4-kms-v3d overlay..." + sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' /boot/config.txt +fi -# Backup asound.conf if [ -f /etc/asound.conf ]; then echo "Backing up existing asound.conf..." cp /etc/asound.conf "/etc/asound.conf.backup.$(date +%Y%m%d%H%M%S)" From 9d709b7ea2da89f91d7d9500718a368ef6154a14 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:50:21 +0100 Subject: [PATCH 03/55] Disabling HDMI Audio --- installation/components/setup_hifiberry.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index da6fa4bad..c5ea167c6 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -10,7 +10,7 @@ if [ "$(id -u)" != "0" ]; then fi # List of HiFiBerry boards -echo -m "\n +echo " Select your HiFiBerry board: 1) DAC for Raspberry Pi 1/DAC+ Light/DAC Zero/MiniAmp/Beocreate/DAC+ DSP/DAC+ RTC 2) DAC+ Standard/Pro/Amp2 @@ -54,6 +54,9 @@ if grep -q 'dtoverlay=vc4-kms-v3d' /boot/config.txt; then sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' /boot/config.txt fi +echo "Disabling HDMI audio..." +sed -i '/hdmi_drive/c\#hdmi_drive=2' /boot/config.txt + if [ -f /etc/asound.conf ]; then echo "Backing up existing asound.conf..." cp /etc/asound.conf "/etc/asound.conf.backup.$(date +%Y%m%d%H%M%S)" From 962113385961d63597a34710a4b331d939be86b2 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 20 Dec 2023 21:47:02 +0100 Subject: [PATCH 04/55] Finalize HiFiBerry doc --- documentation/builders/README.md | 4 ++ documentation/builders/components/Readme.md | 3 -- .../builders/components/hifiberry.md | 41 ------------------- .../components/soundcards/hifiberry.md | 31 ++++++++++++++ installation/components/setup_hifiberry.sh | 23 ----------- 5 files changed, 35 insertions(+), 67 deletions(-) delete mode 100644 documentation/builders/components/Readme.md delete mode 100644 documentation/builders/components/hifiberry.md create mode 100644 documentation/builders/components/soundcards/hifiberry.md diff --git a/documentation/builders/README.md b/documentation/builders/README.md index 3d70bca15..7a2654ba5 100644 --- a/documentation/builders/README.md +++ b/documentation/builders/README.md @@ -13,6 +13,10 @@ * [Card Database](./card-database.md) * [Troubleshooting](./troubleshooting.md) +## Components +* [Soundcards](./components/soundcards/) + * [HiFiBerry Boards](./components/soundcards/hifiberry.md) + ## Advanced * [Bluetooth (and audio buttons)](./bluetooth-audio-buttons.md) diff --git a/documentation/builders/components/Readme.md b/documentation/builders/components/Readme.md deleted file mode 100644 index f4d109032..000000000 --- a/documentation/builders/components/Readme.md +++ /dev/null @@ -1,3 +0,0 @@ -# Phoniebox components directory - -* [Hifberry](./hifiberry.md) \ No newline at end of file diff --git a/documentation/builders/components/hifiberry.md b/documentation/builders/components/hifiberry.md deleted file mode 100644 index 9aa3966f3..000000000 --- a/documentation/builders/components/hifiberry.md +++ /dev/null @@ -1,41 +0,0 @@ -# HiFiBerry - -## Automatic setup - -Use this install script to enable your HiFiBerry board. - -``` -$ cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup-hifiberry.sh && sudo ./setup_hifiberry.sh -``` - -## Manual steps to enable sound through HiFiBerry board - -1. Make sure your onboard sound of your Raspberry Pi is disabled. Check `/boot/config.txt`. The installation - - ``` - dtparam=audio=off - ``` - -2. Run the following command to enable HiFiBerry boards. - - ``` - echo "dtoverlay=hifiberry-dac" | sudo tee -a /boot/config.txt - ``` - -3. Enable volume control. Create or edit the following file: `sudo vi /etc/asound.conf` - - ``` - pcm.hifiberry { - type softvol - slave.pcm "plughw:0" - control.name "HifiBerry" - control.card 0 - } - - pcm.!default { - type plug - slave.pcm "hifiberry" - } - ``` - -4. Restart your device. diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md new file mode 100644 index 000000000..1702c3a18 --- /dev/null +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -0,0 +1,31 @@ +# HiFiBerry + +## Automatic setup + +Run the following command to install any HiFiBerry board. Make sure you reboot your device afterwards. + +``` +$ cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh && sudo ./setup_hifiberry.sh +``` + +## Additional information + +If you like to understand what's happening under the hood, feel free to check the [install script](../../../../installation/components/setup_hifiberry.sh). + +The setup is based on [HiFiBerry's instructions](https://www.hifiberry.com/docs/software/configuring-linux-3-18-x/). + +## How to manually wire your HiFiBerry board + +Most HiFiBerry boards come with 40-pin header that you can directly attach to your Pi. This idles many GPIO pins that may be required for other inputs to be attached (like GPIO buttons or RFID). You can also connect your HiFiBerry board separately. The following table show cases the pins required. + +| Board pin name | Board pin | Physical RPi pin | RPi pin name | +|----------------|-----------|------------------|--------------| +| 3.3V | 1 | 1, 17 | 3V3 power | +| 5V | 2 | 2, 4 | 5V power | +| GND | 6 | 6, 9, 20, 25 | Ground | +| PCM_CLK | 12 | 12 | GPIO18 | +| PCM_FS | 36 | 36 | GPIO19 | +| PCM_DIN | 38 | 38 | GPIO20 | +| PCM_DOUT | 40 | 40 | GPIO21 | + +You can find more information about manually wiring [here](https://forum-raspberrypi.de/forum/thread/44967-kein-ton-ueber-hifiberry-miniamp-am-rpi-4/?postID=401305#post401305). diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index c5ea167c6..24712605e 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -54,27 +54,4 @@ if grep -q 'dtoverlay=vc4-kms-v3d' /boot/config.txt; then sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' /boot/config.txt fi -echo "Disabling HDMI audio..." -sed -i '/hdmi_drive/c\#hdmi_drive=2' /boot/config.txt - -if [ -f /etc/asound.conf ]; then - echo "Backing up existing asound.conf..." - cp /etc/asound.conf "/etc/asound.conf.backup.$(date +%Y%m%d%H%M%S)" -fi - -echo "Configuring sound settings..." -cat > /etc/asound.conf << EOF -pcm.hifiberry { - type softvol - slave.pcm "plughw:0" - control.name "HifiBerry" - control.card 0 -} - -pcm.!default { - type plug - slave.pcm "hifiberry" -} -EOF - echo "Configuration complete. Please restart your device." From 8b316854f938c5bc64f5fab9e7911b6fd64ad4e5 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 20 Dec 2023 21:49:59 +0100 Subject: [PATCH 05/55] Refer to Pi Pinout for convenience --- documentation/builders/components/soundcards/hifiberry.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md index 1702c3a18..412f64052 100644 --- a/documentation/builders/components/soundcards/hifiberry.md +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -18,6 +18,8 @@ The setup is based on [HiFiBerry's instructions](https://www.hifiberry.com/docs/ Most HiFiBerry boards come with 40-pin header that you can directly attach to your Pi. This idles many GPIO pins that may be required for other inputs to be attached (like GPIO buttons or RFID). You can also connect your HiFiBerry board separately. The following table show cases the pins required. +* [Raspberry Pi Pinout](https://github.com/raspberrypi/documentation/blob/develop/documentation/asciidoc/computers/os/using-gpio.adoc) + | Board pin name | Board pin | Physical RPi pin | RPi pin name | |----------------|-----------|------------------|--------------| | 3.3V | 1 | 1, 17 | 3V3 power | From e1dfb53a2c7f0fe08496f4e040114338d3a49949 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 20 Dec 2023 22:02:08 +0100 Subject: [PATCH 06/55] Enable ALSA config as an option as well --- .../components/soundcards/hifiberry.md | 2 ++ installation/components/setup_hifiberry.sh | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md index 412f64052..430527055 100644 --- a/documentation/builders/components/soundcards/hifiberry.md +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -8,6 +8,8 @@ Run the following command to install any HiFiBerry board. Make sure you reboot y $ cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh && sudo ./setup_hifiberry.sh ``` +Optional: You can register your sound card with ALSA. Define the following variable before running the script: `CONFIGURE_ALSA=true` + ## Additional information If you like to understand what's happening under the hood, feel free to check the [install script](../../../../installation/components/setup_hifiberry.sh). diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 24712605e..973656df6 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -54,4 +54,27 @@ if grep -q 'dtoverlay=vc4-kms-v3d' /boot/config.txt; then sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' /boot/config.txt fi +# Check for CONFIGURE_ALSA environment variable +if [ "${CONFIGURE_ALSA}" == "true" ]; then + if [ -f /etc/asound.conf ]; then + echo "Backing up existing asound.conf..." + cp /etc/asound.conf "/etc/asound.conf.backup.$(date +%Y%m%d%H%M%S)" + fi + + echo "Configuring sound settings in asound.conf..." + cat > /etc/asound.conf << EOF +pcm.hifiberry { + type softvol + slave.pcm "plughw:0" + control.name "HifiBerry" + control.card 0 +} + +pcm.!default { + type plug + slave.pcm "hifiberry" +} +EOF +fi + echo "Configuration complete. Please restart your device." From 8174d344cacf081d4c2668d5d8df8fe2c1c97244 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Thu, 21 Dec 2023 00:44:16 +0100 Subject: [PATCH 07/55] Allow script to be run multiple times --- installation/components/setup_hifiberry.sh | 43 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 973656df6..df48daabd 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -9,6 +9,39 @@ if [ "$(id -u)" != "0" ]; then exit 1 fi +check_existing_hifiberry() { + existing_config=$(grep 'dtoverlay=hifiberry-' /boot/config.txt) + if [ ! -z "$existing_config" ]; then + echo "Existing HiFiBerry configuration detected: $existing_config" + read -p "Do you want to proceed with a new configuration? This will remove the existing one. (y/n): " yn + case $yn in + [Yy]* ) + remove_existing_hifiberry + return 0;; + [Nn]* ) + echo "Exiting without making changes."; + exit;; + * ) + echo "Please answer yes or no."; + check_existing_hifiberry;; + esac + fi +} + +remove_existing_hifiberry() { + echo "Removing existing HiFiBerry configuration..." + sed -i '/dtoverlay=hifiberry-/d' /boot/config.txt + sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' /boot/config.txt + sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' /boot/config.txt +} + +enable_hifiberry() { + echo "Enabling HiFiBerry board..." + grep -qxF "dtoverlay=$1" /boot/config.txt || echo "dtoverlay=$1" >> /boot/config.txt +} + +check_existing_hifiberry + # List of HiFiBerry boards echo " Select your HiFiBerry board: @@ -23,11 +56,7 @@ Select your HiFiBerry board: 9) Amp3" read -p "Enter your choice (1-9): " choice -enable_hifiberry() { - echo "Enabling HiFiBerry board..." - grep -qxF "dtoverlay=$1" /boot/config.txt || echo "dtoverlay=$1" >> /boot/config.txt -} - +# Enable selected HiFiBerry board case $choice in 1) enable_hifiberry "hifiberry-dac";; 2) enable_hifiberry "hifiberry-dacplus";; @@ -44,12 +73,12 @@ esac echo "Disabling onboard sound..." sed -i '/dtparam=audio=on/c\dtparam=audio=off' /boot/config.txt -if grep -q 'dtoverlay=vc4-fkms-v3d' /boot/config.txt; then +if grep -qx 'dtoverlay=vc4-fkms-v3d' /boot/config.txt; then echo "Disabling audio in vc4-fkms-v3d overlay..." sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' /boot/config.txt fi -if grep -q 'dtoverlay=vc4-kms-v3d' /boot/config.txt; then +if grep -qx 'dtoverlay=vc4-kms-v3d' /boot/config.txt; then echo "Disabling audio in vc4-kms-v3d overlay..." sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' /boot/config.txt fi From 6ce855cdc88ced5e93a27cd85d9af911aa7e08ad Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Thu, 21 Dec 2023 09:14:54 +0100 Subject: [PATCH 08/55] Add OnOff SHIM as component --- documentation/builders/README.md | 2 ++ .../builders/components/power/onoff-shim.md | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 documentation/builders/components/power/onoff-shim.md diff --git a/documentation/builders/README.md b/documentation/builders/README.md index 7a2654ba5..a67cf3db6 100644 --- a/documentation/builders/README.md +++ b/documentation/builders/README.md @@ -14,6 +14,8 @@ * [Troubleshooting](./troubleshooting.md) ## Components +* [Power](./components/power/) + * [OnOff SHIM for safe power on/off](./components/power/onoff-shim.md) * [Soundcards](./components/soundcards/) * [HiFiBerry Boards](./components/soundcards/hifiberry.md) diff --git a/documentation/builders/components/power/onoff-shim.md b/documentation/builders/components/power/onoff-shim.md new file mode 100644 index 000000000..749e879cf --- /dev/null +++ b/documentation/builders/components/power/onoff-shim.md @@ -0,0 +1,34 @@ +# OnOff SHIM by Pimorino + +The OnOff SHIM from Pimorino allows you to savely start and shutdown your Raspberry Pi through a button. While you can switch of your Phoniebox via an RFID Card (through an RPC command), it is difficult to switch it on again without cutting the physical power supply. + +## Installation + +To install the software, open a terminal and type the following command to run the one-line-installer. A reboot will be required once the installation is finished. + +> [!NOTE] +> The installations will ask you a few questions. You can safely answer with the default response. + +``` +curl https://get.pimoroni.com/onoffshim | bash +``` + +* [Source](https://shop.pimoroni.com/products/onoff-shim?variant=41102600138) + +## How to manually wire OnOff SHIM + +The OnOff SHIM comes with a 12-PIN header which needs soldering. If you want to spare some GPIO pins for other purposes, you can individually wire the OnOff SHIM with the Raspberry Pi. Below you can find a table of Pins to be connected. + +| Board pin name | Board pin | Physical RPi pin | RPi pin name | +|----------------|-----------|------------------|--------------| +| 3.3V | 1 | 1, 17 | 3V3 power | +| 5V | 2 | 2 | 5V power | +| 5V | 4 | 4 | 5V power | +| GND | 6 | 6, 9, 20, 25 | Ground | +| GPLCLK0 | 7 | 7 | GPIO4 | +| GPIO17 | 11 | 11 | GPIO17 | + +## Assembly options + +![](https://cdn.review-images.pimoroni.com/upload-b6276a310ccfbeae93a2d13ec19ab83b-1617096824.jpg?width=640) + From a62c036cd21c4f55cdf212b37014cfca87ebd009 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 26 Dec 2023 00:21:34 +0100 Subject: [PATCH 09/55] Make script more robust based on PR comments --- .../components/soundcards/hifiberry.md | 2 +- installation/components/setup_hifiberry.sh | 36 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md index 430527055..a0afa8206 100644 --- a/documentation/builders/components/soundcards/hifiberry.md +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -5,7 +5,7 @@ Run the following command to install any HiFiBerry board. Make sure you reboot your device afterwards. ``` -$ cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh && sudo ./setup_hifiberry.sh +$ cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh && sudo -E ./setup_hifiberry.sh ``` Optional: You can register your sound card with ALSA. Define the following variable before running the script: `CONFIGURE_ALSA=true` diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index df48daabd..e2d34b20d 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -16,7 +16,6 @@ check_existing_hifiberry() { read -p "Do you want to proceed with a new configuration? This will remove the existing one. (y/n): " yn case $yn in [Yy]* ) - remove_existing_hifiberry return 0;; [Nn]* ) echo "Exiting without making changes."; @@ -70,6 +69,8 @@ case $choice in *) echo "Invalid selection. Exiting."; exit 1;; esac +remove_existing_hifiberry + echo "Disabling onboard sound..." sed -i '/dtparam=audio=on/c\dtparam=audio=off' /boot/config.txt @@ -83,18 +84,34 @@ if grep -qx 'dtoverlay=vc4-kms-v3d' /boot/config.txt; then sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' /boot/config.txt fi -# Check for CONFIGURE_ALSA environment variable -if [ "${CONFIGURE_ALSA}" == "true" ]; then - if [ -f /etc/asound.conf ]; then - echo "Backing up existing asound.conf..." - cp /etc/asound.conf "/etc/asound.conf.backup.$(date +%Y%m%d%H%M%S)" - fi +if [ -z "${CONFIGURE_ALSA}" ]; then + echo "CONFIGURE_ALSA not set. Skipping configuration of sound settings in asound.conf." +else + if [ "${CONFIGURE_ALSA}" == "true" ]; then + if [ -f /etc/asound.conf ]; then + echo "Backing up existing asound.conf..." + cp /etc/asound.conf "/etc/asound.conf.backup.$(date +%Y%m%d%H%M%S)" + fi + + aplay -l - echo "Configuring sound settings in asound.conf..." + # Prompt the user for the card number + while true; do + read -p "Which card number is your HifiBerry sound card? " card_number + + # Check if the input is a number + if [[ "$card_number" =~ ^[0-9]+$ ]]; then + break + else + echo "Please enter a valid number." + fi + done + + echo "Configuring sound settings in asound.conf..." cat > /etc/asound.conf << EOF pcm.hifiberry { type softvol - slave.pcm "plughw:0" + slave.pcm "plughw:$card_number" control.name "HifiBerry" control.card 0 } @@ -104,6 +121,7 @@ pcm.!default { slave.pcm "hifiberry" } EOF + fi fi echo "Configuration complete. Please restart your device." From 0427214660916ca9438531cbc1a30081699a79a8 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Mon, 1 Jan 2024 23:54:21 +0100 Subject: [PATCH 10/55] Update hifiberry soundcard options --- installation/components/setup_hifiberry.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index e2d34b20d..8cabbf3ea 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -44,16 +44,16 @@ check_existing_hifiberry # List of HiFiBerry boards echo " Select your HiFiBerry board: -1) DAC for Raspberry Pi 1/DAC+ Light/DAC Zero/MiniAmp/Beocreate/DAC+ DSP/DAC+ RTC -2) DAC+ Standard/Pro/Amp2 -3) DAC2 HD -4) DAC+ ADC -5) DAC+ ADC Pro -6) Digi+ -7) Digi+ Pro -8) Amp+ (not Amp2) -9) Amp3" -read -p "Enter your choice (1-9): " choice +1) DAC (HiFiBerry MiniAmp, I2S PCM5102A DAC) +2) HiFiBerry DAC+ Standard/Pro/Amp2 +3) HiFiBerry DAC2 HD +4) HiFiBerry DAC+ ADC +5) HiFiBerry DAC+ ADC Pro +6) HiFiBerry Digi+ +7) HiFiBerry Digi+ Pro +8) HiFiBerry Amp+ (not Amp2) +9) HiFiBerry Amp3" +read -p "Enter your choice (1-10): " choice # Enable selected HiFiBerry board case $choice in From c6df305bf48a217742167e6c5f1207ce0e379ce8 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 2 Jan 2024 00:15:46 +0100 Subject: [PATCH 11/55] Automate soundcard detection for asound.conf --- installation/components/setup_hifiberry.sh | 24 ++++++++-------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 8cabbf3ea..7dd462d89 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -93,27 +93,18 @@ else cp /etc/asound.conf "/etc/asound.conf.backup.$(date +%Y%m%d%H%M%S)" fi - aplay -l + card_id=$(cat /proc/asound/cards | grep -oP '(?<=^ )\d+(?= \[sndrpihifiberry\]:)' | head -n 1) - # Prompt the user for the card number - while true; do - read -p "Which card number is your HifiBerry sound card? " card_number - - # Check if the input is a number - if [[ "$card_number" =~ ^[0-9]+$ ]]; then - break - else - echo "Please enter a valid number." - fi - done - - echo "Configuring sound settings in asound.conf..." + if [ -z "$card_id" ]; then + echo " Error: Could not find HifiBerry sound card in /etc/asound.conf." + else + echo "Configuring sound settings in asound.conf..." cat > /etc/asound.conf << EOF pcm.hifiberry { type softvol - slave.pcm "plughw:$card_number" + slave.pcm "plughw:$card_id" control.name "HifiBerry" - control.card 0 + control.card $card_id } pcm.!default { @@ -121,6 +112,7 @@ pcm.!default { slave.pcm "hifiberry" } EOF + fi fi fi From bfaad30b5f8ab48d3c1963812b9e4ee6ece2a3c1 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 2 Jan 2024 00:46:46 +0100 Subject: [PATCH 12/55] use /boot/config based on debian version --- installation/components/setup_hifiberry.sh | 28 ++++++------- installation/includes/02_helpers.sh | 47 ++++++++++++++++++++++ 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 7dd462d89..8fa7d1e3e 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -3,14 +3,14 @@ # This script follows the official HiFiBerry documentation # https://www.hifiberry.com/docs/software/configuring-linux-3-18-x/ +source ../includes/02_helpers.sh + # Check if the script is run as root -if [ "$(id -u)" != "0" ]; then - echo "This script must be run as root" 1>&2 - exit 1 -fi +check_root +boot_config_path=get_boot_config_path check_existing_hifiberry() { - existing_config=$(grep 'dtoverlay=hifiberry-' /boot/config.txt) + existing_config=$(grep 'dtoverlay=hifiberry-' "$boot_config_path") if [ ! -z "$existing_config" ]; then echo "Existing HiFiBerry configuration detected: $existing_config" read -p "Do you want to proceed with a new configuration? This will remove the existing one. (y/n): " yn @@ -29,14 +29,14 @@ check_existing_hifiberry() { remove_existing_hifiberry() { echo "Removing existing HiFiBerry configuration..." - sed -i '/dtoverlay=hifiberry-/d' /boot/config.txt - sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' /boot/config.txt - sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' /boot/config.txt + sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" + sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" + sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path" } enable_hifiberry() { echo "Enabling HiFiBerry board..." - grep -qxF "dtoverlay=$1" /boot/config.txt || echo "dtoverlay=$1" >> /boot/config.txt + grep -qxF "dtoverlay=$1" "$boot_config_path" || echo "dtoverlay=$1" >> "$boot_config_path" } check_existing_hifiberry @@ -72,16 +72,16 @@ esac remove_existing_hifiberry echo "Disabling onboard sound..." -sed -i '/dtparam=audio=on/c\dtparam=audio=off' /boot/config.txt +sed -i '/dtparam=audio=on/c\dtparam=audio=off' "$boot_config_path" -if grep -qx 'dtoverlay=vc4-fkms-v3d' /boot/config.txt; then +if grep -qx 'dtoverlay=vc4-fkms-v3d' "$boot_config_path"; then echo "Disabling audio in vc4-fkms-v3d overlay..." - sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' /boot/config.txt + sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' "$boot_config_path" fi -if grep -qx 'dtoverlay=vc4-kms-v3d' /boot/config.txt; then +if grep -qx 'dtoverlay=vc4-kms-v3d' "$boot_config_path"; then echo "Disabling audio in vc4-kms-v3d overlay..." - sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' /boot/config.txt + sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' "$boot_config_path" fi if [ -z "${CONFIGURE_ALSA}" ]; then diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index 239a18ccf..37c44773e 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -34,6 +34,13 @@ run_with_log_frame() { log "#########################################################" } +check_root() { + if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" 1>&2 + exit 1 + fi +} + get_architecture() { local arch="" if [ "$(uname -m)" = "armv7l" ]; then @@ -49,6 +56,46 @@ get_architecture() { echo $arch } +is_raspian() { + if [[ $(lsb_release -d 2>/dev/null) == *"Raspbian"* ]]; then + echo true + else + echo false + fi +} + +get_debian_version() { + # Read the major version number from /etc/debian_version + local major_version=$(cut -d. -f1 /etc/debian_version) + + case $major_version in + 11) + echo "bullseye" + ;; + 12) + echo "bookworm" + ;; + *) + echo "unknown" + ;; + esac +} + +get_boot_config_path() { + if [ "$(is_raspian)" = true ]; then + local debian_version=get_debian_version + + if [ "$debian_version" = "bookworm" ]; then + echo '/boot/firmware/config.txt' + else + echo '/boot/config.txt' + fi + else + echo "Error: It seems you are not running Raspian OS." + exit 1 + fi +} + validate_url() { local url=$1 wget --spider ${url} >/dev/null 2>&1 From 0da4d7344a8ebcdf2093887a14bb41109b5f334a Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 2 Jan 2024 23:28:18 +0100 Subject: [PATCH 13/55] Reorganize a few things --- installation/components/setup_hifiberry.sh | 29 +++++++++------ installation/includes/02_helpers.sh | 42 +++++++++++----------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 8fa7d1e3e..c7e9caf16 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -5,9 +5,24 @@ source ../includes/02_helpers.sh -# Check if the script is run as root -check_root + +if [ "$(is_root)" = false ]; then + echo "ERROR: This script must be run as root" + exit 1 +fi + boot_config_path=get_boot_config_path +if [ "$(boot_config_path)" = "unknown" ]; then + echo "ERROR: It seems you are not running Raspian OS." + exit 1 +fi + +remove_existing_hifiberry() { + echo "Removing existing HiFiBerry configuration..." + sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" + sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" + sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path" +} check_existing_hifiberry() { existing_config=$(grep 'dtoverlay=hifiberry-' "$boot_config_path") @@ -16,6 +31,7 @@ check_existing_hifiberry() { read -p "Do you want to proceed with a new configuration? This will remove the existing one. (y/n): " yn case $yn in [Yy]* ) + remove_existing_hifiberry; return 0;; [Nn]* ) echo "Exiting without making changes."; @@ -27,13 +43,6 @@ check_existing_hifiberry() { fi } -remove_existing_hifiberry() { - echo "Removing existing HiFiBerry configuration..." - sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" - sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" - sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path" -} - enable_hifiberry() { echo "Enabling HiFiBerry board..." grep -qxF "dtoverlay=$1" "$boot_config_path" || echo "dtoverlay=$1" >> "$boot_config_path" @@ -69,8 +78,6 @@ case $choice in *) echo "Invalid selection. Exiting."; exit 1;; esac -remove_existing_hifiberry - echo "Disabling onboard sound..." sed -i '/dtparam=audio=on/c\dtparam=audio=off' "$boot_config_path" diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index 37c44773e..c6ad01cea 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -34,26 +34,27 @@ run_with_log_frame() { log "#########################################################" } -check_root() { - if [ "$(id -u)" != "0" ]; then - echo "This script must be run as root" 1>&2 - exit 1 - fi +is_root() { + if [ "$(id -u)" != "0" ]; then + echo false + else + echo true + fi } get_architecture() { - local arch="" - if [ "$(uname -m)" = "armv7l" ]; then - arch="armv7" - elif [ "$(uname -m)" = "armv6l" ]; then - arch="armv6" - elif [ "$(uname -m)" = "aarch64" ]; then - arch="arm64" - else - arch="$(uname -m)" - fi - - echo $arch + local arch="" + if [ "$(uname -m)" = "armv7l" ]; then + arch="armv7" + elif [ "$(uname -m)" = "armv6l" ]; then + arch="armv6" + elif [ "$(uname -m)" = "aarch64" ]; then + arch="arm64" + else + arch="$(uname -m)" + fi + + echo $arch } is_raspian() { @@ -86,13 +87,12 @@ get_boot_config_path() { local debian_version=get_debian_version if [ "$debian_version" = "bookworm" ]; then - echo '/boot/firmware/config.txt' + echo "/boot/firmware/config.txt" else - echo '/boot/config.txt' + echo "/boot/config.txt" fi else - echo "Error: It seems you are not running Raspian OS." - exit 1 + echo "unknown" fi } From 2aa6f479b1918669a2a8017b4ea98332e74973e8 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 2 Jan 2024 23:46:03 +0100 Subject: [PATCH 14/55] some bugfixes --- installation/components/setup_hifiberry.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index c7e9caf16..2f19c2c97 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -1,18 +1,17 @@ -#!/bin/bash +#!/usr/bin/env bash # This script follows the official HiFiBerry documentation # https://www.hifiberry.com/docs/software/configuring-linux-3-18-x/ source ../includes/02_helpers.sh - if [ "$(is_root)" = false ]; then echo "ERROR: This script must be run as root" exit 1 fi boot_config_path=get_boot_config_path -if [ "$(boot_config_path)" = "unknown" ]; then +if [ "$boot_config_path" = "unknown" ]; then echo "ERROR: It seems you are not running Raspian OS." exit 1 fi @@ -62,7 +61,7 @@ Select your HiFiBerry board: 7) HiFiBerry Digi+ Pro 8) HiFiBerry Amp+ (not Amp2) 9) HiFiBerry Amp3" -read -p "Enter your choice (1-10): " choice +read -p "Enter your choice (1-9): " choice # Enable selected HiFiBerry board case $choice in From e18189b4dff79d87dd4c08efcf3ae5e23de7714d Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 2 Jan 2024 23:55:40 +0100 Subject: [PATCH 15/55] Final fixes --- installation/components/setup_hifiberry.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 2f19c2c97..1da4cc5a3 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -10,7 +10,7 @@ if [ "$(is_root)" = false ]; then exit 1 fi -boot_config_path=get_boot_config_path +boot_config_path=$(get_boot_config_path) if [ "$boot_config_path" = "unknown" ]; then echo "ERROR: It seems you are not running Raspian OS." exit 1 @@ -27,17 +27,14 @@ check_existing_hifiberry() { existing_config=$(grep 'dtoverlay=hifiberry-' "$boot_config_path") if [ ! -z "$existing_config" ]; then echo "Existing HiFiBerry configuration detected: $existing_config" - read -p "Do you want to proceed with a new configuration? This will remove the existing one. (y/n): " yn + read -p "Do you want to proceed with a new configuration? This will remove the existing one. (Y/n): " yn case $yn in - [Yy]* ) + [yY][eE][sS]|[yY]) remove_existing_hifiberry; return 0;; - [Nn]* ) + *) echo "Exiting without making changes."; exit;; - * ) - echo "Please answer yes or no."; - check_existing_hifiberry;; esac fi } From 9cebeaafa21298edeba78039290d6e953fd8f350 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 2 Jan 2024 23:58:27 +0100 Subject: [PATCH 16/55] Optimize case --- documentation/builders/components/soundcards/hifiberry.md | 2 +- installation/components/setup_hifiberry.sh | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md index a0afa8206..d1ce81b9b 100644 --- a/documentation/builders/components/soundcards/hifiberry.md +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -5,7 +5,7 @@ Run the following command to install any HiFiBerry board. Make sure you reboot your device afterwards. ``` -$ cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh && sudo -E ./setup_hifiberry.sh +cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh && sudo -E ./setup_hifiberry.sh ``` Optional: You can register your sound card with ALSA. Define the following variable before running the script: `CONFIGURE_ALSA=true` diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 1da4cc5a3..264c1cfa3 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -29,12 +29,12 @@ check_existing_hifiberry() { echo "Existing HiFiBerry configuration detected: $existing_config" read -p "Do you want to proceed with a new configuration? This will remove the existing one. (Y/n): " yn case $yn in - [yY][eE][sS]|[yY]) - remove_existing_hifiberry; - return 0;; - *) + [nN][oO]|[nN]) echo "Exiting without making changes."; exit;; + *) + remove_existing_hifiberry; + return 0;; esac fi } From 348413cac590ae2f1c4d1fceb7cb96f08f57c229 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 3 Jan 2024 00:03:51 +0100 Subject: [PATCH 17/55] Update docs --- documentation/builders/components/soundcards/hifiberry.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md index d1ce81b9b..4caf2222b 100644 --- a/documentation/builders/components/soundcards/hifiberry.md +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -1,5 +1,7 @@ # HiFiBerry +The installation script works for the most common set of HiFiBerry boards but also other "DAC" related sound cards like `I2S PCM5102A DAC`. + ## Automatic setup Run the following command to install any HiFiBerry board. Make sure you reboot your device afterwards. @@ -8,7 +10,8 @@ Run the following command to install any HiFiBerry board. Make sure you reboot y cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh && sudo -E ./setup_hifiberry.sh ``` -Optional: You can register your sound card with ALSA. Define the following variable before running the script: `CONFIGURE_ALSA=true` +> [!NOTE] +> **Optional**: You can register your sound card with ALSA. Define the following variable before running the script: `CONFIGURE_ALSA=true` ## Additional information From 56cddb72d3445d78205995a9cd3982e77d08fe47 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Thu, 11 Jan 2024 23:16:20 +0100 Subject: [PATCH 18/55] Uninstall option --- installation/components/setup_hifiberry.sh | 29 +++++++++------------- installation/includes/02_helpers.sh | 14 +++-------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 264c1cfa3..98a8786ee 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -5,22 +5,15 @@ source ../includes/02_helpers.sh -if [ "$(is_root)" = false ]; then - echo "ERROR: This script must be run as root" - exit 1 -fi - boot_config_path=$(get_boot_config_path) -if [ "$boot_config_path" = "unknown" ]; then - echo "ERROR: It seems you are not running Raspian OS." - exit 1 -fi +asound_conf_path="/etc/asound.conf" remove_existing_hifiberry() { echo "Removing existing HiFiBerry configuration..." sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path" + mv "$asound_conf_path" "/etc/asound.conf.bak" } check_existing_hifiberry() { @@ -57,8 +50,9 @@ Select your HiFiBerry board: 6) HiFiBerry Digi+ 7) HiFiBerry Digi+ Pro 8) HiFiBerry Amp+ (not Amp2) -9) HiFiBerry Amp3" -read -p "Enter your choice (1-9): " choice +9) HiFiBerry Amp3 +0) Disable HiFiBerry sound card" +read -p "Enter your choice (0-9): " choice # Enable selected HiFiBerry board case $choice in @@ -71,11 +65,12 @@ case $choice in 7) enable_hifiberry "hifiberry-digi-pro";; 8) enable_hifiberry "hifiberry-amp";; 9) enable_hifiberry "hifiberry-amp3";; + 9) remove_existing_hifiberry;; *) echo "Invalid selection. Exiting."; exit 1;; esac echo "Disabling onboard sound..." -sed -i '/dtparam=audio=on/c\dtparam=audio=off' "$boot_config_path" +sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(on\|true\|yes\|1\)\(.*\)/\1audio=off\4/g" "$boot_config_path" if grep -qx 'dtoverlay=vc4-fkms-v3d' "$boot_config_path"; then echo "Disabling audio in vc4-fkms-v3d overlay..." @@ -91,18 +86,18 @@ if [ -z "${CONFIGURE_ALSA}" ]; then echo "CONFIGURE_ALSA not set. Skipping configuration of sound settings in asound.conf." else if [ "${CONFIGURE_ALSA}" == "true" ]; then - if [ -f /etc/asound.conf ]; then + if [ -f "$asound_conf_path" ]; then echo "Backing up existing asound.conf..." - cp /etc/asound.conf "/etc/asound.conf.backup.$(date +%Y%m%d%H%M%S)" + cp "$asound_conf_path" "/etc/asound.conf.bak" fi card_id=$(cat /proc/asound/cards | grep -oP '(?<=^ )\d+(?= \[sndrpihifiberry\]:)' | head -n 1) if [ -z "$card_id" ]; then - echo " Error: Could not find HifiBerry sound card in /etc/asound.conf." + echo "Error: Could not find HifiBerry sound card in $asound_conf_path." else - echo "Configuring sound settings in asound.conf..." - cat > /etc/asound.conf << EOF + echo "Configuring sound settings in $asound_conf_path..." + cat > "$asound_conf_path" << EOF pcm.hifiberry { type softvol slave.pcm "plughw:$card_id" diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index c6ad01cea..aa33adf5a 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -34,14 +34,6 @@ run_with_log_frame() { log "#########################################################" } -is_root() { - if [ "$(id -u)" != "0" ]; then - echo false - else - echo true - fi -} - get_architecture() { local arch="" if [ "$(uname -m)" = "armv7l" ]; then @@ -58,7 +50,7 @@ get_architecture() { } is_raspian() { - if [[ $(lsb_release -d 2>/dev/null) == *"Raspbian"* ]]; then + if [[ $( . /etc/os-release; printf '%s\n' "$ID"; ) == *"raspbian"* ]]; then echo true else echo false @@ -67,7 +59,7 @@ is_raspian() { get_debian_version() { # Read the major version number from /etc/debian_version - local major_version=$(cut -d. -f1 /etc/debian_version) + local major_version="$( . /etc/os-release; printf '%s\n' "$VERSION_CODENAME"; )" case $major_version in 11) @@ -84,7 +76,7 @@ get_debian_version() { get_boot_config_path() { if [ "$(is_raspian)" = true ]; then - local debian_version=get_debian_version + local debian_version=$(get_debian_version) if [ "$debian_version" = "bookworm" ]; then echo "/boot/firmware/config.txt" From 2cf551674f39cd0b7f229aea7077975ea4b057ed Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Thu, 11 Jan 2024 23:20:15 +0100 Subject: [PATCH 19/55] fix: Remove option was not reachable --- installation/components/setup_hifiberry.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 98a8786ee..c2bdd224e 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -65,7 +65,7 @@ case $choice in 7) enable_hifiberry "hifiberry-digi-pro";; 8) enable_hifiberry "hifiberry-amp";; 9) enable_hifiberry "hifiberry-amp3";; - 9) remove_existing_hifiberry;; + 0) remove_existing_hifiberry;; *) echo "Invalid selection. Exiting."; exit 1;; esac From 1679be2f11497bcbb754a2c4ba8199c93ce4f2cd Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Thu, 11 Jan 2024 23:25:04 +0100 Subject: [PATCH 20/55] fix: enable sudo --- installation/components/setup_hifiberry.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index c2bdd224e..0e4109075 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -10,9 +10,9 @@ asound_conf_path="/etc/asound.conf" remove_existing_hifiberry() { echo "Removing existing HiFiBerry configuration..." - sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" - sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" - sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path" + sudo sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" + sudo sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" + sudo sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path" mv "$asound_conf_path" "/etc/asound.conf.bak" } @@ -70,16 +70,16 @@ case $choice in esac echo "Disabling onboard sound..." -sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(on\|true\|yes\|1\)\(.*\)/\1audio=off\4/g" "$boot_config_path" +sudo sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(on\|true\|yes\|1\)\(.*\)/\1audio=off\4/g" "$boot_config_path" if grep -qx 'dtoverlay=vc4-fkms-v3d' "$boot_config_path"; then echo "Disabling audio in vc4-fkms-v3d overlay..." - sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' "$boot_config_path" + sudo sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' "$boot_config_path" fi if grep -qx 'dtoverlay=vc4-kms-v3d' "$boot_config_path"; then echo "Disabling audio in vc4-kms-v3d overlay..." - sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' "$boot_config_path" + sudo sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' "$boot_config_path" fi if [ -z "${CONFIGURE_ALSA}" ]; then From 240a9387d66c6a65db849a72a24c4cfb13366981 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Thu, 11 Jan 2024 23:40:53 +0100 Subject: [PATCH 21/55] fix: make I/O fail silently --- installation/components/setup_hifiberry.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 0e4109075..ddc3591e4 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -13,7 +13,7 @@ remove_existing_hifiberry() { sudo sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" sudo sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" sudo sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path" - mv "$asound_conf_path" "/etc/asound.conf.bak" + mv -f "$asound_conf_path" "/etc/asound.conf.bak" 2>/dev/null } check_existing_hifiberry() { @@ -65,7 +65,9 @@ case $choice in 7) enable_hifiberry "hifiberry-digi-pro";; 8) enable_hifiberry "hifiberry-amp";; 9) enable_hifiberry "hifiberry-amp3";; - 0) remove_existing_hifiberry;; + 0) + remove_existing_hifiberry; + exit 1;; *) echo "Invalid selection. Exiting."; exit 1;; esac @@ -88,7 +90,7 @@ else if [ "${CONFIGURE_ALSA}" == "true" ]; then if [ -f "$asound_conf_path" ]; then echo "Backing up existing asound.conf..." - cp "$asound_conf_path" "/etc/asound.conf.bak" + cp -f "$asound_conf_path" "/etc/asound.conf.bak" fi card_id=$(cat /proc/asound/cards | grep -oP '(?<=^ )\d+(?= \[sndrpihifiberry\]:)' | head -n 1) From f3e0bb832d1df8af8bac2c9538934bba8587ba48 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 16:34:05 +0100 Subject: [PATCH 22/55] feat: Introduce 1-line installation --- installation/components/setup_hifiberry.sh | 87 +++++++++++++++------- 1 file changed, 60 insertions(+), 27 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index ddc3591e4..9b4070201 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -5,10 +5,53 @@ source ../includes/02_helpers.sh +script_name=$(basename "$0") + +declare -A hifiberry_map=( + ["hifiberry-dac"]="DAC (HiFiBerry MiniAmp, I2S PCM5102A DAC)" + ["hifiberry-dacplus"]="HiFiBerry DAC+ Standard/Pro/Amp2" + ["hifiberry-dacplushd"]="HiFiBerry DAC2 HD" + ["hifiberry-dacplusadc"]="HiFiBerry DAC+ ADC" + ["hifiberry-dacplusadcpro"]="HiFiBerry DAC+ ADC Pro" + ["hifiberry-digi"]="HiFiBerry Digi+" + ["hifiberry-digi-pro"]="HiFiBerry Digi+ Pro" + ["hifiberry-amp"]="HiFiBerry Amp+ (not Amp2)" + ["hifiberry-amp3"]="HiFiBerry Amp3" +) + +# 1-line installation +if [ $# -ge 1 ]; + if { ([ "$1" != "enable" ] && [ "$1" != "disable" ]) || ([ "$1" -= "enable" ] && [ $# -ge 2 ]); } + echo "Error: Invalid provided. +Usage: ./${script_name} [optional] +where can be 'enable' or 'disable'" + exit 1 + fi + + if [ "$1" != "enable" ]; + case "$2" in + "${hifiberry_list[@]}") + echo "Variable is in the list." + ;; + *) + echo "'$2' is not a valid option. You can choose from:" + for key in "${!hifiberry_descriptions[@]}"; do + description="${hifiberry_descriptions[$key]}" + echo "$key) $description" + done + echo "Example usage: ./${script_name} enable hifiberry-dac" + ;; + esac + + + fi +fi + +# Guided installation boot_config_path=$(get_boot_config_path) asound_conf_path="/etc/asound.conf" -remove_existing_hifiberry() { +disable_hifiberry() { echo "Removing existing HiFiBerry configuration..." sudo sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" sudo sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" @@ -26,7 +69,7 @@ check_existing_hifiberry() { echo "Exiting without making changes."; exit;; *) - remove_existing_hifiberry; + disable_hifiberry; return 0;; esac fi @@ -40,35 +83,25 @@ enable_hifiberry() { check_existing_hifiberry # List of HiFiBerry boards -echo " -Select your HiFiBerry board: -1) DAC (HiFiBerry MiniAmp, I2S PCM5102A DAC) -2) HiFiBerry DAC+ Standard/Pro/Amp2 -3) HiFiBerry DAC2 HD -4) HiFiBerry DAC+ ADC -5) HiFiBerry DAC+ ADC Pro -6) HiFiBerry Digi+ -7) HiFiBerry Digi+ Pro -8) HiFiBerry Amp+ (not Amp2) -9) HiFiBerry Amp3 -0) Disable HiFiBerry sound card" +echo "Select your HiFiBerry board:" +for key in "${!hifiberry_descriptions[@]}"; do + description="${hifiberry_descriptions[$key]}" + echo "$key) $description" +done + read -p "Enter your choice (0-9): " choice -# Enable selected HiFiBerry board case $choice in - 1) enable_hifiberry "hifiberry-dac";; - 2) enable_hifiberry "hifiberry-dacplus";; - 3) enable_hifiberry "hifiberry-dacplushd";; - 4) enable_hifiberry "hifiberry-dacplusadc";; - 5) enable_hifiberry "hifiberry-dacplusadcpro";; - 6) enable_hifiberry "hifiberry-digi";; - 7) enable_hifiberry "hifiberry-digi-pro";; - 8) enable_hifiberry "hifiberry-amp";; - 9) enable_hifiberry "hifiberry-amp3";; - 0) - remove_existing_hifiberry; + [0]) + disable_hifiberry; + exit 1;; + [1-9]) + selected_board="${hifiberry_descriptions[$choice]}"; + enable_hifiberry "$selected_board"; + return 0;; + *) + echo "Invalid selection. Exiting."; exit 1;; - *) echo "Invalid selection. Exiting."; exit 1;; esac echo "Disabling onboard sound..." From 0aa34adac49098d7d51510fe6bc98ee71d40e680 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 16:55:49 +0100 Subject: [PATCH 23/55] feat: outsource onboard_sound as its own option --- installation/components/setup_hifiberry.sh | 116 ++++++++++----------- installation/options/onboard_sound.sh | 33 ++++++ 2 files changed, 86 insertions(+), 63 deletions(-) create mode 100644 installation/options/onboard_sound.sh diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 9b4070201..f2a50830f 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -6,7 +6,6 @@ source ../includes/02_helpers.sh script_name=$(basename "$0") - declare -A hifiberry_map=( ["hifiberry-dac"]="DAC (HiFiBerry MiniAmp, I2S PCM5102A DAC)" ["hifiberry-dacplus"]="HiFiBerry DAC+ Standard/Pro/Amp2" @@ -42,8 +41,6 @@ where can be 'enable' or 'disable'" echo "Example usage: ./${script_name} enable hifiberry-dac" ;; esac - - fi fi @@ -51,11 +48,15 @@ fi boot_config_path=$(get_boot_config_path) asound_conf_path="/etc/asound.conf" +enable_hifiberry() { + echo "Enabling HiFiBerry board..." + grep -qxF "dtoverlay=$1" "$boot_config_path" || echo "dtoverlay=$1" >> "$boot_config_path" +} + disable_hifiberry() { echo "Removing existing HiFiBerry configuration..." - sudo sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" - sudo sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" - sudo sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path" + ./../options/onboard_sound.sh enable + echo "Moving potential ${asound_conf_path} to /etc/asound.conf.bak" mv -f "$asound_conf_path" "/etc/asound.conf.bak" 2>/dev/null } @@ -75,64 +76,46 @@ check_existing_hifiberry() { fi } -enable_hifiberry() { - echo "Enabling HiFiBerry board..." - grep -qxF "dtoverlay=$1" "$boot_config_path" || echo "dtoverlay=$1" >> "$boot_config_path" +prompt_board_list() { + echo "Select your HiFiBerry board:" + for key in "${!hifiberry_descriptions[@]}"; do + description="${hifiberry_descriptions[$key]}" + echo "$key) $description" + done + + read -p "Enter your choice (0-9): " choice + + case $choice in + [0]) + disable_hifiberry; + exit 1;; + [1-9]) + selected_board="${hifiberry_descriptions[$choice]}"; + enable_hifiberry "$selected_board"; + return 0;; + *) + echo "Invalid selection. Exiting."; + exit 1;; + esac } -check_existing_hifiberry - -# List of HiFiBerry boards -echo "Select your HiFiBerry board:" -for key in "${!hifiberry_descriptions[@]}"; do - description="${hifiberry_descriptions[$key]}" - echo "$key) $description" -done - -read -p "Enter your choice (0-9): " choice - -case $choice in - [0]) - disable_hifiberry; - exit 1;; - [1-9]) - selected_board="${hifiberry_descriptions[$choice]}"; - enable_hifiberry "$selected_board"; - return 0;; - *) - echo "Invalid selection. Exiting."; - exit 1;; -esac - -echo "Disabling onboard sound..." -sudo sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(on\|true\|yes\|1\)\(.*\)/\1audio=off\4/g" "$boot_config_path" - -if grep -qx 'dtoverlay=vc4-fkms-v3d' "$boot_config_path"; then - echo "Disabling audio in vc4-fkms-v3d overlay..." - sudo sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' "$boot_config_path" -fi - -if grep -qx 'dtoverlay=vc4-kms-v3d' "$boot_config_path"; then - echo "Disabling audio in vc4-kms-v3d overlay..." - sudo sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' "$boot_config_path" -fi - -if [ -z "${CONFIGURE_ALSA}" ]; then - echo "CONFIGURE_ALSA not set. Skipping configuration of sound settings in asound.conf." -else - if [ "${CONFIGURE_ALSA}" == "true" ]; then - if [ -f "$asound_conf_path" ]; then - echo "Backing up existing asound.conf..." - cp -f "$asound_conf_path" "/etc/asound.conf.bak" - fi - - card_id=$(cat /proc/asound/cards | grep -oP '(?<=^ )\d+(?= \[sndrpihifiberry\]:)' | head -n 1) - - if [ -z "$card_id" ]; then - echo "Error: Could not find HifiBerry sound card in $asound_conf_path." - else - echo "Configuring sound settings in $asound_conf_path..." - cat > "$asound_conf_path" << EOF +setup_alsa() { + if [ -z "${CONFIGURE_ALSA}" ]; then + echo "CONFIGURE_ALSA not set. Skipping configuration of sound settings in asound.conf." + else + if [ "${CONFIGURE_ALSA}" == "true" ]; then + if [ -f "$asound_conf_path" ]; then + echo "Backing up existing asound.conf..." + cp -f "$asound_conf_path" "/etc/asound.conf.bak" + fi + + card_id=$(cat /proc/asound/cards | grep -oP '(?<=^ )\d+(?= \[sndrpihifiberry\]:)' | head -n 1) + + if [ -z "$card_id" ]; then + echo "Error: Could not find HifiBerry sound card in $asound_conf_path." + else + echo "Configuring sound settings in $asound_conf_path..." + cat > "$asound_conf_path" << EOF pcm.hifiberry { type softvol slave.pcm "plughw:$card_id" @@ -145,8 +128,15 @@ pcm.!default { slave.pcm "hifiberry" } EOF + fi fi fi -fi +} + +# Execute program +check_existing_hifiberry +prompt_board_list +./../options/onboard_sound.sh disable +setup_alsa echo "Configuration complete. Please restart your device." diff --git a/installation/options/onboard_sound.sh b/installation/options/onboard_sound.sh new file mode 100644 index 000000000..a8acdcbc8 --- /dev/null +++ b/installation/options/onboard_sound.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +source ../includes/02_helpers.sh +script_name=$(basename "$0") +boot_config_path=$(get_boot_config_path) + +if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then + echo "Error: Invalid or no argument provided. +Usage: ./${script_name} + where can be 'enable' or 'disable'" + exit 1 +fi + +arg="$1" + +if [ "$arg" = "enable" ]; then + echo "Enabling Onboard Sound..." + sudo sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" + sudo sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" + sudo sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path" +elif [ "$arg" = "disable" ]; then + echo "Disabling Onboard Sound..." + sudo sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(on\|true\|yes\|1\)\(.*\)/\1audio=off\4/g" "$boot_config_path" + + if grep -qx 'dtoverlay=vc4-fkms-v3d' "$boot_config_path"; then + sudo sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' "$boot_config_path" + fi + + if grep -qx 'dtoverlay=vc4-kms-v3d' "$boot_config_path"; then + sudo sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' "$boot_config_path" + fi +fi + +# TODO Test From 251224a7ab637488912e29f23cc9dd261e5b4421 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 16:59:43 +0100 Subject: [PATCH 24/55] refactor: remove alsa config --- installation/components/setup_hifiberry.sh | 35 ---------------------- 1 file changed, 35 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index f2a50830f..bf07484d5 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -99,44 +99,9 @@ prompt_board_list() { esac } -setup_alsa() { - if [ -z "${CONFIGURE_ALSA}" ]; then - echo "CONFIGURE_ALSA not set. Skipping configuration of sound settings in asound.conf." - else - if [ "${CONFIGURE_ALSA}" == "true" ]; then - if [ -f "$asound_conf_path" ]; then - echo "Backing up existing asound.conf..." - cp -f "$asound_conf_path" "/etc/asound.conf.bak" - fi - - card_id=$(cat /proc/asound/cards | grep -oP '(?<=^ )\d+(?= \[sndrpihifiberry\]:)' | head -n 1) - - if [ -z "$card_id" ]; then - echo "Error: Could not find HifiBerry sound card in $asound_conf_path." - else - echo "Configuring sound settings in $asound_conf_path..." - cat > "$asound_conf_path" << EOF -pcm.hifiberry { - type softvol - slave.pcm "plughw:$card_id" - control.name "HifiBerry" - control.card $card_id -} - -pcm.!default { - type plug - slave.pcm "hifiberry" -} -EOF - fi - fi - fi -} - # Execute program check_existing_hifiberry prompt_board_list ./../options/onboard_sound.sh disable -setup_alsa echo "Configuration complete. Please restart your device." From 3abef5fb6379a9d471048f4e2d3b4017654e5eb1 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 17:04:56 +0100 Subject: [PATCH 25/55] fix: update case function --- installation/components/setup_hifiberry.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index bf07484d5..689c9a779 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -29,9 +29,8 @@ where can be 'enable' or 'disable'" if [ "$1" != "enable" ]; case "$2" in - "${hifiberry_list[@]}") - echo "Variable is in the list." - ;; + "${hifiberry_map[@]}") + return 0;; *) echo "'$2' is not a valid option. You can choose from:" for key in "${!hifiberry_descriptions[@]}"; do @@ -39,6 +38,7 @@ where can be 'enable' or 'disable'" echo "$key) $description" done echo "Example usage: ./${script_name} enable hifiberry-dac" + exit 1 ;; esac fi From 61aa460bf64645a9794cdba5fc7ef4edb2f403b8 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 18:10:50 +0100 Subject: [PATCH 26/55] fix: adding some thens --- installation/components/setup_hifiberry.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 689c9a779..1b299cc00 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -19,15 +19,15 @@ declare -A hifiberry_map=( ) # 1-line installation -if [ $# -ge 1 ]; - if { ([ "$1" != "enable" ] && [ "$1" != "disable" ]) || ([ "$1" -= "enable" ] && [ $# -ge 2 ]); } +if [ $# -ge 1 ]; then + if { ([ "$1" != "enable" ] && [ "$1" != "disable" ]) || ([ "$1" -= "enable" ] && [ $# -ge 2 ]); }; then echo "Error: Invalid provided. Usage: ./${script_name} [optional] where can be 'enable' or 'disable'" exit 1 fi - if [ "$1" != "enable" ]; + if [ "$1" != "enable" ]; then case "$2" in "${hifiberry_map[@]}") return 0;; From ee0c47c3ff329f0a9748366715a8a615c9564a19 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 18:21:59 +0100 Subject: [PATCH 27/55] fix: some iterations did not work --- installation/components/setup_hifiberry.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 1b299cc00..8d4139bc0 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -33,8 +33,8 @@ where can be 'enable' or 'disable'" return 0;; *) echo "'$2' is not a valid option. You can choose from:" - for key in "${!hifiberry_descriptions[@]}"; do - description="${hifiberry_descriptions[$key]}" + for key in "${!hifiberry_map[@]}"; do + description="${hifiberry_map[$key]}" echo "$key) $description" done echo "Example usage: ./${script_name} enable hifiberry-dac" @@ -77,20 +77,24 @@ check_existing_hifiberry() { } prompt_board_list() { + board_count=${#hifiberry_map[@]} + + counter=1 echo "Select your HiFiBerry board:" - for key in "${!hifiberry_descriptions[@]}"; do - description="${hifiberry_descriptions[$key]}" - echo "$key) $description" + for key in "${!hifiberry_map[@]}"; do + description="${hifiberry_map[$key]}" + echo "$counter) $description" + ((counter++)) done - read -p "Enter your choice (0-9): " choice + read -p "Enter your choice (1-$board_count): " choice case $choice in [0]) disable_hifiberry; exit 1;; - [1-9]) - selected_board="${hifiberry_descriptions[$choice]}"; + [1-$board_count]) + selected_board="${hifiberry_map[$choice]}"; enable_hifiberry "$selected_board"; return 0;; *) From 165e07ed098643e04b39f497e4709fa4984bce5b Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 18:34:28 +0100 Subject: [PATCH 28/55] fix: adding another sudo --- installation/components/setup_hifiberry.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 8d4139bc0..a674a5a73 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -50,7 +50,7 @@ asound_conf_path="/etc/asound.conf" enable_hifiberry() { echo "Enabling HiFiBerry board..." - grep -qxF "dtoverlay=$1" "$boot_config_path" || echo "dtoverlay=$1" >> "$boot_config_path" + grep -qxF "dtoverlay=$1" "$boot_config_path" || sudo echo "dtoverlay=$1" >> "$boot_config_path" } disable_hifiberry() { From dc892688a2ea6308d8ab439fe35712669127cfd8 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 18:45:29 +0100 Subject: [PATCH 29/55] refactor: get_key_by_item_number for associated arrays --- installation/components/setup_hifiberry.sh | 2 +- installation/includes/02_helpers.sh | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index a674a5a73..def1b9af7 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -94,7 +94,7 @@ prompt_board_list() { disable_hifiberry; exit 1;; [1-$board_count]) - selected_board="${hifiberry_map[$choice]}"; + selected_board=$(get_key_by_item_number hifiberry_map "$choice") enable_hifiberry "$selected_board"; return 0;; *) diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index aa33adf5a..e362f2f26 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -2,6 +2,21 @@ ### Helpers +# Get key by item number of associated array +get_key_by_item_number() { + local -n array="$1" + local item_number="$2" + local count=0 + + for key in "${!array[@]}"; do + ((count++)) + if [ "$count" -eq "$item_number" ]; then + echo "$key" + return + fi + done +} + # $1->start, $2->end calc_runtime_and_print() { runtime=$(($2-$1)) From 7758da6434ea9b3e1a54cafd1965f3317f4888b7 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 18:49:46 +0100 Subject: [PATCH 30/55] refactor: remove last bits of alsa --- installation/components/setup_hifiberry.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index def1b9af7..58ceddb08 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -46,7 +46,6 @@ fi # Guided installation boot_config_path=$(get_boot_config_path) -asound_conf_path="/etc/asound.conf" enable_hifiberry() { echo "Enabling HiFiBerry board..." @@ -56,8 +55,6 @@ enable_hifiberry() { disable_hifiberry() { echo "Removing existing HiFiBerry configuration..." ./../options/onboard_sound.sh enable - echo "Moving potential ${asound_conf_path} to /etc/asound.conf.bak" - mv -f "$asound_conf_path" "/etc/asound.conf.bak" 2>/dev/null } check_existing_hifiberry() { From cda18f9de3af04a1b7e0140b2a952d9bf7902b1d Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 18:53:24 +0100 Subject: [PATCH 31/55] fix: final touches --- installation/components/setup_hifiberry.sh | 9 +++++---- installation/options/onboard_sound.sh | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 58ceddb08..29ccc9b64 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -50,10 +50,12 @@ boot_config_path=$(get_boot_config_path) enable_hifiberry() { echo "Enabling HiFiBerry board..." grep -qxF "dtoverlay=$1" "$boot_config_path" || sudo echo "dtoverlay=$1" >> "$boot_config_path" + ./../options/onboard_sound.sh disable } disable_hifiberry() { echo "Removing existing HiFiBerry configuration..." + sudo sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" ./../options/onboard_sound.sh enable } @@ -73,7 +75,7 @@ check_existing_hifiberry() { fi } -prompt_board_list() { +main() { board_count=${#hifiberry_map[@]} counter=1 @@ -91,6 +93,7 @@ prompt_board_list() { disable_hifiberry; exit 1;; [1-$board_count]) + check_existing_hifiberry selected_board=$(get_key_by_item_number hifiberry_map "$choice") enable_hifiberry "$selected_board"; return 0;; @@ -101,8 +104,6 @@ prompt_board_list() { } # Execute program -check_existing_hifiberry -prompt_board_list -./../options/onboard_sound.sh disable +main echo "Configuration complete. Please restart your device." diff --git a/installation/options/onboard_sound.sh b/installation/options/onboard_sound.sh index a8acdcbc8..b8b087883 100644 --- a/installation/options/onboard_sound.sh +++ b/installation/options/onboard_sound.sh @@ -14,7 +14,6 @@ arg="$1" if [ "$arg" = "enable" ]; then echo "Enabling Onboard Sound..." - sudo sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" sudo sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" sudo sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path" elif [ "$arg" = "disable" ]; then From 8e584b78b46a8fa7d8217a694ad42cda8b6c6ed7 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 18:57:36 +0100 Subject: [PATCH 32/55] fix: add missing removal only option --- installation/components/setup_hifiberry.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 29ccc9b64..ff4bffbd6 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -85,13 +85,14 @@ main() { echo "$counter) $description" ((counter++)) done + echo "0) Remove existing HiFiBerry configuration" read -p "Enter your choice (1-$board_count): " choice case $choice in [0]) disable_hifiberry; - exit 1;; + return 0;; [1-$board_count]) check_existing_hifiberry selected_board=$(get_key_by_item_number hifiberry_map "$choice") From 3740abbf39c2535146025f094ab586eeac5681c5 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 19:05:50 +0100 Subject: [PATCH 33/55] fix: outsource example_usage for 1-line install --- installation/components/setup_hifiberry.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index ff4bffbd6..a91b825fb 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -19,11 +19,20 @@ declare -A hifiberry_map=( ) # 1-line installation +example_usage() { + for key in "${!hifiberry_map[@]}"; do + description="${hifiberry_map[$key]}" + echo "$key) $description" + done + echo "Example usage: ./${script_name} enable hifiberry-dac" +} + if [ $# -ge 1 ]; then if { ([ "$1" != "enable" ] && [ "$1" != "disable" ]) || ([ "$1" -= "enable" ] && [ $# -ge 2 ]); }; then echo "Error: Invalid provided. -Usage: ./${script_name} [optional] +Usage: ./${script_name} where can be 'enable' or 'disable'" + example_usage exit 1 fi @@ -33,11 +42,7 @@ where can be 'enable' or 'disable'" return 0;; *) echo "'$2' is not a valid option. You can choose from:" - for key in "${!hifiberry_map[@]}"; do - description="${hifiberry_map[$key]}" - echo "$key) $description" - done - echo "Example usage: ./${script_name} enable hifiberry-dac" + example_usage exit 1 ;; esac From 35189e00338b5a1f5075050b183431c907f96c6e Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 23:38:50 +0100 Subject: [PATCH 34/55] fix: condition for 1-line installation --- installation/components/setup_hifiberry.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index a91b825fb..dd6aa0e96 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -28,7 +28,10 @@ example_usage() { } if [ $# -ge 1 ]; then - if { ([ "$1" != "enable" ] && [ "$1" != "disable" ]) || ([ "$1" -= "enable" ] && [ $# -ge 2 ]); }; then + $status="$1" + $board="$2" + + if [[ "$status" != "enable" && "$status" != "disable" ]] || [[ "$status" == "enable" && -z "$board" ]]; then echo "Error: Invalid provided. Usage: ./${script_name} where can be 'enable' or 'disable'" @@ -92,7 +95,7 @@ main() { done echo "0) Remove existing HiFiBerry configuration" - read -p "Enter your choice (1-$board_count): " choice + read -p "Enter your choice (0-$board_count): " choice case $choice in [0]) From fd67e1eb3442529dff3adaa7ef8e48b089602724 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 23:44:37 +0100 Subject: [PATCH 35/55] fix: another fix for if conditions --- installation/components/setup_hifiberry.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index dd6aa0e96..9258fbf92 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -28,13 +28,12 @@ example_usage() { } if [ $# -ge 1 ]; then - $status="$1" - $board="$2" - - if [[ "$status" != "enable" && "$status" != "disable" ]] || [[ "$status" == "enable" && -z "$board" ]]; then - echo "Error: Invalid provided. + if [[ "$1" != "enable" && "$1" != "disable" ]] || [[ "$1" == "enable" && -z $# -ge 2 ]]; then + echo "Error: Invalid arguments provided. Usage: ./${script_name} -where can be 'enable' or 'disable'" +where can be 'enable' or 'disable'. + +The following board options exist:" example_usage exit 1 fi From 00e03edfbe886f1258acafebd14adaff92892015 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 23:49:23 +0100 Subject: [PATCH 36/55] refactor: move 1-line installation down --- installation/components/setup_hifiberry.sh | 53 ++++++++++++---------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 9258fbf92..d15cc5476 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -27,30 +27,6 @@ example_usage() { echo "Example usage: ./${script_name} enable hifiberry-dac" } -if [ $# -ge 1 ]; then - if [[ "$1" != "enable" && "$1" != "disable" ]] || [[ "$1" == "enable" && -z $# -ge 2 ]]; then - echo "Error: Invalid arguments provided. -Usage: ./${script_name} -where can be 'enable' or 'disable'. - -The following board options exist:" - example_usage - exit 1 - fi - - if [ "$1" != "enable" ]; then - case "$2" in - "${hifiberry_map[@]}") - return 0;; - *) - echo "'$2' is not a valid option. You can choose from:" - example_usage - exit 1 - ;; - esac - fi -fi - # Guided installation boot_config_path=$(get_boot_config_path) @@ -112,6 +88,35 @@ main() { } # Execute program +if [ $# -ge 1 ]; then + if [[ "$1" != "enable" && "$1" != "disable" ]] || [[ "$1" == "enable" && -z $# -ge 2 ]]; then + echo "Error: Invalid arguments provided. +Usage: ./${script_name} +where can be 'enable' or 'disable'. + +The following board options exist:" + example_usage + exit 1 + fi + + if [ "$1" == "disable" ]; then + disable_hifiberry + exit 1 + fi + + if [ "$1" == "enable" ]; then + case "$2" in + "${hifiberry_map[@]}") + return 0;; + *) + echo "'$2' is not a valid option. You can choose from:" + example_usage + exit 1 + ;; + esac + fi +fi + main echo "Configuration complete. Please restart your device." From 4ff95a1c2a5e16a5693ad729495d368f68a82f5b Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 23:54:02 +0100 Subject: [PATCH 37/55] gs --- installation/components/setup_hifiberry.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index d15cc5476..981157696 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -89,7 +89,7 @@ main() { # Execute program if [ $# -ge 1 ]; then - if [[ "$1" != "enable" && "$1" != "disable" ]] || [[ "$1" == "enable" && -z $# -ge 2 ]]; then + if [[ "$1" != "enable" && "$1" != "disable" ]] || [[ "$1" == "enable" &&-z "$2" ]]; then echo "Error: Invalid arguments provided. Usage: ./${script_name} where can be 'enable' or 'disable'. @@ -99,11 +99,6 @@ The following board options exist:" exit 1 fi - if [ "$1" == "disable" ]; then - disable_hifiberry - exit 1 - fi - if [ "$1" == "enable" ]; then case "$2" in "${hifiberry_map[@]}") @@ -115,6 +110,11 @@ The following board options exist:" ;; esac fi + + if [ "$1" == "disable" ]; then + disable_hifiberry + exit 1 + fi fi main From 2434315b4c683587006d6767076d0731d0c4a8f7 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 12 Jan 2024 23:54:31 +0100 Subject: [PATCH 38/55] another fix --- installation/components/setup_hifiberry.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 981157696..c3440bf2b 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -89,7 +89,7 @@ main() { # Execute program if [ $# -ge 1 ]; then - if [[ "$1" != "enable" && "$1" != "disable" ]] || [[ "$1" == "enable" &&-z "$2" ]]; then + if [[ "$1" != "enable" && "$1" != "disable" ]] || [[ "$1" == "enable" && -z "$2" ]]; then echo "Error: Invalid arguments provided. Usage: ./${script_name} where can be 'enable' or 'disable'. From 38797d21793ad1b30c4d08f0dbf15d3c416e6f76 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sat, 13 Jan 2024 00:06:44 +0100 Subject: [PATCH 39/55] fix: write array check differently --- installation/components/setup_hifiberry.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index c3440bf2b..1134695b7 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -6,6 +6,8 @@ source ../includes/02_helpers.sh script_name=$(basename "$0") +boot_config_path=$(get_boot_config_path) + declare -A hifiberry_map=( ["hifiberry-dac"]="DAC (HiFiBerry MiniAmp, I2S PCM5102A DAC)" ["hifiberry-dacplus"]="HiFiBerry DAC+ Standard/Pro/Amp2" @@ -18,7 +20,6 @@ declare -A hifiberry_map=( ["hifiberry-amp3"]="HiFiBerry Amp3" ) -# 1-line installation example_usage() { for key in "${!hifiberry_map[@]}"; do description="${hifiberry_map[$key]}" @@ -27,9 +28,6 @@ example_usage() { echo "Example usage: ./${script_name} enable hifiberry-dac" } -# Guided installation -boot_config_path=$(get_boot_config_path) - enable_hifiberry() { echo "Enabling HiFiBerry board..." grep -qxF "dtoverlay=$1" "$boot_config_path" || sudo echo "dtoverlay=$1" >> "$boot_config_path" @@ -87,7 +85,7 @@ main() { esac } -# Execute program +# 1-line installation if [ $# -ge 1 ]; then if [[ "$1" != "enable" && "$1" != "disable" ]] || [[ "$1" == "enable" && -z "$2" ]]; then echo "Error: Invalid arguments provided. @@ -100,15 +98,14 @@ The following board options exist:" fi if [ "$1" == "enable" ]; then - case "$2" in - "${hifiberry_map[@]}") + if [[ -v hifiberry_map["$2"] ]]; then return 0;; - *) + else echo "'$2' is not a valid option. You can choose from:" example_usage exit 1 ;; - esac + fi fi if [ "$1" == "disable" ]; then @@ -117,6 +114,7 @@ The following board options exist:" fi fi +# Guided installation main echo "Configuration complete. Please restart your device." From cd31cf5dab8545604fff68567714522dd9412a71 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sat, 13 Jan 2024 00:15:59 +0100 Subject: [PATCH 40/55] refactor: final touches --- installation/components/setup_hifiberry.sh | 66 ++++++++++------------ 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 1134695b7..542956705 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -56,35 +56,6 @@ check_existing_hifiberry() { fi } -main() { - board_count=${#hifiberry_map[@]} - - counter=1 - echo "Select your HiFiBerry board:" - for key in "${!hifiberry_map[@]}"; do - description="${hifiberry_map[$key]}" - echo "$counter) $description" - ((counter++)) - done - echo "0) Remove existing HiFiBerry configuration" - - read -p "Enter your choice (0-$board_count): " choice - - case $choice in - [0]) - disable_hifiberry; - return 0;; - [1-$board_count]) - check_existing_hifiberry - selected_board=$(get_key_by_item_number hifiberry_map "$choice") - enable_hifiberry "$selected_board"; - return 0;; - *) - echo "Invalid selection. Exiting."; - exit 1;; - esac -} - # 1-line installation if [ $# -ge 1 ]; then if [[ "$1" != "enable" && "$1" != "disable" ]] || [[ "$1" == "enable" && -z "$2" ]]; then @@ -99,13 +70,13 @@ The following board options exist:" if [ "$1" == "enable" ]; then if [[ -v hifiberry_map["$2"] ]]; then - return 0;; - else - echo "'$2' is not a valid option. You can choose from:" - example_usage + enable_hifiberry "$2" exit 1 - ;; fi + + echo "'$2' is not a valid option. You can choose from:" + example_usage + exit 1 fi if [ "$1" == "disable" ]; then @@ -115,6 +86,31 @@ The following board options exist:" fi # Guided installation -main +board_count=${#hifiberry_map[@]} +counter=1 + +echo "Select your HiFiBerry board:" +for key in "${!hifiberry_map[@]}"; do + description="${hifiberry_map[$key]}" + echo "$counter) $description" + ((counter++)) +done +echo "0) Remove existing HiFiBerry configuration" + +read -p "Enter your choice (0-$board_count): " choice + +case $choice in + [0]) + disable_hifiberry; + return 0;; + [1-$board_count]) + check_existing_hifiberry + selected_board=$(get_key_by_item_number hifiberry_map "$choice") + enable_hifiberry "$selected_board"; + return 0;; + *) + echo "Invalid selection. Exiting."; + exit 1;; +esac echo "Configuration complete. Please restart your device." From 8e0707f0983293e7ec9317291b634baaaac999a0 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sat, 13 Jan 2024 00:26:21 +0100 Subject: [PATCH 41/55] feat: enable silent mode for check_existing_hifiberry --- installation/components/setup_hifiberry.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 542956705..6dd6e269d 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -43,6 +43,11 @@ disable_hifiberry() { check_existing_hifiberry() { existing_config=$(grep 'dtoverlay=hifiberry-' "$boot_config_path") if [ ! -z "$existing_config" ]; then + if [ "$1" = "silent" ]; then + disable_hifiberry + return 0 + fi + echo "Existing HiFiBerry configuration detected: $existing_config" read -p "Do you want to proceed with a new configuration? This will remove the existing one. (Y/n): " yn case $yn in @@ -70,6 +75,7 @@ The following board options exist:" if [ "$1" == "enable" ]; then if [[ -v hifiberry_map["$2"] ]]; then + check_existing_hifiberry "silent" enable_hifiberry "$2" exit 1 fi @@ -79,10 +85,8 @@ The following board options exist:" exit 1 fi - if [ "$1" == "disable" ]; then - disable_hifiberry - exit 1 - fi + disable_hifiberry + exit 1 fi # Guided installation @@ -102,12 +106,10 @@ read -p "Enter your choice (0-$board_count): " choice case $choice in [0]) disable_hifiberry; - return 0;; [1-$board_count]) check_existing_hifiberry selected_board=$(get_key_by_item_number hifiberry_map "$choice") enable_hifiberry "$selected_board"; - return 0;; *) echo "Invalid selection. Exiting."; exit 1;; From b66c430dda9c901f404e7629e6ee6747b256a81b Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sat, 13 Jan 2024 00:32:22 +0100 Subject: [PATCH 42/55] fix: reintroduce sudo check --- installation/components/setup_hifiberry.sh | 7 +++++++ installation/includes/02_helpers.sh | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 6dd6e269d..85e4f8213 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -5,6 +5,11 @@ source ../includes/02_helpers.sh +if [ "$(is_sudo)" = false ]; then + echo "ERROR: This script must be run as root" + exit 1 +fi + script_name=$(basename "$0") boot_config_path=$(get_boot_config_path) @@ -106,10 +111,12 @@ read -p "Enter your choice (0-$board_count): " choice case $choice in [0]) disable_hifiberry; + ;; [1-$board_count]) check_existing_hifiberry selected_board=$(get_key_by_item_number hifiberry_map "$choice") enable_hifiberry "$selected_board"; + ;; *) echo "Invalid selection. Exiting."; exit 1;; diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index e362f2f26..83bab7276 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -49,6 +49,14 @@ run_with_log_frame() { log "#########################################################" } +is_sudo() { + if [ "$(id -u)" != "0" ]; then + echo false + else + echo true + fi +} + get_architecture() { local arch="" if [ "$(uname -m)" = "armv7l" ]; then From 3e217cccabd82fdef49c55cba6fbd717417dcb51 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sat, 13 Jan 2024 00:49:56 +0100 Subject: [PATCH 43/55] fix: documentation --- .../builders/components/soundcards/hifiberry.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md index 4caf2222b..03465beef 100644 --- a/documentation/builders/components/soundcards/hifiberry.md +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -7,11 +7,22 @@ The installation script works for the most common set of HiFiBerry boards but al Run the following command to install any HiFiBerry board. Make sure you reboot your device afterwards. ``` -cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh && sudo -E ./setup_hifiberry.sh +cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh +sudo ./setup_hifiberry.sh ``` -> [!NOTE] -> **Optional**: You can register your sound card with ALSA. Define the following variable before running the script: `CONFIGURE_ALSA=true` +If you know you HifiBerry Board identifier, you can run the script as a 1-liner as well + +``` +sudo ./setup_hifiberry.sh enable hifiberry-dac +``` + +If you like to disable your HiFiberry Sound card and enable onboard sound, run the folliwing command + + +``` +sudo ./setup_hifiberry.sh disable +``` ## Additional information From 4aa34bf4a2ba062c9a7698128ac5d3f9cae24ae9 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sat, 13 Jan 2024 23:54:50 +0100 Subject: [PATCH 44/55] fix: final touches again --- installation/components/setup_hifiberry.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 85e4f8213..98993f66a 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -35,7 +35,7 @@ example_usage() { enable_hifiberry() { echo "Enabling HiFiBerry board..." - grep -qxF "dtoverlay=$1" "$boot_config_path" || sudo echo "dtoverlay=$1" >> "$boot_config_path" + grep -qxF "dtoverlay=$1" "$boot_config_path" || echo "dtoverlay=$1" | sudo tee -a "$boot_config_path" > /dev/null ./../options/onboard_sound.sh disable } @@ -54,8 +54,8 @@ check_existing_hifiberry() { fi echo "Existing HiFiBerry configuration detected: $existing_config" - read -p "Do you want to proceed with a new configuration? This will remove the existing one. (Y/n): " yn - case $yn in + read -p "Do you want to proceed with a new configuration? This will remove the existing one. (Y/n): " choice + case $choice in [nN][oO]|[nN]) echo "Exiting without making changes."; exit;; @@ -107,7 +107,6 @@ done echo "0) Remove existing HiFiBerry configuration" read -p "Enter your choice (0-$board_count): " choice - case $choice in [0]) disable_hifiberry; From d1e2f58b0238c4029d88d6600dad7a28ce102c2c Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sat, 13 Jan 2024 23:57:52 +0100 Subject: [PATCH 45/55] fix: remove is_sudo again --- installation/components/setup_hifiberry.sh | 5 ----- installation/includes/02_helpers.sh | 8 -------- 2 files changed, 13 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 98993f66a..d7b33d035 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -5,11 +5,6 @@ source ../includes/02_helpers.sh -if [ "$(is_sudo)" = false ]; then - echo "ERROR: This script must be run as root" - exit 1 -fi - script_name=$(basename "$0") boot_config_path=$(get_boot_config_path) diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index 83bab7276..e362f2f26 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -49,14 +49,6 @@ run_with_log_frame() { log "#########################################################" } -is_sudo() { - if [ "$(id -u)" != "0" ]; then - echo false - else - echo true - fi -} - get_architecture() { local arch="" if [ "$(uname -m)" = "armv7l" ]; then From a43bafdb4693523ab7097307489aa97ac6f8bfaa Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sun, 14 Jan 2024 00:01:30 +0100 Subject: [PATCH 46/55] fix: Remove last sudo occurrences --- documentation/builders/components/soundcards/hifiberry.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md index 03465beef..bb26aadbe 100644 --- a/documentation/builders/components/soundcards/hifiberry.md +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -8,20 +8,20 @@ Run the following command to install any HiFiBerry board. Make sure you reboot y ``` cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh -sudo ./setup_hifiberry.sh +./setup_hifiberry.sh ``` If you know you HifiBerry Board identifier, you can run the script as a 1-liner as well ``` -sudo ./setup_hifiberry.sh enable hifiberry-dac +./setup_hifiberry.sh enable hifiberry-dac ``` If you like to disable your HiFiberry Sound card and enable onboard sound, run the folliwing command ``` -sudo ./setup_hifiberry.sh disable +./setup_hifiberry.sh disable ``` ## Additional information From 8e1695501bab9773501bd9e769d8689f2443a904 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sun, 14 Jan 2024 21:26:02 +0100 Subject: [PATCH 47/55] fix: bullet proof --- .../builders/components/power/onoff-shim.md | 2 +- .../components/soundcards/hifiberry.md | 4 +-- documentation/developers/docker.md | 2 +- installation/components/setup_hifiberry.sh | 2 +- installation/includes/02_helpers.sh | 28 +++++++------------ installation/options/onboard_sound.sh | 11 ++------ 6 files changed, 18 insertions(+), 31 deletions(-) diff --git a/documentation/builders/components/power/onoff-shim.md b/documentation/builders/components/power/onoff-shim.md index 749e879cf..7dee3e1c3 100644 --- a/documentation/builders/components/power/onoff-shim.md +++ b/documentation/builders/components/power/onoff-shim.md @@ -7,7 +7,7 @@ The OnOff SHIM from Pimorino allows you to savely start and shutdown your Raspbe To install the software, open a terminal and type the following command to run the one-line-installer. A reboot will be required once the installation is finished. > [!NOTE] -> The installations will ask you a few questions. You can safely answer with the default response. +> The installation will ask you a few questions. You can safely answer with the default response. ``` curl https://get.pimoroni.com/onoffshim | bash diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md index bb26aadbe..f207c0133 100644 --- a/documentation/builders/components/soundcards/hifiberry.md +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -7,7 +7,7 @@ The installation script works for the most common set of HiFiBerry boards but al Run the following command to install any HiFiBerry board. Make sure you reboot your device afterwards. ``` -cd; cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh +cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh ./setup_hifiberry.sh ``` @@ -17,7 +17,7 @@ If you know you HifiBerry Board identifier, you can run the script as a 1-liner ./setup_hifiberry.sh enable hifiberry-dac ``` -If you like to disable your HiFiberry Sound card and enable onboard sound, run the folliwing command +If you like to disable your HiFiberry Sound card and enable onboard sound, run the following command ``` diff --git a/documentation/developers/docker.md b/documentation/developers/docker.md index 80651ce84..4171ababd 100644 --- a/documentation/developers/docker.md +++ b/documentation/developers/docker.md @@ -15,7 +15,7 @@ need to adapt some of those commands to your needs. ## Prerequisites 1. Install required software: Docker, Compose and pulseaudio - * Check installations guide for [Mac](#mac), [Windows](#windows) or [Linux](#linux) + * Check installation guide for [Mac](#mac), [Windows](#windows) or [Linux](#linux) 2. Pull the Jukebox repository: diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index d7b33d035..6f7dbf1ff 100644 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -107,8 +107,8 @@ case $choice in disable_hifiberry; ;; [1-$board_count]) - check_existing_hifiberry selected_board=$(get_key_by_item_number hifiberry_map "$choice") + check_existing_hifiberry enable_hifiberry "$selected_board"; ;; *) diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index e362f2f26..97a87d9cb 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -72,31 +72,23 @@ is_raspian() { fi } -get_debian_version() { - # Read the major version number from /etc/debian_version - local major_version="$( . /etc/os-release; printf '%s\n' "$VERSION_CODENAME"; )" - - case $major_version in - 11) - echo "bullseye" - ;; - 12) - echo "bookworm" - ;; - *) - echo "unknown" - ;; - esac +get_debian_version_number() { + source /etc/os-release + echo "$VERSION_ID" } get_boot_config_path() { if [ "$(is_raspian)" = true ]; then - local debian_version=$(get_debian_version) + local debian_version_number=$(get_debian_version_number) - if [ "$debian_version" = "bookworm" ]; then + # Bullseye and lower + if [ "$debian_version_number" -le 11 ]; then + echo "/boot/config.txt" + # Bookworm and higher + elif [ "$debian_version_number" -ge 12 ]; then echo "/boot/firmware/config.txt" else - echo "/boot/config.txt" + echo "unknown" fi else echo "unknown" diff --git a/installation/options/onboard_sound.sh b/installation/options/onboard_sound.sh index b8b087883..3305f43e3 100644 --- a/installation/options/onboard_sound.sh +++ b/installation/options/onboard_sound.sh @@ -14,19 +14,14 @@ arg="$1" if [ "$arg" = "enable" ]; then echo "Enabling Onboard Sound..." + sudo sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(off\|false\|no\|0\)\(.*\)/\1audio=on\4/g" "$boot_config_path" sudo sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" sudo sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path" elif [ "$arg" = "disable" ]; then echo "Disabling Onboard Sound..." sudo sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(on\|true\|yes\|1\)\(.*\)/\1audio=off\4/g" "$boot_config_path" - - if grep -qx 'dtoverlay=vc4-fkms-v3d' "$boot_config_path"; then - sudo sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' "$boot_config_path" - fi - - if grep -qx 'dtoverlay=vc4-kms-v3d' "$boot_config_path"; then - sudo sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' "$boot_config_path" - fi + sudo sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' "$boot_config_path" + sudo sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' "$boot_config_path" fi # TODO Test From 8c96690121f25d1ad1dfa5d68333126a7772b033 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sun, 14 Jan 2024 21:47:09 +0100 Subject: [PATCH 48/55] Make bash files executable --- installation/components/setup_hifiberry.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 installation/components/setup_hifiberry.sh diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh old mode 100644 new mode 100755 From b9f1ed641dd0e8f652ddee21b1a25f4a0e674849 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sun, 14 Jan 2024 21:48:53 +0100 Subject: [PATCH 49/55] fix: Update documentation --- installation/options/onboard_sound.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 installation/options/onboard_sound.sh diff --git a/installation/options/onboard_sound.sh b/installation/options/onboard_sound.sh old mode 100644 new mode 100755 From 66acd47a78eaae2ee0e691922b7729f36b84b467 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sun, 14 Jan 2024 21:54:22 +0100 Subject: [PATCH 50/55] fix: 1-line path does not worj --- documentation/builders/components/soundcards/hifiberry.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md index f207c0133..e62297eb7 100644 --- a/documentation/builders/components/soundcards/hifiberry.md +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -7,7 +7,7 @@ The installation script works for the most common set of HiFiBerry boards but al Run the following command to install any HiFiBerry board. Make sure you reboot your device afterwards. ``` -cd ~/RPi-Jukebox-RFID/installation/components && chmod +x setup_hifiberry.sh +cd ~/RPi-Jukebox-RFID/installation/components ./setup_hifiberry.sh ``` From 709f57638b18a9c8c8b1335d6c39ad6c7bb92b1d Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Mon, 15 Jan 2024 09:53:09 +0100 Subject: [PATCH 51/55] Update documentation/builders/components/soundcards/hifiberry.md Co-authored-by: s-martin --- documentation/builders/components/soundcards/hifiberry.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md index e62297eb7..86bc24d63 100644 --- a/documentation/builders/components/soundcards/hifiberry.md +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -6,7 +6,7 @@ The installation script works for the most common set of HiFiBerry boards but al Run the following command to install any HiFiBerry board. Make sure you reboot your device afterwards. -``` +```bash cd ~/RPi-Jukebox-RFID/installation/components ./setup_hifiberry.sh ``` From 09b6e485e75dd6971fe0c3ef7a8b39cce35a43b3 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Mon, 15 Jan 2024 09:53:15 +0100 Subject: [PATCH 52/55] Update documentation/builders/components/soundcards/hifiberry.md Co-authored-by: s-martin --- documentation/builders/components/soundcards/hifiberry.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md index 86bc24d63..90d40ab1d 100644 --- a/documentation/builders/components/soundcards/hifiberry.md +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -20,7 +20,7 @@ If you know you HifiBerry Board identifier, you can run the script as a 1-liner If you like to disable your HiFiberry Sound card and enable onboard sound, run the following command -``` +```bash ./setup_hifiberry.sh disable ``` From 83b5d99c9af66be8ae67ec81f2626d25cb7450c5 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Mon, 15 Jan 2024 09:53:28 +0100 Subject: [PATCH 53/55] Update documentation/builders/components/soundcards/hifiberry.md Co-authored-by: s-martin --- documentation/builders/components/soundcards/hifiberry.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/builders/components/soundcards/hifiberry.md b/documentation/builders/components/soundcards/hifiberry.md index 90d40ab1d..1f19fa96d 100644 --- a/documentation/builders/components/soundcards/hifiberry.md +++ b/documentation/builders/components/soundcards/hifiberry.md @@ -13,7 +13,7 @@ cd ~/RPi-Jukebox-RFID/installation/components If you know you HifiBerry Board identifier, you can run the script as a 1-liner as well -``` +```bash ./setup_hifiberry.sh enable hifiberry-dac ``` From 94e9bcfd21d6a5aef3e474a74d408588a9ed53ab Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 16 Jan 2024 07:59:04 +0100 Subject: [PATCH 54/55] fix: Update regex for commented code --- installation/components/setup_hifiberry.sh | 6 +++--- installation/options/onboard_sound.sh | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/installation/components/setup_hifiberry.sh b/installation/components/setup_hifiberry.sh index 6f7dbf1ff..dc2da8d6e 100755 --- a/installation/components/setup_hifiberry.sh +++ b/installation/components/setup_hifiberry.sh @@ -30,18 +30,18 @@ example_usage() { enable_hifiberry() { echo "Enabling HiFiBerry board..." - grep -qxF "dtoverlay=$1" "$boot_config_path" || echo "dtoverlay=$1" | sudo tee -a "$boot_config_path" > /dev/null + grep -qxF "^dtoverlay=$1" "$boot_config_path" || echo "dtoverlay=$1" | sudo tee -a "$boot_config_path" > /dev/null ./../options/onboard_sound.sh disable } disable_hifiberry() { echo "Removing existing HiFiBerry configuration..." - sudo sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path" + sudo sed -i '/^dtoverlay=hifiberry-/d' "$boot_config_path" ./../options/onboard_sound.sh enable } check_existing_hifiberry() { - existing_config=$(grep 'dtoverlay=hifiberry-' "$boot_config_path") + existing_config=$(grep '^dtoverlay=hifiberry-' "$boot_config_path") if [ ! -z "$existing_config" ]; then if [ "$1" = "silent" ]; then disable_hifiberry diff --git a/installation/options/onboard_sound.sh b/installation/options/onboard_sound.sh index 3305f43e3..475a9161d 100755 --- a/installation/options/onboard_sound.sh +++ b/installation/options/onboard_sound.sh @@ -15,13 +15,13 @@ arg="$1" if [ "$arg" = "enable" ]; then echo "Enabling Onboard Sound..." sudo sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(off\|false\|no\|0\)\(.*\)/\1audio=on\4/g" "$boot_config_path" - sudo sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path" - sudo sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path" + sudo sed -i '/^dtoverlay=vc4-fkms-v3d/{s/,audio=off//g;}' "$boot_config_path" + sudo sed -i '/^dtoverlay=vc4-kms-v3d/{s/,noaudio//g;}' "$boot_config_path" elif [ "$arg" = "disable" ]; then echo "Disabling Onboard Sound..." sudo sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(on\|true\|yes\|1\)\(.*\)/\1audio=off\4/g" "$boot_config_path" - sudo sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' "$boot_config_path" - sudo sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' "$boot_config_path" + sudo sed -i '/^dtoverlay=vc4-fkms-v3d/{s/,audio=off//g;s/$/,audio=off/g;}' "$boot_config_path" + sudo sed -i '/^dtoverlay=vc4-kms-v3d/{s/,noaudio//g;s/$/,noaudio/g;}' "$boot_config_path" fi # TODO Test From 4cb9ffd0e79993c3a1822f8e5cb4a7eff02af906 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 16 Jan 2024 08:06:26 +0100 Subject: [PATCH 55/55] Adding OnOff Shim resource --- documentation/builders/components/power/onoff-shim.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/builders/components/power/onoff-shim.md b/documentation/builders/components/power/onoff-shim.md index 7dee3e1c3..b83ea6140 100644 --- a/documentation/builders/components/power/onoff-shim.md +++ b/documentation/builders/components/power/onoff-shim.md @@ -28,6 +28,8 @@ The OnOff SHIM comes with a 12-PIN header which needs soldering. If you want to | GPLCLK0 | 7 | 7 | GPIO4 | | GPIO17 | 11 | 11 | GPIO17 | +* More information can be found here: https://pinout.xyz/pinout/onoff_shim + ## Assembly options ![](https://cdn.review-images.pimoroni.com/upload-b6276a310ccfbeae93a2d13ec19ab83b-1617096824.jpg?width=640)