Skip to content

Commit

Permalink
moved logging setup to function and added usage
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinSchiller committed Nov 20, 2023
1 parent 45fa079 commit 1d1648d
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions installation/install-jukebox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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)
Expand Down Expand Up @@ -73,6 +74,27 @@ _check_user() {
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
else
exec 3>&1 1>>"${INSTALLATION_LOGFILE}" 2>&1 || { echo "ERROR: Cannot create log file."; exit 1; }
fi
echo "Log start: ${INSTALL_ID}"
}

# Generic emergency error handler that exits the script immediately
# Print additional custom message if passed as first argument
# Examples:
Expand All @@ -94,6 +116,9 @@ Check install log for details:" | tee /dev/fd/3
}

download_jukebox_source() {
echo "Downloading Phoniebox software from Github ..." 1>&3
echo "Download Source: ${GIT_URL}/${GIT_BRANCH}" | tee /dev/fd/3

wget -qO- "${GIT_URL}/tarball/${GIT_BRANCH}" | tar xz
# Use case insensitive search/sed because user names in Git Hub are case insensitive
GIT_REPO_DOWNLOAD=$(find . -maxdepth 1 -type d -iname "${GIT_USER}-${GIT_REPO_NAME}-*")
Expand All @@ -116,19 +141,12 @@ download_jukebox_source() {
_check_os_type
_check_user

### RUN INSTALLATION
### SETUP LOGGING
cd "${HOME_PATH}"
INSTALLATION_LOGFILE="${HOME_PATH}/INSTALL-${INSTALL_ID}.log"
if [ "$CI_RUNNING" == "true" ]; then
exec 3>&1 2>&1
else
exec 3>&1 1>>"${INSTALLATION_LOGFILE}" 2>&1 || { echo "Cannot create log file. Panic."; exit 1; }
fi
echo "Log start: ${INSTALL_ID}"
_setup_logging

### RUN INSTALLATION
clear 1>&3
echo "Downloading Phoniebox software from Github ..." 1>&3
echo "Download Source: ${GIT_URL}/${GIT_BRANCH}" | tee /dev/fd/3

download_jukebox_source

Expand Down

0 comments on commit 1d1648d

Please sign in to comment.