From b713bac312cb42ce54715097d1838e5cf7aea301 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:20:48 +0100 Subject: [PATCH 01/28] Categorize install options --- installation/routines/customize_options.sh | 25 ++++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/installation/routines/customize_options.sh b/installation/routines/customize_options.sh index 7409a6e07..74fbb5dc8 100644 --- a/installation/routines/customize_options.sh +++ b/installation/routines/customize_options.sh @@ -327,22 +327,19 @@ Do you want to install Node? [Y/n]" } _run_customize_options() { - _option_ipv6 - _option_static_ip - _option_autohotspot - _option_bluetooth - _option_disable_onboard_audio - _option_mpd - _option_rfid_reader - _option_samba - _option_webapp + _option_ipv6 # Optional: Not required for installation + _option_static_ip # Optional: Not required for installation + _option_autohotspot # Optional: Not required for installation + _option_bluetooth # Optional: Not required for installation + _option_disable_onboard_audio # Optional: Should be merged with other audio installations, like HifiBerry + _option_mpd # !!Required, without options + _option_rfid_reader # !!Required, with options + _option_samba # !!Required, without options + _option_webapp # !!Required, without options if [[ $ENABLE_WEBAPP == true ]] ; then - _option_webapp_devel_build - _option_kiosk_mode + _option_webapp_devel_build # Optional: Not required for installation + _option_kiosk_mode # Optional: Not required for installation fi - # Bullseye is currently under active development and should be updated in any case. - # Hence, removing the step below as it becomse mandatory - # _options_update_raspi_os } customize_options() { From 3eb53d7b648e8bc7bb7030cfd09524ae16b3c9cd Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 9 Jan 2024 15:17:00 +0100 Subject: [PATCH 02/28] Move code for IVP6 into separate function; allow both enable/disable options --- installation/routines/optimize_boot_time.sh | 16 +------- installation/routines/options/ipv6.sh | 41 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 installation/routines/options/ipv6.sh diff --git a/installation/routines/optimize_boot_time.sh b/installation/routines/optimize_boot_time.sh index bb6f71902..425e64fa2 100644 --- a/installation/routines/optimize_boot_time.sh +++ b/installation/routines/optimize_boot_time.sh @@ -5,7 +5,6 @@ OPTIMIZE_DHCP_CONF="/etc/dhcpcd.conf" OPTIMIZE_BOOT_CMDLINE_OPTIONS="consoleblank=1 logo.nologo quiet loglevel=0 plymouth.enable=0 vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fastboot noatime nodiratime noram" OPTIMIZE_DHCP_CONF_HEADER="## Jukebox DHCP Config" -OPTIMIZE_IPV6_CONF_HEADER="## Jukebox IPV6 Config" OPTIMIZE_BOOT_CONF_HEADER="## Jukebox Boot Config" _optimize_disable_irrelevant_services() { @@ -62,22 +61,9 @@ EOF fi } -# TODO: Allow both Enable and Disable _optimize_ipv6_arp() { if [ "$DISABLE_IPv6" = true ] ; then - print_lc " Disabling IPV6" - if grep -q "${OPTIMIZE_IPV6_CONF_HEADER}" "$OPTIMIZE_DHCP_CONF"; then - log " Skipping. Already set up!" - else - sudo tee -a $OPTIMIZE_DHCP_CONF <<-EOF - -${OPTIMIZE_IPV6_CONF_HEADER} -noarp -ipv4only -noipv6 - -EOF - fi + ./options/ipv6.sh disable fi } diff --git a/installation/routines/options/ipv6.sh b/installation/routines/options/ipv6.sh new file mode 100644 index 000000000..7e5c95cda --- /dev/null +++ b/installation/routines/options/ipv6.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +source ../../includes/02_helpers.sh + +if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then + print_lc "Error: Invalid or no argument provided. +Usage: ./ipv6.sh + where can be 'enable' or 'disable'" + exit 1 +fi + +arg="$1" + +DHCP_CONF_PATH="/etc/dhcpcd.conf" +START_MARKER="## Jukebox IPV6 Config Start" +END_MARKER="## Jukebox IPV6 Config End" + +if [ "$arg" = "enable" ]; then + print_lc "Enabling IPv6..." + sed -i "/$START_MARKER/,/$END_MARKER/d" "$DHCP_CONF_PATH" +elif [ "$arg" = "disable" ]; then + print_lc "Disabling IPv6..." + cp "$DHCP_CONF_PATH" "${DHCP_CONF_PATH}.bak" + + # Only disable if it is enabled + if ! grep -q "${START_MARKER}" "$DHCP_CONF_PATH"; then + sudo tee -a $DHCP_CONF_PATH <<-EOF +${START_MARKER} +noarp +ipv4only +noipv6 +${END_MARKER} +EOF + fi +fi + +# Test +if [ "$arg" = "enable" ]; then + verify_file_does_not_contain_string "${START_MARKER}" "${DHCP_CONF_PATH}" +elif [ "$arg" = "disable" ]; then + verify_file_contains_string_once "${START_MARKER}" "${DHCP_CONF_PATH}" +fi From a36ded9fc717a868c617c326c384dbb24f37de76 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 9 Jan 2024 15:54:21 +0100 Subject: [PATCH 03/28] Change folder location for options --- installation/{routines => }/options/ipv6.sh | 2 +- installation/routines/optimize_boot_time.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename installation/{routines => }/options/ipv6.sh (96%) diff --git a/installation/routines/options/ipv6.sh b/installation/options/ipv6.sh similarity index 96% rename from installation/routines/options/ipv6.sh rename to installation/options/ipv6.sh index 7e5c95cda..e3b98886b 100644 --- a/installation/routines/options/ipv6.sh +++ b/installation/options/ipv6.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -source ../../includes/02_helpers.sh +source ../includes/02_helpers.sh if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then print_lc "Error: Invalid or no argument provided. diff --git a/installation/routines/optimize_boot_time.sh b/installation/routines/optimize_boot_time.sh index 425e64fa2..324313127 100644 --- a/installation/routines/optimize_boot_time.sh +++ b/installation/routines/optimize_boot_time.sh @@ -63,7 +63,7 @@ EOF _optimize_ipv6_arp() { if [ "$DISABLE_IPv6" = true ] ; then - ./options/ipv6.sh disable + ./../options/ipv6.sh disable fi } From e99159f801299d396e397e6ca39200698f2cf9f4 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 9 Jan 2024 20:52:32 +0100 Subject: [PATCH 04/28] [ipv6] remove unnecessary test --- installation/routines/optimize_boot_time.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installation/routines/optimize_boot_time.sh b/installation/routines/optimize_boot_time.sh index 324313127..463642d0c 100644 --- a/installation/routines/optimize_boot_time.sh +++ b/installation/routines/optimize_boot_time.sh @@ -128,9 +128,9 @@ _optimize_check() { verify_file_contains_string "${CURRENT_IP_ADDRESS}" "${OPTIMIZE_DHCP_CONF}" verify_file_contains_string "${CURRENT_GATEWAY}" "${OPTIMIZE_DHCP_CONF}" fi - if [ "$DISABLE_IPv6" = true ] ; then - verify_file_contains_string_once "${OPTIMIZE_IPV6_CONF_HEADER}" "${OPTIMIZE_DHCP_CONF}" - fi + # if [ "$DISABLE_IPv6" = true ] ; then + # verify_file_contains_string_once "${OPTIMIZE_IPV6_CONF_HEADER}" "${OPTIMIZE_DHCP_CONF}" + # fi if [ "$DISABLE_BOOT_SCREEN" = true ] ; then verify_file_contains_string_once "${OPTIMIZE_BOOT_CONF_HEADER}" "${RPI_BOOT_CONFIG_FILE}" fi From f7aa58ec91c7d35f4b4ecad9e5ac16f4a1f233d2 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 9 Jan 2024 21:03:05 +0100 Subject: [PATCH 05/28] refactor: Allow to enable/disable bluetooth --- installation/options/bluetooth.sh | 30 +++++++++++++++++++++ installation/routines/optimize_boot_time.sh | 13 ++++----- 2 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 installation/options/bluetooth.sh diff --git a/installation/options/bluetooth.sh b/installation/options/bluetooth.sh new file mode 100644 index 000000000..e2b9daac9 --- /dev/null +++ b/installation/options/bluetooth.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +source ../includes/02_helpers.sh + +if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then + print_lc "Error: Invalid or no argument provided. +Usage: ./bluetooth.sh + where can be 'enable' or 'disable'" + exit 1 +fi + +arg="$1" + +if [ "$arg" = "enable" ]; then + print_lc "Enabling Bluetooth..." + sudo systemctl enable hciuart.service + sudo systemctl enable bluetooth.service +elif [ "$arg" = "disable" ]; then + print_lc "Disabling Bluetooth..." + sudo systemctl disable hciuart.service + sudo systemctl disable bluetooth.service +fi + +# Test +if [ "$arg" = "enable" ]; then + verify_optional_service_enablement hciuart.service enabled + verify_optional_service_enablement bluetooth.service enabled +elif [ "$arg" = "disable" ]; then + verify_optional_service_enablement hciuart.service disabled + verify_optional_service_enablement bluetooth.service disabled +fi diff --git a/installation/routines/optimize_boot_time.sh b/installation/routines/optimize_boot_time.sh index 463642d0c..e2396ee44 100644 --- a/installation/routines/optimize_boot_time.sh +++ b/installation/routines/optimize_boot_time.sh @@ -25,12 +25,9 @@ _optimize_disable_irrelevant_services() { sudo systemctl disable apt-daily-upgrade.timer } -# TODO: If false, actually make sure bluetooth is enabled _optimize_handle_bluetooth() { if [ "$DISABLE_BLUETOOTH" = true ] ; then - print_lc " Disable bluetooth" - sudo systemctl disable hciuart.service - sudo systemctl disable bluetooth.service + ./../options/bluetooth.sh disable fi } @@ -117,10 +114,10 @@ _optimize_check() { verify_optional_service_enablement apt-daily.timer disabled verify_optional_service_enablement apt-daily-upgrade.timer disabled - if [ "$DISABLE_BLUETOOTH" = true ] ; then - verify_optional_service_enablement hciuart.service disabled - verify_optional_service_enablement bluetooth.service disabled - fi + # if [ "$DISABLE_BLUETOOTH" = true ] ; then + # verify_optional_service_enablement hciuart.service disabled + # verify_optional_service_enablement bluetooth.service disabled + # fi if [ "$ENABLE_STATIC_IP" = true ] ; then verify_file_contains_string_once "${OPTIMIZE_DHCP_CONF_HEADER}" "${OPTIMIZE_DHCP_CONF}" From 085ec439820bb8bb44c221159f0625c0f2db2e43 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 10 Jan 2024 08:32:34 +0100 Subject: [PATCH 06/28] refactor: Allow to enable/disable and set static ip --- installation/options/static_ip.sh | 71 +++++++++++++++++++++ installation/routines/optimize_boot_time.sh | 35 +++------- 2 files changed, 80 insertions(+), 26 deletions(-) create mode 100644 installation/options/static_ip.sh diff --git a/installation/options/static_ip.sh b/installation/options/static_ip.sh new file mode 100644 index 000000000..1530ec001 --- /dev/null +++ b/installation/options/static_ip.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +### TODO: Should be converted to NetworkManager + +source ../includes/02_helpers.sh + +if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then + print_lc "Error: Invalid or no statusument provided. +Usage: ./static_ip.sh [optional] + where can be 'enable' or 'disable'" + exit 1 +fi + +DHCP_CONF_PATH="/etc/dhcpcd.conf" +START_MARKER="## Jukebox DHCP Config Start" +END_MARKER="## Jukebox DHCP Config End" + +CURRENT_ROUTE=$(ip route get 8.8.8.8) +CURRENT_GATEWAY=$(echo "${CURRENT_ROUTE}" | awk '{ print $3; exit }') +CURRENT_INTERFACE=$(echo "${CURRENT_ROUTE}" | awk '{ print $5; exit }') +CURRENT_IP_ADDRESS=$(echo "${CURRENT_ROUTE}" | awk '{ print $7; exit }') + +status="$1" +ipaddress="${1:-$CURRENT_IP_ADDRESS}" # No IP address provided, use current IP address + +_set_static_ip() { + local ipaddress="$1" + + # Check static IP has not been set + if grep -q "${START_MARKER}" "$DHCP_CONF_PATH"; then + _remove_static_ip + fi + + log " ${CURRENT_INTERFACE} is the default network interface" + log " ${CURRENT_GATEWAY} is the Router Gateway address" + log " Using ${CURRENT_IP_ADDRESS} as the static IP for now" + + sudo tee -a $DHCP_CONF_PATH <<-EOF +${START_MARKER} +interface ${CURRENT_INTERFACE} +static ip_address=${CURRENT_IP_ADDRESS}/24 +static routers=${CURRENT_GATEWAY} +static domain_name_servers=${CURRENT_GATEWAY} +${END_MARKER} +EOF +} + +_remove_static_ip() { + sed -i "/$START_MARKER/,/$END_MARKER/d" "$DHCP_CONF_PATH" +} + +# Logic +cp "$DHCP_CONF_PATH" "${DHCP_CONF_PATH}.bak" + +if [ "$status" = "enable" ]; then + print_lc "Enabling Static IP..." + _set_static_ip "$ipaddress" +elif [ "$status" = "disable" ]; then + print_lc "Disabling Static IP..." + _remove_static_ip +fi + +# Test +if [ "$status" = "enable" ]; then + verify_file_contains_string_once "${START_MARKER}" "${DHCP_CONF_PATH}" + verify_file_contains_string "${CURRENT_INTERFACE}" "${DHCP_CONF_PATH}" + verify_file_contains_string "${ipaddress}" "${DHCP_CONF_PATH}" + verify_file_contains_string "${CURRENT_GATEWAY}" "${DHCP_CONF_PATH}" +elif [ "$status" = "disable" ]; then + verify_file_contains_string_once "${START_MARKER}" "${DHCP_CONF_PATH}" +fi diff --git a/installation/routines/optimize_boot_time.sh b/installation/routines/optimize_boot_time.sh index e2396ee44..d1d0f21e1 100644 --- a/installation/routines/optimize_boot_time.sh +++ b/installation/routines/optimize_boot_time.sh @@ -35,26 +35,9 @@ _optimize_handle_bluetooth() { _optimize_static_ip() { # Static IP Address and DHCP optimizations if [ "$ENABLE_STATIC_IP" = true ] ; then - print_lc " Set static IP address" - if grep -q "${OPTIMIZE_DHCP_CONF_HEADER}" "$OPTIMIZE_DHCP_CONF"; then - log " Skipping. Already set up!" - else - # DHCP has not been configured - log " ${CURRENT_INTERFACE} is the default network interface" - log " ${CURRENT_GATEWAY} is the Router Gateway address" - log " Using ${CURRENT_IP_ADDRESS} as the static IP for now" - - sudo tee -a $OPTIMIZE_DHCP_CONF <<-EOF - -${OPTIMIZE_DHCP_CONF_HEADER} -interface ${CURRENT_INTERFACE} -static ip_address=${CURRENT_IP_ADDRESS}/24 -static routers=${CURRENT_GATEWAY} -static domain_name_servers=${CURRENT_GATEWAY} - -EOF - - fi + ./../options/static_ip.sh enable + else + ./../options/static_ip.sh disable fi } @@ -119,12 +102,12 @@ _optimize_check() { # verify_optional_service_enablement bluetooth.service disabled # fi - if [ "$ENABLE_STATIC_IP" = true ] ; then - verify_file_contains_string_once "${OPTIMIZE_DHCP_CONF_HEADER}" "${OPTIMIZE_DHCP_CONF}" - verify_file_contains_string "${CURRENT_INTERFACE}" "${OPTIMIZE_DHCP_CONF}" - verify_file_contains_string "${CURRENT_IP_ADDRESS}" "${OPTIMIZE_DHCP_CONF}" - verify_file_contains_string "${CURRENT_GATEWAY}" "${OPTIMIZE_DHCP_CONF}" - fi + # if [ "$ENABLE_STATIC_IP" = true ] ; then + # verify_file_contains_string_once "${OPTIMIZE_DHCP_CONF_HEADER}" "${OPTIMIZE_DHCP_CONF}" + # verify_file_contains_string "${CURRENT_INTERFACE}" "${OPTIMIZE_DHCP_CONF}" + # verify_file_contains_string "${CURRENT_IP_ADDRESS}" "${OPTIMIZE_DHCP_CONF}" + # verify_file_contains_string "${CURRENT_GATEWAY}" "${OPTIMIZE_DHCP_CONF}" + # fi # if [ "$DISABLE_IPv6" = true ] ; then # verify_file_contains_string_once "${OPTIMIZE_IPV6_CONF_HEADER}" "${OPTIMIZE_DHCP_CONF}" # fi From 5abd1ff8ae93a752c6b84a1a93b95fa004f72ad2 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:11:56 +0100 Subject: [PATCH 07/28] refactor: Keep raspi-config service alive --- installation/routines/optimize_boot_time.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/installation/routines/optimize_boot_time.sh b/installation/routines/optimize_boot_time.sh index d1d0f21e1..a557ea169 100644 --- a/installation/routines/optimize_boot_time.sh +++ b/installation/routines/optimize_boot_time.sh @@ -15,9 +15,6 @@ _optimize_disable_irrelevant_services() { sudo systemctl disable triggerhappy.service sudo systemctl disable triggerhappy.socket - log " Disable raspi-config.service" - sudo systemctl disable raspi-config.service - log " Disable apt-daily.service & apt-daily-upgrade.service" sudo systemctl disable apt-daily.service sudo systemctl disable apt-daily-upgrade.service @@ -91,7 +88,6 @@ _optimize_check() { verify_optional_service_enablement keyboard-setup.service disabled verify_optional_service_enablement triggerhappy.service disabled verify_optional_service_enablement triggerhappy.socket disabled - verify_optional_service_enablement raspi-config.service disabled verify_optional_service_enablement apt-daily.service disabled verify_optional_service_enablement apt-daily-upgrade.service disabled verify_optional_service_enablement apt-daily.timer disabled From 04b84debfa875ffdb98543f1e48b2f0c9ceb86f2 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:12:16 +0100 Subject: [PATCH 08/28] refactor: Allow to enable/disable and set boot screen --- installation/options/boot_screen.sh | 22 +++++++++++++++++++++ installation/routines/optimize_boot_time.sh | 19 ++++-------------- 2 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 installation/options/boot_screen.sh diff --git a/installation/options/boot_screen.sh b/installation/options/boot_screen.sh new file mode 100644 index 000000000..25adcb278 --- /dev/null +++ b/installation/options/boot_screen.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +source ../includes/02_helpers.sh + +if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then + print_lc "Error: Invalid or no argument provided. +Usage: ./ipv6.sh + where can be 'enable' or 'disable'" + exit 1 +fi + +arg="$1" +boot_config_path=$(get_boot_config_path) + +if [ "$arg" = "enable" ]; then + print_lc "Enabling RPi rainbow screen..." + sudo raspi-config nonint do_boot_splash 0 +elif [ "$arg" = "disable" ]; then + print_lc "Disabling RPi rainbow screen..." + sudo raspi-config nonint do_boot_splash 1 +fi + +# Test, no test required. Depending on raspi-config to test diff --git a/installation/routines/optimize_boot_time.sh b/installation/routines/optimize_boot_time.sh index a557ea169..63c4f201d 100644 --- a/installation/routines/optimize_boot_time.sh +++ b/installation/routines/optimize_boot_time.sh @@ -44,20 +44,9 @@ _optimize_ipv6_arp() { fi } -# TODO: Allow both Enable and Disable _optimize_handle_boot_screen() { if [ "$DISABLE_BOOT_SCREEN" = true ] ; then - log " Disable RPi rainbow screen" - if grep -q "${OPTIMIZE_BOOT_CONF_HEADER}" "$RPI_BOOT_CONFIG_FILE"; then - log " Skipping. Already set up!" - else - sudo tee -a $RPI_BOOT_CONFIG_FILE <<-EOF - -${OPTIMIZE_BOOT_CONF_HEADER} -disable_splash=1 - -EOF - fi + ./../options/boot_screen.sh disable fi } @@ -107,9 +96,9 @@ _optimize_check() { # if [ "$DISABLE_IPv6" = true ] ; then # verify_file_contains_string_once "${OPTIMIZE_IPV6_CONF_HEADER}" "${OPTIMIZE_DHCP_CONF}" # fi - if [ "$DISABLE_BOOT_SCREEN" = true ] ; then - verify_file_contains_string_once "${OPTIMIZE_BOOT_CONF_HEADER}" "${RPI_BOOT_CONFIG_FILE}" - fi + # if [ "$DISABLE_BOOT_SCREEN" = true ] ; then + # verify_file_contains_string_once "${OPTIMIZE_BOOT_CONF_HEADER}" "${RPI_BOOT_CONFIG_FILE}" + # fi if [ "$DISABLE_BOOT_LOGS_PRINT" = true ] ; then for option in $OPTIMIZE_BOOT_CMDLINE_OPTIONS From ba53cbe8e0ef7f02019aeaab3c52b15cad2e19c2 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:13:07 +0100 Subject: [PATCH 09/28] fix: Typo in boot_screen.sh --- installation/options/boot_screen.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/options/boot_screen.sh b/installation/options/boot_screen.sh index 25adcb278..6354d2830 100644 --- a/installation/options/boot_screen.sh +++ b/installation/options/boot_screen.sh @@ -3,7 +3,7 @@ source ../includes/02_helpers.sh if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then print_lc "Error: Invalid or no argument provided. -Usage: ./ipv6.sh +Usage: ./boot_screen.sh where can be 'enable' or 'disable'" exit 1 fi From 188d544483a675d5f041208e41d8880e79940db4 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:22:15 +0100 Subject: [PATCH 10/28] Revert "refactor: Keep raspi-config service alive" This reverts commit 5abd1ff8ae93a752c6b84a1a93b95fa004f72ad2. --- installation/routines/optimize_boot_time.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/installation/routines/optimize_boot_time.sh b/installation/routines/optimize_boot_time.sh index 63c4f201d..3d7ee880d 100644 --- a/installation/routines/optimize_boot_time.sh +++ b/installation/routines/optimize_boot_time.sh @@ -15,6 +15,9 @@ _optimize_disable_irrelevant_services() { sudo systemctl disable triggerhappy.service sudo systemctl disable triggerhappy.socket + log " Disable raspi-config.service" + sudo systemctl disable raspi-config.service + log " Disable apt-daily.service & apt-daily-upgrade.service" sudo systemctl disable apt-daily.service sudo systemctl disable apt-daily-upgrade.service @@ -77,6 +80,7 @@ _optimize_check() { verify_optional_service_enablement keyboard-setup.service disabled verify_optional_service_enablement triggerhappy.service disabled verify_optional_service_enablement triggerhappy.socket disabled + verify_optional_service_enablement raspi-config.service disabled verify_optional_service_enablement apt-daily.service disabled verify_optional_service_enablement apt-daily-upgrade.service disabled verify_optional_service_enablement apt-daily.timer disabled From 735b6990cc445d84cb2f7fc417d6284f9f3277ff Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:33:27 +0100 Subject: [PATCH 11/28] fix: Add mixing verify_file_does_not_contain_string function --- installation/includes/02_helpers.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index 239a18ccf..8c1ffe982 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -169,6 +169,21 @@ verify_file_contains_string() { log " CHECK" } +verify_file_does_not_contain_string() { + local string="$1" + local file="$2" + log " Verify '${string}' not found in '${file}'" + + if [[ -z "${string}" || -z "${file}" ]]; then + exit_on_error "ERROR: at least one parameter value is missing!" + fi + + if grep -iq "${string}" "${file}"; then + exit_on_error "ERROR: '${string}' found in '${file}'" + fi + log " CHECK" +} + verify_file_contains_string_once() { local string="$1" local file="$2" From c99ded408c522be2e4bcaae025a670dc6e5d3d57 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:35:37 +0100 Subject: [PATCH 12/28] fix: Do not depend on raspi-config for boot_screen --- installation/options/boot_screen.sh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/installation/options/boot_screen.sh b/installation/options/boot_screen.sh index 6354d2830..851a4a0a5 100644 --- a/installation/options/boot_screen.sh +++ b/installation/options/boot_screen.sh @@ -11,12 +11,32 @@ fi arg="$1" boot_config_path=$(get_boot_config_path) +_enable_boot_screen() { + sudo sed -i 's/^disable_splash=1/disable_splash=0/' "$boot_config_path" + if ! grep -q "^disable_splash" "$boot_config_path"; then + echo "disable_splash=0" | sudo tee -a "$boot_config_path" + fi +} + +_disable_boot_screen() { + sudo sed -i 's/^disable_splash=0/disable_splash=1/' "$boot_config_path" + if ! grep -q "^disable_splash" "$boot_config_path"; then + echo "disable_splash=1" | sudo tee -a "$boot_config_path" + fi +} + +# Logic if [ "$arg" = "enable" ]; then print_lc "Enabling RPi rainbow screen..." - sudo raspi-config nonint do_boot_splash 0 + _enable_boot_screen elif [ "$arg" = "disable" ]; then print_lc "Disabling RPi rainbow screen..." - sudo raspi-config nonint do_boot_splash 1 + _disable_boot_screen fi -# Test, no test required. Depending on raspi-config to test +# Tests +if [ "$arg" = "enable" ]; then + verify_file_does_not_contain_string "disable_splash=" "${boot_config_path}" +elif [ "$arg" = "disable" ]; then + verify_file_contains_string_once "disable_splash=1" "${boot_config_path}" +fi From 22ef685e271475faf476dfcf0e5b2ed70bc7edad Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:03:44 +0100 Subject: [PATCH 13/28] fix: Typo --- installation/options/static_ip.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/options/static_ip.sh b/installation/options/static_ip.sh index 1530ec001..14ae3decc 100644 --- a/installation/options/static_ip.sh +++ b/installation/options/static_ip.sh @@ -5,7 +5,7 @@ source ../includes/02_helpers.sh if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then - print_lc "Error: Invalid or no statusument provided. + print_lc "Error: Invalid or no status provided. Usage: ./static_ip.sh [optional] where can be 'enable' or 'disable'" exit 1 From b89435fb344cfb6825677645bdcf5a36b0315aa0 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Mon, 22 Jan 2024 23:08:22 +0100 Subject: [PATCH 14/28] refactor: abstract boot_path function --- installation/includes/02_helpers.sh | 14 +++++++++++--- installation/options/onboard_sound.sh | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index 73ed7fffe..5efe9eb4a 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -88,16 +88,16 @@ get_debian_version_number() { echo "$VERSION_ID" } -get_boot_config_path() { +get_boot_path() { if [ "$(is_raspian)" = true ]; then local debian_version_number=$(get_debian_version_number) # Bullseye and lower if [ "$debian_version_number" -le 11 ]; then - echo "/boot/config.txt" + echo "/boot/$1" # Bookworm and higher elif [ "$debian_version_number" -ge 12 ]; then - echo "/boot/firmware/config.txt" + echo "/boot/firmware/$1" else echo "unknown" fi @@ -106,6 +106,14 @@ get_boot_config_path() { fi } +get_boot_config_path() { + get_boot_path "config.txt" +} + +get_boot_cmdline_path() { + get_boot_path "cmdline.txt" +} + validate_url() { local url=$1 wget --spider ${url} >/dev/null 2>&1 diff --git a/installation/options/onboard_sound.sh b/installation/options/onboard_sound.sh index 475a9161d..2e13cfbee 100755 --- a/installation/options/onboard_sound.sh +++ b/installation/options/onboard_sound.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash source ../includes/02_helpers.sh + script_name=$(basename "$0") boot_config_path=$(get_boot_config_path) From 8e4ec13de1c338d2e3085e429992e2a4cf7ce405 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Mon, 22 Jan 2024 23:11:05 +0100 Subject: [PATCH 15/28] refactor: outsource boot_logs and systemctl_services --- installation/options/boot_logs.sh | 51 ++++++++++++++ installation/options/systemctl_services.sh | 57 ++++++++++++++++ installation/routines/optimize_boot_time.sh | 76 +-------------------- 3 files changed, 110 insertions(+), 74 deletions(-) create mode 100644 installation/options/boot_logs.sh create mode 100644 installation/options/systemctl_services.sh diff --git a/installation/options/boot_logs.sh b/installation/options/boot_logs.sh new file mode 100644 index 000000000..69de3f3ac --- /dev/null +++ b/installation/options/boot_logs.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +source ../includes/02_helpers.sh + +if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then + print_lc "Error: Invalid or no argument provided. +Usage: ./boot_logs.sh + where can be 'enable' or 'disable'" + exit 1 +fi + +arg="$1" +boot_cmdline_path=$(get_boot_cmdline_path) +boot_cmdline_options="consoleblank=1 logo.nologo quiet loglevel=0 plymouth.enable=0 vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fastboot noatime nodiratime noram" + +if [ "$arg" = "enable" ]; then + print_lc "Enable Boot logs..." + + if [ -s "${boot_cmdline_path}" ]; then + for option in $boot_cmdline_options; do + sudo sed -i "s/\s*$option\s*/ /" "${boot_cmdline_path}" + done + fi +elif [ "$arg" = "disable" ]; then + print_lc "Disable Boot logs..." + + if [ ! -s "${boot_cmdline_path}" ];then + sudo tee "${boot_cmdline_path}" <<-EOF +${boot_cmdline_options} +EOF + else + for option in $boot_cmdline_options + do + if ! grep -qiw "$option" "${boot_cmdline_path}" ; then + sudo sed -i "s/$/ $option/" "${boot_cmdline_path}" + fi + done + fi +fi + +# Test +if [ "$arg" = "enable" ]; then + for option in $boot_cmdline_options + do + verify_file_does_not_contain_string $option "${boot_cmdline_path}" + done +elif [ "$arg" = "disable" ]; then + for option in $boot_cmdline_options + do + verify_file_contains_string_once $option "${boot_cmdline_path}" + done +fi diff --git a/installation/options/systemctl_services.sh b/installation/options/systemctl_services.sh new file mode 100644 index 000000000..c830c3624 --- /dev/null +++ b/installation/options/systemctl_services.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +source ../includes/02_helpers.sh + +if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then + print_lc "Error: Invalid or no argument provided. +Usage: ./systemctl_services.sh + where can be 'enable' or 'disable'" + exit 1 +fi + +arg="$1" + +if [ "$arg" = "enable" ]; then + print_lc "Enable default services..." + + sudo systemctl enable keyboard-setup.service + sudo systemctl enable triggerhappy.service + sudo systemctl enable triggerhappy.socket + sudo systemctl enable raspi-config.service + sudo systemctl enable apt-daily.service + sudo systemctl enable apt-daily-upgrade.service + sudo systemctl enable apt-daily.timer + sudo systemctl enable apt-daily-upgrade.timer +elif [ "$arg" = "disable" ]; then + print_lc "Disable default services..." + + sudo systemctl disable keyboard-setup.service + sudo systemctl disable triggerhappy.service + sudo systemctl disable triggerhappy.socket + sudo systemctl disable raspi-config.service + sudo systemctl disable apt-daily.service + sudo systemctl disable apt-daily-upgrade.service + sudo systemctl disable apt-daily.timer + sudo systemctl disable apt-daily-upgrade.timer +fi + +# Test +if [ "$arg" = "enable" ]; then + verify_optional_service_enablement keyboard-setup.service enabled + verify_optional_service_enablement triggerhappy.service enabled + verify_optional_service_enablement triggerhappy.socket enabled + verify_optional_service_enablement raspi-config.service enabled + verify_optional_service_enablement apt-daily.service enabled + verify_optional_service_enablement apt-daily-upgrade.service enabled + verify_optional_service_enablement apt-daily.timer enabled + verify_optional_service_enablement apt-daily-upgrade.timer enabled + +elif [ "$arg" = "disable" ]; then + verify_optional_service_enablement keyboard-setup.service disabled + verify_optional_service_enablement triggerhappy.service disabled + verify_optional_service_enablement triggerhappy.socket disabled + verify_optional_service_enablement raspi-config.service disabled + verify_optional_service_enablement apt-daily.service disabled + verify_optional_service_enablement apt-daily-upgrade.service disabled + verify_optional_service_enablement apt-daily.timer disabled + verify_optional_service_enablement apt-daily-upgrade.timer disabled +fi diff --git a/installation/routines/optimize_boot_time.sh b/installation/routines/optimize_boot_time.sh index 3d7ee880d..843ac2cd5 100644 --- a/installation/routines/optimize_boot_time.sh +++ b/installation/routines/optimize_boot_time.sh @@ -2,27 +2,8 @@ # Reference: https://panther.software/configuration-code/raspberry-pi-3-4-faster-boot-time-in-few-easy-steps/ -OPTIMIZE_DHCP_CONF="/etc/dhcpcd.conf" -OPTIMIZE_BOOT_CMDLINE_OPTIONS="consoleblank=1 logo.nologo quiet loglevel=0 plymouth.enable=0 vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fastboot noatime nodiratime noram" -OPTIMIZE_DHCP_CONF_HEADER="## Jukebox DHCP Config" -OPTIMIZE_BOOT_CONF_HEADER="## Jukebox Boot Config" - _optimize_disable_irrelevant_services() { - log " Disable keyboard-setup.service" - sudo systemctl disable keyboard-setup.service - - log " Disable triggerhappy.service" - sudo systemctl disable triggerhappy.service - sudo systemctl disable triggerhappy.socket - - log " Disable raspi-config.service" - sudo systemctl disable raspi-config.service - - log " Disable apt-daily.service & apt-daily-upgrade.service" - sudo systemctl disable apt-daily.service - sudo systemctl disable apt-daily-upgrade.service - sudo systemctl disable apt-daily.timer - sudo systemctl disable apt-daily-upgrade.timer + ./../options/systemctl_services.sh disable } _optimize_handle_bluetooth() { @@ -53,65 +34,12 @@ _optimize_handle_boot_screen() { fi } -# TODO: Allow both Enable and Disable _optimize_handle_boot_logs() { if [ "$DISABLE_BOOT_LOGS_PRINT" = true ] ; then - log " Disable boot logs" - - if [ ! -s "${RPI_BOOT_CMDLINE_FILE}" ];then - sudo tee "${RPI_BOOT_CMDLINE_FILE}" <<-EOF -${OPTIMIZE_BOOT_CMDLINE_OPTIONS} -EOF - else - for option in $OPTIMIZE_BOOT_CMDLINE_OPTIONS - do - if ! grep -qiw "$option" "${RPI_BOOT_CMDLINE_FILE}" ; then - sudo sed -i "s/$/ $option/" "${RPI_BOOT_CMDLINE_FILE}" - fi - done - fi + ./../options/boot_logs.sh disable fi } - -_optimize_check() { - print_verify_installation - - verify_optional_service_enablement keyboard-setup.service disabled - verify_optional_service_enablement triggerhappy.service disabled - verify_optional_service_enablement triggerhappy.socket disabled - verify_optional_service_enablement raspi-config.service disabled - verify_optional_service_enablement apt-daily.service disabled - verify_optional_service_enablement apt-daily-upgrade.service disabled - verify_optional_service_enablement apt-daily.timer disabled - verify_optional_service_enablement apt-daily-upgrade.timer disabled - - # if [ "$DISABLE_BLUETOOTH" = true ] ; then - # verify_optional_service_enablement hciuart.service disabled - # verify_optional_service_enablement bluetooth.service disabled - # fi - - # if [ "$ENABLE_STATIC_IP" = true ] ; then - # verify_file_contains_string_once "${OPTIMIZE_DHCP_CONF_HEADER}" "${OPTIMIZE_DHCP_CONF}" - # verify_file_contains_string "${CURRENT_INTERFACE}" "${OPTIMIZE_DHCP_CONF}" - # verify_file_contains_string "${CURRENT_IP_ADDRESS}" "${OPTIMIZE_DHCP_CONF}" - # verify_file_contains_string "${CURRENT_GATEWAY}" "${OPTIMIZE_DHCP_CONF}" - # fi - # if [ "$DISABLE_IPv6" = true ] ; then - # verify_file_contains_string_once "${OPTIMIZE_IPV6_CONF_HEADER}" "${OPTIMIZE_DHCP_CONF}" - # fi - # if [ "$DISABLE_BOOT_SCREEN" = true ] ; then - # verify_file_contains_string_once "${OPTIMIZE_BOOT_CONF_HEADER}" "${RPI_BOOT_CONFIG_FILE}" - # fi - - if [ "$DISABLE_BOOT_LOGS_PRINT" = true ] ; then - for option in $OPTIMIZE_BOOT_CMDLINE_OPTIONS - do - verify_file_contains_string_once $option "${RPI_BOOT_CMDLINE_FILE}" - done - fi -} - _run_optimize_boot_time() { _optimize_disable_irrelevant_services _optimize_handle_bluetooth From 735063f1a3f75ea96c3f73e0329b99a65cdbbf1f Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 23 Jan 2024 22:56:19 +0100 Subject: [PATCH 16/28] Remove option 'Disable on-chip audio' in favor of self-service --- documentation/builders/audio.md | 18 ++++++++++++++++++ installation/includes/01_default_config.sh | 2 -- installation/routines/set_raspi_config.sh | 12 ------------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/documentation/builders/audio.md b/documentation/builders/audio.md index 54bfe72bf..59241f3fc 100644 --- a/documentation/builders/audio.md +++ b/documentation/builders/audio.md @@ -13,6 +13,24 @@ Audio outputs run via PulseAudio and the basic configuration should be easy. There is a [configuration tool](../developers/coreapps.md#Audio), to setup the configuration for the Jukebox Core App. +### Disable On-Chip audio + +If you are planning on using an external sound card (e.g. USB, HifiBerry, PirateAudio, etc), we recommend to disable the on-chip audio. It will make the sound configuration easier. +If you are planning to only use Bluetooth speakers, leave the on-chip audio enabled! + +Run the following command to manage the On-chip audio. Make sure you reboot your device afterwards. + +```bash +cd ~/RPi-Jukebox-RFID/installation/options +./onboard_sound.sh disable +``` + +If you like to enable it, use the following command: + +```bash +./onboard_sound.sh enable +``` + ### To set up the audio 1. Follow the setup steps according to your sound card diff --git a/installation/includes/01_default_config.sh b/installation/includes/01_default_config.sh index ec7b67b66..f1f8dbe2c 100644 --- a/installation/includes/01_default_config.sh +++ b/installation/includes/01_default_config.sh @@ -17,8 +17,6 @@ ENABLE_RFID_READER=true ENABLE_SAMBA=true ENABLE_WEBAPP=true ENABLE_KIOSK_MODE=false -DISABLE_ONBOARD_AUDIO=false -DISABLE_ONBOARD_AUDIO_BACKUP="${RPI_BOOT_CONFIG_FILE}.backup.audio_on_$(date +%d.%m.%y_%H.%M.%S)" # Always try to use GIT with SSH first, and on failure drop down to HTTPS GIT_USE_SSH=${GIT_USE_SSH:-"true"} diff --git a/installation/routines/set_raspi_config.sh b/installation/routines/set_raspi_config.sh index 7f39a0ba5..96358a209 100644 --- a/installation/routines/set_raspi_config.sh +++ b/installation/routines/set_raspi_config.sh @@ -14,18 +14,6 @@ _run_set_raspi_config() { # power management of wifi: switch off to avoid disconnecting log " Disable Wifi power management to avoid disconnecting" sudo iwconfig wlan0 power off - - # On-board audio - if [ "$DISABLE_ONBOARD_AUDIO" == true ]; then - log " Disable on-chip BCM audio" - if grep -q -E "^dtparam=([^,]*,)*audio=(on|true|yes|1).*" "${RPI_BOOT_CONFIG_FILE}" ; then - log " Backup ${RPI_BOOT_CONFIG_FILE} --> ${DISABLE_ONBOARD_AUDIO_BACKUP}" - sudo cp "${RPI_BOOT_CONFIG_FILE}" "${DISABLE_ONBOARD_AUDIO_BACKUP}" - sudo sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(on\|true\|yes\|1\)\(.*\)/\1audio=off\4/g" "${RPI_BOOT_CONFIG_FILE}" - else - log " On board audio seems to be off already. Not touching ${RPI_BOOT_CONFIG_FILE}" - fi - fi } set_raspi_config() { From 334465e85961a167599ec76e8552702f065ff07a Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 23 Jan 2024 22:56:19 +0100 Subject: [PATCH 17/28] Remove option 'Disable on-chip audio' in favor of self-service --- installation/routines/customize_options.sh | 32 ---------------------- 1 file changed, 32 deletions(-) diff --git a/installation/routines/customize_options.sh b/installation/routines/customize_options.sh index ce623b563..22d0e803c 100644 --- a/installation/routines/customize_options.sh +++ b/installation/routines/customize_options.sh @@ -263,37 +263,6 @@ Would you like to update the operating system? [Y/n]" log "UPDATE_RASPI_OS=${UPDATE_RASPI_OS}" } -_option_disable_onboard_audio() { - # Disable BCM on-chip audio (typically Headphones) - # not needed when external sound card is sued - clear_c - print_c "--------------------- ON-CHIP AUDIO --------------------- - -If you are using an external sound card (e.g. USB, -HifiBerry, PirateAudio, etc), we recommend to disable -the on-chip audio. It will make the ALSA sound -configuration easier. -If you are planning to only use Bluetooth speakers, -leave the on-chip audio enabled! -(This will touch your boot configuration in -${RPI_BOOT_CONFIG_FILE}. -We will do our best not to mess anything up. However, -a backup copy will be written to -${DISABLE_ONBOARD_AUDIO_BACKUP} ) - -Disable Pi's on-chip audio (headphone / jack output)? [y/N]" - read -r response - case "$response" in - [yY][eE][sS]|[yY]) - DISABLE_ONBOARD_AUDIO=true - ;; - *) - ;; - esac - log "DISABLE_ONBOARD_AUDIO=${DISABLE_ONBOARD_AUDIO}" - -} - _option_webapp_devel_build() { # Let's detect if we are on the official release branch if [[ "$GIT_BRANCH" != "${GIT_BRANCH_RELEASE}" && "$GIT_BRANCH" != "${GIT_BRANCH_DEVELOP}" ]] || [[ "$GIT_USER" != "$GIT_UPSTREAM_USER" ]] || [[ "$CI_RUNNING" == "true" ]] ; then @@ -335,7 +304,6 @@ _run_customize_options() { _option_static_ip # Optional: Not required for installation _option_autohotspot # Optional: Not required for installation _option_bluetooth # Optional: Not required for installation - _option_disable_onboard_audio # Optional: Should be merged with other audio installations, like HifiBerry _option_mpd # !!Required, without options _option_rfid_reader # !!Required, with options _option_samba # !!Required, without options From a1ebeedbb1e79f213ee8d3df65f194e39d4ee5b1 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 23 Jan 2024 23:09:37 +0100 Subject: [PATCH 18/28] rename: optimize_boot_time to optimized_defaults --- installation/routines/install.sh | 2 +- .../{optimize_boot_time.sh => optimized_defaults.sh} | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename installation/routines/{optimize_boot_time.sh => optimized_defaults.sh} (91%) diff --git a/installation/routines/install.sh b/installation/routines/install.sh index f1f2a5f80..862851f9f 100644 --- a/installation/routines/install.sh +++ b/installation/routines/install.sh @@ -13,7 +13,7 @@ install() { setup_jukebox_webapp setup_kiosk_mode setup_rfid_reader - optimize_boot_time + optimized_defaults setup_autohotspot cleanup } diff --git a/installation/routines/optimize_boot_time.sh b/installation/routines/optimized_defaults.sh similarity index 91% rename from installation/routines/optimize_boot_time.sh rename to installation/routines/optimized_defaults.sh index 843ac2cd5..6310203a4 100644 --- a/installation/routines/optimize_boot_time.sh +++ b/installation/routines/optimized_defaults.sh @@ -40,7 +40,7 @@ _optimize_handle_boot_logs() { fi } -_run_optimize_boot_time() { +_run_optimized_defaults() { _optimize_disable_irrelevant_services _optimize_handle_bluetooth _optimize_static_ip @@ -50,6 +50,6 @@ _run_optimize_boot_time() { _optimize_check } -optimize_boot_time() { - run_with_log_frame _run_optimize_boot_time "Optimize boot time" +optimized_defaults() { + run_with_log_frame _run_optimized_defaults "Optimize boot time" } From 9451924a4573899b110719896cf879021d9decab Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 23 Jan 2024 23:10:56 +0100 Subject: [PATCH 19/28] fix: make options scripts executable --- installation/options/bluetooth.sh | 0 installation/options/boot_logs.sh | 0 installation/options/boot_screen.sh | 0 installation/options/ipv6.sh | 0 installation/options/static_ip.sh | 0 installation/options/systemctl_services.sh | 0 6 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 installation/options/bluetooth.sh mode change 100644 => 100755 installation/options/boot_logs.sh mode change 100644 => 100755 installation/options/boot_screen.sh mode change 100644 => 100755 installation/options/ipv6.sh mode change 100644 => 100755 installation/options/static_ip.sh mode change 100644 => 100755 installation/options/systemctl_services.sh diff --git a/installation/options/bluetooth.sh b/installation/options/bluetooth.sh old mode 100644 new mode 100755 diff --git a/installation/options/boot_logs.sh b/installation/options/boot_logs.sh old mode 100644 new mode 100755 diff --git a/installation/options/boot_screen.sh b/installation/options/boot_screen.sh old mode 100644 new mode 100755 diff --git a/installation/options/ipv6.sh b/installation/options/ipv6.sh old mode 100644 new mode 100755 diff --git a/installation/options/static_ip.sh b/installation/options/static_ip.sh old mode 100644 new mode 100755 diff --git a/installation/options/systemctl_services.sh b/installation/options/systemctl_services.sh old mode 100644 new mode 100755 From 08cfcb7933eae45fdf5faeb3179c7d1eafa44c39 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 23 Jan 2024 23:28:34 +0100 Subject: [PATCH 20/28] refactor: introduce optimized defaults, opinionated improvements --- installation/includes/01_default_config.sh | 3 --- installation/routines/optimized_defaults.sh | 30 ++++----------------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/installation/includes/01_default_config.sh b/installation/includes/01_default_config.sh index f1f8dbe2c..5bacf43ed 100644 --- a/installation/includes/01_default_config.sh +++ b/installation/includes/01_default_config.sh @@ -6,10 +6,7 @@ DISABLE_IPv6=true ENABLE_AUTOHOTSPOT=false AUTOHOTSPOT_CHANGE_PASSWORD=false AUTOHOTSPOT_PASSWORD="PlayItLoud!" -DISABLE_BLUETOOTH=true DISABLE_SSH_QOS=true -DISABLE_BOOT_SCREEN=true -DISABLE_BOOT_LOGS_PRINT=true SETUP_MPD=true ENABLE_MPD_OVERWRITE_INSTALL=true UPDATE_RASPI_OS=${UPDATE_RASPI_OS:-"true"} diff --git a/installation/routines/optimized_defaults.sh b/installation/routines/optimized_defaults.sh index 6310203a4..9bacfb539 100644 --- a/installation/routines/optimized_defaults.sh +++ b/installation/routines/optimized_defaults.sh @@ -2,16 +2,6 @@ # Reference: https://panther.software/configuration-code/raspberry-pi-3-4-faster-boot-time-in-few-easy-steps/ -_optimize_disable_irrelevant_services() { - ./../options/systemctl_services.sh disable -} - -_optimize_handle_bluetooth() { - if [ "$DISABLE_BLUETOOTH" = true ] ; then - ./../options/bluetooth.sh disable - fi -} - # TODO: Allow options to enable/disable wifi, Dynamic/Static IP etc. _optimize_static_ip() { # Static IP Address and DHCP optimizations @@ -28,28 +18,18 @@ _optimize_ipv6_arp() { fi } -_optimize_handle_boot_screen() { - if [ "$DISABLE_BOOT_SCREEN" = true ] ; then +_run_optimized_defaults() { + ./../options/systemctl_services.sh disable + ./../options/bluetooth.sh disable ./../options/boot_screen.sh disable - fi -} - -_optimize_handle_boot_logs() { - if [ "$DISABLE_BOOT_LOGS_PRINT" = true ] ; then ./../options/boot_logs.sh disable - fi -} + ./../options/ssh_qos.sh disable -_run_optimized_defaults() { - _optimize_disable_irrelevant_services - _optimize_handle_bluetooth _optimize_static_ip _optimize_ipv6_arp - _optimize_handle_boot_screen - _optimize_handle_boot_logs _optimize_check } optimized_defaults() { - run_with_log_frame _run_optimized_defaults "Optimize boot time" + run_with_log_frame _run_optimized_defaults "Optimize boot time and system settings" } From 4ed3a9c548cab143533add3c6ef7b929e2d3faf0 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 23 Jan 2024 23:29:10 +0100 Subject: [PATCH 21/28] refactor: make ssh_qos.sh an option --- installation/options/ssh_qos.sh | 35 +++++++++++++++++++++ installation/routines/install.sh | 1 - installation/routines/optimized_defaults.sh | 1 - installation/routines/set_ssh_qos.sh | 11 ------- 4 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 installation/options/ssh_qos.sh delete mode 100644 installation/routines/set_ssh_qos.sh diff --git a/installation/options/ssh_qos.sh b/installation/options/ssh_qos.sh new file mode 100644 index 000000000..a92a186d0 --- /dev/null +++ b/installation/options/ssh_qos.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# The latest version of SSH installed on the Raspberry Pi 3 uses QoS headers, +# which disagrees with some routers and other hardware. This causes immense +# delays when remotely accessing the RPi over ssh. + +source ../includes/02_helpers.sh + +if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then + print_lc "Error: Invalid or no argument provided. +Usage: ./ssh_qos.sh + where can be 'enable' or 'disable'" + exit 1 +fi + +arg="$1" + +if [ "$arg" = "enable" ]; then + print_lc "Enabling SSH QoS..." + sudo sed -i '/^IPQoS 0x00 0x00/d' /etc/ssh/sshd_config + sudo sed -i '/^IPQoS 0x00 0x00/d' /etc/ssh/ssh_config +elif [ "$arg" = "disable" ]; then + print_lc "Disabling SSH QoS..." + echo -e "IPQoS 0x00 0x00\n" | sudo tee -a /etc/ssh/sshd_config + echo -e "IPQoS 0x00 0x00\n" | sudo tee -a /etc/ssh/ssh_config +fi + +# Test +if [ "$arg" = "enable" ]; then + verify_file_does_not_contain_string "IPQoS 0x00 0x00" "/etc/ssh/sshd_config" + verify_file_does_not_contain_string "IPQoS 0x00 0x00" "/etc/ssh/ssh_config" +elif [ "$arg" = "disable" ]; then + verify_file_contains_string_once "IPQoS 0x00 0x00" "/etc/ssh/sshd_config" + verify_file_contains_string_once "IPQoS 0x00 0x00" "/etc/ssh/ssh_config" +fi diff --git a/installation/routines/install.sh b/installation/routines/install.sh index 862851f9f..2aadf042a 100644 --- a/installation/routines/install.sh +++ b/installation/routines/install.sh @@ -4,7 +4,6 @@ install() { clear_c show_slow_hardware_message set_raspi_config - set_ssh_qos update_raspi_os init_git_repo_from_tardir setup_jukebox_core diff --git a/installation/routines/optimized_defaults.sh b/installation/routines/optimized_defaults.sh index 9bacfb539..d624dee2f 100644 --- a/installation/routines/optimized_defaults.sh +++ b/installation/routines/optimized_defaults.sh @@ -27,7 +27,6 @@ _run_optimized_defaults() { _optimize_static_ip _optimize_ipv6_arp - _optimize_check } optimized_defaults() { diff --git a/installation/routines/set_ssh_qos.sh b/installation/routines/set_ssh_qos.sh deleted file mode 100644 index 76242f712..000000000 --- a/installation/routines/set_ssh_qos.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set_ssh_qos() { - if [ "$DISABLE_SSH_QOS" == true ] ; then - # The latest version of SSH installed on the Raspberry Pi 3 uses QoS headers, which disagrees with some - # routers and other hardware. This causes immense delays when remotely accessing the RPi over ssh. - log " Set SSH QoS to best effort" - echo -e "IPQoS 0x00 0x00\n" | sudo tee -a /etc/ssh/sshd_config - echo -e "IPQoS 0x00 0x00\n" | sudo tee -a /etc/ssh/ssh_config - fi -} From c4a7530f1bbf9698e5cf08cf22e8a82ff406b15e Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Tue, 23 Jan 2024 23:40:10 +0100 Subject: [PATCH 22/28] fix: remove unnecessary variable --- installation/includes/01_default_config.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/installation/includes/01_default_config.sh b/installation/includes/01_default_config.sh index 5bacf43ed..fd9a7c7b2 100644 --- a/installation/includes/01_default_config.sh +++ b/installation/includes/01_default_config.sh @@ -6,7 +6,6 @@ DISABLE_IPv6=true ENABLE_AUTOHOTSPOT=false AUTOHOTSPOT_CHANGE_PASSWORD=false AUTOHOTSPOT_PASSWORD="PlayItLoud!" -DISABLE_SSH_QOS=true SETUP_MPD=true ENABLE_MPD_OVERWRITE_INSTALL=true UPDATE_RASPI_OS=${UPDATE_RASPI_OS:-"true"} From 02b4bf068136466da1868a3b1e3503e4bf57776c Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 24 Jan 2024 08:39:03 +0100 Subject: [PATCH 23/28] fix: remove bluetooth from installation questionaire --- installation/routines/customize_options.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/installation/routines/customize_options.sh b/installation/routines/customize_options.sh index 22d0e803c..360330875 100644 --- a/installation/routines/customize_options.sh +++ b/installation/routines/customize_options.sh @@ -303,7 +303,6 @@ _run_customize_options() { _option_ipv6 # Optional: Not required for installation _option_static_ip # Optional: Not required for installation _option_autohotspot # Optional: Not required for installation - _option_bluetooth # Optional: Not required for installation _option_mpd # !!Required, without options _option_rfid_reader # !!Required, with options _option_samba # !!Required, without options From d812fc1a18abf8b1aaf3da521d9221d3e12e36e7 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Wed, 24 Jan 2024 08:44:55 +0100 Subject: [PATCH 24/28] refactor: move former raspi-config changes into optimized_defaults --- installation/routines/install.sh | 1 - installation/routines/optimized_defaults.sh | 11 +++++++++++ installation/routines/set_raspi_config.sh | 21 --------------------- 3 files changed, 11 insertions(+), 22 deletions(-) delete mode 100644 installation/routines/set_raspi_config.sh diff --git a/installation/routines/install.sh b/installation/routines/install.sh index 2aadf042a..8e08ae284 100644 --- a/installation/routines/install.sh +++ b/installation/routines/install.sh @@ -3,7 +3,6 @@ install() { customize_options clear_c show_slow_hardware_message - set_raspi_config update_raspi_os init_git_repo_from_tardir setup_jukebox_core diff --git a/installation/routines/optimized_defaults.sh b/installation/routines/optimized_defaults.sh index d624dee2f..4169c9da8 100644 --- a/installation/routines/optimized_defaults.sh +++ b/installation/routines/optimized_defaults.sh @@ -19,6 +19,17 @@ _optimize_ipv6_arp() { } _run_optimized_defaults() { + # Source: https://raspberrypi.stackexchange.com/a/66939 + # Autologin + log "Enable Autologin for user" + sudo raspi-config nonint do_boot_behaviour B2 + # Wait for network at boot + # log "Enable 'Wait for network at boot'" + # sudo raspi-config nonint do_boot_wait 1 + # power management of wifi: switch off to avoid disconnecting + log "Disable Wifi power management to avoid disconnecting" + sudo iwconfig wlan0 power off + ./../options/systemctl_services.sh disable ./../options/bluetooth.sh disable ./../options/boot_screen.sh disable diff --git a/installation/routines/set_raspi_config.sh b/installation/routines/set_raspi_config.sh deleted file mode 100644 index 96358a209..000000000 --- a/installation/routines/set_raspi_config.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash - -_run_set_raspi_config() { - # Source: https://raspberrypi.stackexchange.com/a/66939 - - # Autologin - log " Enable Autologin for user" - sudo raspi-config nonint do_boot_behaviour B2 - - # Wait for network at boot - # log " Enable 'Wait for network at boot'" - # sudo raspi-config nonint do_boot_wait 1 - - # power management of wifi: switch off to avoid disconnecting - log " Disable Wifi power management to avoid disconnecting" - sudo iwconfig wlan0 power off -} - -set_raspi_config() { - run_with_log_frame _run_set_raspi_config "Set default raspi-config" -} From de693f77322b3346ec7ca6a181ea3dcc383205fc Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 1 Mar 2024 21:41:12 +0100 Subject: [PATCH 25/28] Align new install script with NetworkManager update --- installation/includes/02_helpers.sh | 30 +++ installation/options/static_ip.sh | 1 + installation/routines/optimize_boot_time.sh | 210 -------------------- 3 files changed, 31 insertions(+), 210 deletions(-) delete mode 100644 installation/routines/optimize_boot_time.sh diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index 54d15df7f..9f8400c1b 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -128,6 +128,36 @@ download_from_url() { return $? } +_add_options_to_cmdline() { + local options="$1" + + local cmdlineFile=$(get_boot_cmdline_path) + if [ ! -s "${cmdlineFile}" ];then + sudo tee "${cmdlineFile}" <<-EOF +${options} +EOF + else + for option in $options + do + if ! grep -qiw "$option" "${cmdlineFile}" ; then + sudo sed -i "s/$/ $option/" "${cmdlineFile}" + fi + done + fi +} + +_remove_options_from_cmdline() { + local options="$1" + + local cmdlineFile=$(get_boot_cmdline_path) + + if [ -s "${cmdlineFile}" ]; then + for option in $options; do + sudo sed -i "/$option/d" "${cmdlineFile}" + done + fi +} + ### Verify helpers print_verify_installation() { log "\n diff --git a/installation/options/static_ip.sh b/installation/options/static_ip.sh index 9a8fe6b02..222244ea4 100755 --- a/installation/options/static_ip.sh +++ b/installation/options/static_ip.sh @@ -40,6 +40,7 @@ interface ${CURRENT_INTERFACE} static ip_address=${ipaddress}/24 static routers=${CURRENT_GATEWAY} static domain_name_servers=${CURRENT_GATEWAY} +noarp ${END_MARKER} EOF } diff --git a/installation/routines/optimize_boot_time.sh b/installation/routines/optimize_boot_time.sh deleted file mode 100644 index e3761c31d..000000000 --- a/installation/routines/optimize_boot_time.sh +++ /dev/null @@ -1,210 +0,0 @@ -#!/usr/bin/env bash - -# Reference: https://panther.software/configuration-code/raspberry-pi-3-4-faster-boot-time-in-few-easy-steps/ - -OPTIMIZE_DHCP_CONF="/etc/dhcpcd.conf" -OPTIMIZE_BOOT_CMDLINE_OPTIONS="consoleblank=1 logo.nologo quiet loglevel=0 plymouth.enable=0 vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fastboot noatime nodiratime noram" -OPTIMIZE_BOOT_CMDLINE_OPTIONS_IPV6="ipv6.disable=1" -OPTIMIZE_DHCP_CONF_HEADER="## Jukebox DHCP Config" -OPTIMIZE_BOOT_CONF_HEADER="## Jukebox Boot Config" - -_optimize_disable_irrelevant_services() { - log " Disable keyboard-setup.service" - sudo systemctl disable keyboard-setup.service - - log " Disable triggerhappy.service" - sudo systemctl disable triggerhappy.service - sudo systemctl disable triggerhappy.socket - - log " Disable raspi-config.service" - sudo systemctl disable raspi-config.service - - log " Disable apt-daily.service & apt-daily-upgrade.service" - sudo systemctl disable apt-daily.service - sudo systemctl disable apt-daily-upgrade.service - sudo systemctl disable apt-daily.timer - sudo systemctl disable apt-daily-upgrade.timer -} - -_add_options_to_cmdline() { - local options="$1" - - local cmdlineFile=$(get_boot_cmdline_path) - if [ ! -s "${cmdlineFile}" ];then - sudo tee "${cmdlineFile}" <<-EOF -${options} -EOF - else - for option in $options - do - if ! grep -qiw "$option" "${cmdlineFile}" ; then - sudo sed -i "s/$/ $option/" "${cmdlineFile}" - fi - done - fi -} - -# TODO: If false, actually make sure bluetooth is enabled -_optimize_handle_bluetooth() { - if [ "$DISABLE_BLUETOOTH" = true ] ; then - print_lc " Disable bluetooth" - sudo systemctl disable hciuart.service - sudo systemctl disable bluetooth.service - fi -} - -# TODO: Allow options to enable/disable wifi, Dynamic/Static IP etc. -_optimize_static_ip() { - # Static IP Address and DHCP optimizations - if [[ $(is_dhcpcd_enabled) == true ]]; then - if [ "$ENABLE_STATIC_IP" = true ] ; then - print_lc " Set static IP address" - if grep -q "${OPTIMIZE_DHCP_CONF_HEADER}" "$OPTIMIZE_DHCP_CONF"; then - log " Skipping. Already set up!" - else - # DHCP has not been configured - log " ${CURRENT_INTERFACE} is the default network interface" - log " ${CURRENT_GATEWAY} is the Router Gateway address" - log " Using ${CURRENT_IP_ADDRESS} as the static IP for now" - - sudo tee -a $OPTIMIZE_DHCP_CONF <<-EOF - -${OPTIMIZE_DHCP_CONF_HEADER} -interface ${CURRENT_INTERFACE} -static ip_address=${CURRENT_IP_ADDRESS}/24 -static routers=${CURRENT_GATEWAY} -static domain_name_servers=${CURRENT_GATEWAY} -noarp - -EOF - - fi - fi - fi -} - -# TODO: Allow both Enable and Disable -# Disable ipv6 thoroughly on the system with kernel parameter -_optimize_ipv6_arp() { - if [ "$DISABLE_IPv6" = true ] ; then - print_lc " Disabling IPV6" - _add_options_to_cmdline "${OPTIMIZE_BOOT_CMDLINE_OPTIONS_IPV6}" - fi -} - -# TODO: Allow both Enable and Disable -_optimize_handle_boot_screen() { - local configFile=$(get_boot_config_path) - if [ "$DISABLE_BOOT_SCREEN" = true ] ; then - log " Disable RPi rainbow screen" - if grep -q "${OPTIMIZE_BOOT_CONF_HEADER}" "$configFile"; then - log " Skipping. Already set up!" - else - sudo tee -a $configFile <<-EOF - -${OPTIMIZE_BOOT_CONF_HEADER} -disable_splash=1 - -EOF - fi - fi -} - -# TODO: Allow both Enable and Disable -_optimize_handle_boot_logs() { - if [ "$DISABLE_BOOT_LOGS_PRINT" = true ] ; then - log " Disable boot logs" - - _add_options_to_cmdline "${OPTIMIZE_BOOT_CMDLINE_OPTIONS}" - fi -} - -get_nm_active_profile() -{ - local active_profile=$(nmcli -g DEVICE,CONNECTION device status | grep "^${CURRENT_INTERFACE}" | cut -d':' -f2) - echo "$active_profile" -} - -_optimize_static_ip_NetworkManager() { - if [[ $(is_NetworkManager_enabled) == true ]]; then - if [ "$ENABLE_STATIC_IP" = true ] ; then - print_lc " Set static IP address" - log " ${CURRENT_INTERFACE} is the default network interface" - log " ${CURRENT_GATEWAY} is the Router Gateway address" - log " Using ${CURRENT_IP_ADDRESS} as the static IP for now" - local active_profile=$(get_nm_active_profile) - sudo nmcli connection modify "$active_profile" ipv4.method manual ipv4.address "${CURRENT_IP_ADDRESS}/24" ipv4.gateway "$CURRENT_GATEWAY" ipv4.dns "$CURRENT_GATEWAY" - #else - # for future deactivation - #sudo nmcli connection modify "$active_profile" ipv4.method auto ipv4.address "" ipv4.gateway "" ipv4.dns "" - fi - fi -} - - -_optimize_check() { - print_verify_installation - - local cmdlineFile=$(get_boot_cmdline_path) - local configFile=$(get_boot_config_path) - - - verify_optional_service_enablement keyboard-setup.service disabled - verify_optional_service_enablement triggerhappy.service disabled - verify_optional_service_enablement triggerhappy.socket disabled - verify_optional_service_enablement raspi-config.service disabled - verify_optional_service_enablement apt-daily.service disabled - verify_optional_service_enablement apt-daily-upgrade.service disabled - verify_optional_service_enablement apt-daily.timer disabled - verify_optional_service_enablement apt-daily-upgrade.timer disabled - - if [ "$DISABLE_BLUETOOTH" = true ] ; then - verify_optional_service_enablement hciuart.service disabled - verify_optional_service_enablement bluetooth.service disabled - fi - - if [ "$ENABLE_STATIC_IP" = true ] ; then - if [[ $(is_dhcpcd_enabled) == true ]]; then - verify_file_contains_string_once "${OPTIMIZE_DHCP_CONF_HEADER}" "${OPTIMIZE_DHCP_CONF}" - verify_file_contains_string "${CURRENT_INTERFACE}" "${OPTIMIZE_DHCP_CONF}" - verify_file_contains_string "${CURRENT_IP_ADDRESS}" "${OPTIMIZE_DHCP_CONF}" - verify_file_contains_string "${CURRENT_GATEWAY}" "${OPTIMIZE_DHCP_CONF}" - fi - - if [[ $(is_NetworkManager_enabled) == true ]]; then - local active_profile=$(get_nm_active_profile) - local active_profile_path="/etc/NetworkManager/system-connections/${active_profile}.nmconnection" - verify_files_exists "${active_profile_path}" - verify_file_contains_string "${CURRENT_IP_ADDRESS}" "${active_profile_path}" - verify_file_contains_string "${CURRENT_GATEWAY}" "${active_profile_path}" - fi - fi - if [ "$DISABLE_IPv6" = true ] ; then - verify_file_contains_string_once "${OPTIMIZE_BOOT_CMDLINE_OPTIONS_IPV6}" "${cmdlineFile}" - fi - if [ "$DISABLE_BOOT_SCREEN" = true ] ; then - verify_file_contains_string_once "${OPTIMIZE_BOOT_CONF_HEADER}" "${configFile}" - fi - - if [ "$DISABLE_BOOT_LOGS_PRINT" = true ] ; then - for option in $OPTIMIZE_BOOT_CMDLINE_OPTIONS - do - verify_file_contains_string_once $option "${cmdlineFile}" - done - fi -} - -_run_optimize_boot_time() { - _optimize_disable_irrelevant_services - _optimize_handle_boot_screen - _optimize_handle_boot_logs - _optimize_handle_bluetooth - _optimize_static_ip - _optimize_static_ip_NetworkManager - _optimize_ipv6_arp - _optimize_check -} - -optimize_boot_time() { - run_with_log_frame _run_optimize_boot_time "Optimize boot time" -} From 989571d60c9bc84852c63605059a9fd56d98657d Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 1 Mar 2024 22:32:17 +0100 Subject: [PATCH 26/28] Do not disable IPv6 automatically in installation. Still keep function as separate option --- installation/includes/00_constants.sh | 1 + installation/includes/01_default_config.sh | 1 - installation/includes/02_helpers.sh | 10 +++++++++ installation/options/ipv6.sh | 21 ++++++++++++++++++- installation/routines/customize_options.sh | 21 ------------------- installation/routines/optimized_defaults.sh | 8 ------- installation/routines/setup_jukebox_webapp.sh | 12 ----------- 7 files changed, 31 insertions(+), 43 deletions(-) diff --git a/installation/includes/00_constants.sh b/installation/includes/00_constants.sh index 574febed3..217c28f7b 100644 --- a/installation/includes/00_constants.sh +++ b/installation/includes/00_constants.sh @@ -5,6 +5,7 @@ SYSTEMD_USR_PATH="/usr/lib/systemd/user" VIRTUAL_ENV="${INSTALLATION_PATH}/.venv" # Do not change this directory! It must match MPDs expectation where to find the user configuration MPD_CONF_PATH="${HOME}/.config/mpd/mpd.conf" +WEBAPP_NGINX_SITE_DEFAULT_CONF="/etc/nginx/sites-available/default" # The default upstream user, release branch, and develop branch # These are used to prepare the repo for developers diff --git a/installation/includes/01_default_config.sh b/installation/includes/01_default_config.sh index 42d49f971..620aebcee 100644 --- a/installation/includes/01_default_config.sh +++ b/installation/includes/01_default_config.sh @@ -2,7 +2,6 @@ BUILD_LIBZMQ_WITH_DRAFTS_ON_DEVICE=${BUILD_LIBZMQ_WITH_DRAFTS_ON_DEVICE:-"false"} ENABLE_STATIC_IP=true -DISABLE_IPv6=true ENABLE_AUTOHOTSPOT=false AUTOHOTSPOT_PROFILE="Phoniebox_Hotspot" AUTOHOTSPOT_SSID="$AUTOHOTSPOT_PROFILE" diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index 9f8400c1b..23d5df662 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -158,6 +158,16 @@ _remove_options_from_cmdline() { fi } +is_package_installed() { + local package_name=$1 + + if apt list --installed 2>/dev/null | grep -q "$package_name"; then + echo "true" + else + echo "false" + fi +} + ### Verify helpers print_verify_installation() { log "\n diff --git a/installation/options/ipv6.sh b/installation/options/ipv6.sh index e25861c99..aead30703 100755 --- a/installation/options/ipv6.sh +++ b/installation/options/ipv6.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +source ../includes/00_constants.sh source ../includes/02_helpers.sh if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then @@ -11,18 +12,36 @@ fi arg="$1" cmdlineFile=$(get_boot_cmdline_path) OPTIONS_IPV6="ipv6.disable=1" +nginx_is_installed=$(is_package_installed nginx) if [ "$arg" = "enable" ]; then print_lc "Enabling IPv6..." - _remove_options_to_cmdline "${OPTIONS_IPV6}" # TODO implement _remove_options_to_cmdline + _remove_options_to_cmdline "${OPTIONS_IPV6}" + + if [ "$nginx_is_installed" = "true" ]; then + if ! grep -q 'listen \[::\]:80' "${WEBAPP_NGINX_SITE_DEFAULT_CONF}"; then + echo 'listen [::]:80' | sudo tee -a "${WEBAPP_NGINX_SITE_DEFAULT_CONF}" > /dev/null + fi + fi + elif [ "$arg" = "disable" ]; then print_lc "Disabling IPv6..." _add_options_to_cmdline "${OPTIONS_IPV6}" + + if [ "$nginx_is_installed" = "true" ]; then + sudo sed -i '/listen \[::\]:80/d' "${WEBAPP_NGINX_SITE_DEFAULT_CONF}" + fi fi # Test if [ "$arg" = "enable" ]; then verify_file_does_not_contain_string "${OPTIONS_IPV6}" "${cmdlineFile}" + if [ "$nginx_is_installed" = "true" ]; then + verify_file_contains_string "listen [::]:80" "${WEBAPP_NGINX_SITE_DEFAULT_CONF}" + fi elif [ "$arg" = "disable" ]; then verify_file_contains_string_once "${OPTIONS_IPV6}" "${cmdlineFile}" + if [ "$nginx_is_installed" = "true" ]; then + verify_file_does_not_contain_string "listen [::]:80" "${WEBAPP_NGINX_SITE_DEFAULT_CONF}" + fi fi diff --git a/installation/routines/customize_options.sh b/installation/routines/customize_options.sh index 328b70a68..db5ac92c0 100644 --- a/installation/routines/customize_options.sh +++ b/installation/routines/customize_options.sh @@ -28,26 +28,6 @@ Set a static IP? [Y/n]" log "ENABLE_STATIC_IP=${ENABLE_STATIC_IP}" } -_option_ipv6() { - # DISABLE_IPv6 - clear_c - print_c "------------------------- IP V6 ------------------------- - -IPv6 is only needed if you intend to use it. -Otherwise it can be disabled. - -Do you want to disable IPv6? [Y/n]" - read -r response - case "$response" in - [nN][oO]|[nN]) - DISABLE_IPv6=false - ;; - *) - ;; - esac - log "DISABLE_IPv6=${DISABLE_IPv6}" -} - _option_autohotspot() { # ENABLE_AUTOHOTSPOT clear_c @@ -347,7 +327,6 @@ Do you want to build the Web App? [Y/n]" } _run_customize_options() { - _option_ipv6 # Optional: Not required for installation _option_static_ip # Optional: Not required for installation _option_autohotspot # Optional: Not required for installation _option_mpd # !!Required, without options diff --git a/installation/routines/optimized_defaults.sh b/installation/routines/optimized_defaults.sh index 4169c9da8..9b3b57210 100644 --- a/installation/routines/optimized_defaults.sh +++ b/installation/routines/optimized_defaults.sh @@ -4,7 +4,6 @@ # TODO: Allow options to enable/disable wifi, Dynamic/Static IP etc. _optimize_static_ip() { - # Static IP Address and DHCP optimizations if [ "$ENABLE_STATIC_IP" = true ] ; then ./../options/static_ip.sh enable else @@ -12,12 +11,6 @@ _optimize_static_ip() { fi } -_optimize_ipv6_arp() { - if [ "$DISABLE_IPv6" = true ] ; then - ./../options/ipv6.sh disable - fi -} - _run_optimized_defaults() { # Source: https://raspberrypi.stackexchange.com/a/66939 # Autologin @@ -37,7 +30,6 @@ _run_optimized_defaults() { ./../options/ssh_qos.sh disable _optimize_static_ip - _optimize_ipv6_arp } optimized_defaults() { diff --git a/installation/routines/setup_jukebox_webapp.sh b/installation/routines/setup_jukebox_webapp.sh index f95e547f1..b129d7e1d 100644 --- a/installation/routines/setup_jukebox_webapp.sh +++ b/installation/routines/setup_jukebox_webapp.sh @@ -1,8 +1,5 @@ #!/usr/bin/env bash -# Constants -WEBAPP_NGINX_SITE_DEFAULT_CONF="/etc/nginx/sites-available/default" - # Node major version used. # If changed also update in .github\actions\build-webapp\action.yml NODE_MAJOR=20 @@ -117,10 +114,6 @@ _jukebox_webapp_register_as_system_service_with_nginx() { sudo cp -f "${INSTALLATION_PATH}/resources/default-settings/nginx.default" "${WEBAPP_NGINX_SITE_DEFAULT_CONF}" sudo sed -i "s|%%INSTALLATION_PATH%%|${INSTALLATION_PATH}|g" "${WEBAPP_NGINX_SITE_DEFAULT_CONF}" - if [ "$DISABLE_IPv6" = true ] ; then - sudo sed -i '/listen \[::\]:80/d' "${WEBAPP_NGINX_SITE_DEFAULT_CONF}" - fi - # make sure nginx can access the home directory of the user sudo chmod o+x "${HOME_PATH}" @@ -150,11 +143,6 @@ _jukebox_webapp_check() { verify_apt_packages nginx verify_files_exists "${WEBAPP_NGINX_SITE_DEFAULT_CONF}" - - if [ "$DISABLE_IPv6" = true ] ; then - verify_file_does_not_contain_string "listen [::]:80" "${WEBAPP_NGINX_SITE_DEFAULT_CONF}" - fi - verify_service_enablement nginx.service enabled } From db609d68d88cc3ce0782d2430153ccdc522cda31 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 1 Mar 2024 22:39:49 +0100 Subject: [PATCH 27/28] Get back some functions from previous commits --- installation/includes/02_helpers.sh | 64 +++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index 23d5df662..c308ed75b 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -128,6 +128,70 @@ download_from_url() { return $? } +get_string_length() { + local string="$1" + # "-n" option is needed otherwise an additional linebreak char is added by echo + echo -n ${string} | wc -m +} + +_get_service_enablement() { + local service="$1" + local option="${2:+$2 }" # optional, dont't quote in 'systemctl' call! + + if [[ -z "${service}" ]]; then + exit_on_error "ERROR: at least one parameter value is missing!" + fi + + local actual_enablement=$(systemctl is-enabled ${option}${service} 2>/dev/null) + + echo "$actual_enablement" +} + +is_service_enabled() { + local service="$1" + local option="$2" + local actual_enablement=$(_get_service_enablement $service $option) + + if [[ "$actual_enablement" == "enabled" ]]; then + echo true + else + echo false + fi +} + +is_dhcpcd_enabled() { + echo $(is_service_enabled "dhcpcd.service") +} + +is_NetworkManager_enabled() { + echo $(is_service_enabled "NetworkManager.service") +} + +# create flag file if files does no exist (*.remove) or copy present conf to backup file (*.orig) +# to correctly handling de-/activation of corresponding feature +config_file_backup() { + local config_file="$1" + local config_flag_file="${config_file}.remove" + local config_orig_file="${config_file}.orig" + if [ ! -f "${config_file}" ]; then + sudo touch "${config_flag_file}" + elif [ ! -f "${config_orig_file}" ] && [ ! -f "${config_flag_file}" ]; then + sudo cp "${config_file}" "${config_orig_file}" + fi +} + +# revert config files backed up with `config_file_backup` +config_file_revert() { + local config_file="$1" + local config_flag_file="${config_file}.remove" + local config_orig_file="${config_file}.orig" + if [ -f "${config_flag_file}" ]; then + sudo rm "${config_flag_file}" "${config_file}" + elif [ -f "${config_orig_file}" ]; then + sudo mv "${config_orig_file}" "${config_file}" + fi +} + _add_options_to_cmdline() { local options="$1" From 56843652540fdeb0b73648077f4f9ed8a7ff2f26 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sat, 2 Mar 2024 07:35:32 +0100 Subject: [PATCH 28/28] Delete set_raspi_config file --- installation/routines/set_raspi_config.sh | 35 ----------------------- 1 file changed, 35 deletions(-) delete mode 100644 installation/routines/set_raspi_config.sh diff --git a/installation/routines/set_raspi_config.sh b/installation/routines/set_raspi_config.sh deleted file mode 100644 index ef4707c91..000000000 --- a/installation/routines/set_raspi_config.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -_run_set_raspi_config() { - # Source: https://raspberrypi.stackexchange.com/a/66939 - - # Autologin - log " Enable Autologin for user" - sudo raspi-config nonint do_boot_behaviour B2 - - # Wait for network at boot - # log " Enable 'Wait for network at boot'" - # sudo raspi-config nonint do_boot_wait 1 - - # power management of wifi: switch off to avoid disconnecting - log " Disable Wifi power management to avoid disconnecting" - sudo iwconfig wlan0 power off - - # On-board audio - if [ "$DISABLE_ONBOARD_AUDIO" == true ]; then - local configFile=$(get_boot_config_path) - log " Disable on-chip BCM audio" - if grep -q -E "^dtparam=([^,]*,)*audio=(on|true|yes|1).*" "${configFile}" ; then - local configFile_backup="${configFile}.backup.audio_on_$(date +%d.%m.%y_%H.%M.%S)" - log " Backup ${configFile} --> ${configFile_backup}" - sudo cp "${configFile}" "${configFile_backup}" - sudo sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(on\|true\|yes\|1\)\(.*\)/\1audio=off\4/g" "${configFile}" - else - log " On board audio seems to be off already. Not touching ${configFile}" - fi - fi -} - -set_raspi_config() { - run_with_log_frame _run_set_raspi_config "Set default raspi-config" -}