diff --git a/documentation/builders/audio.md b/documentation/builders/audio.md index 93c46dd54..fffc096af 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/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 a3115fee6..620aebcee 100644 --- a/installation/includes/01_default_config.sh +++ b/installation/includes/01_default_config.sh @@ -2,17 +2,12 @@ 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" AUTOHOTSPOT_PASSWORD="PlayItLoud!" AUTOHOTSPOT_IP="10.0.0.1" AUTOHOTSPOT_COUNTRYCODE="DE" -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"} @@ -20,7 +15,6 @@ ENABLE_RFID_READER=true ENABLE_SAMBA=true ENABLE_WEBAPP=true ENABLE_KIOSK_MODE=false -DISABLE_ONBOARD_AUDIO=false # 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/includes/02_helpers.sh b/installation/includes/02_helpers.sh index dfad65187..c308ed75b 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -192,6 +192,46 @@ config_file_revert() { fi } +_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 +} + +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/bluetooth.sh b/installation/options/bluetooth.sh new file mode 100755 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/options/boot_logs.sh b/installation/options/boot_logs.sh new file mode 100755 index 000000000..858c7b089 --- /dev/null +++ b/installation/options/boot_logs.sh @@ -0,0 +1,34 @@ +#!/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_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..." + _remove_options_to_cmdline "${boot_cmdline_options}" + +elif [ "$arg" = "disable" ]; then + print_lc "Disable Boot logs..." + _add_options_to_cmdline "${boot_cmdline_options}" +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/boot_screen.sh b/installation/options/boot_screen.sh new file mode 100755 index 000000000..851a4a0a5 --- /dev/null +++ b/installation/options/boot_screen.sh @@ -0,0 +1,42 @@ +#!/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_screen.sh + where can be 'enable' or 'disable'" + exit 1 +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..." + _enable_boot_screen +elif [ "$arg" = "disable" ]; then + print_lc "Disabling RPi rainbow screen..." + _disable_boot_screen +fi + +# 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 diff --git a/installation/options/ipv6.sh b/installation/options/ipv6.sh new file mode 100755 index 000000000..aead30703 --- /dev/null +++ b/installation/options/ipv6.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +source ../includes/00_constants.sh +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" +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}" + + 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/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) 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/options/static_ip.sh b/installation/options/static_ip.sh new file mode 100755 index 000000000..222244ea4 --- /dev/null +++ b/installation/options/static_ip.sh @@ -0,0 +1,125 @@ +#!/usr/bin/env bash + +source ../includes/02_helpers.sh + +if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then + print_lc "Error: Invalid or no status provided. +Usage: ./static_ip.sh [optional] + where can be 'enable' or 'disable'" + exit 1 +fi + +status="$1" + +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 }') +ipaddress="${1:-$CURRENT_IP_ADDRESS}" # No IP address provided, use current IP address + +# DHCP +DHCP_CONF_PATH="/etc/dhcpcd.conf" +START_MARKER="## Jukebox DHCP Config Start" +END_MARKER="## Jukebox DHCP Config End" + +_set_static_ip_dhcp() { + 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 ${ipaddress} as the static IP" + + sudo tee -a $DHCP_CONF_PATH <<-EOF +${START_MARKER} +interface ${CURRENT_INTERFACE} +static ip_address=${ipaddress}/24 +static routers=${CURRENT_GATEWAY} +static domain_name_servers=${CURRENT_GATEWAY} +noarp +${END_MARKER} +EOF +} + +_remove_static_ip_dhcp() { + sed -i "/$START_MARKER/,/$END_MARKER/d" "$DHCP_CONF_PATH" +} + +# NetworkManager +get_nm_active_profile() +{ + local active_profile=$(nmcli -g DEVICE,CONNECTION device status | grep "^${CURRENT_INTERFACE}" | cut -d':' -f2) + echo "$active_profile" +} + +_set_static_ip_NetworkManager() { + local ipaddress="$1" + + if [[ $(is_NetworkManager_enabled) == true ]]; then + log "${CURRENT_INTERFACE} is the default network interface" + log "${CURRENT_GATEWAY} is the Router Gateway address" + log "Using ${ipaddress} as the static IP" + local active_profile=$(get_nm_active_profile) + sudo nmcli connection modify "$active_profile" ipv4.method manual ipv4.address "${ipaddress}/24" ipv4.gateway "$CURRENT_GATEWAY" ipv4.dns "$CURRENT_GATEWAY" + fi +} + +_remove_static_ip_NetworkManager() { + # for future deactivation + #sudo nmcli connection modify "$active_profile" ipv4.method auto ipv4.address "" ipv4.gateway "" ipv4.dns "" + print_lc "Currently not implemented" +} + + +# Logic +if [ "$status" = "enable" ]; then + print_lc "Enabling Static IP..." +elif [ "$status" = "disable" ]; then + print_lc "Disabling Static IP..." +fi + + +if [[ $(is_dhcpcd_enabled) == true ]]; then + cp "$DHCP_CONF_PATH" "${DHCP_CONF_PATH}.bak" + + if [ "$status" = "enable" ]; then + _set_static_ip_dhcp "$ipaddress" + elif [ "$status" = "disable" ]; then + _remove_static_ip_dhcp + 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 + +elif [[ $(is_NetworkManager_enabled) == true ]]; then + if [ "$status" = "enable" ]; then + _set_static_ip_NetworkManager "$ipaddress" + elif [ "$status" = "disable" ]; then + _remove_static_ip_NetworkManager + fi + + # Test + if [ "$status" = "enable" ]; then + active_profile=$(get_nm_active_profile) + active_profile_path="/etc/NetworkManager/system-connections/${active_profile}.nmconnection" + verify_files_exists "${active_profile_path}" + verify_file_contains_string "${ipaddress}" "${active_profile_path}" + verify_file_contains_string "${CURRENT_GATEWAY}" "${active_profile_path}" + elif [ "$status" = "disable" ]; then + # TODO: Implement tests for disablement + fi + +else + print_lc "No network service enabled. Aborting!" +fi diff --git a/installation/options/systemctl_services.sh b/installation/options/systemctl_services.sh new file mode 100755 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/customize_options.sh b/installation/routines/customize_options.sh index de1dd5a19..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 @@ -310,36 +290,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 file. -We will do our best not to mess anything up. However, -a backup copy will be written. Please check the install -log after for further details.) - -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 @@ -377,22 +327,16 @@ Do you want to build the Web App? [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_static_ip # Optional: Not required for installation + _option_autohotspot # Optional: Not required for installation + _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() { diff --git a/installation/routines/install.sh b/installation/routines/install.sh index 4ff3e1ac9..bff6c96a1 100644 --- a/installation/routines/install.sh +++ b/installation/routines/install.sh @@ -3,8 +3,6 @@ install() { customize_options clear_c show_slow_hardware_message - set_raspi_config - set_ssh_qos update_raspi_os init_git_repo_from_tardir setup_jukebox_core @@ -13,7 +11,7 @@ install() { setup_jukebox_webapp setup_kiosk_mode setup_rfid_reader - optimize_boot_time + optimized_defaults setup_autohotspot setup_postinstall cleanup 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" -} diff --git a/installation/routines/optimized_defaults.sh b/installation/routines/optimized_defaults.sh new file mode 100644 index 000000000..9b3b57210 --- /dev/null +++ b/installation/routines/optimized_defaults.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Reference: https://panther.software/configuration-code/raspberry-pi-3-4-faster-boot-time-in-few-easy-steps/ + +# TODO: Allow options to enable/disable wifi, Dynamic/Static IP etc. +_optimize_static_ip() { + if [ "$ENABLE_STATIC_IP" = true ] ; then + ./../options/static_ip.sh enable + else + ./../options/static_ip.sh disable + fi +} + +_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 + ./../options/boot_logs.sh disable + ./../options/ssh_qos.sh disable + + _optimize_static_ip +} + +optimized_defaults() { + run_with_log_frame _run_optimized_defaults "Optimize boot time and system settings" +} 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" -} 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 -} 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 }