From 46b360d7e72c2df1e8f18c48c3b4b83c65a3f5c3 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:06:16 +0100 Subject: [PATCH] Introduce proper logging functions --- installation/README.md | 20 +++- installation/includes/02_helpers.sh | 68 +++++------ installation/includes/03_welcome.sh | 8 +- installation/includes/05_finish.sh | 14 +-- installation/install-jukebox.sh | 110 +++++++++--------- installation/routines/customize_options.sh | 85 +++++++------- installation/routines/optimize_boot_time.sh | 30 ++--- installation/routines/set_raspi_config.sh | 12 +- installation/routines/set_ssh_qos.sh | 2 +- installation/routines/setup_git.sh | 76 ++++++------ installation/routines/setup_jukebox_core.sh | 22 ++-- installation/routines/setup_jukebox_webapp.sh | 12 +- installation/routines/setup_kiosk_mode.sh | 4 +- installation/routines/setup_mpd.sh | 8 +- installation/routines/setup_rfid_reader.sh | 2 +- installation/routines/setup_samba.sh | 6 +- 16 files changed, 246 insertions(+), 233 deletions(-) diff --git a/installation/README.md b/installation/README.md index b2a496348..a12f02d9c 100644 --- a/installation/README.md +++ b/installation/README.md @@ -3,14 +3,26 @@ ## Logging - Bash Script output rules ```bash -Output to both console and logfile: "$ command | tee /dev/fd/3" -Output to console only "$ command 1>&3" -Output to logfile only: "$ command" -No output to both console and logfile: "$ command > /dev/null" +print_lc "This message will be logged to both console and logfile" +print_c "This message will only be logged to the console" +log "This message will only be logged to the logfile" +clear 1>&3 ``` + + + [Learn more about bash script outputs](https://stackoverflow.com/questions/18460186/writing-outputs-to-log-file-and-console) ## Installation [Install Phoniebox software](../documentation/builders/installation.md#install-phoniebox-software) + + + + + + + + +1>&3 \ No newline at end of file diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index a8deca9c3..3945265f7 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -17,21 +17,21 @@ run_with_timer() { $1; # Executes the function passed as an argument - calc_runtime_and_print time_start $(date +%s) | tee /dev/fd/3 + calc_runtime_and_print time_start $(date +%s) | log } run_with_log_frame() { local time_start=$(date +%s); local description="$2" - echo -e "\n\n" - echo "#########################################################" - echo "${description}" | tee /dev/fd/3 + log "\n\n" + log "#########################################################" + print_lc "${description}" $1; # Executes the function passed as an argument local done_in=$(calc_runtime_and_print time_start $(date +%s)) - echo -e "\n${done_in} - ${description}" - echo "#########################################################" + log "\n${done_in} - ${description}" + log "#########################################################" } get_architecture() { @@ -69,16 +69,16 @@ get_version_string() { ### Verify helpers print_verify_installation() { - echo "" - echo " -------------------------------------------------------" - echo " Check installation" - echo "" + log "\n + ------------------------------------------------------- + Check installation +" } # Check if the file(s) exists verify_files_exists() { local files="$@" - echo " Verify '${files}' exists" + log " Verify '${files}' exists" if [[ -z "${files}" ]]; then exit_on_error "ERROR: at least one parameter value is missing!" @@ -88,13 +88,13 @@ verify_files_exists() { do test ! -f ${file} && exit_on_error "ERROR: '${file}' does not exists or is not a file!" done - echo " CHECK" + log " CHECK" } # Check if the dir(s) exists verify_dirs_exists() { local dirs="$@" - echo " Verify '${dirs}' exists" + log " Verify '${dirs}' exists" if [[ -z "${dirs}" ]]; then exit_on_error "ERROR: at least one parameter value is missing!" @@ -104,7 +104,7 @@ verify_dirs_exists() { do test ! -d ${dir} && exit_on_error "ERROR: '${dir}' does not exists or is not a dir!" done - echo " CHECK" + log " CHECK" } # Check if the file(s) has/have the expected owner and modifications @@ -113,7 +113,7 @@ verify_files_chmod_chown() { local user_expected=$2 local group_expected=$3 local files="${@:4}" - echo " Verify '${mod_expected}' '${user_expected}:${group_expected}' is set for '${files}'" + log " Verify '${mod_expected}' '${user_expected}:${group_expected}' is set for '${files}'" if [[ -z "${mod_expected}" || -z "${user_expected}" || -z "${group_expected}" || -z "${files}" ]]; then exit_on_error "ERROR: at least one parameter value is missing!" @@ -130,7 +130,7 @@ verify_files_chmod_chown() { test ! "${user_expected}" == "${user_actual}" && exit_on_error "ERROR: '${file}' actual owner '${user_actual}' differs from expected '${user_expected}'!" test ! "${group_expected}" == "${group_actual}" && exit_on_error "ERROR: '${file}' actual group '${group_actual}' differs from expected '${group_expected}'!" done - echo " CHECK" + log " CHECK" } # Check if the dir(s) has/have the expected owner and modifications @@ -139,7 +139,7 @@ verify_dirs_chmod_chown() { local user_expected=$2 local group_expected=$3 local dirs="${@:4}" - echo " Verify '${mod_expected}' '${user_expected}:${group_expected}' is set for '${dirs}'" + log " Verify '${mod_expected}' '${user_expected}:${group_expected}' is set for '${dirs}'" if [[ -z "${mod_expected}" || -z "${user_expected}" || -z "${group_expected}" || -z "${dirs}" ]]; then exit_on_error "ERROR: at least one parameter value is missing!" @@ -156,13 +156,13 @@ verify_dirs_chmod_chown() { test ! "${user_expected}" == "${user_actual}" && exit_on_error "ERROR: '${dir}' actual owner '${user_actual}' differs from expected '${user_expected}'!" test ! "${group_expected}" == "${group_actual}" && exit_on_error "ERROR: '${dir}' actual group '${group_actual}' differs from expected '${group_expected}'!" done - echo " CHECK" + log " CHECK" } verify_file_contains_string() { local string="$1" local file="$2" - echo " Verify '${string}' found in '${file}'" + log " Verify '${string}' found in '${file}'" if [[ -z "${string}" || -z "${file}" ]]; then exit_on_error "ERROR: at least one parameter value is missing!" @@ -171,13 +171,13 @@ verify_file_contains_string() { if [[ ! $(grep -iw "${string}" "${file}") ]]; then exit_on_error "ERROR: '${string}' not found in '${file}'" fi - echo " CHECK" + log " CHECK" } verify_file_contains_string_once() { local string="$1" local file="$2" - echo " Verify '${string}' found in '${file}'" + log " Verify '${string}' found in '${file}'" if [[ -z "${string}" || -z "${file}" ]]; then exit_on_error "ERROR: at least one parameter value is missing!" @@ -189,14 +189,14 @@ verify_file_contains_string_once() { elif [ "$file_contains_string_count" -gt 1 ]; then exit_on_error "ERROR: '${string}' found more than once in '${file}'" fi - echo " CHECK" + log " CHECK" } verify_service_state() { local service="$1" local desired_state="$2" local option="${3:+$3 }" # optional, dont't quote in next call! - echo " Verify service '${option}${service}' is '${desired_state}'" + log " Verify service '${option}${service}' is '${desired_state}'" if [[ -z "${service}" || -z "${desired_state}" ]]; then exit_on_error "ERROR: at least one parameter value is missing!" @@ -206,14 +206,14 @@ verify_service_state() { if [[ ! "${actual_state}" == "${desired_state}" ]]; then exit_on_error "ERROR: service '${option}${service}' is not '${desired_state}' (state: '${actual_state}')." fi - echo " CHECK" + log " CHECK" } verify_service_enablement() { local service="$1" local desired_enablement="$2" local option="${3:+$3 }" # optional, dont't quote in next call! - echo " Verify service ${option}${service} is ${desired_enablement}" + log " Verify service ${option}${service} is ${desired_enablement}" if [[ -z "${service}" || -z "${desired_enablement}" ]]; then exit_on_error "ERROR: at least one parameter value is missing!" @@ -223,14 +223,14 @@ verify_service_enablement() { if [[ ! "${actual_enablement}" == "${desired_enablement}" ]]; then exit_on_error "ERROR: service ${option}${service} is not ${desired_enablement} (state: ${actual_enablement})." fi - echo " CHECK" + log " CHECK" } verify_optional_service_enablement() { local service="$1" local desired_enablement="$2" local option="${3:+$3 }" # optional, dont't quote in next call! - echo " Verify service ${option}${service} is ${desired_enablement}" + log " Verify service ${option}${service} is ${desired_enablement}" if [[ -z "${service}" || -z "${desired_enablement}" ]]; then exit_on_error "ERROR: at least one parameter value is missing!" @@ -238,13 +238,13 @@ verify_optional_service_enablement() { local actual_enablement=$(systemctl is-enabled ${option}${service}) 2>/dev/null if [[ -z "${actual_enablement}" ]]; then - echo " INFO: optional service ${option}${service} is not installed." + log " INFO: optional service ${option}${service} is not installed." elif [[ "${actual_enablement}" == "static" ]]; then - echo " INFO: optional service ${option}${service} is set static." + log " INFO: optional service ${option}${service} is set static." elif [[ ! "${actual_enablement}" == "${desired_enablement}" ]]; then exit_on_error "ERROR: service ${option}${service} is not ${desired_enablement} (state: ${actual_enablement})." fi - echo " CHECK" + log " CHECK" } # Reads a textfile and returns all lines as args. @@ -259,7 +259,7 @@ get_args_from_file() { # Check if all passed packages are installed. Fail on first missing. verify_apt_packages() { local packages="$@" - echo " Verify packages are installed: '${packages}'" + log " Verify packages are installed: '${packages}'" if [[ -z "${packages}" ]]; then exit_on_error "ERROR: at least one parameter value is missing!" @@ -272,13 +272,13 @@ verify_apt_packages() { exit_on_error "ERROR: ${package} is not installed" fi done - echo " CHECK" + log " CHECK" } # Check if all passed modules are installed. Fail on first missing. verify_pip_modules() { local modules="$@" - echo " Verify modules are installed: '${modules}'" + log " Verify modules are installed: '${modules}'" if [[ -z "${modules}" ]]; then exit_on_error "ERROR: at least one parameter value is missing!" @@ -291,5 +291,5 @@ verify_pip_modules() { exit_on_error "ERROR: ${module} is not installed" fi done - echo " CHECK" + log " CHECK" } diff --git a/installation/includes/03_welcome.sh b/installation/includes/03_welcome.sh index 7aeaa56ab..19a9b4016 100644 --- a/installation/includes/03_welcome.sh +++ b/installation/includes/03_welcome.sh @@ -2,7 +2,7 @@ welcome() { clear 1>&3 - echo "######################################################### + print_c "######################################################### # # # ___ __ ______ _ __________ ____ __ _ _ # # / _ \/ // / __ \/ |/ / _/ __/( _ \ / \( \/ ) # @@ -29,16 +29,16 @@ in a separate SSH session: cd; tail -f ${INSTALLATION_LOGFILE} Let's set up your Phoniebox. -Do you want to start the installation? [Y/n]" 1>&3 +Do you want to start the installation? [Y/n]" read -r response case "$response" in [nN][oO]|[nN]) exit ;; *) - echo "Starting installation + print_c "Starting installation --------------------- -" 1>&3 +" ;; esac } diff --git a/installation/includes/05_finish.sh b/installation/includes/05_finish.sh index 55489ff46..22ba6ae80 100644 --- a/installation/includes/05_finish.sh +++ b/installation/includes/05_finish.sh @@ -2,7 +2,7 @@ finish() { local local_hostname=$(hostname) - echo -e "####################### FINISHED ######################## + print_lc "####################### FINISHED ######################## Installation complete! @@ -14,19 +14,19 @@ Your SSH connection will disconnect. After the reboot, you can access the WebApp in your browser at http://${local_hostname}.local or http://${CURRENT_IP_ADDRESS} Don't forget to upload files. -" | tee /dev/fd/3 -echo "Do you want to reboot now? [Y/n]" 1>&3 +" +print_c "Do you want to reboot now? [Y/n]" read -r response case "$response" in [nN][oO]|[nN]) - echo "Reboot aborted" | tee /dev/fd/3 - echo "DONE: finish" + print_lc "Reboot aborted" + log "DONE: finish" exit ;; *) - echo "Rebooting ..." | tee /dev/fd/3 - echo "DONE: finish" + print_lc "Rebooting ..." + log "DONE: finish" sudo reboot ;; esac diff --git a/installation/install-jukebox.sh b/installation/install-jukebox.sh index 90f78800f..b78ccfeba 100755 --- a/installation/install-jukebox.sh +++ b/installation/install-jukebox.sh @@ -17,48 +17,15 @@ GIT_BRANCH=${GIT_BRANCH:-"future3/main"} # Constants GIT_REPO_NAME="RPi-Jukebox-RFID" GIT_URL="https://github.com/${GIT_USER}/${GIT_REPO_NAME}" -echo GIT_BRANCH $GIT_BRANCH -echo GIT_URL $GIT_URL - CURRENT_USER="${SUDO_USER:-$(whoami)}" CURRENT_USER_GROUP=$(id -gn "$CURRENT_USER") HOME_PATH=$(getent passwd "$CURRENT_USER" | cut -d: -f6) -echo "Current User: $CURRENT_USER" -echo "User home dir: $HOME_PATH" INSTALLATION_PATH="${HOME_PATH}/${GIT_REPO_NAME}" INSTALL_ID=$(date +%s) INSTALLATION_LOGFILE="${HOME_PATH}/INSTALL-${INSTALL_ID}.log" -# Check if current distro is a 32 bit version -# Support for 64 bit Distros has not been checked (or precisely: is known not to work) -# All RaspianOS versions report as machine "armv6l" or "armv7l", if 32 bit (even the ARMv8 cores!) -_check_os_type() { - local os_type=$(uname -m) - - echo -e "\nChecking OS type '$os_type'" - - if [[ $os_type == "armv7l" || $os_type == "armv6l" ]]; then - echo -e " ... OK!\n" - else - echo "ERROR: Only 32 bit operating systems supported. Please use a 32bit version of RaspianOS!" - echo "You can fix this problem for 64bit kernels: https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/2041" - exit 1 - fi -} - # Manipulate file descriptor for logging -# Behavior: -# Write To logfile: -# default stdout will only write to logfile -# default stderr will only write to logfile -# e.g echo "write only to logfile" -# Write To console (user window): -# redirect to fd 3 will only write to the console -# e.g. echo "write only to console" 1>&3 -# Write To both: -# use tee to write output to logfile and console -# e.g. echo "write to both" | tee /dev/fd/3 _setup_logging(){ if [ "$CI_RUNNING" == "true" ]; then exec 3>&1 2>&1 @@ -68,40 +35,75 @@ _setup_logging(){ echo "Log start: ${INSTALL_ID}" } +# Function to log to both console and logfile +print_lc() { + local message="$1" + echo -e "$message" | tee /dev/fd/3 +} + +# Function to log to logfile only +log() { + local message="$1" + echo -e "$message" +} + +# Function to log to console only +print_c() { + local message="$1" + echo -e "$message" >&3 +} + # Generic emergency error handler that exits the script immediately # Print additional custom message if passed as first argument # Examples: # a command || exit_on_error # a command || exit_on_error "Execution of command failed" exit_on_error () { - echo -e "\n****************************************" | tee /dev/fd/3 - echo "ERROR OCCURRED! + print_lc "\n****************************************" + print_lc "ERROR OCCURRED! A non-recoverable error occurred. -Check install log for details:" | tee /dev/fd/3 - echo "$INSTALLATION_LOGFILE" | tee /dev/fd/3 - echo "****************************************" | tee /dev/fd/3 +Check install log for details:" + print_lc "$INSTALLATION_LOGFILE" + print_lc "****************************************" if [[ -n $1 ]]; then - echo "$1" | tee /dev/fd/3 - echo "****************************************" | tee /dev/fd/3 + print_lc "$1" + print_lc "****************************************" fi - echo "Abort!" + log "Abort!" exit 1 } +# Check if current distro is a 32 bit version +# Support for 64 bit Distros has not been checked (or precisely: is known not to work) +# All RaspianOS versions report as machine "armv6l" or "armv7l", if 32 bit (even the ARMv8 cores!) +_check_os_type() { + local os_type=$(uname -m) + + print_lc "\nChecking OS type '$os_type'" + + if [[ $os_type == "armv7l" || $os_type == "armv6l" ]]; then + print_lc " ... OK!\n" + else + print_lc "ERROR: Only 32 bit operating systems supported. Please use a 32bit version of RaspianOS!" + print_lc "You can fix this problem for 64bit kernels: https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/2041" + exit 1 + fi +} + _download_jukebox_source() { - echo -e "\n\n" - echo "#########################################################" - echo "Downloading Phoniebox software from Github ..." 1>&3 - echo "Download Source: ${GIT_URL}/${GIT_BRANCH}" | tee /dev/fd/3 + log "\n\n" + log "#########################################################" + print_c "Downloading Phoniebox software from Github ..." 1>&3 + print_lc "Download Source: ${GIT_URL}/${GIT_BRANCH}" cd "${HOME_PATH}" || exit_on_error "ERROR: Changing to home dir failed." wget -qO- "${GIT_URL}/tarball/${GIT_BRANCH}" | tar xz # Use case insensitive search/sed because user names in Git Hub are case insensitive local git_repo_download=$(find . -maxdepth 1 -type d -iname "${GIT_USER}-${GIT_REPO_NAME}-*") - echo "GIT REPO DOWNLOAD = $git_repo_download" + log "GIT REPO DOWNLOAD = $git_repo_download" GIT_HASH=$(echo "$git_repo_download" | sed -rn "s/.*${GIT_USER}-${GIT_REPO_NAME}-([0-9a-fA-F]+)/\1/ip") # Save the git hash for this particular download for later git repo initialization - echo "GIT HASH = $GIT_HASH" + log "GIT HASH = $GIT_HASH" if [[ -z "${git_repo_download}" ]]; then exit_on_error "ERROR: Couldn't find git download." fi @@ -109,8 +111,8 @@ _download_jukebox_source() { exit_on_error "ERROR: Couldn't determine git hash from download." fi mv "$git_repo_download" "$GIT_REPO_NAME" - echo -e "\nDONE: Downloading Phoniebox software from Github" - echo "#########################################################" + log "\nDONE: Downloading Phoniebox software from Github" + log "#########################################################" } _load_sources() { @@ -124,14 +126,18 @@ _load_sources() { done } +### SETUP LOGGING +_setup_logging ### CHECK PREREQUISITE _check_os_type -### SETUP LOGGING -_setup_logging - ### RUN INSTALLATION +log GIT_BRANCH $GIT_BRANCH +log GIT_URL $GIT_URL +log "Current User: $CURRENT_USER" +log "User home dir: $HOME_PATH" + _download_jukebox_source cd "${INSTALLATION_PATH}" || exit_on_error "ERROR: Changing to install dir failed." _load_sources diff --git a/installation/routines/customize_options.sh b/installation/routines/customize_options.sh index 1590383d1..fe1344d7a 100644 --- a/installation/routines/customize_options.sh +++ b/installation/routines/customize_options.sh @@ -9,14 +9,14 @@ _option_static_ip() { CURRENT_INTERFACE=$(echo "${CURRENT_ROUTE}" | awk '{ print $5; exit }') CURRENT_IP_ADDRESS=$(echo "${CURRENT_ROUTE}" | awk '{ print $7; exit }') clear 1>&3 - echo "----------------------- STATIC IP ----------------------- + print_c "----------------------- STATIC IP ----------------------- Setting a static IP will save a lot of start up time. The static adress will be '${CURRENT_IP_ADDRESS}' from interface '${CURRENT_INTERFACE}' with the gateway '${CURRENT_GATEWAY}'. -Set a static IP? [Y/n]" 1>&3 +Set a static IP? [Y/n]" read -r response case "$response" in [nN][oO]|[nN]) @@ -25,18 +25,18 @@ Set a static IP? [Y/n]" 1>&3 *) ;; esac - echo "ENABLE_STATIC_IP=${ENABLE_STATIC_IP}" + log "ENABLE_STATIC_IP=${ENABLE_STATIC_IP}" } _option_ipv6() { # DISABLE_IPv6 clear 1>&3 - echo "------------------------- IP V6 ------------------------- + 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]" 1>&3 +Do you want to disable IPv6? [Y/n]" read -r response case "$response" in [nN][oO]|[nN]) @@ -45,19 +45,19 @@ Do you want to disable IPv6? [Y/n]" 1>&3 *) ;; esac - echo "DISABLE_IPv6=${DISABLE_IPv6}" + log "DISABLE_IPv6=${DISABLE_IPv6}" } _option_autohotspot() { # ENABLE_AUTOHOTSPOT clear 1>&3 - echo "---------------------- AUTOHOTSPOT ---------------------- + print_c "---------------------- AUTOHOTSPOT ---------------------- When enabled, this service spins up a WiFi hotspot when the Phoniebox is unable to connect to a known WiFi. This way you can still access it. -Do you want to enable an Autohotpot? [y/N]" 1>&3 +Do you want to enable an Autohotpot? [y/N]" read -r response case "$response" in [yY][eE][sS]|[yY]) @@ -68,13 +68,13 @@ Do you want to enable an Autohotpot? [y/N]" 1>&3 esac if [ "$ENABLE_AUTOHOTSPOT" = true ]; then - echo "Do you want to set a custom Password? (default: ${AUTOHOTSPOT_PASSWORD}) [y/N] " 1>&3 + print_c "Do you want to set a custom Password? (default: ${AUTOHOTSPOT_PASSWORD}) [y/N] " read -r response_pw_q case "$response_pw_q" in [yY][eE][sS]|[yY]) while [ $(echo ${response_pw}|wc -m) -lt 8 ] do - echo "Please type the new password (at least 8 character)." 1>&3 + print_c "Please type the new password (at least 8 character)." read -r response_pw done AUTOHOTSPOT_PASSWORD="${response_pw}" @@ -84,29 +84,28 @@ Do you want to enable an Autohotpot? [y/N]" 1>&3 esac if [ "$ENABLE_STATIC_IP" = true ]; then - echo "Wifi hotspot cannot be enabled with static IP. Disabling static IP configuration." 1>&3 - echo "--------------------- - " 1>&3 + print_c "Wifi hotspot cannot be enabled with static IP. Disabling static IP configuration." + print_c "---------------------\n\n" ENABLE_STATIC_IP=false - echo "ENABLE_STATIC_IP=${ENABLE_STATIC_IP}" + print_lc "ENABLE_STATIC_IP=${ENABLE_STATIC_IP}" fi fi - echo "ENABLE_AUTOHOTSPOT=${ENABLE_AUTOHOTSPOT}" + log "ENABLE_AUTOHOTSPOT=${ENABLE_AUTOHOTSPOT}" if [ "$ENABLE_AUTOHOTSPOT" = true ]; then - echo "AUTOHOTSPOT_PASSWORD=${AUTOHOTSPOT_PASSWORD}" + log "AUTOHOTSPOT_PASSWORD=${AUTOHOTSPOT_PASSWORD}" fi } _option_bluetooth() { # DISABLE_BLUETOOTH clear 1>&3 - echo "----------------------- BLUETOOTH ----------------------- + print_c "----------------------- BLUETOOTH ----------------------- Turning off Bluetooth will save energy and start up time, if you do not plan to use it. -Do you want to disable Bluetooth? [Y/n]" 1>&3 +Do you want to disable Bluetooth? [Y/n]" read -r response case "$response" in [nN][oO]|[nN]) @@ -115,18 +114,18 @@ Do you want to disable Bluetooth? [Y/n]" 1>&3 *) ;; esac - echo "DISABLE_BLUETOOTH=${DISABLE_BLUETOOTH}" + log "DISABLE_BLUETOOTH=${DISABLE_BLUETOOTH}" } _option_mpd() { clear 1>&3 if [[ "$SETUP_MPD" == true ]]; then if [[ -f "${MPD_CONF_PATH}" || -f "${SYSTEMD_USR_PATH}/mpd.service" ]]; then - echo "-------------------------- MPD -------------------------- + print_c "-------------------------- MPD -------------------------- It seems there is a MPD already installed. Note: It is important that MPD runs as a user service! -Would you like to overwrite your configuration? [Y/n]" 1>&3 +Would you like to overwrite your configuration? [Y/n]" read -r response case "$response" in [nN][oO]|[nN]) @@ -138,23 +137,23 @@ Would you like to overwrite your configuration? [Y/n]" 1>&3 fi fi - echo "SETUP_MPD=${SETUP_MPD}" + log "SETUP_MPD=${SETUP_MPD}" if [ "$SETUP_MPD" == true ]; then - echo "ENABLE_MPD_OVERWRITE_INSTALL=${ENABLE_MPD_OVERWRITE_INSTALL}" + log "ENABLE_MPD_OVERWRITE_INSTALL=${ENABLE_MPD_OVERWRITE_INSTALL}" fi } _option_rfid_reader() { # ENABLE_RFID_READER clear 1>&3 - echo "---------------------- RFID READER ---------------------- + print_c "---------------------- RFID READER ---------------------- Phoniebox can be controlled with rfid cards/tags, if you have a rfid reader connected. Choose yes to setup a reader. You get prompted for the type selection and configuration later on. -Do you want to setup a rfid reader? [Y/n]" 1>&3 +Do you want to setup a rfid reader? [Y/n]" read -r response case "$response" in [nN][oO]|[nN]) @@ -163,20 +162,20 @@ Do you want to setup a rfid reader? [Y/n]" 1>&3 *) ;; esac - echo "ENABLE_RFID_READER=${ENABLE_RFID_READER}" + log "ENABLE_RFID_READER=${ENABLE_RFID_READER}" } _option_samba() { # ENABLE_SAMBA clear 1>&3 - echo "------------------------- SAMBA ------------------------- + print_c "------------------------- SAMBA ------------------------- Samba is required to conveniently copy files to your Phoniebox via a network share. If you don't need it, feel free to skip the installation. If you are unsure, stick to YES! -Do you want to install Samba? [Y/n]" 1>&3 +Do you want to install Samba? [Y/n]" read -r response case "$response" in [nN][oO]|[nN]) @@ -185,18 +184,18 @@ Do you want to install Samba? [Y/n]" 1>&3 *) ;; esac - echo "ENABLE_SAMBA=${ENABLE_SAMBA}" + log "ENABLE_SAMBA=${ENABLE_SAMBA}" } _option_webapp() { # ENABLE_WEBAPP clear 1>&3 - echo "------------------------ WEBAPP ------------------------- + print_c "------------------------ WEBAPP ------------------------- This is only required if you want to use a graphical interface to manage your Phoniebox! -Would you like to install the web application? [Y/n]" 1>&3 +Would you like to install the web application? [Y/n]" read -r response case "$response" in [nN][oO]|[nN]) @@ -206,20 +205,20 @@ Would you like to install the web application? [Y/n]" 1>&3 *) ;; esac - echo "ENABLE_WEBAPP=${ENABLE_WEBAPP}" + log "ENABLE_WEBAPP=${ENABLE_WEBAPP}" } _option_kiosk_mode() { # ENABLE_KIOSK_MODE clear 1>&3 - echo "----------------------- KIOSK MODE ---------------------- + print_c "----------------------- KIOSK MODE ---------------------- If you have a screen attached to your RPi, this will launch the web application right after boot. It will only install the necessary xserver dependencies and not the entire RPi desktop environment. -Would you like to enable the Kiosk Mode? [y/N]" 1>&3 +Would you like to enable the Kiosk Mode? [y/N]" read -r response case "$response" in [yY][eE][sS]|[yY]) @@ -228,18 +227,18 @@ Would you like to enable the Kiosk Mode? [y/N]" 1>&3 *) ;; esac - echo "ENABLE_KIOSK_MODE=${ENABLE_KIOSK_MODE}" + log "ENABLE_KIOSK_MODE=${ENABLE_KIOSK_MODE}" } _options_update_raspi_os() { # UPDATE_RASPI_OS clear 1>&3 - echo "----------------------- UPDATE OS ----------------------- + print_c "----------------------- UPDATE OS ----------------------- This shall be done eventually, but increases the installation time a lot. -Would you like to update the operating system? [Y/n]" 1>&3 +Would you like to update the operating system? [Y/n]" read -r response case "$response" in [nN][oO]|[nN]) @@ -248,14 +247,14 @@ Would you like to update the operating system? [Y/n]" 1>&3 *) ;; esac - echo "UPDATE_RASPI_OS=${UPDATE_RASPI_OS}" + 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 1>&3 - echo "--------------------- ON-CHIP AUDIO --------------------- + print_c "--------------------- ON-CHIP AUDIO --------------------- If you are using an external sound card (e.g. USB, HifiBerry, PirateAudio, etc), we recommend to disable @@ -269,7 +268,7 @@ 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]" 1>&3 +Disable Pi's on-chip audio (headphone / jack output)? [y/N]" read -r response case "$response" in [yY][eE][sS]|[yY]) @@ -278,7 +277,7 @@ Disable Pi's on-chip audio (headphone / jack output)? [y/N]" 1>&3 *) ;; esac - echo "DISABLE_ONBOARD_AUDIO=${DISABLE_ONBOARD_AUDIO}" + log "DISABLE_ONBOARD_AUDIO=${DISABLE_ONBOARD_AUDIO}" } @@ -292,13 +291,13 @@ _option_webapp_devel_build() { fi if [[ "$ENABLE_WEBAPP_PROD_DOWNLOAD" == false ]]; then clear 1>&3 - echo "--------------------- WEBAPP NODE --------------------- + print_c "--------------------- WEBAPP NODE --------------------- You are installing from a non-release branch. This means, you will need to build the web app locally. For that you'll need Node. -Do you want to install Node? [Y/n]" 1>&3 +Do you want to install Node? [Y/n]" read -r response case "$response" in [nN][oO]|[nN]) diff --git a/installation/routines/optimize_boot_time.sh b/installation/routines/optimize_boot_time.sh index 383f790c0..bb6f71902 100644 --- a/installation/routines/optimize_boot_time.sh +++ b/installation/routines/optimize_boot_time.sh @@ -9,17 +9,17 @@ OPTIMIZE_IPV6_CONF_HEADER="## Jukebox IPV6 Config" OPTIMIZE_BOOT_CONF_HEADER="## Jukebox Boot Config" _optimize_disable_irrelevant_services() { - echo " Disable keyboard-setup.service" + log " Disable keyboard-setup.service" sudo systemctl disable keyboard-setup.service - echo " Disable triggerhappy.service" + log " Disable triggerhappy.service" sudo systemctl disable triggerhappy.service sudo systemctl disable triggerhappy.socket - echo " Disable raspi-config.service" + log " Disable raspi-config.service" sudo systemctl disable raspi-config.service - echo " Disable apt-daily.service & apt-daily-upgrade.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 @@ -29,7 +29,7 @@ _optimize_disable_irrelevant_services() { # TODO: If false, actually make sure bluetooth is enabled _optimize_handle_bluetooth() { if [ "$DISABLE_BLUETOOTH" = true ] ; then - echo " Disable bluetooth" | tee /dev/fd/3 + print_lc " Disable bluetooth" sudo systemctl disable hciuart.service sudo systemctl disable bluetooth.service fi @@ -39,14 +39,14 @@ _optimize_handle_bluetooth() { _optimize_static_ip() { # Static IP Address and DHCP optimizations if [ "$ENABLE_STATIC_IP" = true ] ; then - echo " Set static IP address" | tee /dev/fd/3 + print_lc " Set static IP address" if grep -q "${OPTIMIZE_DHCP_CONF_HEADER}" "$OPTIMIZE_DHCP_CONF"; then - echo " Skipping. Already set up!" + log " Skipping. Already set up!" else # DHCP has not been configured - echo " ${CURRENT_INTERFACE} is the default network interface" - echo " ${CURRENT_GATEWAY} is the Router Gateway address" - echo " Using ${CURRENT_IP_ADDRESS} as the static IP for now" + 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 @@ -65,9 +65,9 @@ EOF # TODO: Allow both Enable and Disable _optimize_ipv6_arp() { if [ "$DISABLE_IPv6" = true ] ; then - echo " Disabling IPV6" | tee /dev/fd/3 + print_lc " Disabling IPV6" if grep -q "${OPTIMIZE_IPV6_CONF_HEADER}" "$OPTIMIZE_DHCP_CONF"; then - echo " Skipping. Already set up!" + log " Skipping. Already set up!" else sudo tee -a $OPTIMIZE_DHCP_CONF <<-EOF @@ -84,9 +84,9 @@ EOF # TODO: Allow both Enable and Disable _optimize_handle_boot_screen() { if [ "$DISABLE_BOOT_SCREEN" = true ] ; then - echo " Disable RPi rainbow screen" + log " Disable RPi rainbow screen" if grep -q "${OPTIMIZE_BOOT_CONF_HEADER}" "$RPI_BOOT_CONFIG_FILE"; then - echo " Skipping. Already set up!" + log " Skipping. Already set up!" else sudo tee -a $RPI_BOOT_CONFIG_FILE <<-EOF @@ -101,7 +101,7 @@ EOF # TODO: Allow both Enable and Disable _optimize_handle_boot_logs() { if [ "$DISABLE_BOOT_LOGS_PRINT" = true ] ; then - echo " Disable boot logs" + log " Disable boot logs" if [ ! -s "${RPI_BOOT_CMDLINE_FILE}" ];then sudo tee "${RPI_BOOT_CMDLINE_FILE}" <<-EOF diff --git a/installation/routines/set_raspi_config.sh b/installation/routines/set_raspi_config.sh index a9cb7b6f1..7f39a0ba5 100644 --- a/installation/routines/set_raspi_config.sh +++ b/installation/routines/set_raspi_config.sh @@ -4,26 +4,26 @@ _run_set_raspi_config() { # Source: https://raspberrypi.stackexchange.com/a/66939 # Autologin - echo " Enable Autologin for user" + log " Enable Autologin for user" sudo raspi-config nonint do_boot_behaviour B2 # Wait for network at boot - # echo " Enable '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 - echo " Disable Wifi power management 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 - echo " Disable on-chip BCM audio" + log " Disable on-chip BCM audio" if grep -q -E "^dtparam=([^,]*,)*audio=(on|true|yes|1).*" "${RPI_BOOT_CONFIG_FILE}" ; then - echo " Backup ${RPI_BOOT_CONFIG_FILE} --> ${DISABLE_ONBOARD_AUDIO_BACKUP}" + 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 - echo " On board audio seems to be off already. Not touching ${RPI_BOOT_CONFIG_FILE}" + log " On board audio seems to be off already. Not touching ${RPI_BOOT_CONFIG_FILE}" fi fi } diff --git a/installation/routines/set_ssh_qos.sh b/installation/routines/set_ssh_qos.sh index eaca62fed..76242f712 100644 --- a/installation/routines/set_ssh_qos.sh +++ b/installation/routines/set_ssh_qos.sh @@ -4,7 +4,7 @@ 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. - echo " Set SSH QoS to best effort" + 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_git.sh b/installation/routines/setup_git.sh index 613062f43..8fb03e98e 100644 --- a/installation/routines/setup_git.sh +++ b/installation/routines/setup_git.sh @@ -2,7 +2,7 @@ GIT_ABORT_MSG="Aborting dir to git repo conversion. Your directory content is untouched, you simply cannot use git for updating / developing" _git_install_os_dependencies() { - echo " Install Git dependencies" + log " Install Git dependencies" sudo apt-get -y update; sudo apt-get -y install \ git \ --no-install-recommends \ @@ -12,9 +12,9 @@ _git_install_os_dependencies() { } _git_convert_tardir_git_repo() { - echo "****************************************************" - echo "*** Converting tar-ball download into git repository" - echo "****************************************************" + log "**************************************************** +*** Converting tar-ball download into git repository +****************************************************" # Just in case, the git version is not new enough, we split up git init -b "${GIT_BRANCH}" into: git -c init.defaultBranch=main init @@ -30,21 +30,19 @@ _git_convert_tardir_git_repo() { # We simply get everything from the beginning of future 3 development but excluding Version 2.X if [[ $GIT_USE_SSH == true ]]; then git remote add origin "git@github.com:${GIT_USER}/${GIT_REPO_NAME}.git" - echo "" - echo "*** Git fetch (SSH) *******************************" + log "\n*** Git fetch (SSH) *******************************" # Prevent: The authenticity of host 'github.com (140.82.121.4)' can't be established. # Do only for this one command, so we do not disable the checks forever if ! git -c core.sshCommand='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' fetch origin "${GIT_BRANCH}" --set-upstream --shallow-since=2021-04-21 --tags; then - echo "" - echo "*** NOTICE *****************************************" - echo "* Error in getting Git Repository using SSH! USING FALLBACK HTTPS." - echo "* Note: This is only relevant for developers!" - echo "* Did you forget to upload the ssh key for this machine to GitHub?" - echo "* Defaulting to HTTPS protocol. You can change back to SSH later with" - echo "* git remote set-url origin git@github.com:${GIT_USER}/${GIT_REPO_NAME}.git" - echo "* git remote set-url upstream git@github.com:${GIT_UPSTREAM_USER}/${GIT_REPO_NAME}.git" - echo "" + log "\n*** NOTICE ***************************************** +* Error in getting Git Repository using SSH! USING FALLBACK HTTPS. +* Note: This is only relevant for developers! +* Did you forget to upload the ssh key for this machine to GitHub? +* Defaulting to HTTPS protocol. You can change back to SSH later with +* git remote set-url origin git@github.com:${GIT_USER}/${GIT_REPO_NAME}.git +* git remote set-url upstream git@github.com:${GIT_UPSTREAM_USER}/${GIT_REPO_NAME}.git" + git remote remove origin GIT_USE_SSH=false else @@ -60,32 +58,31 @@ _git_convert_tardir_git_repo() { if [[ "$GIT_USER" != "$GIT_UPSTREAM_USER" ]]; then git remote add upstream "https://github.com/${GIT_UPSTREAM_USER}/${GIT_REPO_NAME}.git" fi - echo "" - echo "*** Git fetch (HTTPS) *****************************" + log "\n*** Git fetch (HTTPS) *****************************" if ! git fetch origin --set-upstream --shallow-since=2021-04-21 --tags "${GIT_BRANCH}"; then - echo "Error: Could not fetch repository!" - echo -e "$GIT_ABORT_MSG" + log "Error: Could not fetch repository!" + log "$GIT_ABORT_MSG" return fi fi HASH_BRANCH=$(git rev-parse FETCH_HEAD) || { echo -e "$GIT_ABORT_MSG"; return; } - echo "" - echo "*** FETCH_HEAD ($GIT_BRANCH) = $HASH_BRANCH" + + log "\n*** FETCH_HEAD ($GIT_BRANCH) = $HASH_BRANCH" git add . # Checkout the exact hash that we have downloaded as tarball - echo "*** Git checkout commit" + log "*** Git checkout commit" git -c advice.detachedHead=false checkout "$GIT_HASH" || { echo -e "$GIT_ABORT_MSG"; return; } HASH_HEAD=$(git rev-parse HEAD) || { echo -e "$GIT_ABORT_MSG"; return; } - echo "*** REQUESTED COMMIT = $HASH_HEAD" + log "*** REQUESTED COMMIT = $HASH_HEAD" # Let's move onto the relevant branch, WITHOUT touching the current checked-out commit # Since we have fetched with --set-upstream above this initializes the tracking branch - echo "*** Git initialize branch" + log "*** Git initialize branch" git checkout -b "$GIT_BRANCH" if [[ "$GIT_USER" != "$GIT_UPSTREAM_USER" ]]; then - echo "*** Get upstream release tags" + log "*** Get upstream release tags" # Always get the upstream release branch to get all release tags # in case they have not been copied to user repository git fetch upstream --shallow-since=2021-04-21 --tags "${GIT_BRANCH_RELEASE}" @@ -101,7 +98,7 @@ _git_convert_tardir_git_repo() { if [[ $GIT_BRANCH != "${GIT_BRANCH_RELEASE}" ]]; then OUTPUT=$(git fetch origin --shallow-since=2021-04-21 --tags "${GIT_BRANCH_RELEASE}" 2>&1) if [[ $? -ne 128 ]]; then - echo "*** Preparing ${GIT_BRANCH_RELEASE} in background" + log "*** Preparing ${GIT_BRANCH_RELEASE} in background" echo -e "$OUTPUT" fi unset OUTPUT @@ -109,7 +106,7 @@ _git_convert_tardir_git_repo() { if [[ $GIT_BRANCH != "${GIT_BRANCH_DEVELOP}" ]]; then OUTPUT=$(git fetch origin --shallow-since=2021-04-21 --tags "${GIT_BRANCH_DEVELOP}" 2>&1) if [[ $? -ne 128 ]]; then - echo "*** Preparing ${GIT_BRANCH_DEVELOP} in background" + log "*** Preparing ${GIT_BRANCH_DEVELOP} in background" echo -e "$OUTPUT" fi unset OUTPUT @@ -117,25 +114,24 @@ _git_convert_tardir_git_repo() { # Provide some status outputs to the user if [[ "${HASH_BRANCH}" != "${HASH_HEAD}" ]]; then - echo "" - echo "*** IMPORTANT NOTICE *******************************" - echo "* Your requested branch has moved on while you were installing." - echo "* Don't worry! We will stay within the exact download version!" - echo "* But we set up the git repo to be ready for updating." - echo "* To start updating (observe updating guidelines!), do:" - echo "* $ git pull origin $GIT_BRANCH" - echo "" + log "\n*** IMPORTANT NOTICE ******************************* +* Your requested branch has moved on while you were installing. +* Don't worry! We will stay within the exact download version! +* But we set up the git repo to be ready for updating. +* To start updating (observe updating guidelines!), do: +* $ git pull origin $GIT_BRANCH" + fi - echo "*** Git remotes ************************************" + log "*** Git remotes ************************************" git remote -v - echo "*** Git status *************************************" + log "*** Git status *************************************" git status -sb - echo "*** Git log ****************************************" + log "*** Git log ****************************************" git log --oneline "HEAD^..origin/$GIT_BRANCH" - echo "*** Git describe ***********************************" + log "*** Git describe ***********************************" git describe --tag --dirty='-dirty' - echo "****************************************************" + log "****************************************************" cp -f .githooks/* .git/hooks diff --git a/installation/routines/setup_jukebox_core.sh b/installation/routines/setup_jukebox_core.sh index 6b070ff6c..a7d0f29b6 100644 --- a/installation/routines/setup_jukebox_core.sh +++ b/installation/routines/setup_jukebox_core.sh @@ -9,16 +9,16 @@ JUKEBOX_PULSE_CONFIG="${HOME_PATH}"/.config/pulse/default.pa JUKEBOX_SERVICE_NAME="${SYSTEMD_USR_PATH}/jukebox-daemon.service" _show_slow_hardware_message() { -echo " -------------------------------------------------------------------- + print_c " -------------------------------------------------------------------- | Your hardware is a little slower so this step will take a while. | | Go watch a movie but don't let your computer go to sleep for the | | SSH connection to remain intact. | - --------------------------------------------------------------------" 1>&3 + --------------------------------------------------------------------" } # Functions _jukebox_core_install_os_dependencies() { - echo " Install Jukebox OS dependencies" | tee /dev/fd/3 + print_lc " Install Jukebox OS dependencies" local apt_packages=$(get_args_from_file "${INSTALLATION_PATH}/packages-core.txt") sudo apt-get -y update && sudo apt-get -y install \ @@ -30,7 +30,7 @@ _jukebox_core_install_os_dependencies() { } _jukebox_core_install_python_requirements() { - echo " Install Python requirements" | tee /dev/fd/3 + print_lc " Install Python requirements" cd "${INSTALLATION_PATH}" || exit_on_error @@ -42,13 +42,13 @@ _jukebox_core_install_python_requirements() { } _jukebox_core_configure_pulseaudio() { - echo " Copy PulseAudio configuration" | tee /dev/fd/3 + print_lc " Copy PulseAudio configuration" mkdir -p $(dirname "$JUKEBOX_PULSE_CONFIG") cp -f "${INSTALLATION_PATH}/resources/default-settings/pulseaudio.default.pa" "${JUKEBOX_PULSE_CONFIG}" } _jukebox_core_build_libzmq_with_drafts() { - echo " Building libzmq v${JUKEBOX_ZMQ_VERSION} with drafts support" | tee /dev/fd/3 + print_lc " Building libzmq v${JUKEBOX_ZMQ_VERSION} with drafts support" local zmq_filename="zeromq-${JUKEBOX_ZMQ_VERSION}" local zmq_tar_filename="${zmq_filename}.tar.gz" local cpu_count=${CPU_COUNT:-$(python3 -c "import os; print(os.cpu_count())")} @@ -63,7 +63,7 @@ _jukebox_core_build_libzmq_with_drafts() { } _jukebox_core_download_prebuilt_libzmq_with_drafts() { - echo " Download pre-compiled libzmq with drafts support" + log " Download pre-compiled libzmq with drafts support" local zmq_tar_filename="libzmq.tar.gz" ARCH=$(get_architecture) @@ -83,7 +83,7 @@ _jukebox_core_build_and_install_pyzmq() { # https://pyzmq.readthedocs.io/en/latest/howto/draft.html # https://github.com/MonsieurV/ZeroMQ-RPi/blob/master/README.md # https://github.com/zeromq/pyzmq/issues/1523#issuecomment-1593120264 - echo " Install pyzmq with libzmq-drafts to support WebSockets" | tee /dev/fd/3 + print_lc " Install pyzmq with libzmq-drafts to support WebSockets" if ! pip list | grep -F pyzmq >> /dev/null; then @@ -101,18 +101,18 @@ _jukebox_core_build_and_install_pyzmq() { ZMQ_PREFIX="${JUKEBOX_ZMQ_PREFIX}" ZMQ_DRAFT_API=1 \ pip install -v --no-binary pyzmq --pre pyzmq else - echo " Skipping. pyzmq already installed" | tee /dev/fd/3 + print_lc " Skipping. pyzmq already installed" fi } _jukebox_core_install_settings() { - echo " Register Jukebox settings" | tee /dev/fd/3 + print_lc " Register Jukebox settings" cp -f "${INSTALLATION_PATH}/resources/default-settings/jukebox.default.yaml" "${SETTINGS_PATH}/jukebox.yaml" cp -f "${INSTALLATION_PATH}/resources/default-settings/logger.default.yaml" "${SETTINGS_PATH}/logger.yaml" } _jukebox_core_register_as_service() { - echo " Register Jukebox Core user service" | tee /dev/fd/3 + print_lc " Register Jukebox Core user service" sudo cp -f "${INSTALLATION_PATH}/resources/default-services/jukebox-daemon.service" "${JUKEBOX_SERVICE_NAME}" sudo sed -i "s|%%INSTALLATION_PATH%%|${INSTALLATION_PATH}|g" "${JUKEBOX_SERVICE_NAME}" diff --git a/installation/routines/setup_jukebox_webapp.sh b/installation/routines/setup_jukebox_webapp.sh index 9dc74bf12..f7407f96c 100644 --- a/installation/routines/setup_jukebox_webapp.sh +++ b/installation/routines/setup_jukebox_webapp.sh @@ -15,13 +15,13 @@ _jukebox_webapp_install_node() { sudo apt-get -y update if which node > /dev/null; then - echo " Found existing NodeJS. Hence, updating NodeJS" | tee /dev/fd/3 + print_lc " Found existing NodeJS. Hence, updating NodeJS" sudo npm cache clean -f sudo npm install --silent -g n sudo n --quiet latest sudo npm update --silent -g else - echo " Install NodeJS" | tee /dev/fd/3 + print_lc " Install NodeJS" # Zero and older versions of Pi with ARMv6 only # support experimental NodeJS @@ -45,7 +45,7 @@ _jukebox_webapp_install_node() { # TODO: Avoid building the app locally # Instead implement a Github Action that prebuilds on commititung a git tag _jukebox_webapp_build() { - echo " Building web application" | tee /dev/fd/3 + print_lc " Building web application" cd "${INSTALLATION_PATH}/src/webapp" || exit_on_error npm ci --prefer-offline --no-audit --production rm -rf build @@ -54,11 +54,11 @@ _jukebox_webapp_build() { } _jukebox_webapp_download() { - echo " Downloading web application" | tee /dev/fd/3 + print_lc " Downloading web application" local JUKEBOX_VERSION=$(get_version_string "${INSTALLATION_PATH}/src/jukebox/jukebox/version.py") local TAR_FILENAME="webapp-build.tar.gz" local DOWNLOAD_URL="https://github.com/MiczFlor/RPi-Jukebox-RFID/releases/download/v${JUKEBOX_VERSION}/webapp-v${JUKEBOX_VERSION}.tar.gz" - echo " DOWNLOAD_URL: ${DOWNLOAD_URL}" + log " DOWNLOAD_URL: ${DOWNLOAD_URL}" cd "${INSTALLATION_PATH}/src/webapp" || exit_on_error # URL must be set to default repo as installation can be run from different repos as well where releases may not exist @@ -69,7 +69,7 @@ _jukebox_webapp_download() { } _jukebox_webapp_register_as_system_service_with_nginx() { - echo " Install and configure nginx" | tee /dev/fd/3 + print_lc " Install and configure nginx" sudo apt-get -qq -y update sudo apt-get -y purge apache2 sudo apt-get -y install nginx diff --git a/installation/routines/setup_kiosk_mode.sh b/installation/routines/setup_kiosk_mode.sh index f8d07971c..b6e543768 100644 --- a/installation/routines/setup_kiosk_mode.sh +++ b/installation/routines/setup_kiosk_mode.sh @@ -7,7 +7,7 @@ KIOSK_MODE_CHROMIUM_CUSTOM_DISABLE_UPDATE_CHECK='/etc/chromium-browser/customiza KIOSK_MODE_CHROMIUM_FLAG_UPDATE_INTERVAL='--check-for-update-interval=31536000' _kiosk_mode_install_os_dependencies() { - echo " Install Kiosk Mode dependencies" | tee /dev/fd/3 + print_lc " Install Kiosk Mode dependencies" # Resource: # https://blog.r0b.io/post/minimal-rpi-kiosk/ sudo apt-get -qq -y install --no-install-recommends \ @@ -19,7 +19,7 @@ _kiosk_mode_install_os_dependencies() { } _kiosk_mode_set_autostart() { - echo " Configure Kiosk Mode" | tee /dev/fd/3 + print_lc " Configure Kiosk Mode" local _DISPLAY='$DISPLAY' local _XDG_VTNR='$XDG_VTNR' diff --git a/installation/routines/setup_mpd.sh b/installation/routines/setup_mpd.sh index 40ffe8aac..6a95a95e5 100644 --- a/installation/routines/setup_mpd.sh +++ b/installation/routines/setup_mpd.sh @@ -4,11 +4,11 @@ AUDIOFOLDERS_PATH="${SHARED_PATH}/audiofolders" PLAYLISTS_PATH="${SHARED_PATH}/playlists" _mpd_install_os_dependencies() { - echo " Install MPD OS dependencies" + log " Install MPD OS dependencies" sudo apt-get -y update - echo "Note: Installing MPD might cause a message: 'Job failed. See journalctl -xe for details'" - echo "It can be ignored! It's an artefact of the MPD installation - nothing we can do about it." + log "Note: Installing MPD might cause a message: 'Job failed. See journalctl -xe for details' +It can be ignored! It's an artefact of the MPD installation - nothing we can do about it." sudo apt-get -y install \ mpd mpc \ --no-install-recommends \ @@ -18,7 +18,7 @@ _mpd_install_os_dependencies() { } _mpd_configure() { - echo " Configure MPD as user local service" | tee /dev/fd/3 + print_lc " Configure MPD as user local service" # Make sure system-wide mpd is disabled sudo systemctl stop mpd.socket diff --git a/installation/routines/setup_rfid_reader.sh b/installation/routines/setup_rfid_reader.sh index b5e8b4bbc..61361574a 100644 --- a/installation/routines/setup_rfid_reader.sh +++ b/installation/routines/setup_rfid_reader.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash _run_setup_rfid_reader() { - python "${INSTALLATION_PATH}/src/jukebox/run_register_rfid_reader.py" | tee /dev/fd/3 + python "${INSTALLATION_PATH}/src/jukebox/run_register_rfid_reader.py" | log } setup_rfid_reader() { diff --git a/installation/routines/setup_samba.sh b/installation/routines/setup_samba.sh index 100d7370d..c1875113e 100644 --- a/installation/routines/setup_samba.sh +++ b/installation/routines/setup_samba.sh @@ -4,7 +4,7 @@ SMB_CONF="/etc/samba/smb.conf" SMB_CONF_HEADER="## Jukebox Samba Config" _samba_install_os_dependencies() { - echo " Install Samba Core dependencies" + log " Install Samba Core dependencies" sudo apt-get -qq -y update; sudo apt-get -qq -y install \ samba samba-common-bin \ --no-install-recommends \ @@ -14,12 +14,12 @@ _samba_install_os_dependencies() { } _samba_set_user() { - echo " Configure Samba" | tee /dev/fd/3 + print_lc " Configure Samba" local SMB_PASSWD="raspberry" # Samba has not been configured if grep -q "$SMB_CONF_HEADER" "$SMB_CONF"; then - echo " Skipping. Already set up!" | tee /dev/fd/3 + print_lc " Skipping. Already set up!" else # Create Samba user (echo "${SMB_PASSWD}"; echo "${SMB_PASSWD}") | sudo smbpasswd -s -a "${CURRENT_USER}"