Improve screen output

This commit is contained in:
Michael Boelen 2016-05-14 17:42:51 +02:00
parent b72b510301
commit e7afd92533

View File

@ -49,6 +49,7 @@
LOCAL_VERSION="-" LOCAL_VERSION="-"
SERVER_VERSION="" SERVER_VERSION=""
PERFORM_UPGRADE=0 PERFORM_UPGRADE=0
QUIET=0
WGET_EXISTS=`which wget 2> /dev/null` WGET_EXISTS=`which wget 2> /dev/null`
CURL_EXISTS=`which curl 2> /dev/null` CURL_EXISTS=`which curl 2> /dev/null`
@ -58,42 +59,42 @@ FETCH_EXISTS=`which fetch 2> /dev/null`
if [ "$1" = "release" ]; then if [ "$1" = "release" ]; then
if [ "${UPDATE_SERVER_PROTOCOL}" = "" ] ; then if [ "${UPDATE_SERVER_PROTOCOL}" = "" ] ; then
Display --indent 2 --text "Error: Unknown protocol, please specify (http, https) in profile (update_server_protocol)" ${ECHOCMD} "Error: Unknown protocol, please specify (http, https) in profile (update_server_protocol)"
ExitFatal ExitFatal
fi fi
if [ "${UPDATE_SERVER_ADDRESS}" = "" ] ; then if [ "${UPDATE_SERVER_ADDRESS}" = "" ] ; then
Display --indent 2 --text "Error: Unknown download address, please specify in profile (update_server_address)" ${ECHOCMD} "Error: Unknown download address, please specify in profile (update_server_address)"
ExitFatal ExitFatal
fi fi
if [ "${UPDATE_LATEST_VERSION_DOWNLOAD}" = "" ] ; then if [ "${UPDATE_LATEST_VERSION_DOWNLOAD}" = "" ] ; then
Display --indent 2 --text "Error: No URL to latest download has been specifiedrsion on the server, please specify in profile (update_latest_version_download)" ${ECHOCMD} "Error: No URL to latest download has been specifiedrsion on the server, please specify in profile (update_latest_version_download)"
ExitFatal ExitFatal
fi fi
if [ "${UPDATE_LATEST_VERSION_INFO}" = "" ] ; then if [ "${UPDATE_LATEST_VERSION_INFO}" = "" ] ; then
Display --indent 2 --text "Error: No URL has been specified to know the latest version on the server, please specify in profile (update_latest_version_info)" ${ECHOCMD} "Error: No URL has been specified to know the latest version on the server, please specify in profile (update_latest_version_info)"
ExitFatal ExitFatal
fi fi
if [ "${UPDATE_LOCAL_DIRECTORY}" = "" ] ; then if [ "${UPDATE_LOCAL_DIRECTORY}" = "" ] ; then
Display --indent 2 --text "Error: No local directory has been specified to store Lynis files. Please specify in profile (update_local_directory)" ${ECHOCMD} "Error: No local directory has been specified to store Lynis files. Please specify in profile (update_local_directory)"
ExitFatal ExitFatal
else else
if [ ! -d ${UPDATE_LOCAL_DIRECTORY} ]; then if [ ! -d ${UPDATE_LOCAL_DIRECTORY} ]; then
Display --indent 2 --text "Error: Directory ${UPDATE_LOCAL_DIRECTORY} does not exist" ${ECHOCMD} "Error: Directory ${UPDATE_LOCAL_DIRECTORY} does not exist"
ExitFatal ExitFatal
fi fi
fi fi
if [ "${UPDATE_LOCAL_VERSION_INFO}" = "" ] ; then if [ "${UPDATE_LOCAL_VERSION_INFO}" = "" ] ; then
Display --indent 2 --text "Error: No data file has been specified to determine local Lynis version, please specify in profile (update_local_version_info)" ${ECHOCMD} "Error: No data file has been specified to determine local Lynis version, please specify in profile (update_local_version_info)"
ExitFatal ExitFatal
fi fi
if [ ! -f ${UPDATE_LOCAL_VERSION_INFO} ]; then if [ ! -f ${UPDATE_LOCAL_VERSION_INFO} ]; then
Display --indent 2 --text "Note: local data file ${UPDATE_LOCAL_VERSION_INFO} does not exist. It will be created after updating. (update_local_version_info)" ${ECHOCMD} "Note: local data file ${UPDATE_LOCAL_VERSION_INFO} does not exist. It will be created after updating. (update_local_version_info)"
else else
LOCAL_VERSION=`cat ${UPDATE_LOCAL_VERSION_INFO}` LOCAL_VERSION=`cat ${UPDATE_LOCAL_VERSION_INFO}`
fi fi
@ -104,9 +105,9 @@ if [ "$1" = "release" ]; then
# Create temporary file # Create temporary file
CreateTempFile CreateTempFile
TMP_FILE="${TEMP_FILE}" TMP_FILE="${TEMP_FILE}"
if [ "${TMP_FILE}" = "" ]; then Display --indent 2 --text "Could not create a temporary file. Exiting..."; ExitFatal; fi if [ "${TMP_FILE}" = "" ]; then ${ECHOCMD} "Could not create a temporary file. Exiting..."; ExitFatal; fi
Display --indent 2 --text "${CYAN}[Phase 1] Downloading details${NORMAL}" ${ECHOCMD} "${CYAN}[Phase 1] Downloading details${NORMAL}"
if [ ! "${WGET_EXISTS}" = "" ]; then if [ ! "${WGET_EXISTS}" = "" ]; then
LogText "Using wget to download release information" LogText "Using wget to download release information"
LAST_COMMAND_HELP="wget --output-document ${TMP_FILE} ${FULLPATH}" LAST_COMMAND_HELP="wget --output-document ${TMP_FILE} ${FULLPATH}"
@ -118,7 +119,7 @@ if [ "$1" = "release" ]; then
curl --fail -o ${TMP_FILE} ${FULLPATH} 2> /dev/null curl --fail -o ${TMP_FILE} ${FULLPATH} 2> /dev/null
EXIT_CODE=$? EXIT_CODE=$?
else else
Display --indent 2 --text "No download tool available to perform download" ${ECHOCMD} "No download tool available to perform download"
ExitFatal ExitFatal
fi fi
@ -128,43 +129,43 @@ if [ "$1" = "release" ]; then
rm -f ${TMP_FILE} rm -f ${TMP_FILE}
fi fi
else else
Display --indent 2 --text "Temporary file variable is empty, which is unexpected. Aborting.." ${ECHOCMD} "Temporary file variable is empty, which is unexpected. Aborting.."
ExitFatal ExitFatal
fi fi
# Determine if downloading meta data was successful # Determine if downloading meta data was successful
if [ ${EXIT_CODE} -eq 0 ]; then if [ ${EXIT_CODE} -eq 0 ]; then
if [ "${SERVER_VERSION}" = "" ]; then if [ "${SERVER_VERSION}" = "" ]; then
Display --indent 2 --text "No version found on the server. Aborting.." ${ECHOCMD} "No version found on the server. Aborting.."
ExitFatal ExitFatal
else else
Display --indent 2 --text "Version found on server: ${SERVER_VERSION}" ${ECHOCMD} "Version found on server: ${SERVER_VERSION}"
Display --indent 2 --text "Local version found: ${LOCAL_VERSION}" ${ECHOCMD} "Local version found: ${LOCAL_VERSION}"
fi fi
else else
Display --indent 2 --text "${RED}Error: ${WHITE}Download utility returned an unexpected error code.${NORMAL} Aborting.." ${ECHOCMD} "${RED}Error: ${WHITE}Download utility returned an unexpected error code.${NORMAL} Aborting.."
Display --indent 2 --text "Error code: ${EXIT_CODE}" ${ECHOCMD} "Error code: ${EXIT_CODE}"
Display --indent 2 --text "Suggested command: ${LAST_COMMAND_HELP}" ${ECHOCMD} "Suggested command: ${LAST_COMMAND_HELP}"
ExitFatal ExitFatal
fi fi
#========================================================================================================================================== #==========================================================================================================================================
Display --indent 2 --text " " ${ECHOCMD} " "
Display --indent 2 --text "${CYAN}[Phase 2] Compare results${NORMAL}" ${ECHOCMD} "${CYAN}[Phase 2] Compare results${NORMAL}"
if [ ! "${LOCAL_VERSION}" = "${SERVER_VERSION}" ]; then if [ ! "${LOCAL_VERSION}" = "${SERVER_VERSION}" ]; then
Display --indent 2 --text "Different version available, moving to upgrade phase" ${ECHOCMD} "Different version available, moving to upgrade phase"
PERFORM_UPGRADE=1 PERFORM_UPGRADE=1
else else
Display --indent 2 --text "${GREEN}No upgrade needed${NORMAL}" ${ECHOCMD} "${GREEN}No upgrade needed${NORMAL}"
fi fi
# Go to phase 3 if upgrade is needed # Go to phase 3 if upgrade is needed
if [ ${PERFORM_UPGRADE} -eq 1 ]; then if [ ${PERFORM_UPGRADE} -eq 1 ]; then
FULLPATH="${UPDATE_SERVER_PROTOCOL}://${UPDATE_SERVER_ADDRESS}${UPDATE_LATEST_VERSION_DOWNLOAD}" FULLPATH="${UPDATE_SERVER_PROTOCOL}://${UPDATE_SERVER_ADDRESS}${UPDATE_LATEST_VERSION_DOWNLOAD}"
Display --indent 2 --text " " ${ECHOCMD} " "
Display --indent 2 --text "[Phase 3] Downloading latest release" ${ECHOCMD} "[Phase 3] Downloading latest release"
Display --indent 2 --text "Download location: ${FULLPATH}" ${ECHOCMD} "Download location: ${FULLPATH}"
if [ ! "${WGET_EXISTS}" = "" ]; then if [ ! "${WGET_EXISTS}" = "" ]; then
LogText "Using wget to download latest release" LogText "Using wget to download latest release"
LAST_COMMAND_HELP="wget --output-document ${TMP_FILE} ${FULLPATH}" LAST_COMMAND_HELP="wget --output-document ${TMP_FILE} ${FULLPATH}"
@ -178,24 +179,24 @@ if [ "$1" = "release" ]; then
fi fi
if [ ${EXIT_CODE} -eq 0 ]; then if [ ${EXIT_CODE} -eq 0 ]; then
if [ -f ${TMP_FILE} ]; then if [ -f ${TMP_FILE} ]; then
Display --indent 2 --text "Download successful" ${ECHOCMD} "Download successful"
# Extract the file to the related path, with 'lynis' appended # Extract the file to the related path, with 'lynis' appended
# Note: by default the tarball includes 'lynis' as directory # Note: by default the tarball includes 'lynis' as directory
if [ ! -d ${UPDATE_LOCAL_DIRECTORY} ]; then if [ ! -d ${UPDATE_LOCAL_DIRECTORY} ]; then
Display --indent 2 --text "Error: directory ${UPDATE_LOCAL_DIRECTORY} does not exist" ${ECHOCMD} "Error: directory ${UPDATE_LOCAL_DIRECTORY} does not exist"
ExitFatal ExitFatal
fi fi
Display --indent 2 --text "Extracting latest version to path ${UPDATE_LOCAL_DIRECTORY}" ${ECHOCMD} "Extracting latest version to path ${UPDATE_LOCAL_DIRECTORY}"
if [ ! -d ${UPDATE_LOCAL_DIRECTORY}/lynis ]; then if [ ! -d ${UPDATE_LOCAL_DIRECTORY}/lynis ]; then
Display --indent 2 --text "Creating 'lynis' directory in ${UPDATE_LOCAL_DIRECTORY}" ${ECHOCMD} "Creating 'lynis' directory in ${UPDATE_LOCAL_DIRECTORY}"
mkdir ${UPDATE_LOCAL_DIRECTORY}/lynis mkdir ${UPDATE_LOCAL_DIRECTORY}/lynis
if [ $? -gt 0 ]; then if [ $? -gt 0 ]; then
Display --indent 2 --text "Error: could not create directory ${UPDATE_LOCAL_DIRECTORY}/lynis" ${ECHOCMD} "Error: could not create directory ${UPDATE_LOCAL_DIRECTORY}/lynis"
ExitFatal ExitFatal
fi fi
fi fi
if [ -d ${UPDATE_LOCAL_DIRECTORY}/lynis ]; then if [ -d ${UPDATE_LOCAL_DIRECTORY}/lynis ]; then
Display --indent 2 --text "Extracting files to ${UPDATE_LOCAL_DIRECTORY}" ${ECHOCMD} "Extracting files to ${UPDATE_LOCAL_DIRECTORY}"
tar xzf ${TMP_FILE} -C ${UPDATE_LOCAL_DIRECTORY} tar xzf ${TMP_FILE} -C ${UPDATE_LOCAL_DIRECTORY}
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
# Check if we can find the Lynis binary (in the created 'lynis' directory) # Check if we can find the Lynis binary (in the created 'lynis' directory)
@ -203,22 +204,22 @@ if [ "$1" = "release" ]; then
# If version was downloaded, update local version # If version was downloaded, update local version
echo ${SERVER_VERSION} > ${UPDATE_LOCAL_VERSION_INFO} echo ${SERVER_VERSION} > ${UPDATE_LOCAL_VERSION_INFO}
else else
Display --indent 2 --text "Error: could not find downloaded file on disk" ${ECHOCMD} "Error: could not find downloaded file on disk"
fi fi
else else
Display --indent 2 --text "Error: File extraction failed" ${ECHOCMD} "Error: File extraction failed"
ExitFatal ExitFatal
fi fi
else else
Display --indent 2 --text "Error: could not find lynis directory" ${ECHOCMD} "Error: could not find lynis directory"
fi fi
else else
Display --indent 2 --text "Error: could not find downloaded file on disk" ${ECHOCMD} "Error: could not find downloaded file on disk"
ExitFatal ExitFatal
fi fi
else else
Display --indent 2 --text "Error: could not download latest release" ${ECHOCMD} "Error: could not download latest release"
Display --indent 2 --text "Suggestion: ${LAST_COMMAND_HELP}" ${ECHOCMD} "Suggestion: ${LAST_COMMAND_HELP}"
ExitFatal ExitFatal
fi fi
fi fi
@ -231,9 +232,9 @@ if [ "$1" = "release" ]; then
fi fi
fi fi
Display --indent 2 --text " " ${ECHOCMD} " "
Display --indent 2 --text "Done" ${ECHOCMD} "Done"
Display --indent 2 --text " " ${ECHOCMD} " "
ExitClean ExitClean
# Update check # Update check
@ -275,9 +276,10 @@ elif [ "$1" = "info" ]; then
ExitClean ExitClean
else else
Display --indent 2 --text "${RED}Error: ${WHITE}Unknown parameter $1.${NORMAL} Aborting.." ${ECHOCMD} "${RED}Error: ${WHITE}Unknown parameter $1.${NORMAL} Aborting.."
ExitFatal ExitFatal
fi fi
QUIET=1
# The End # The End