From d253dc17bcd218b4ee90f3576a38bbcd59f3b779 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 5 Oct 2024 16:20:44 +0100 Subject: [PATCH 01/17] Bug fixes and code cleanup --- remote_website_install.sh | 124 ++++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 45 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index be9ac1392..0236842bd 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -1,5 +1,7 @@ #!/bin/bash +# shellcheck disable=SC2317 + # Install or upgrade a remote Allsky Website. # shellcheck disable=SC2155 [[ -z ${ALLSKY_HOME} ]] && export ALLSKY_HOME="$( realpath "$( dirname "${BASH_ARGV0}" )" )" @@ -16,13 +18,6 @@ source "${ALLSKY_SCRIPTS}/installUpgradeFunctions.sh" || exit "${EXIT_ERROR_STOP # shellcheck disable=SC2034 DISPLAY_MSG_LOG="${ALLSKY_LOGS}/${ME}.log" -# Titles for various dialogs -DIALOG_BACK_TITLE="Allsky Remote Website Installer" -DIALOG_WELCOME_TITLE="Allsky Remote Website Installer" -DIALOG_PRE_CHECK="Pre Installation Checks" -DIALOG_INSTALL="Installing Remote Website" -DIALOG_TITLE_LOG="Allsky Remote Website Installation Log" - # Config variables HAVE_NEW_CONFIG="false" HAVE_OLD_CONFIG="false" @@ -32,8 +27,8 @@ CONFIG_TO_USE="" CONFIG_MESSAGE="" # Dialog size variables -DIALOG_WIDTH=60 -DIALOG_HEIGHT=20 +DIALOG_WIDTH=70 +DIALOG_HEIGHT=25 # logging options LOG_TYPE="--logonly" @@ -48,8 +43,15 @@ REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" REMOTE_PROTOCOL="$( settings ".remotewebsiteprotocol" )" WEBSITE_EXISTS="false" +# Titles for various dialogs +DIALOG_BACK_TITLE="Allsky Remote Website Installer" +DIALOG_WELCOME_TITLE="Allsky Remote Website Installer" +DIALOG_PRE_CHECK="Pre Installation Checks" +DIALOG_INSTALL="Installing Remote Website" +DIALOG_TITLE_LOG="Allsky Remote Website Installation Log" + # Old Allksy files that should be remoevd if they exist -OLD_FILES_TO_REMOVE=("config.json" "configuration.json" "virtualsky.json") +OLD_FILES_TO_REMOVE=("config.js" "configuration.json" "virtualsky.json") # TODO: DO we want to do this or backup any old logs, its better to have a single # log per run rather than a file thats just appended to. @@ -94,6 +96,24 @@ function press_any_key() read -r -n1 -s } +# Adds the remote website URL to the dialog text +function add_dialog_heading() +{ + local DIALOG_TEXT=$1 + local DRED="\Z1" + local DNORMAL="\Zn" + if [[ ${TEXT_ONLY} == "true" ]]; then + DRED="${RED}" + DNORMAL="${NC}" + fi + + local PADDING=$(( ((DIALOG_WIDTH-6) - ${#REMOTE_URL}) / 2 )) + local URL=$(printf "%${PADDING}s%s" "" "$REMOTE_URL") + + DIALOG_TEXT="\n${DRED}${URL}${DNORMAL}\n${DIALOG_TEXT}" + + echo "${DIALOG_TEXT}" +} # Displays an info Dialog, or in text mode just displays the text # $1 - The backtitle for the dialog # $2 - The title for the dialog @@ -104,10 +124,12 @@ function display_info_dialog() { local DIALOG_TEXT=$3 + DIALOG_TEXT=$(add_dialog_heading "${DIALOG_TEXT}") if [[ ${TEXT_ONLY} == "false" ]]; then local BACK_TITLE=$1 local DIALOG_TITLE=$2 dialog \ + --colors\ --backtitle "${BACK_TITLE}" \ --title "${DIALOG_TITLE}" \ --infobox "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} @@ -129,10 +151,12 @@ function display_prompt_dialog() local DIALOG_TEXT=$3 local RESULT + DIALOG_TEXT=$(add_dialog_heading "${DIALOG_TEXT}") if [[ ${TEXT_ONLY} == "false" ]]; then local BACK_TITLE=$1 local DIALOG_TITLE=$2 dialog \ + --colors\ --backtitle "${BACK_TITLE}" \ --title "${DIALOG_TITLE}" \ --yesno "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} @@ -156,10 +180,12 @@ function display_message_box() { local DIALOG_TEXT=$3 + DIALOG_TEXT=$(add_dialog_heading "${DIALOG_TEXT}") if [[ ${TEXT_ONLY} == "false" ]]; then local BACK_TITLE=$1 local DIALOG_TITLE=$2 dialog \ + --colors\ --backtitle "${BACK_TITLE}" \ --title "${DIALOG_TITLE}" \ --msgbox "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} @@ -185,6 +211,7 @@ function display_log_file() local DIALOG_TITLE=$2 dialog \ --clear\ + --colors\ --backtitle "${BACK_TITLE}"\ --title "${DIALOG_TITLE}"\ --textbox "${FILENAME}" 22 77 @@ -201,17 +228,18 @@ function display_log_file() # # If there is a remote-configuration.json in the /config folder then use it # If there is a remote-configuration.json in the allsky-OLD/config folder then use it -# If there is a remote website with a remote-configuration.json file then save it in /config -# If there is a remote website and it has an old configuration file (configuration.json) save it as -# remote-configuration.json in the /config folder and update the placeholder -# If there is a remote website and it has an old configuration file (configuration.json) then -# TODO: What do we do +# Otherwise +# If there is a remote website with a configuration.json file then save it in /config +# If there is a remote website and it has an old configuration file (config.js) then +# create a new remote-configuration.json in /config # function pre_install_checks() { local MESSAGE="" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "\nRunning pre installation checks.\n\nPlease wait as this process can take a few minutes to complete." + local DIALOG_TEXT="\nRunning pre installation checks.\n\nPlease wait as this process can take a few minutes to complete.\n\n" + DIALOG_TEXT+="\n1 - Checking for local files" + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" display_msg "${LOG_TYPE}" info "$(date) Start pre installation checks." @@ -227,9 +255,16 @@ function pre_install_checks() HAVE_OLD_CONFIG="true" fi + DIALOG_TEXT+="\n2 - Checking if remote website exists" + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + check_if_website_exists if [[ "${WEBSITE_EXISTS}" == "true" ]]; then + + DIALOG_TEXT+="\n3 - Checking for remote website configuration file" + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + local NEW_CONFIG_FILES=("configuration.json") check_if_files_exist "${REMOTE_URL}" "false" "${NEW_CONFIG_FILES[@]}" local NEW_CONFIG_FILE_EXISTS=$? @@ -239,7 +274,10 @@ function pre_install_checks() display_msg "${LOG_TYPE}" progress "$(date) ${MESSAGE}" fi - local REALLY_OLD_CONFIG_FILES=("config.json") + DIALOG_TEXT+="\n4 - Checking for old remote website configuration file" + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + + local REALLY_OLD_CONFIG_FILES=("config.js") check_if_files_exist "${REMOTE_URL}" "false" "${REALLY_OLD_CONFIG_FILES[@]}" local OLD_CONFIG_FILE_EXISTS=$? if [[ ${OLD_CONFIG_FILE_EXISTS} -eq 0 ]]; then @@ -270,9 +308,9 @@ function pre_install_checks() CONFIG_MESSAGE="Remote new" else if [[ "${HAVE_REALLY_OLD_REMOTE_CONFIG}" == "true" ]]; then - display_msg "${LOG_TYPE}" progress "$(date) Will use the really old format website configuration file on the remote website, will be downloaded and updated" + display_msg "${LOG_TYPE}" progress "$(date) Old config.js found. A new configuration file will be created and the user will have to updae it manually" CONFIG_TO_USE="remotereallyold" - CONFIG_MESSAGE="Remote Really old" + CONFIG_MESSAGE=" repos config i.e. a new config" fi fi fi @@ -293,6 +331,14 @@ function pre_install_checks() function display_welcome() { local CONTINUE=0 + + local DRED="\Z1" + local DNORMAL="\Zn" + if [[ ${TEXT_ONLY} == "true" ]]; then + DRED="${RED}" + DNORMAL="${NC}" + fi + if [[ ${AUTO_CONFIRM} == "false" ]]; then display_msg "${LOG_TYPE}" progress "$(date) Displayed the welcome dialog" display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_WELCOME_TITLE}" "\n\ @@ -305,7 +351,9 @@ function display_welcome() 4) Upload the remote website configuration file\n 5) Enable the remote website in the WebUI settings\n\n\ \ - WARNING: This will overwrite ALL files on the remote server and REMOVE any old Allsky files.\n\n\ + ${DRED}WARNING:${DNORMAL}\n\ + - This will overwrite files on the remote server\n\ + - REMOVE any old Allsky system files on the remote server.\n\n\ Are you sure you wish to continue?" CONTINUE=$? @@ -345,9 +393,12 @@ function display_aborted() function display_complete() { local EXTRA_TEXT="" - if [[ ${CREATED_NEW_CONFIG} == "true" ]]; then + if [[ "${CONFIG_TO_USE}" == "new" ]]; then EXTRA_TEXT="\nA new configuration file was created for the website. Please use the WebUI editor and replace any 'XX_NEED_TO_UPDATE_XX' with the correct values" fi + if [[ "${CONFIG_TO_USE}" == "remotereallyold" ]]; then + EXTRA_TEXT="\nSince you have a very old Allsky website a new configuration file was created for the website. Please use the WebUI editor and replace any 'XX_NEED_TO_UPDATE_XX' with the correct values" + fi display_msg "${LOG_TYPE}" info "$(date) INSTALLATON COMPLETED.\n" display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\n\ @@ -396,8 +447,8 @@ function create_website_config() display_msg "${LOG_TYPE}" info "$(date) Creating remote website configuration file" # We need a new config file so copy it from the repo and replace as many of the placeholders as we can - if [[ "${CONFIG_TO_USE}" == "new" ]]; then - SOURCE_FILE="${ALLSKY_REPO}/configuration.json" + if [[ "${CONFIG_TO_USE}" == "new" || "${CONFIG_TO_USE}" == "remotereallyold" ]]; then + SOURCE_FILE="${ALLSKY_REPO}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}.repo" DEST_FILE="${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" cp "${SOURCE_FILE}" "${DEST_FILE}" replace_website_placeholders "remote" @@ -418,30 +469,13 @@ function create_website_config() # Use the new remote config file since none were found locally if [[ "${CONFIG_TO_USE}" == "remotenew" ]]; then - if [[ $( wget -O "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_URL}/${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME}" ) -eq 0 ]]; then + if [[ $( wget -O "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_URL}/${ALLSKY_WEBSITE_CONFIGURATION_FILE}" ) -eq 0 ]]; then replace_website_placeholders "remote" - display_msg "${LOG_TYPE}" info "$(date) Downloading ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from ${REMOTE_URL}, creating a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" + display_msg "${LOG_TYPE}" info "$(date) Downloading ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}, creating a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" else - display_aborted "Failed to download ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from ${REMOTE_URL}" "true" + display_aborted "Failed to download ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}" "true" fi fi - - if [[ "${CONFIG_TO_USE}" == "remoteold" ]]; then - # Have an older format remote config file so use it. NOTE: This file will be deleted as - # part of the installation process so this will never be the case after an upgrade unless - # the user uplaods the file. - if [[ $( wget -O "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_URL}/configuration.json" ) -eq 0 ]]; then - replace_website_placeholders "remote" - display_msg "${LOG_TYPE}" info "$(date) Downloading configuration.json from ${REMOTE_URL}, creating a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} and updating placeholders" - else - display_aborted "Failed to download configuration.json from ${REMOTE_URL}" "true" - fi - fi - - if [[ "${CONFIG_TO_USE}" == "remotereallyold" ]]; then - #TODO: What do we do here? - : - fi } # Check if a remote file, or array of files, exists via http @@ -510,7 +544,7 @@ function remove_remote_file() # Check if a remote website exists. The check is done by looking for the following files # -# If any of these files config.json, configuration.json, remote_configuration.json exist and +# If any of these files config.js, configuration.json, remote_configuration.json exist and # all of these index.php, functions.php exist then assume we have a remote website # # Returns - 0 - Found a rempote website, 1 - No remote website found @@ -553,7 +587,7 @@ function upload_remote_website() fi if [[ ${AUTO_CONFIRM} == "false" ]]; then - display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nTo continue the Allsky website must be uploaded. This will overwrite ALL files on the remote server and REMOVE any old Allsky files. \n\nAre you sure you wish to continue" + display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nTo continue the Allsky website must be uploaded. This will overwrite ALL website files on the remote server and REMOVE any old Allsky files. \n\nAre you sure you wish to continue" CONTINUE=$? EXTRA_TEXT=", user agreed to upload and remove all old Allsky files" else From c62bd0ddcc2baf3aa4de5320f433ed92f6ff6fc8 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 6 Oct 2024 15:49:56 +0100 Subject: [PATCH 02/17] Moved Sun 6 Oct 15:49:56 BST 2024 to core common script, moved colour variables to variables.sh --- remote_website_install.sh | 78 ++++++++++++++---------------- scripts/installUpgradeFunctions.sh | 4 +- variables.sh | 2 + 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index 0236842bd..55cc0daf4 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -100,17 +100,15 @@ function press_any_key() function add_dialog_heading() { local DIALOG_TEXT=$1 - local DRED="\Z1" - local DNORMAL="\Zn" if [[ ${TEXT_ONLY} == "true" ]]; then - DRED="${RED}" - DNORMAL="${NC}" + DIALOG_RED="${RED}" + DIALOG_NORMAL="${NC}" fi local PADDING=$(( ((DIALOG_WIDTH-6) - ${#REMOTE_URL}) / 2 )) local URL=$(printf "%${PADDING}s%s" "" "$REMOTE_URL") - DIALOG_TEXT="\n${DRED}${URL}${DNORMAL}\n${DIALOG_TEXT}" + DIALOG_TEXT="\n${DIALOG_RED}${URL}${DIALOG_NORMAL}\n${DIALOG_TEXT}" echo "${DIALOG_TEXT}" } @@ -240,18 +238,18 @@ function pre_install_checks() local DIALOG_TEXT="\nRunning pre installation checks.\n\nPlease wait as this process can take a few minutes to complete.\n\n" DIALOG_TEXT+="\n1 - Checking for local files" display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - display_msg "${LOG_TYPE}" info "$(date) Start pre installation checks." + display_msg "${LOG_TYPE}" info "Start pre installation checks." if [[ -f "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" ]]; then MESSAGE="Found current configuration file in ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." - display_msg "${LOG_TYPE}" progress "$(date) ${MESSAGE}" + display_msg "${LOG_TYPE}" progress "${MESSAGE}" HAVE_NEW_CONFIG="true" fi if [[ -f "${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}" ]]; then MESSAGE="Found -OLD configuration file in ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}." - display_msg "${LOG_TYPE}" progress "$(date) ${MESSAGE}" + display_msg "${LOG_TYPE}" progress "${MESSAGE}" HAVE_OLD_CONFIG="true" fi @@ -271,7 +269,7 @@ function pre_install_checks() if [[ ${NEW_CONFIG_FILE_EXISTS} -eq 0 ]]; then HAVE_NEW_REMOTE_CONFIG="true" MESSAGE="Found current configuration on the remote server." - display_msg "${LOG_TYPE}" progress "$(date) ${MESSAGE}" + display_msg "${LOG_TYPE}" progress "${MESSAGE}" fi DIALOG_TEXT+="\n4 - Checking for old remote website configuration file" @@ -283,7 +281,7 @@ function pre_install_checks() if [[ ${OLD_CONFIG_FILE_EXISTS} -eq 0 ]]; then HAVE_REALLY_OLD_REMOTE_CONFIG="true" MESSAGE="Found really old format website configuration file on the remote website." - display_msg "${LOG_TYPE}" progress "$(date) ${MESSAGE}" + display_msg "${LOG_TYPE}" progress "${MESSAGE}" fi fi @@ -292,23 +290,23 @@ function pre_install_checks() if [[ "${HAVE_NEW_REMOTE_CONFIG}" == "true" ]]; then EXTRA_TEXT=", A remote configuration file was found but the local version will be used instead" fi - display_msg "${LOG_TYPE}" progress "$(date) Will use the local remote configuration file${EXTRA_TEXT}" + display_msg "${LOG_TYPE}" progress "Will use the local remote configuration file${EXTRA_TEXT}" CONFIG_TO_USE="current" CONFIG_MESSAGE="Current" else if [[ "${HAVE_OLD_CONFIG}" == "true" ]]; then - display_msg "${LOG_TYPE}" progress "$(date) Will use the -OLD configuration file, placeholders will be updated" + display_msg "${LOG_TYPE}" progress "Will use the -OLD configuration file, placeholders will be updated" CONFIG_TO_USE="old" CONFIG_MESSAGE="allsky-OLD" else if [[ "${WEBSITE_EXISTS}" == "true" ]]; then if [[ "${HAVE_NEW_REMOTE_CONFIG}" == "true" ]]; then - display_msg "${LOG_TYPE}" progress "$(date) Will use the new format website configuration file on the remote website, will be downloaded and saved locally" + display_msg "${LOG_TYPE}" progress "Will use the new format website configuration file on the remote website, will be downloaded and saved locally" CONFIG_TO_USE="remotenew" CONFIG_MESSAGE="Remote new" else if [[ "${HAVE_REALLY_OLD_REMOTE_CONFIG}" == "true" ]]; then - display_msg "${LOG_TYPE}" progress "$(date) Old config.js found. A new configuration file will be created and the user will have to updae it manually" + display_msg "${LOG_TYPE}" progress "Old config.js found. A new configuration file will be created and the user will have to updae it manually" CONFIG_TO_USE="remotereallyold" CONFIG_MESSAGE=" repos config i.e. a new config" fi @@ -318,13 +316,13 @@ function pre_install_checks() fi if [[ "${CONFIG_TO_USE}" == "" ]]; then - display_msg "${LOG_TYPE}" progress "$(date) Unable to determine the configuration file to use. A new one will be created" + display_msg "${LOG_TYPE}" progress "Unable to determine the configuration file to use. A new one will be created" CONFIG_TO_USE="new" fi check_connectivity - display_msg "${LOG_TYPE}" info "$(date) Completed pre installation checks." + display_msg "${LOG_TYPE}" info "Completed pre installation checks." } # Displays the welcome dialog indicating what steps will be taken @@ -332,15 +330,13 @@ function display_welcome() { local CONTINUE=0 - local DRED="\Z1" - local DNORMAL="\Zn" if [[ ${TEXT_ONLY} == "true" ]]; then - DRED="${RED}" - DNORMAL="${NC}" + DIALOG_RED="${RED}" + DIALOG_NORMAL="${NC}" fi if [[ ${AUTO_CONFIRM} == "false" ]]; then - display_msg "${LOG_TYPE}" progress "$(date) Displayed the welcome dialog" + display_msg "${LOG_TYPE}" progress "Displayed the welcome dialog" display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_WELCOME_TITLE}" "\n\ Welcome the the Allsky Remote Website Installer\n\n\ This script will perform the following tasks\n\n\ @@ -351,14 +347,14 @@ function display_welcome() 4) Upload the remote website configuration file\n 5) Enable the remote website in the WebUI settings\n\n\ \ - ${DRED}WARNING:${DNORMAL}\n\ + ${DIALOG_RED}WARNING:${DIALOG_NORMAL}\n\ - This will overwrite files on the remote server\n\ - REMOVE any old Allsky system files on the remote server.\n\n\ Are you sure you wish to continue?" CONTINUE=$? else - display_msg "${LOG_TYPE}" progress "$(date) Ignored welcome prompt as auto confirm option specified" + display_msg "${LOG_TYPE}" progress "Ignored welcome prompt as auto confirm option specified" fi if [[ ${CONTINUE} -ne 0 ]]; then @@ -374,7 +370,7 @@ function display_aborted() local EXTRA_TEXT=$1 local SHOW_LOG=$2 - display_msg "${LOG_TYPE}" warning "$(date) USER ABORTED INSTALLATION ${EXTRA_TEXT}." + display_msg "${LOG_TYPE}" warning "USER ABORTED INSTALLATION ${EXTRA_TEXT}." ERROR_MSG="\nThe installation of the remote website has been aborted ${EXTRA_TEXT}." if [[ ${SHOW_LOG} == "true" ]]; then @@ -400,7 +396,7 @@ function display_complete() EXTRA_TEXT="\nSince you have a very old Allsky website a new configuration file was created for the website. Please use the WebUI editor and replace any 'XX_NEED_TO_UPDATE_XX' with the correct values" fi - display_msg "${LOG_TYPE}" info "$(date) INSTALLATON COMPLETED.\n" + display_msg "${LOG_TYPE}" info "INSTALLATON COMPLETED.\n" display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\n\ The installation of the remote website has been completed.\n\n\ Please use the editor in the Allsky WebUI to manage any changes to the\ @@ -411,7 +407,7 @@ function display_complete() # Check connectivity to the remote website function check_connectivity() { - display_msg "${LOG_TYPE}" info "$(date) Checking remote website connectivity." + display_msg "${LOG_TYPE}" info "Checking remote website connectivity." "${ALLSKY_SCRIPTS}/testUpload.sh" --website --silent >> "${DISPLAY_MSG_LOG}" 2>&1 RESULT=$? @@ -425,7 +421,7 @@ function check_connectivity() display_aborted "${ERROR_MSG}" "true" else local MESSAGE="The remote website connectivity test succeeded." - display_msg "${LOG_TYPE}" info "$(date) ${MESSAGE}" + display_msg "${LOG_TYPE}" info "${MESSAGE}" remove_remote_file "testUpload.sh.txt" show_debug_message "testUpload.sh.txt deleted from the remote server" fi @@ -435,7 +431,7 @@ function check_connectivity() function show_debug_message() { if [[ ${DEBUG} == "true" ]]; then - display_msg "${LOG_TYPE}" debug "$(date) ${1}" + display_msg "${LOG_TYPE}" debug "${1}" fi } @@ -444,7 +440,7 @@ function show_debug_message() function create_website_config() { display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nCreating configuration file from ${CONFIG_MESSAGE}" - display_msg "${LOG_TYPE}" info "$(date) Creating remote website configuration file" + display_msg "${LOG_TYPE}" info "Creating remote website configuration file" # We need a new config file so copy it from the repo and replace as many of the placeholders as we can if [[ "${CONFIG_TO_USE}" == "new" || "${CONFIG_TO_USE}" == "remotereallyold" ]]; then @@ -452,26 +448,26 @@ function create_website_config() DEST_FILE="${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" cp "${SOURCE_FILE}" "${DEST_FILE}" replace_website_placeholders "remote" - display_msg "${LOG_TYPE}" info "$(date) Created a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from the repo version and updating placeholders" + display_msg "${LOG_TYPE}" info "Created a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from the repo version and updating placeholders" fi # Use the current config file so do nothing if [[ "${CONFIG_TO_USE}" == "current" ]]; then - display_msg "${LOG_TYPE}" info "$(date) Using the existing ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} remote configuration file so nothing created" + display_msg "${LOG_TYPE}" info "Using the existing ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} remote configuration file so nothing created" fi # Use the config file from allsky-OLD, copy it and replace as many of the placeholders as we can if [[ "${CONFIG_TO_USE}" == "old" ]]; then cp "${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" replace_website_placeholders "remote" - display_msg "${LOG_TYPE}" info "$(date) Copying ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from the allsky-OLD directory and updating placeholders" + display_msg "${LOG_TYPE}" info "Copying ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from the allsky-OLD directory and updating placeholders" fi # Use the new remote config file since none were found locally if [[ "${CONFIG_TO_USE}" == "remotenew" ]]; then if [[ $( wget -O "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_URL}/${ALLSKY_WEBSITE_CONFIGURATION_FILE}" ) -eq 0 ]]; then replace_website_placeholders "remote" - display_msg "${LOG_TYPE}" info "$(date) Downloading ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}, creating a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" + display_msg "${LOG_TYPE}" info "Downloading ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}, creating a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" else display_aborted "Failed to download ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}" "true" fi @@ -536,7 +532,7 @@ function remove_remote_file() bye" > /dev/null 2>&1 #TODO: Check response code - display_msg "${LOG_TYPE}" info "$(date) Deleted file ${FILENAME} from ${REMOTE_HOST}" + display_msg "${LOG_TYPE}" info "Deleted file ${FILENAME} from ${REMOTE_HOST}" fi @@ -564,7 +560,7 @@ function check_if_website_exists() check_if_files_exist "${REMOTE_URL}" "and" "${WEBSITE_FILES[@]}" local WEBSITE_EXISTS_RESULT=$? if [[ ${WEBSITE_EXISTS_RESULT} -eq 0 ]]; then - display_msg "${LOG_TYPE}" progress "$(date) Found remote Allsky website at ${REMOTE_URL}" + display_msg "${LOG_TYPE}" progress "Found remote Allsky website at ${REMOTE_URL}" RESULT=0 WEBSITE_EXISTS="true" fi @@ -604,7 +600,7 @@ function upload_remote_website() MESSAGE+=", excluding videos, startrails and keograms as the website exists" fi - display_msg "${LOG_TYPE}" progress "$(date) ${MESSAGE}${EXTRA_TEXT}" + display_msg "${LOG_TYPE}" progress "${MESSAGE}${EXTRA_TEXT}" display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\n${MESSAGE}\n\nPlease wait this process could take several minutes" # Save the current stdout and stderr @@ -628,13 +624,13 @@ function upload_remote_website() # Restore stdout and stderr to the terminal exec 1>&3 2>&4 - display_msg "${LOG_TYPE}" progress "$(date) Website upload complete" + display_msg "${LOG_TYPE}" progress "Website upload complete" else display_aborted "at the website upload" fi else - display_msg "${LOG_TYPE}" info "$(date) Skipping upload as --skipupload provided on command line\n" + display_msg "${LOG_TYPE}" info "Skipping upload as --skipupload provided on command line\n" fi } @@ -642,13 +638,13 @@ function upload_remote_website() function upload_config_file() { display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nUploading remote Allsky configuration file" - display_msg "${LOG_TYPE}" progress "$(date) Starting website configuration file upload" + display_msg "${LOG_TYPE}" progress "Starting website configuration file upload" REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" RESULT="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_DIR}" "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" )" if [[ ! ${RESULT} ]]; then show_debug_message "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} uploaded to ${REMOTE_DIR}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}" - display_msg "${LOG_TYPE}" progress "$(date) Completed website configuration file upload" + display_msg "${LOG_TYPE}" progress "Completed website configuration file upload" else display_aborted "at the configuration file upload" "true" fi @@ -688,7 +684,7 @@ function enable_remote_website() { display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nEnabling remote website" update_json_file ".useremotewebsite" "true" "${SETTINGS_FILE}" - display_msg "${LOG_TYPE}" info "$(date) Remote website enabled.\n" + display_msg "${LOG_TYPE}" info "Remote website enabled.\n" } ############################################## main body diff --git a/scripts/installUpgradeFunctions.sh b/scripts/installUpgradeFunctions.sh index 54f8a292b..4ec069515 100644 --- a/scripts/installUpgradeFunctions.sh +++ b/scripts/installUpgradeFunctions.sh @@ -248,7 +248,7 @@ function display_msg() # Outer "echo -e" handles "\n" (2 characters) in input. # No "-e" needed on inner "echo". - echo -e "$( echo "${LOGMSG}${MESSAGE2}" | + echo -e "$( echo "$(date) ${LOGMSG}${MESSAGE2}" | sed -e "s/${ESC}/033/g" -e "s/033\[/033X/g" \ -e "s/${G}//g" \ -e "s/${Y}//g" \ @@ -257,7 +257,7 @@ function display_msg() -e "s/${N}//g" \ )" else - echo "${LOGMSG}${MESSAGE2}" + echo "$(date) ${LOGMSG}${MESSAGE2}" fi >> "${DISPLAY_MSG_LOG}" } diff --git a/variables.sh b/variables.sh index d96c70dd2..6e40739e8 100644 --- a/variables.sh +++ b/variables.sh @@ -17,6 +17,7 @@ if [[ -z "${ALLSKY_VARIABLE_SET}" ]]; then # The "w" colors are for when output may go to a web page. if tty --silent ; then ON_TTY="true" + DIALOG_RED="\Z1"; DIALOG_NORMAL="\Zn" GREEN="\033[0;32m"; wOK="${GREEN}" YELLOW="\033[0;33m"; wWARNING="${YELLOW}" RED="\033[0;31m"; wERROR="${RED}" @@ -27,6 +28,7 @@ if [[ -z "${ALLSKY_VARIABLE_SET}" ]]; then wBR="\n" else ON_TTY="false" + DIALOG_RED=""; DIALOG_NORMAL="" GREEN=""; wOK="" YELLOW=""; wWARNING="" RED=""; wERROR="" From ba83eb79ae29821f9bdc762e78e76dad61dfd394 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sat, 19 Oct 2024 18:18:19 -0600 Subject: [PATCH 03/17] Update remote_website_install.sh: updates for conventions * Do not truncate log file - it's helpful to see all the attempts a user made. * Updates for shell conventions, e.g., ${1} instead of $1. --- remote_website_install.sh | 981 +++++++++++++++++++------------------- 1 file changed, 478 insertions(+), 503 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index 55cc0daf4..e35e17eeb 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -3,6 +3,7 @@ # shellcheck disable=SC2317 # Install or upgrade a remote Allsky Website. + # shellcheck disable=SC2155 [[ -z ${ALLSKY_HOME} ]] && export ALLSKY_HOME="$( realpath "$( dirname "${BASH_ARGV0}" )" )" ME="$( basename "${BASH_ARGV0}" )" @@ -16,7 +17,7 @@ source "${ALLSKY_SCRIPTS}/installUpgradeFunctions.sh" || exit "${EXIT_ERROR_STOP # display_msg() sends log entries to this file. # shellcheck disable=SC2034 -DISPLAY_MSG_LOG="${ALLSKY_LOGS}/${ME}.log" +DISPLAY_MSG_LOG="${ALLSKY_LOGS}/${ME/.sh/}.log" # Config variables HAVE_NEW_CONFIG="false" @@ -30,10 +31,10 @@ CONFIG_MESSAGE="" DIALOG_WIDTH=70 DIALOG_HEIGHT=25 -# logging options +# Logging options LOG_TYPE="--logonly" -# Rempote connectivity variables +# Remote connectivity variables REMOTE_URL="$( settings ".remotewebsiteurl" "${SETTINGS_FILE}" )" REMOTE_USER="$( settings ".REMOTEWEBSITE_USER" "${ALLSKY_ENV}" )" REMOTE_HOST="$( settings ".REMOTEWEBSITE_HOST" "${ALLSKY_ENV}" )" @@ -50,607 +51,580 @@ DIALOG_PRE_CHECK="Pre Installation Checks" DIALOG_INSTALL="Installing Remote Website" DIALOG_TITLE_LOG="Allsky Remote Website Installation Log" -# Old Allksy files that should be remoevd if they exist +# Old Allksy Website files that should be remoevd if they exist OLD_FILES_TO_REMOVE=("config.js" "configuration.json" "virtualsky.json") -# TODO: DO we want to do this or backup any old logs, its better to have a single -# log per run rather than a file thats just appended to. - -# Truncate log file -: > "${DISPLAY_MSG_LOG}" - ############################################## functions -# Prompt the user to enter (y)/(yes) or (n)/(no) -# This function is only used when running in text (--text) mode +# Prompt the user to enter (y)/(yes) or (n)/(no). +# This function is only used when running in text (--text) mode. function enter_yes_no() { - local RESULT - local ANSWER - - while true; do - echo -e "$1" - read -r -p "Do you want to continue? (y/n): " ANSWER - ANSWER=$(echo "${ANSWER}" | tr '[:upper:]' '[:lower:]') - - if [[ "${ANSWER}" == "y" || "${ANSWER}" == "yes" ]]; then - RESULT=0 - break - elif [[ "${ANSWER}" == "n" || "${ANSWER}" == "no" ]]; then - RESULT=1 - break - else - echo "Invalid response. Please enter y/yes or n/no." - fi - done - - return ${RESULT} + local TEXT="${1}" + local RESULT + local ANSWER + + while true; do + echo -e "${TEXT}" + read -r -p "Do you want to continue? (y/n): " ANSWER + ANSWER="${ANSWER,,}" # convert to lowercase + + if [[ "${ANSWER}" == "y" || "${ANSWER}" == "yes" ]]; then + RESULT=0 + break + elif [[ "${ANSWER}" == "n" || "${ANSWER}" == "no" ]]; then + RESULT=1 + break + else + echo "Invalid response. Please enter y/yes or n/no." + fi + done + + return ${RESULT} } -# prompt the user to press any key -# This function is only used when running in text (--text) mode +# prompt the user to press any key. +# This function is only used when running in text (--text) mode. function press_any_key() { - echo -e "$1" - echo "Press any key to continue..." - read -r -n1 -s + echo -e "${1}\nPress any key to continue..." + read -r -n1 -s } -# Adds the remote website URL to the dialog text +# Adds the remote Website URL to the dialog text. function add_dialog_heading() { - local DIALOG_TEXT=$1 - if [[ ${TEXT_ONLY} == "true" ]]; then - DIALOG_RED="${RED}" - DIALOG_NORMAL="${NC}" - fi - - local PADDING=$(( ((DIALOG_WIDTH-6) - ${#REMOTE_URL}) / 2 )) - local URL=$(printf "%${PADDING}s%s" "" "$REMOTE_URL") - - DIALOG_TEXT="\n${DIALOG_RED}${URL}${DIALOG_NORMAL}\n${DIALOG_TEXT}" - - echo "${DIALOG_TEXT}" + local DIALOG_TEXT="${1}" + if [[ ${TEXT_ONLY} == "true" ]]; then + DIALOG_RED="${RED}" + DIALOG_NORMAL="${NC}" + fi + + local PADDING=$(( ((DIALOG_WIDTH-6) - ${#REMOTE_URL}) / 2 )) + local URL=$(printf "%${PADDING}s%s" "" "$REMOTE_URL") + + echo -e "\n${DIALOG_RED}${URL}${DIALOG_NORMAL}\n${DIALOG_TEXT}" } -# Displays an info Dialog, or in text mode just displays the text -# $1 - The backtitle for the dialog -# $2 - The title for the dialog -# $3 - The text to disply in the dialog + +# Displays an info Dialog, or in text mode just displays the text. +# ${1} - The backtitle for the dialog +# ${2} - The title for the dialog +# ${3} - The text to disply in the dialog # # Returns - Nothing function display_info_dialog() { - local DIALOG_TEXT=$3 - - DIALOG_TEXT=$(add_dialog_heading "${DIALOG_TEXT}") - if [[ ${TEXT_ONLY} == "false" ]]; then - local BACK_TITLE=$1 - local DIALOG_TITLE=$2 - dialog \ - --colors\ - --backtitle "${BACK_TITLE}" \ - --title "${DIALOG_TITLE}" \ - --infobox "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} - else - echo -e "${DIALOG_TEXT}" - fi + local DIALOG_TEXT="${3}" + + DIALOG_TEXT="$( add_dialog_heading "${DIALOG_TEXT}" )" + if [[ ${TEXT_ONLY} == "true" ]]; then + echo -e "${DIALOG_TEXT}" + return + fi + local BACK_TITLE="${1}" + local DIALOG_TITLE="${2}" + dialog \ + --colors \ + --backtitle "${BACK_TITLE}" \ + --title "${DIALOG_TITLE}" \ + --infobox "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} } # Displays an prompt Dialog, or in text mode just displays the text -# and prompts the user to enter y or n -# $1 - The backtitle for the dialog -# $2 - The title for the dialog -# $3 - The text to disply in the dialog +# and prompts the user to enter y or n. +# ${1} - The backtitle for the dialog +# ${2} - The title for the dialog +# ${3} - The text to disply in the dialog # # Returns - The exiit code (0 - Yes, >0 No) function display_prompt_dialog() { - local DIALOG_TEXT=$3 - local RESULT - - DIALOG_TEXT=$(add_dialog_heading "${DIALOG_TEXT}") - if [[ ${TEXT_ONLY} == "false" ]]; then - local BACK_TITLE=$1 - local DIALOG_TITLE=$2 - dialog \ - --colors\ - --backtitle "${BACK_TITLE}" \ - --title "${DIALOG_TITLE}" \ - --yesno "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} - else - enter_yes_no "${DIALOG_TEXT}" - fi - - RESULT=$? - - return ${RESULT} + local DIALOG_TEXT="${3}" + + DIALOG_TEXT="$( add_dialog_heading "${DIALOG_TEXT}" )" + if [[ ${TEXT_ONLY} == "text" ]]; then + enter_yes_no "${DIALOG_TEXT}" + return + fi + + local BACK_TITLE="${1}" + local DIALOG_TITLE="${2}" + dialog \ + --colors\ + --backtitle "${BACK_TITLE}" \ + --title "${DIALOG_TITLE}" \ + --yesno "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} + return $? } # Displays an message Dialog, or in text mode just displays the text -# and prmots the user to press any key -# $1 - The backtitle for the dialog -# $2 - The title for the dialog -# $3 - The text to disply in the dialog +# and prompts the user to press any key. +# ${1} - The backtitle for the dialog +# ${2} - The title for the dialog +# ${3} - The text to disply in the dialog # # Returns - Nothing function display_message_box() { - local DIALOG_TEXT=$3 - - DIALOG_TEXT=$(add_dialog_heading "${DIALOG_TEXT}") - if [[ ${TEXT_ONLY} == "false" ]]; then - local BACK_TITLE=$1 - local DIALOG_TITLE=$2 - dialog \ - --colors\ - --backtitle "${BACK_TITLE}" \ - --title "${DIALOG_TITLE}" \ - --msgbox "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} - else - press_any_key "${DIALOG_TEXT}" - fi + local DIALOG_TEXT="${3}" + DIALOG_TEXT="$( add_dialog_heading "${DIALOG_TEXT}" )" + if [[ ${TEXT_ONLY} == "true" ]]; then + press_any_key "${DIALOG_TEXT}" + return + fi + + local BACK_TITLE="${1}" + local DIALOG_TITLE="${2}" + dialog \ + --colors \ + --backtitle "${BACK_TITLE}" \ + --title "${DIALOG_TITLE}" \ + --msgbox "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} } -# Displays a file Dialog, or in text mode just displays the file -# $1 - The backtitle for the dialog -# $2 - The title for the dialog -# $3 - The filename to display +# Displays a file Dialog, or in text mode just displays the file. +# ${1} - The backtitle for the dialog +# ${2} - The title for the dialog +# ${3} - The filename to display # # Returns - Nothing function display_log_file() { + local FILENAME="${3}" - local FILENAME=$3 - - if [[ ${TEXT_ONLY} == "false" ]]; then - local BACK_TITLE=$1 - local DIALOG_TITLE=$2 - dialog \ - --clear\ - --colors\ - --backtitle "${BACK_TITLE}"\ - --title "${DIALOG_TITLE}"\ - --textbox "${FILENAME}" 22 77 - else - cat "${FILENAME}" - fi + if [[ ${TEXT_ONLY} == "true" ]]; then + cat "${FILENAME}" + return + fi + + local BACK_TITLE="${1}" + local DIALOG_TITLE="${2}" + dialog \ + --clear\ + --colors\ + --backtitle "${BACK_TITLE}"\ + --title "${DIALOG_TITLE}"\ + --textbox "${FILENAME}" 22 77 } -# Runs the pre installation checks. This function will determine the following -# - Is there a remote website -# - Which configuration file to use for the remote website +# Runs the pre installation checks. This function will determine the following: +# - Is there a remote Website +# - Which configuration file to use for the remote Website # -# The configuration file to use is decided using the following, in order -# -# If there is a remote-configuration.json in the /config folder then use it -# If there is a remote-configuration.json in the allsky-OLD/config folder then use it -# Otherwise -# If there is a remote website with a configuration.json file then save it in /config -# If there is a remote website and it has an old configuration file (config.js) then -# create a new remote-configuration.json in /config +# The configuration file to use is decided using the following, in order: # +# If there is a remote-configuration.json in the /config folder then use it. +# If there is a remote-configuration.json in the allsky-OLD/config folder then use it. +# Otherwise: +# If there is a remote Website with a configuration.json file then save it in /config. +# If there is a remote Website and it has an old configuration file (config.js) then +# create a new remote-configuration.json in /config. function pre_install_checks() { - local MESSAGE="" - - local DIALOG_TEXT="\nRunning pre installation checks.\n\nPlease wait as this process can take a few minutes to complete.\n\n" - DIALOG_TEXT+="\n1 - Checking for local files" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - display_msg "${LOG_TYPE}" info "Start pre installation checks." - - - if [[ -f "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" ]]; then - MESSAGE="Found current configuration file in ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." - display_msg "${LOG_TYPE}" progress "${MESSAGE}" - HAVE_NEW_CONFIG="true" - fi - - if [[ -f "${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}" ]]; then - MESSAGE="Found -OLD configuration file in ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}." - display_msg "${LOG_TYPE}" progress "${MESSAGE}" - HAVE_OLD_CONFIG="true" - fi - - DIALOG_TEXT+="\n2 - Checking if remote website exists" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - - check_if_website_exists - - if [[ "${WEBSITE_EXISTS}" == "true" ]]; then - - DIALOG_TEXT+="\n3 - Checking for remote website configuration file" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - - local NEW_CONFIG_FILES=("configuration.json") - check_if_files_exist "${REMOTE_URL}" "false" "${NEW_CONFIG_FILES[@]}" - local NEW_CONFIG_FILE_EXISTS=$? - if [[ ${NEW_CONFIG_FILE_EXISTS} -eq 0 ]]; then - HAVE_NEW_REMOTE_CONFIG="true" - MESSAGE="Found current configuration on the remote server." - display_msg "${LOG_TYPE}" progress "${MESSAGE}" - fi - - DIALOG_TEXT+="\n4 - Checking for old remote website configuration file" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - - local REALLY_OLD_CONFIG_FILES=("config.js") - check_if_files_exist "${REMOTE_URL}" "false" "${REALLY_OLD_CONFIG_FILES[@]}" - local OLD_CONFIG_FILE_EXISTS=$? - if [[ ${OLD_CONFIG_FILE_EXISTS} -eq 0 ]]; then - HAVE_REALLY_OLD_REMOTE_CONFIG="true" - MESSAGE="Found really old format website configuration file on the remote website." - display_msg "${LOG_TYPE}" progress "${MESSAGE}" - fi - fi - - if [[ "${HAVE_NEW_CONFIG}" == "true" ]]; then - local EXTRA_TEXT="." - if [[ "${HAVE_NEW_REMOTE_CONFIG}" == "true" ]]; then - EXTRA_TEXT=", A remote configuration file was found but the local version will be used instead" - fi - display_msg "${LOG_TYPE}" progress "Will use the local remote configuration file${EXTRA_TEXT}" - CONFIG_TO_USE="current" - CONFIG_MESSAGE="Current" - else - if [[ "${HAVE_OLD_CONFIG}" == "true" ]]; then - display_msg "${LOG_TYPE}" progress "Will use the -OLD configuration file, placeholders will be updated" - CONFIG_TO_USE="old" - CONFIG_MESSAGE="allsky-OLD" - else - if [[ "${WEBSITE_EXISTS}" == "true" ]]; then - if [[ "${HAVE_NEW_REMOTE_CONFIG}" == "true" ]]; then - display_msg "${LOG_TYPE}" progress "Will use the new format website configuration file on the remote website, will be downloaded and saved locally" - CONFIG_TO_USE="remotenew" - CONFIG_MESSAGE="Remote new" - else - if [[ "${HAVE_REALLY_OLD_REMOTE_CONFIG}" == "true" ]]; then - display_msg "${LOG_TYPE}" progress "Old config.js found. A new configuration file will be created and the user will have to updae it manually" - CONFIG_TO_USE="remotereallyold" - CONFIG_MESSAGE=" repos config i.e. a new config" - fi - fi - fi - fi - fi - - if [[ "${CONFIG_TO_USE}" == "" ]]; then - display_msg "${LOG_TYPE}" progress "Unable to determine the configuration file to use. A new one will be created" - CONFIG_TO_USE="new" - fi - - check_connectivity - - display_msg "${LOG_TYPE}" info "Completed pre installation checks." + local MSG="" + local DIALOG_TEXT="\nRunning pre installation checks." + DIALOG_TEXT+="\n\nPlease wait as this can take a few minutes to complete.\n\n" + + DIALOG_TEXT+="\n1 - Checking for local files" + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + display_msg "${LOG_TYPE}" info "Start pre installation checks." + + if [[ -f ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then + MSG="Found current configuration file: ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." + display_msg "${LOG_TYPE}" progress "${MSG}" + HAVE_NEW_CONFIG="true" + fi + + if [[ -f ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then + MSG="Found -OLD configuration file: ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}." + display_msg "${LOG_TYPE}" progress "${MSG}" + HAVE_OLD_CONFIG="true" + fi + + DIALOG_TEXT+="\n2 - Checking if remote Website exists" + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + + check_if_website_exists # Sets ${WEBSITE_EXISTS} + if [[ ${WEBSITE_EXISTS} == "true" ]]; then + + DIALOG_TEXT+="\n3 - Checking for remote Website configuration file" + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + + local NEW_CONFIG_FILES=("configuration.json") + if check_if_files_exist "${REMOTE_URL}" "false" "${NEW_CONFIG_FILES[@]}" ; then + HAVE_NEW_REMOTE_CONFIG="true" + MSG="Found current configuration on the remote server." + display_msg "${LOG_TYPE}" progress "${MSG}" + fi + + DIALOG_TEXT+="\n4 - Checking for old remote Website configuration file" + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + + local REALLY_OLD_CONFIG_FILES=("config.js") + if check_if_files_exist "${REMOTE_URL}" "false" "${REALLY_OLD_CONFIG_FILES[@]}" ; then + HAVE_REALLY_OLD_REMOTE_CONFIG="true" + MSG="Found really old format Website configuration file on the remote Website." + display_msg "${LOG_TYPE}" progress "${MSG}" + fi + fi + + if [[ "${HAVE_NEW_CONFIG}" == "true" ]]; then + MSG="Using the local remote configuration file" + if [[ "${HAVE_NEW_REMOTE_CONFIG}" == "true" ]]; then + MSG+=", a remote configuration file was found but using the local version instead" + fi + display_msg "${LOG_TYPE}" progress "${MSG}." + CONFIG_TO_USE="current" + CONFIG_MESSAGE="Current" + else + if [[ "${HAVE_OLD_CONFIG}" == "true" ]]; then + MSG="Using the -OLD configuration file; placeholders will be updated." + display_msg "${LOG_TYPE}" progress "${MSG}" + CONFIG_TO_USE="old" + CONFIG_MESSAGE="$( basename '${PRIOR_ALLSKY_DIR}' )" + else + if [[ "${WEBSITE_EXISTS}" == "true" ]]; then + if [[ "${HAVE_NEW_REMOTE_CONFIG}" == "true" ]]; then + MSG="Using new format Website configuration file on the remote Website;" + MSG+=" it will be downloaded and saved locally." + display_msg "${LOG_TYPE}" progress "${MSG}" + CONFIG_TO_USE="remotenew" + CONFIG_MESSAGE="Remote new" + else + if [[ "${HAVE_REALLY_OLD_REMOTE_CONFIG}" == "true" ]]; then + MSG="Old config.js found." + MSG+=" Creating a new configuration file that the user must manually update." + display_msg "${LOG_TYPE}" progress "${MSG}" + CONFIG_TO_USE="remotereallyold" + CONFIG_MESSAGE=" repos config i.e. a new config" + fi + fi + fi + fi + fi + + if [[ "${CONFIG_TO_USE}" == "" ]]; then + MSG="Unable to determine the configuration file to use. A new one will be created." + display_msg "${LOG_TYPE}" progress "${MSG}" + CONFIG_TO_USE="new" + fi + + check_connectivity + + display_msg "${LOG_TYPE}" info "Completed pre installation checks." } # Displays the welcome dialog indicating what steps will be taken function display_welcome() { - local CONTINUE=0 - - if [[ ${TEXT_ONLY} == "true" ]]; then - DIALOG_RED="${RED}" - DIALOG_NORMAL="${NC}" - fi - - if [[ ${AUTO_CONFIRM} == "false" ]]; then - display_msg "${LOG_TYPE}" progress "Displayed the welcome dialog" - display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_WELCOME_TITLE}" "\n\ - Welcome the the Allsky Remote Website Installer\n\n\ - This script will perform the following tasks\n\n\ + if [[ ${TEXT_ONLY} == "true" ]]; then + DIALOG_RED="${RED}" + DIALOG_NORMAL="${NC}" + fi + + if [[ ${AUTO_CONFIRM} == "false" ]]; then + display_msg "${LOG_TYPE}" progress "Displayed the welcome dialog" + local DIALOG_MSG="\n\ + Welcome the the Allsky Remote Website Installer!\n\n\ + This script will perform the following tasks:\n\n\ \ - 1) Check the remote website connectivity - PASSED\n\ - 2) Use the ${CONFIG_MESSAGE} Configuration file\n\ - 3) Upload the remote website code\n\ - 4) Upload the remote website configuration file\n - 5) Enable the remote website in the WebUI settings\n\n\ + 1) Check the remote Website connectivity - PASSED\n\ + 2) Use the ${CONFIG_MESSAGE} configuration file\n\ + 3) Upload the remote Website code\n\ + 4) Upload the remote Website configuration file\n + 5) Enable the remote Website in the WebUI settings\n\n\ \ ${DIALOG_RED}WARNING:${DIALOG_NORMAL}\n\ - - This will overwrite files on the remote server\n\ - - REMOVE any old Allsky system files on the remote server.\n\n\ + - This will overwrite files on the remote server, and\n\ + - REMOVE any old Allsky files on the remote server.\n\n\ Are you sure you wish to continue?" - CONTINUE=$? - else - display_msg "${LOG_TYPE}" progress "Ignored welcome prompt as auto confirm option specified" - fi - - if [[ ${CONTINUE} -ne 0 ]]; then - display_aborted "at the Welcome dialog" - fi + if ! display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_WELCOME_TITLE}" "${DIALOG_MSG}" ; then + display_aborted "at the Welcome dialog" "false" + fi + else + display_msg "${LOG_TYPE}" progress "Ignored welcome prompt as auto confirm option specified." + fi } -# Displays the aborted dialog. This is used when an error is encountered or the user cancels -# $1 - Extra text to display in the dialog -# $2 - "true"/"false" - Flag to indicate if the user should be prompted to show the installation log +# Displays the aborted dialog. This is used when an error is encountered or the user cancels. +# ${1} - Extra text to display in the dialog +# ${2} - "true"/"false" - Flag to indicate if the user should be prompted to show the installation log function display_aborted() { - local EXTRA_TEXT=$1 - local SHOW_LOG=$2 - - display_msg "${LOG_TYPE}" warning "USER ABORTED INSTALLATION ${EXTRA_TEXT}." - ERROR_MSG="\nThe installation of the remote website has been aborted ${EXTRA_TEXT}." - - if [[ ${SHOW_LOG} == "true" ]]; then - display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${ERROR_MSG}\n\nWould you like to view the installation log?" - local DISPLAY_LOG=$? - if [[ ${DISPLAY_LOG} -eq 0 ]]; then - display_log_file "${DIALOG_BACK_TITLE}" "${DIALOG_TITLE_LOG}" "${DISPLAY_MSG_LOG}" - fi - else - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${ERROR_MSG}" - fi - exit 1 + local EXTRA_TEXT="${1}" + local SHOW_LOG="${2}" + + display_msg "${LOG_TYPE}" warning "USER ABORTED INSTALLATION ${EXTRA_TEXT}." + local ERROR_MSG="\nThe installation of the remote Website has been aborted ${EXTRA_TEXT}." + + if [[ ${SHOW_LOG} == "true" ]]; then + MSG="\n\nWould you like to view the installation log?" ; then + if display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${ERROR_MSG}\n\n${MSG}" ; then + display_log_file "${DIALOG_BACK_TITLE}" "${DIALOG_TITLE_LOG}" "${DISPLAY_MSG_LOG}" + fi + else + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${ERROR_MSG}" + fi + + exit 1 } -# Displays the completed dialog, used at the end of the installation process +# Displays the completed dialog, used at the end of the installation process. function display_complete() { - local EXTRA_TEXT="" - if [[ "${CONFIG_TO_USE}" == "new" ]]; then - EXTRA_TEXT="\nA new configuration file was created for the website. Please use the WebUI editor and replace any 'XX_NEED_TO_UPDATE_XX' with the correct values" - fi - if [[ "${CONFIG_TO_USE}" == "remotereallyold" ]]; then - EXTRA_TEXT="\nSince you have a very old Allsky website a new configuration file was created for the website. Please use the WebUI editor and replace any 'XX_NEED_TO_UPDATE_XX' with the correct values" - fi - - display_msg "${LOG_TYPE}" info "INSTALLATON COMPLETED.\n" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\n\ - The installation of the remote website has been completed.\n\n\ - Please use the editor in the Allsky WebUI to manage any changes to the\ - website.${EXTRA_TEXT}" + local EXTRA_TEXT="" + if [[ ${CONFIG_TO_USE} == "new" ]]; then + EXTRA_TEXT="\nA new configuration file was created for the Website." + EXTRA_TEXT+=" Please use the WebUI editor and replace any '${NEED_TO_UPDATE}' with the correct values" + elif [[ ${CONFIG_TO_USE} == "remotereallyold" ]]; then + EXTRA_TEXT="\nYou have a very old Allsky Website so a new configuration file was created." + EXTRA_TEXT+=" Please use the WebUI 'Editor' page to replace any '${NEED_TO_UPDATE}' with the correct values." + fi + display_msg "${LOG_TYPE}" info "INSTALLATON COMPLETED.\n" + + MSG="\n\ + The installation of the remote Website has been completed.\n\n\ + Please use the 'Editor' page in the Allsky WebUI to manage any changes to the Website.${EXTRA_TEXT}" + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "%{MSG}" } -# Check connectivity to the remote website -function check_connectivity() +# Check connectivity to the remote Website. +function check_connectivity() { - display_msg "${LOG_TYPE}" info "Checking remote website connectivity." - "${ALLSKY_SCRIPTS}/testUpload.sh" --website --silent >> "${DISPLAY_MSG_LOG}" 2>&1 - RESULT=$? + local TEST_FILE="${ME}.txt" - if [[ ${RESULT} -ne 0 ]]; then - local ERROR_MSG="\nERROR: The remote website connectivity check failed. Result code ${RESULT} \n\nPlease check the 'Websites and Remote Server Settings' in the WebUI.\n\n\ + display_msg "${LOG_TYPE}" info "Checking remote Website connectivity." + if "${ALLSKY_SCRIPTS}/testUpload.sh" --website --silent --file "${TEST_FILE}" >> "${DISPLAY_MSG_LOG}" 2>&1 ; then + local ERROR_MSG="\nERROR: The remote Website connectivity check failed. Result code ${RESULT}" + ERROR_MSG+="\n\nPlease check the 'Websites and Remote Server Settings' in the WebUI.\n\n\ HOST: ${REMOTE_HOST} PROTOCOL: ${REMOTE_PROTOCOL}\n\ USER: ${REMOTE_USER}\n\ PASSWORD: ${REMOTE_PASSWORD}\n\ FOLDER: ${REMOTE_DIR}" - display_aborted "${ERROR_MSG}" "true" - else - local MESSAGE="The remote website connectivity test succeeded." - display_msg "${LOG_TYPE}" info "${MESSAGE}" - remove_remote_file "testUpload.sh.txt" - show_debug_message "testUpload.sh.txt deleted from the remote server" - fi + display_aborted "${ERROR_MSG}" "true" + else + local MSG="The remote Website connectivity test succeeded." + display_msg "${LOG_TYPE}" info "${MSG}" + remove_remote_file "${TEST_FILE}" + show_debug_message "${TEST_FILE} deleted from the remote server" + fi } -# Displays a debug message in the log if the debug flag has been specified on the command line -function show_debug_message() +# Displays a debug message in the log if the debug flag has been specified on the command line. +function show_debug_message() { - if [[ ${DEBUG} == "true" ]]; then - display_msg "${LOG_TYPE}" debug "${1}" - fi + if [[ ${DEBUG} == "true" ]]; then + display_msg "${LOG_TYPE}" debug "${1}" + fi } -# Creates the remote website configuration file if needed, see 'pre_install_checks' for details on which configuration file -# is used +# Creates the remote Website configuration file if needed. +# See 'pre_install_checks' for details on which configuration file is used. function create_website_config() -{ - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nCreating configuration file from ${CONFIG_MESSAGE}" - display_msg "${LOG_TYPE}" info "Creating remote website configuration file" - - # We need a new config file so copy it from the repo and replace as many of the placeholders as we can - if [[ "${CONFIG_TO_USE}" == "new" || "${CONFIG_TO_USE}" == "remotereallyold" ]]; then - SOURCE_FILE="${ALLSKY_REPO}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}.repo" - DEST_FILE="${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" - cp "${SOURCE_FILE}" "${DEST_FILE}" - replace_website_placeholders "remote" - display_msg "${LOG_TYPE}" info "Created a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from the repo version and updating placeholders" - fi - - # Use the current config file so do nothing - if [[ "${CONFIG_TO_USE}" == "current" ]]; then - display_msg "${LOG_TYPE}" info "Using the existing ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} remote configuration file so nothing created" - fi - - # Use the config file from allsky-OLD, copy it and replace as many of the placeholders as we can - if [[ "${CONFIG_TO_USE}" == "old" ]]; then - cp "${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" - replace_website_placeholders "remote" - display_msg "${LOG_TYPE}" info "Copying ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from the allsky-OLD directory and updating placeholders" - fi - - # Use the new remote config file since none were found locally - if [[ "${CONFIG_TO_USE}" == "remotenew" ]]; then - if [[ $( wget -O "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_URL}/${ALLSKY_WEBSITE_CONFIGURATION_FILE}" ) -eq 0 ]]; then - replace_website_placeholders "remote" - display_msg "${LOG_TYPE}" info "Downloading ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}, creating a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" - else - display_aborted "Failed to download ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}" "true" - fi - fi +{ + local MSG="\nCreating configuration file from ${CONFIG_MESSAGE}" + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" + display_msg "${LOG_TYPE}" info "Creating remote Website configuration file" + + if [[ ${CONFIG_TO_USE} == "new" || ${CONFIG_TO_USE} == "remotereallyold" ]]; then + # We need a new config file so copy it from the repo and replace as many + # of the placeholders as we can + DEST_FILE="${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" + cp "${REPO_WEBCONFIG_FILE}" "${DEST_FILE}" + replace_website_placeholders "remote" + MSG="Created a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from repo and updated placeholders." + display_msg "${LOG_TYPE}" info "${MSG}" + + elif [[ ${CONFIG_TO_USE} == "current" ]]; then + # Use the current config file so do nothing + MSG="Using existing ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} so nothing created." + display_msg "${LOG_TYPE}" info "${MSG}" + + elif [[ ${CONFIG_TO_USE} == "old" ]]; then + # Use the config file from allsky-OLD, copy it and replace as many of the placeholders as we can + cp "${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" + replace_website_placeholders "remote" + MSG="Copying ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from the" + MSG+=" $( basename '${PRIOR_ALLSKY_DIR}' ) directory and updating placeholders." + display_msg "${LOG_TYPE}" info "${MSG}" + + elif [[ "${CONFIG_TO_USE}" == "remotenew" ]]; then + # Use the new remote config file since none were found locally + if wget -O "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_URL}/${ALLSKY_WEBSITE_CONFIGURATION_FILE}" ; then + replace_website_placeholders "remote" + MSG="Downloading ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}," + MSG+=" and creating a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." + display_msg "${LOG_TYPE}" info "${MSG}" + else + MSG="Failed to download ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}" + display_aborted "${MSG}" "true" + fi + fi } -# Check if a remote file, or array of files, exists via http -# $1 - The base url -# $2 - "true"/"false" If true then all files must exist, if "false" then any of the files can exist +# Check if a remote file, or array of files, exist. +# ${1} - The base url +# ${2} - "true"/"false" If true then all files must exist, if "false" then any of the files can exist. +# ${3}... - the files # -# Returns - 0 if the file(s) exist, 1 if not +# Returns - 0 if the file(s) exist, 1 if ANY file doesn't exist. function check_if_files_exist() { - local URL=$1 - shift - local AND=$1 - shift - local RESULT=1 - - for file in "$@"; do - url="${URL}/${file}" - http_status=$(curl -o /dev/null -s -w "%{http_code}" "$url") - - if [ "${http_status}" -eq 200 ]; then - show_debug_message "File ${file} ${url} exists on the remote server" - RESULT=0 - else - show_debug_message "File ${file} ${url} doesnt exists on the remote server" - if [[ $AND == "true" ]]; then - RESULT=1 - break - fi - fi - done - - return "${RESULT}" + local URL="${1}" + local AND="${2}" + shift 2 + local RESULT=1 + + for FILE in "$@"; do + url="${URL}/${FILE}" + http_status=$(curl -o /dev/null -s -w "%{http_code}" "$url") + + if [ ${http_status} -eq 200 ]; then + show_debug_message "File ${FILE} ${url} exists on the remote server" + RESULT=0 + else + show_debug_message "File ${FILE} ${url} doesnt exists on the remote server" + if [[ ${AND} == "true" ]]; then + RESULT=1 + break + fi + fi + done + + return ${RESULT} } -# Deletes a file from the remote server. If a URL is specified then the file is first checked to make sure it exists -# $1 - The name of the file to delete -# $2 - The url of the remote website, used to check if a file exists +# Deletes a file from the remote server. +# If a URL is specified then the file is first checked to make sure it exists. +# ${1} - The name of the file to delete +# ${2} - The url of the remote Website, used to check if a file exists # # Returns - Nothing function remove_remote_file() { - local FILENAME=$1 - local URL=$2 - local CONTINUE="true" - - if [[ -n "${URL}" ]]; then - check_if_files_exist "${REMOTE_URL}" "false" "${FILENAME}" - local FILE_EXISTS=$? - if [[ ${FILE_EXISTS} -ne 0 ]]; then - CONTINUE="false" - fi - fi + local FILENAME="${1}" + local URL="${2}" - if [[ "${CONTINUE}" == "true" ]]; then - lftp -u "${REMOTE_USER}","${REMOTE_PASSWORD}" "${REMOTE_PORT}" "${REMOTE_PROTOCOL}://${REMOTE_HOST}" -e " - cd ${REMOTE_DIR} - rm ${FILENAME} - bye" > /dev/null 2>&1 + if [[ -n ${URL} ]]; then + check_if_files_exist "${REMOTE_URL}" "false" "${FILENAME}" || return + fi - #TODO: Check response code - display_msg "${LOG_TYPE}" info "Deleted file ${FILENAME} from ${REMOTE_HOST}" +# TODO: This assumes ftp is used to upload files + lftp -u "${REMOTE_USER},${REMOTE_PASSWORD}" "${REMOTE_PORT}" "${REMOTE_PROTOCOL}://${REMOTE_HOST}" -e " + cd '${REMOTE_DIR}' + rm '${FILENAME}' + bye" > /dev/null 2>&1 - fi + #TODO: Check response code + display_msg "${LOG_TYPE}" info "Deleted file ${FILENAME} from ${REMOTE_HOST}" } -# Check if a remote website exists. The check is done by looking for the following files +# Check if a remote Website exists. The check is done by looking for the following files: # -# If any of these files config.js, configuration.json, remote_configuration.json exist and -# all of these index.php, functions.php exist then assume we have a remote website +# If any of the ${CONFIG_FILES} files exist and +# all of the ${WEBSITE_FILES} exist then assume we have a remote Website. # -# Returns - 0 - Found a rempote website, 1 - No remote website found +# Returns - Nothing, but set the global variable ${WEBSITE_EXISTS}. function check_if_website_exists() { - local RESULT=1 - - local CONFIG_FILES=("config.json" "configuration.json" "remote_configuration.json") - local WEBSITE_FILES=("index.php" "functions.php") - - check_if_files_exist "${REMOTE_URL}" "false" "${CONFIG_FILES[@]}" - local CONFIG_FILE_EXISTS=$? - - if [[ ${CONFIG_FILE_EXISTS} -eq 0 ]]; then - show_debug_message "Found remote website config file" + local CONFIG_FILES=("config.json" "configuration.json" "remote_configuration.json") + local WEBSITE_FILES=("index.php" "functions.php") - check_if_files_exist "${REMOTE_URL}" "and" "${WEBSITE_FILES[@]}" - local WEBSITE_EXISTS_RESULT=$? - if [[ ${WEBSITE_EXISTS_RESULT} -eq 0 ]]; then - display_msg "${LOG_TYPE}" progress "Found remote Allsky website at ${REMOTE_URL}" - RESULT=0 - WEBSITE_EXISTS="true" - fi - fi + if check_if_files_exist "${REMOTE_URL}" "false" "${CONFIG_FILES[@]}" ; then + show_debug_message "Found remote website config file" - return "${RESULT}" + if check_if_files_exist "${REMOTE_URL}" "and" "${WEBSITE_FILES[@]}" ; then + display_msg "${LOG_TYPE}" progress "Found remote Allsky Website at ${REMOTE_URL}" + WEBSITE_EXISTS="true" + return + fi + fi + WEBSITE_EXISTS="false" } -# Uploads the webits code. The code is copied from ~/allsky/html/allsky and removes any old -# Allsky files that will no longer be needed +# Uploads the Website code. The code is copied from ${ALLSKY_WEBSITE} and removes any old +# Allsky files that will no longer be needed. function upload_remote_website() { - if [[ ${SKIP_UPLOAD} == "false" ]]; then - local CONTINUE=0 - local EXTRA_TEXT="" - local EXCLUDE_FOLDERS="" - - if [[ ${REMOTE_PORT} -ne "" ]]; then - REMOTE_PORT="-p ${REMOTE_PORT}" - fi - - if [[ ${AUTO_CONFIRM} == "false" ]]; then - display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nTo continue the Allsky website must be uploaded. This will overwrite ALL website files on the remote server and REMOVE any old Allsky files. \n\nAre you sure you wish to continue" - CONTINUE=$? - EXTRA_TEXT=", user agreed to upload and remove all old Allsky files" - else - show_debug_message "Ignored confirm website upload as auto confirm option specified" - EXTRA_TEXT=", auto confirm option specified" - fi - - if [[ ${CONTINUE} -eq 0 ]]; then - - local MESSAGE="Starting Upload of the remote website" - - if [[ ${WEBSITE_EXISTS} == "true" ]]; then - EXCLUDE_FOLDERS="--exclude keograms --exclude startrails --exclude videos" - MESSAGE+=", excluding videos, startrails and keograms as the website exists" - fi - - display_msg "${LOG_TYPE}" progress "${MESSAGE}${EXTRA_TEXT}" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\n${MESSAGE}\n\nPlease wait this process could take several minutes" - - # Save the current stdout and stderr - exec 3>&1 4>&2 - # Redirect both stdout and stderr to the log file, appending so we capture commands and files that are uploaded - exec >> "$DISPLAY_MSG_LOG" 2>&1 - - lftp -u "${REMOTE_USER}","${REMOTE_PASSWORD}" "${REMOTE_PORT}" "${REMOTE_PROTOCOL}://${REMOTE_HOST}" -e " - lcd ${ALLSKY_WEBSITE} - cd ${REMOTE_DIR} - set dns:fatal-timeout 10 - set net:max-retries 2 - set net:timeout 10 - mirror --reverse --verbose --overwrite --ignore-time --transfer-all ${EXCLUDE_FOLDERS} - quit" - - # Remove any old core files no longer required - for FILE_TO_DELETE in "${OLD_FILES_TO_REMOVE[@]}"; do - remove_remote_file "${FILE_TO_DELETE}" "${REMOTE_URL}" - done - - # Restore stdout and stderr to the terminal - exec 1>&3 2>&4 - display_msg "${LOG_TYPE}" progress "Website upload complete" - else - display_aborted "at the website upload" - fi - - else - display_msg "${LOG_TYPE}" info "Skipping upload as --skipupload provided on command line\n" - fi + if [[ ${SKIP_UPLOAD} == "true" ]]; then + display_msg "${LOG_TYPE}" info "Skipping upload as --skipupload provided on command line\n" + fi + + local EXTRA_TEXT="" + local EXCLUDE_FOLDERS="" + + if [[ -n ${REMOTE_PORT} ]]; then + REMOTE_PORT="-p ${REMOTE_PORT}" + fi + + if [[ ${AUTO_CONFIRM} == "false" ]]; then + MSG="\nTo continue the Allsky Website must be uploaded." + MSG+=" This will overwrite ALL remote Website source files and REMOVE any old Allsky files." + MSG+="\n\nAre you sure you wish to continue? " + if ! display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" ; then + display_aborted "at the Website upload" "false" + fi + EXTRA_TEXT=", user agreed to upload and remove all old Allsky files" + else + show_debug_message "Ignored confirm Website upload as auto confirm option specified" + EXTRA_TEXT=", auto confirm option specified" + fi + + local MSG="Starting upload to the remote Website" + if [[ ${WEBSITE_EXISTS} == "true" ]]; then + EXCLUDE_FOLDERS="--exclude keograms --exclude startrails --exclude videos" + MSG+=", excluding videos, startrails, and keograms" + fi + display_msg "${LOG_TYPE}" progress "${MSG}${EXTRA_TEXT}." + + MSG="\n${MESSAGE}\n\nPlease wait as this process could take several minutes..." + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" + + { +# TODO: upload.sh should have a "--mirror directory" option. + lftp -u "${REMOTE_USER},${REMOTE_PASSWORD}" "${REMOTE_PORT}" "${REMOTE_PROTOCOL}://${REMOTE_HOST}" -e " + lcd '${ALLSKY_WEBSITE}' + cd '${REMOTE_DIR}' + set dns:fatal-timeout 10 + set net:max-retries 2 + set net:timeout 10 + mirror --reverse --verbose --overwrite --ignore-time --transfer-all ${EXCLUDE_FOLDERS} + quit" + + # Remove any old core files no longer required + for FILE_TO_DELETE in "${OLD_FILES_TO_REMOVE[@]}"; do + remove_remote_file "${FILE_TO_DELETE}" "${REMOTE_URL}" + done + } >> "$DISPLAY_MSG_LOG" 2>&1 + + display_msg "${LOG_TYPE}" progress "Website upload complete" } -# Uploads the configuration file for the remote website. +# Uploads the configuration file for the remote Website. function upload_config_file() { - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nUploading remote Allsky configuration file" - display_msg "${LOG_TYPE}" progress "Starting website configuration file upload" - REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" - - RESULT="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_DIR}" "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" )" - if [[ ! ${RESULT} ]]; then - show_debug_message "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} uploaded to ${REMOTE_DIR}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}" - display_msg "${LOG_TYPE}" progress "Completed website configuration file upload" - else - display_aborted "at the configuration file upload" "true" - fi + local MSG="\nUploading remote Allsky configuration file" + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" + display_msg "${LOG_TYPE}" progress "Starting Website configuration file upload" + local REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" + + local RESULT="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_DIR}" "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" )" +# TODO: Is this checking the return code from upload.sh? + if [[ ! ${RESULT} ]]; then + show_debug_message "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} uploaded to ${REMOTE_DIR}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}" + display_msg "${LOG_TYPE}" progress "Completed Website configuration file upload" + else + display_aborted "at the configuration file upload" "true" + fi } -# Displays the scrips help +# Displays the script's help. usage_and_exit() { local RET C MSG @@ -669,22 +643,22 @@ usage_and_exit() echo echo "'--debug' adds addtional debugging information to the installation log." echo - echo "'--skipupload' Skips uploading of the remote website code. Must only be used if advised by Allsky support." + echo "'--skipupload' Skips uploading of the remote Website code. Must only be used if advised by Allsky support." echo echo "'--auto' Accepts all prompts by default" echo echo "'--text' Text only mode, do not use any dialogs" - echo + echo } >&2 - exit "${RET}" + exit ${RET} } -# Enables the remote website +# Enable the remote Website. function enable_remote_website() { - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nEnabling remote website" - update_json_file ".useremotewebsite" "true" "${SETTINGS_FILE}" - display_msg "${LOG_TYPE}" info "Remote website enabled.\n" + display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nEnabling remote Website" + update_json_file ".useremotewebsite" "true" "${SETTINGS_FILE}" + display_msg "${LOG_TYPE}" info "Remote Website enabled.\n" } ############################################## main body @@ -697,13 +671,13 @@ DEBUG="false" while [[ $# -gt 0 ]]; do ARG="${1}" - case "${ARG}" in + case "${ARG,,}" in --help) HELP="true" ;; - --debug) - DEBUG="true" - ;; + --debug) + DEBUG="true" + ;; --skipupload) SKIP_UPLOAD="true" ;; @@ -712,8 +686,8 @@ while [[ $# -gt 0 ]]; do ;; --text) TEXT_ONLY="true" - LOG_TYPE="--log" - ;; + LOG_TYPE="--log" + ;; *) display_msg --log error "Unknown argument: '${ARG}'." OK="false" @@ -726,10 +700,11 @@ done [[ ${OK} == "false" ]] && usage_and_exit 1 display_msg "${LOG_TYPE}" info "STARTING INSTALLATON AT $( date ).\n" + pre_install_checks display_welcome create_website_config upload_remote_website upload_config_file enable_remote_website -display_complete \ No newline at end of file +display_complete From 90fbe5adb70ba91753519f56db04a867fe474893 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sat, 19 Oct 2024 18:24:40 -0600 Subject: [PATCH 04/17] Update remote_website_install.sh: shellcheck fix --- remote_website_install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index e35e17eeb..117824dab 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -361,7 +361,7 @@ function display_aborted() local ERROR_MSG="\nThe installation of the remote Website has been aborted ${EXTRA_TEXT}." if [[ ${SHOW_LOG} == "true" ]]; then - MSG="\n\nWould you like to view the installation log?" ; then + MSG="\n\nWould you like to view the installation log?" if display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${ERROR_MSG}\n\n${MSG}" ; then display_log_file "${DIALOG_BACK_TITLE}" "${DIALOG_TITLE_LOG}" "${DISPLAY_MSG_LOG}" fi From 7eb1bcd9f5dbfcbc767fac6f0f70890ea8913cee Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sat, 19 Oct 2024 18:38:43 -0600 Subject: [PATCH 05/17] Update remote_website_install.sh: shellcheck fixes --- remote_website_install.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index 117824dab..5151391cb 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -232,7 +232,7 @@ function pre_install_checks() display_msg "${LOG_TYPE}" info "Start pre installation checks." if [[ -f ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then - MSG="Found current configuration file: ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." + MSG="Found current remote configuration file: ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." display_msg "${LOG_TYPE}" progress "${MSG}" HAVE_NEW_CONFIG="true" fi @@ -283,7 +283,7 @@ function pre_install_checks() MSG="Using the -OLD configuration file; placeholders will be updated." display_msg "${LOG_TYPE}" progress "${MSG}" CONFIG_TO_USE="old" - CONFIG_MESSAGE="$( basename '${PRIOR_ALLSKY_DIR}' )" + CONFIG_MESSAGE="$( basename "${PRIOR_ALLSKY_DIR}" )" else if [[ "${WEBSITE_EXISTS}" == "true" ]]; then if [[ "${HAVE_NEW_REMOTE_CONFIG}" == "true" ]]; then @@ -450,10 +450,10 @@ function create_website_config() cp "${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" replace_website_placeholders "remote" MSG="Copying ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from the" - MSG+=" $( basename '${PRIOR_ALLSKY_DIR}' ) directory and updating placeholders." + MSG+=" $( basename "${PRIOR_ALLSKY_DIR}" ) directory and updating placeholders." display_msg "${LOG_TYPE}" info "${MSG}" - elif [[ "${CONFIG_TO_USE}" == "remotenew" ]]; then + elif [[ ${CONFIG_TO_USE} == "remotenew" ]]; then # Use the new remote config file since none were found locally if wget -O "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_URL}/${ALLSKY_WEBSITE_CONFIGURATION_FILE}" ; then replace_website_placeholders "remote" @@ -482,16 +482,16 @@ function check_if_files_exist() for FILE in "$@"; do url="${URL}/${FILE}" - http_status=$(curl -o /dev/null -s -w "%{http_code}" "$url") + HTTP_STATUS="$( curl -o /dev/null --silent --write-out "%{http_code}" "$url" )" - if [ ${http_status} -eq 200 ]; then - show_debug_message "File ${FILE} ${url} exists on the remote server" + local PRE_MSG="File ${FILE} ${url}" + if [ ${HTTP_STATUS} == "200" ]; then + show_debug_message "${PRE_MSG} exists on the remote server" RESULT=0 else - show_debug_message "File ${FILE} ${url} doesnt exists on the remote server" + show_debug_message "${PRE_MSG} does not exists on the remote server" if [[ ${AND} == "true" ]]; then - RESULT=1 - break + return 1 fi fi done @@ -650,7 +650,7 @@ usage_and_exit() echo "'--text' Text only mode, do not use any dialogs" echo } >&2 - exit ${RET} + exit "${RET}" } # Enable the remote Website. From f3552034aefc9bbda65ad1b91aa4711b7e81e999 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sat, 19 Oct 2024 20:06:55 -0600 Subject: [PATCH 06/17] Update variables.sh: replace spaces with tabs --- variables.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variables.sh b/variables.sh index 6e40739e8..36aa96dc3 100644 --- a/variables.sh +++ b/variables.sh @@ -17,7 +17,7 @@ if [[ -z "${ALLSKY_VARIABLE_SET}" ]]; then # The "w" colors are for when output may go to a web page. if tty --silent ; then ON_TTY="true" - DIALOG_RED="\Z1"; DIALOG_NORMAL="\Zn" + DIALOG_RED="\Z1"; DIALOG_NORMAL="\Zn" GREEN="\033[0;32m"; wOK="${GREEN}" YELLOW="\033[0;33m"; wWARNING="${YELLOW}" RED="\033[0;31m"; wERROR="${RED}" @@ -28,7 +28,7 @@ if [[ -z "${ALLSKY_VARIABLE_SET}" ]]; then wBR="\n" else ON_TTY="false" - DIALOG_RED=""; DIALOG_NORMAL="" + DIALOG_RED=""; DIALOG_NORMAL="" GREEN=""; wOK="" YELLOW=""; wWARNING="" RED=""; wERROR="" From e8c2a39d3041372a579e629cf27129e015441825 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sat, 19 Oct 2024 20:12:38 -0600 Subject: [PATCH 07/17] Update remote_website_install.sh: created display_box() display_box() displays yesno, info, or msg boxes, depending on the first argument. This eliminates duplicate code. Replaced all ${LOG_ONLY} with either --log or --logonly --- remote_website_install.sh | 280 +++++++++++++++++--------------------- 1 file changed, 127 insertions(+), 153 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index 5151391cb..9183031ff 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -31,9 +31,6 @@ CONFIG_MESSAGE="" DIALOG_WIDTH=70 DIALOG_HEIGHT=25 -# Logging options -LOG_TYPE="--logonly" - # Remote connectivity variables REMOTE_URL="$( settings ".remotewebsiteurl" "${SETTINGS_FILE}" )" REMOTE_USER="$( settings ".REMOTEWEBSITE_USER" "${ALLSKY_ENV}" )" @@ -61,7 +58,7 @@ OLD_FILES_TO_REMOVE=("config.js" "configuration.json" "virtualsky.json") function enter_yes_no() { local TEXT="${1}" - local RESULT + local RESULT=1 local ANSWER while true; do @@ -69,14 +66,12 @@ function enter_yes_no() read -r -p "Do you want to continue? (y/n): " ANSWER ANSWER="${ANSWER,,}" # convert to lowercase - if [[ "${ANSWER}" == "y" || "${ANSWER}" == "yes" ]]; then - RESULT=0 - break - elif [[ "${ANSWER}" == "n" || "${ANSWER}" == "no" ]]; then - RESULT=1 - break + if [[ ${ANSWER} == "y" || ${ANSWER} == "yes" ]]; then + return 0 + elif [[ ${ANSWER} == "n" || ${ANSWER} == "no" ]]; then + return 1 else - echo "Invalid response. Please enter y/yes or n/no." + echo -e "\nInvalid response. Please enter y/yes or n/no." fi done @@ -92,6 +87,9 @@ function press_any_key() } # Adds the remote Website URL to the dialog text. + +# TODO FIX: Eric thinks seeing the remote URL confusing. + function add_dialog_heading() { local DIALOG_TEXT="${1}" @@ -101,87 +99,58 @@ function add_dialog_heading() fi local PADDING=$(( ((DIALOG_WIDTH-6) - ${#REMOTE_URL}) / 2 )) - local URL=$(printf "%${PADDING}s%s" "" "$REMOTE_URL") + local URL=$(printf "%${PADDING}s%s" "" "${REMOTE_URL}") echo -e "\n${DIALOG_RED}${URL}${DIALOG_NORMAL}\n${DIALOG_TEXT}" } -# Displays an info Dialog, or in text mode just displays the text. -# ${1} - The backtitle for the dialog -# ${2} - The title for the dialog -# ${3} - The text to disply in the dialog +# Displays the specified type of Dialog, or in text mode just displays the text. +# ${1} - The box type +# ${2} - The backtitle for the dialog +# ${3} - The title for the dialog +# ${4} - The text to disply in the dialog +# ${5} - Optional additional arguments to dialog # -# Returns - Nothing -function display_info_dialog() +# Return - 1 if the user selected "No"; 0 otherwise +function display_box() { - local DIALOG_TEXT="${3}" + local DIALOG_TYPE="${1}" + local DIALOG_TEXT="${4}" DIALOG_TEXT="$( add_dialog_heading "${DIALOG_TEXT}" )" if [[ ${TEXT_ONLY} == "true" ]]; then - echo -e "${DIALOG_TEXT}" - return + local RET=0 + if [[ ${DIALOG_TYPE} == "--msgbox" ]]; then + press_any_key "${DIALOG_TEXT}" + elif [[ ${DIALOG_TYPE} == "--yesno" ]]; then + enter_yes_no "${DIALOG_TEXT}" + RET=$? + else + echo -e "${DIALOG_TEXT}" + fi + return ${RET} fi - local BACK_TITLE="${1}" - local DIALOG_TITLE="${2}" + local BACK_TITLE="${2}" + local DIALOG_TITLE="${3}" + local MORE_ARGS="${5}" dialog \ --colors \ --backtitle "${BACK_TITLE}" \ --title "${DIALOG_TITLE}" \ - --infobox "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} + "${DIALOG_TYPE}" ${MORE_ARGS} "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} + return $? } -# Displays an prompt Dialog, or in text mode just displays the text -# and prompts the user to enter y or n. -# ${1} - The backtitle for the dialog -# ${2} - The title for the dialog -# ${3} - The text to disply in the dialog -# -# Returns - The exiit code (0 - Yes, >0 No) -function display_prompt_dialog() +function display_info_box() { - local DIALOG_TEXT="${3}" - - DIALOG_TEXT="$( add_dialog_heading "${DIALOG_TEXT}" )" - if [[ ${TEXT_ONLY} == "text" ]]; then - enter_yes_no "${DIALOG_TEXT}" - return - fi - - local BACK_TITLE="${1}" - local DIALOG_TITLE="${2}" - dialog \ - --colors\ - --backtitle "${BACK_TITLE}" \ - --title "${DIALOG_TITLE}" \ - --yesno "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} - return $? + display_box "--infobox" "${1}" "${2}" "${3}" } -# Displays an message Dialog, or in text mode just displays the text -# and prompts the user to press any key. -# ${1} - The backtitle for the dialog -# ${2} - The title for the dialog -# ${3} - The text to disply in the dialog -# -# Returns - Nothing -function display_message_box() +function display_prompt_dialog() { - local DIALOG_TEXT="${3}" - - DIALOG_TEXT="$( add_dialog_heading "${DIALOG_TEXT}" )" - if [[ ${TEXT_ONLY} == "true" ]]; then - press_any_key "${DIALOG_TEXT}" - return - fi - - local BACK_TITLE="${1}" - local DIALOG_TITLE="${2}" - dialog \ - --colors \ - --backtitle "${BACK_TITLE}" \ - --title "${DIALOG_TITLE}" \ - --msgbox "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} + display_box "--yesno" "${1}" "${2}" "${3}" + # Returns - The exit code (0 - Yes, >0 No) } # Displays a file Dialog, or in text mode just displays the file. @@ -228,92 +197,93 @@ function pre_install_checks() DIALOG_TEXT+="\n\nPlease wait as this can take a few minutes to complete.\n\n" DIALOG_TEXT+="\n1 - Checking for local files" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - display_msg "${LOG_TYPE}" info "Start pre installation checks." + display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + display_msg --logonly progress "Start pre installation checks." if [[ -f ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then MSG="Found current remote configuration file: ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." - display_msg "${LOG_TYPE}" progress "${MSG}" + display_msg --logonly info "${MSG}" HAVE_NEW_CONFIG="true" fi if [[ -f ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then MSG="Found -OLD configuration file: ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}." - display_msg "${LOG_TYPE}" progress "${MSG}" + display_msg --logonly info "${MSG}" HAVE_OLD_CONFIG="true" fi DIALOG_TEXT+="\n2 - Checking if remote Website exists" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" check_if_website_exists # Sets ${WEBSITE_EXISTS} if [[ ${WEBSITE_EXISTS} == "true" ]]; then - DIALOG_TEXT+="\n3 - Checking for remote Website configuration file" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" local NEW_CONFIG_FILES=("configuration.json") if check_if_files_exist "${REMOTE_URL}" "false" "${NEW_CONFIG_FILES[@]}" ; then HAVE_NEW_REMOTE_CONFIG="true" - MSG="Found current configuration on the remote server." - display_msg "${LOG_TYPE}" progress "${MSG}" + MSG="Found current configuration file on the remote server." + display_msg --logonly info "${MSG}" fi DIALOG_TEXT+="\n4 - Checking for old remote Website configuration file" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" local REALLY_OLD_CONFIG_FILES=("config.js") if check_if_files_exist "${REMOTE_URL}" "false" "${REALLY_OLD_CONFIG_FILES[@]}" ; then HAVE_REALLY_OLD_REMOTE_CONFIG="true" MSG="Found really old format Website configuration file on the remote Website." - display_msg "${LOG_TYPE}" progress "${MSG}" + display_msg --logonly info "${MSG}" fi fi - if [[ "${HAVE_NEW_CONFIG}" == "true" ]]; then + if [[ ${HAVE_NEW_CONFIG} == "true" ]]; then MSG="Using the local remote configuration file" - if [[ "${HAVE_NEW_REMOTE_CONFIG}" == "true" ]]; then + if [[ ${HAVE_NEW_REMOTE_CONFIG} == "true" ]]; then MSG+=", a remote configuration file was found but using the local version instead" fi - display_msg "${LOG_TYPE}" progress "${MSG}." + display_msg --logonly info "${MSG}." CONFIG_TO_USE="current" - CONFIG_MESSAGE="Current" - else - if [[ "${HAVE_OLD_CONFIG}" == "true" ]]; then - MSG="Using the -OLD configuration file; placeholders will be updated." - display_msg "${LOG_TYPE}" progress "${MSG}" - CONFIG_TO_USE="old" - CONFIG_MESSAGE="$( basename "${PRIOR_ALLSKY_DIR}" )" + CONFIG_MESSAGE="the current remote" + + elif [[ ${HAVE_OLD_CONFIG} == "true" ]]; then + MSG="Using the -OLD configuration file; placeholders will be updated." + display_msg --logonly info "${MSG}" + CONFIG_TO_USE="old" + CONFIG_MESSAGE="the $( basename "${PRIOR_ALLSKY_DIR}" )" + + elif [[ ${WEBSITE_EXISTS} == "true" ]]; then + if [[ ${HAVE_NEW_REMOTE_CONFIG} == "true" ]]; then + MSG="Using new format Website configuration file on the remote Website;" + MSG+=" it will be downloaded and saved locally." + display_msg --logonly info "${MSG}" + CONFIG_TO_USE="remotenew" + CONFIG_MESSAGE="the remote Website's" else - if [[ "${WEBSITE_EXISTS}" == "true" ]]; then - if [[ "${HAVE_NEW_REMOTE_CONFIG}" == "true" ]]; then - MSG="Using new format Website configuration file on the remote Website;" - MSG+=" it will be downloaded and saved locally." - display_msg "${LOG_TYPE}" progress "${MSG}" - CONFIG_TO_USE="remotenew" - CONFIG_MESSAGE="Remote new" - else - if [[ "${HAVE_REALLY_OLD_REMOTE_CONFIG}" == "true" ]]; then - MSG="Old config.js found." - MSG+=" Creating a new configuration file that the user must manually update." - display_msg "${LOG_TYPE}" progress "${MSG}" - CONFIG_TO_USE="remotereallyold" - CONFIG_MESSAGE=" repos config i.e. a new config" - fi - fi + if [[ ${HAVE_REALLY_OLD_REMOTE_CONFIG} == "true" ]]; then + MSG="Old config.js found." + MSG+=" Creating a new configuration file that the user must manually update." + display_msg --logonly info "${MSG}" + CONFIG_TO_USE="remotereallyold" + CONFIG_MESSAGE="a new" fi fi fi - if [[ "${CONFIG_TO_USE}" == "" ]]; then + if [[ -z ${CONFIG_TO_USE} ]]; then MSG="Unable to determine the configuration file to use. A new one will be created." - display_msg "${LOG_TYPE}" progress "${MSG}" + display_msg --logonly info "${MSG}" CONFIG_TO_USE="new" fi check_connectivity - display_msg "${LOG_TYPE}" info "Completed pre installation checks." + display_msg --logonly info "Completed pre installation checks." + + # Prompt the user to continue. This is so they can see the above messages. + DIALOG_TEXT+="\n\n\nPress OK to continue" + display_box "--msgbox" "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" } # Displays the welcome dialog indicating what steps will be taken @@ -325,16 +295,16 @@ function display_welcome() fi if [[ ${AUTO_CONFIRM} == "false" ]]; then - display_msg "${LOG_TYPE}" progress "Displayed the welcome dialog" + display_msg --logonly info "Displaying the welcome dialog" local DIALOG_MSG="\n\ - Welcome the the Allsky Remote Website Installer!\n\n\ + Welcome to the Allsky Remote Website Installer!\n\n\ This script will perform the following tasks:\n\n\ \ 1) Check the remote Website connectivity - PASSED\n\ - 2) Use the ${CONFIG_MESSAGE} configuration file\n\ + 2) Use ${CONFIG_MESSAGE} configuration file\n\ 3) Upload the remote Website code\n\ - 4) Upload the remote Website configuration file\n - 5) Enable the remote Website in the WebUI settings\n\n\ + 4) Upload the remote Website configuration file\n\ + 5) Enable the remote Website\n\n\ \ ${DIALOG_RED}WARNING:${DIALOG_NORMAL}\n\ - This will overwrite files on the remote server, and\n\ @@ -345,7 +315,7 @@ function display_welcome() display_aborted "at the Welcome dialog" "false" fi else - display_msg "${LOG_TYPE}" progress "Ignored welcome prompt as auto confirm option specified." + display_msg --logonly info "Ignored welcome prompt as auto confirm option specified." fi } @@ -357,16 +327,19 @@ function display_aborted() local EXTRA_TEXT="${1}" local SHOW_LOG="${2}" - display_msg "${LOG_TYPE}" warning "USER ABORTED INSTALLATION ${EXTRA_TEXT}." + display_msg --logonly info "USER ABORTED INSTALLATION ${EXTRA_TEXT}." local ERROR_MSG="\nThe installation of the remote Website has been aborted ${EXTRA_TEXT}." if [[ ${SHOW_LOG} == "true" ]]; then - MSG="\n\nWould you like to view the installation log?" - if display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${ERROR_MSG}\n\n${MSG}" ; then +# TODO: Instead of displaying the log file, which is very detailed, +# how about if we tell the user to attach the log file to any GitHub message they post? + MSG="${ERROR_MSG}\n\nWould you like to view the installation log?" + if display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" ; then display_log_file "${DIALOG_BACK_TITLE}" "${DIALOG_TITLE_LOG}" "${DISPLAY_MSG_LOG}" fi else - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${ERROR_MSG}" + display_box "--msgbox" "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${ERROR_MSG}" "--clear" + display_msg info "${ERROR_MSG}" fi exit 1 @@ -384,12 +357,12 @@ function display_complete() EXTRA_TEXT+=" Please use the WebUI 'Editor' page to replace any '${NEED_TO_UPDATE}' with the correct values." fi - display_msg "${LOG_TYPE}" info "INSTALLATON COMPLETED.\n" + display_msg --logonly info "INSTALLATON COMPLETED.\n" MSG="\n\ The installation of the remote Website has been completed.\n\n\ Please use the 'Editor' page in the Allsky WebUI to manage any changes to the Website.${EXTRA_TEXT}" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "%{MSG}" + display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "%{MSG}" } # Check connectivity to the remote Website. @@ -397,21 +370,22 @@ function check_connectivity() { local TEST_FILE="${ME}.txt" - display_msg "${LOG_TYPE}" info "Checking remote Website connectivity." - if "${ALLSKY_SCRIPTS}/testUpload.sh" --website --silent --file "${TEST_FILE}" >> "${DISPLAY_MSG_LOG}" 2>&1 ; then - local ERROR_MSG="\nERROR: The remote Website connectivity check failed. Result code ${RESULT}" + display_msg --logonly info "Checking remote Website connectivity." + if ERR="$( "${ALLSKY_SCRIPTS}/testUpload.sh" --website --silent --file "${TEST_FILE}" 2>&1 )" ; then + local MSG="The remote Website connectivity test succeeded." + display_msg --logonly info "${MSG}" + remove_remote_file "${TEST_FILE}" + show_debug_message "${TEST_FILE} deleted from the remote server" + else + local ERROR_MSG="\nERROR: The remote Website connectivity check failed." ERROR_MSG+="\n\nPlease check the 'Websites and Remote Server Settings' in the WebUI.\n\n\ - HOST: ${REMOTE_HOST} PROTOCOL: ${REMOTE_PROTOCOL}\n\ + HOST: ${REMOTE_HOST}\n\ + PROTOCOL: ${REMOTE_PROTOCOL}\n\ USER: ${REMOTE_USER}\n\ - PASSWORD: ${REMOTE_PASSWORD}\n\ - FOLDER: ${REMOTE_DIR}" + REMOTE FOLDER: ${REMOTE_DIR}\n\n\ + ${ERR}" display_aborted "${ERROR_MSG}" "true" - else - local MSG="The remote Website connectivity test succeeded." - display_msg "${LOG_TYPE}" info "${MSG}" - remove_remote_file "${TEST_FILE}" - show_debug_message "${TEST_FILE} deleted from the remote server" fi } @@ -419,7 +393,7 @@ function check_connectivity() function show_debug_message() { if [[ ${DEBUG} == "true" ]]; then - display_msg "${LOG_TYPE}" debug "${1}" + display_msg --logonly debug "${1}" fi } @@ -428,8 +402,8 @@ function show_debug_message() function create_website_config() { local MSG="\nCreating configuration file from ${CONFIG_MESSAGE}" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" - display_msg "${LOG_TYPE}" info "Creating remote Website configuration file" + display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" + display_msg --logonly info "Creating remote Website configuration file" if [[ ${CONFIG_TO_USE} == "new" || ${CONFIG_TO_USE} == "remotereallyold" ]]; then # We need a new config file so copy it from the repo and replace as many @@ -438,12 +412,12 @@ function create_website_config() cp "${REPO_WEBCONFIG_FILE}" "${DEST_FILE}" replace_website_placeholders "remote" MSG="Created a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from repo and updated placeholders." - display_msg "${LOG_TYPE}" info "${MSG}" + display_msg --logonly info "${MSG}" elif [[ ${CONFIG_TO_USE} == "current" ]]; then # Use the current config file so do nothing MSG="Using existing ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} so nothing created." - display_msg "${LOG_TYPE}" info "${MSG}" + display_msg --logonly info "${MSG}" elif [[ ${CONFIG_TO_USE} == "old" ]]; then # Use the config file from allsky-OLD, copy it and replace as many of the placeholders as we can @@ -451,7 +425,7 @@ function create_website_config() replace_website_placeholders "remote" MSG="Copying ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from the" MSG+=" $( basename "${PRIOR_ALLSKY_DIR}" ) directory and updating placeholders." - display_msg "${LOG_TYPE}" info "${MSG}" + display_msg --logonly info "${MSG}" elif [[ ${CONFIG_TO_USE} == "remotenew" ]]; then # Use the new remote config file since none were found locally @@ -459,7 +433,7 @@ function create_website_config() replace_website_placeholders "remote" MSG="Downloading ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}," MSG+=" and creating a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." - display_msg "${LOG_TYPE}" info "${MSG}" + display_msg --logonly info "${MSG}" else MSG="Failed to download ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}" display_aborted "${MSG}" "true" @@ -522,7 +496,7 @@ function remove_remote_file() #TODO: Check response code - display_msg "${LOG_TYPE}" info "Deleted file ${FILENAME} from ${REMOTE_HOST}" + display_msg --logonly info "Deleted file ${FILENAME} from ${REMOTE_HOST}" } # Check if a remote Website exists. The check is done by looking for the following files: @@ -540,7 +514,7 @@ function check_if_website_exists() show_debug_message "Found remote website config file" if check_if_files_exist "${REMOTE_URL}" "and" "${WEBSITE_FILES[@]}" ; then - display_msg "${LOG_TYPE}" progress "Found remote Allsky Website at ${REMOTE_URL}" + display_msg --log progress "Found remote Allsky Website at ${REMOTE_URL}" WEBSITE_EXISTS="true" return fi @@ -553,7 +527,7 @@ function check_if_website_exists() function upload_remote_website() { if [[ ${SKIP_UPLOAD} == "true" ]]; then - display_msg "${LOG_TYPE}" info "Skipping upload as --skipupload provided on command line\n" + display_msg --logonly info "Skipping upload as --skipupload provided on command line\n" fi local EXTRA_TEXT="" @@ -581,10 +555,10 @@ function upload_remote_website() EXCLUDE_FOLDERS="--exclude keograms --exclude startrails --exclude videos" MSG+=", excluding videos, startrails, and keograms" fi - display_msg "${LOG_TYPE}" progress "${MSG}${EXTRA_TEXT}." + display_msg --log progress "${MSG}${EXTRA_TEXT}." MSG="\n${MESSAGE}\n\nPlease wait as this process could take several minutes..." - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" + display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" { # TODO: upload.sh should have a "--mirror directory" option. @@ -603,22 +577,22 @@ function upload_remote_website() done } >> "$DISPLAY_MSG_LOG" 2>&1 - display_msg "${LOG_TYPE}" progress "Website upload complete" + display_msg --logonly info "Website upload complete" } # Uploads the configuration file for the remote Website. function upload_config_file() { local MSG="\nUploading remote Allsky configuration file" - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" - display_msg "${LOG_TYPE}" progress "Starting Website configuration file upload" + display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" + display_msg --log progress "Starting Website configuration file upload" local REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" local RESULT="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_DIR}" "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" )" # TODO: Is this checking the return code from upload.sh? if [[ ! ${RESULT} ]]; then show_debug_message "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} uploaded to ${REMOTE_DIR}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}" - display_msg "${LOG_TYPE}" progress "Completed Website configuration file upload" + display_msg --logonly progress "Completed Website configuration file upload" else display_aborted "at the configuration file upload" "true" fi @@ -656,9 +630,9 @@ usage_and_exit() # Enable the remote Website. function enable_remote_website() { - display_info_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nEnabling remote Website" + display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nEnabling remote Website" update_json_file ".useremotewebsite" "true" "${SETTINGS_FILE}" - display_msg "${LOG_TYPE}" info "Remote Website enabled.\n" + display_msg --log info "Remote Website enabled.\n" } ############################################## main body @@ -699,7 +673,7 @@ done [[ ${HELP} == "true" ]] && usage_and_exit 0 [[ ${OK} == "false" ]] && usage_and_exit 1 -display_msg "${LOG_TYPE}" info "STARTING INSTALLATON AT $( date ).\n" +display_msg --logonly info "STARTING INSTALLATON AT $( date ).\n" pre_install_checks display_welcome From 5f4897b6323f5057a9cb4e7c75d73ff62f2f43a6 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sat, 19 Oct 2024 20:15:39 -0600 Subject: [PATCH 08/17] Update remote_website_install.sh: shellcheck fix --- remote_website_install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index 9183031ff..a7dfd032d 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -134,6 +134,7 @@ function display_box() local BACK_TITLE="${2}" local DIALOG_TITLE="${3}" local MORE_ARGS="${5}" + # shellcheck disable=SC2086 dialog \ --colors \ --backtitle "${BACK_TITLE}" \ @@ -459,7 +460,7 @@ function check_if_files_exist() HTTP_STATUS="$( curl -o /dev/null --silent --write-out "%{http_code}" "$url" )" local PRE_MSG="File ${FILE} ${url}" - if [ ${HTTP_STATUS} == "200" ]; then + if [[ ${HTTP_STATUS} == "200" ]] ; then show_debug_message "${PRE_MSG} exists on the remote server" RESULT=0 else From 55a4a75705609333a3845f03e5ff504bc7dd4c1e Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sat, 19 Oct 2024 20:26:07 -0600 Subject: [PATCH 09/17] Update variables.sh: Add bold to 'dialog' command --- variables.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/variables.sh b/variables.sh index 36aa96dc3..2fa716b77 100644 --- a/variables.sh +++ b/variables.sh @@ -18,6 +18,7 @@ if [[ -z "${ALLSKY_VARIABLE_SET}" ]]; then if tty --silent ; then ON_TTY="true" DIALOG_RED="\Z1"; DIALOG_NORMAL="\Zn" + DIALOG_BOLD="\Zb" GREEN="\033[0;32m"; wOK="${GREEN}" YELLOW="\033[0;33m"; wWARNING="${YELLOW}" RED="\033[0;31m"; wERROR="${RED}" @@ -29,6 +30,7 @@ if [[ -z "${ALLSKY_VARIABLE_SET}" ]]; then else ON_TTY="false" DIALOG_RED=""; DIALOG_NORMAL="" + DIALOG_BOLD="" GREEN=""; wOK="" YELLOW=""; wWARNING="" RED=""; wERROR="" From 9656ed24291f85a35cc8233f6a499c83b887b1ad Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sat, 19 Oct 2024 20:27:18 -0600 Subject: [PATCH 10/17] Update remote_website_install.sh: Use bold for dialog questions --- remote_website_install.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index a7dfd032d..04289c01d 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -139,7 +139,8 @@ function display_box() --colors \ --backtitle "${BACK_TITLE}" \ --title "${DIALOG_TITLE}" \ - "${DIALOG_TYPE}" ${MORE_ARGS} "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} + ${MORE_ARGS} \ + "${DIALOG_TYPE}" "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} return $? } @@ -283,7 +284,7 @@ function pre_install_checks() display_msg --logonly info "Completed pre installation checks." # Prompt the user to continue. This is so they can see the above messages. - DIALOG_TEXT+="\n\n\nPress OK to continue" + DIALOG_TEXT+="\n\n\n${DIALOG_BOLD}Press OK to continue${DIALOG_NORMAL}" display_box "--msgbox" "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" } @@ -309,8 +310,8 @@ function display_welcome() \ ${DIALOG_RED}WARNING:${DIALOG_NORMAL}\n\ - This will overwrite files on the remote server, and\n\ - - REMOVE any old Allsky files on the remote server.\n\n\ - Are you sure you wish to continue?" + - REMOVE any old Allsky files on the remote server.\n\n\n\ + ${DIALOG_BOLD}Are you sure you wish to continue?${DIALOG_NORMAL}" if ! display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_WELCOME_TITLE}" "${DIALOG_MSG}" ; then display_aborted "at the Welcome dialog" "false" @@ -340,6 +341,7 @@ function display_aborted() fi else display_box "--msgbox" "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${ERROR_MSG}" "--clear" + clear # to get rid of background color for 'dialog' command display_msg info "${ERROR_MSG}" fi @@ -363,7 +365,7 @@ function display_complete() MSG="\n\ The installation of the remote Website has been completed.\n\n\ Please use the 'Editor' page in the Allsky WebUI to manage any changes to the Website.${EXTRA_TEXT}" - display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "%{MSG}" + display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" } # Check connectivity to the remote Website. From 38d1f76621b2a1b610017bdb7fcd66e6fa249052 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sat, 19 Oct 2024 20:30:58 -0600 Subject: [PATCH 11/17] Update variables.sh: use underline instead of bold Depending on user options, bold may turn characters lighter, not darker. --- variables.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variables.sh b/variables.sh index 2fa716b77..63d0fbde5 100644 --- a/variables.sh +++ b/variables.sh @@ -18,7 +18,7 @@ if [[ -z "${ALLSKY_VARIABLE_SET}" ]]; then if tty --silent ; then ON_TTY="true" DIALOG_RED="\Z1"; DIALOG_NORMAL="\Zn" - DIALOG_BOLD="\Zb" + DIALOG_UNDERLINE="\Zu" GREEN="\033[0;32m"; wOK="${GREEN}" YELLOW="\033[0;33m"; wWARNING="${YELLOW}" RED="\033[0;31m"; wERROR="${RED}" @@ -30,7 +30,7 @@ if [[ -z "${ALLSKY_VARIABLE_SET}" ]]; then else ON_TTY="false" DIALOG_RED=""; DIALOG_NORMAL="" - DIALOG_BOLD="" + DIALOG_UNDERLINE="" GREEN=""; wOK="" YELLOW=""; wWARNING="" RED=""; wERROR="" From f7fc63862a711095b89c0e5803aa9045b4028722 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sat, 19 Oct 2024 20:31:33 -0600 Subject: [PATCH 12/17] Update remote_website_install.sh: use underline --- remote_website_install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index 04289c01d..4c04fe35e 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -284,7 +284,7 @@ function pre_install_checks() display_msg --logonly info "Completed pre installation checks." # Prompt the user to continue. This is so they can see the above messages. - DIALOG_TEXT+="\n\n\n${DIALOG_BOLD}Press OK to continue${DIALOG_NORMAL}" + DIALOG_TEXT+="\n\n\n${DIALOG_UNDERLINE}Press OK to continue${DIALOG_NORMAL}" display_box "--msgbox" "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" } @@ -311,7 +311,7 @@ function display_welcome() ${DIALOG_RED}WARNING:${DIALOG_NORMAL}\n\ - This will overwrite files on the remote server, and\n\ - REMOVE any old Allsky files on the remote server.\n\n\n\ - ${DIALOG_BOLD}Are you sure you wish to continue?${DIALOG_NORMAL}" + ${DIALOG_UNDERLINE}Are you sure you wish to continue?${DIALOG_NORMAL}" if ! display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_WELCOME_TITLE}" "${DIALOG_MSG}" ; then display_aborted "at the Welcome dialog" "false" From a92e667953aba4c9eb72870c07c35f8c768029d4 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sat, 19 Oct 2024 21:20:52 -0600 Subject: [PATCH 13/17] Update remote_website_install.sh: misc improvements * Add file to OLD_FILES_TO_REMOVE * When aborting, display a text message instead of a dialog box. * Use --head in curl to avoid downloading huge files. * Various wording changes. --- remote_website_install.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index 4c04fe35e..d9ba6f08b 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -49,7 +49,7 @@ DIALOG_INSTALL="Installing Remote Website" DIALOG_TITLE_LOG="Allsky Remote Website Installation Log" # Old Allksy Website files that should be remoevd if they exist -OLD_FILES_TO_REMOVE=("config.js" "configuration.json" "virtualsky.json") +OLD_FILES_TO_REMOVE=("config.js" "configuration.json" "virtualsky.json" "README.md") ############################################## functions @@ -235,7 +235,7 @@ function pre_install_checks() local REALLY_OLD_CONFIG_FILES=("config.js") if check_if_files_exist "${REMOTE_URL}" "false" "${REALLY_OLD_CONFIG_FILES[@]}" ; then HAVE_REALLY_OLD_REMOTE_CONFIG="true" - MSG="Found really old format Website configuration file on the remote Website." + MSG="Found old-format config.js file on the remote Website." display_msg --logonly info "${MSG}" fi fi @@ -335,13 +335,12 @@ function display_aborted() if [[ ${SHOW_LOG} == "true" ]]; then # TODO: Instead of displaying the log file, which is very detailed, # how about if we tell the user to attach the log file to any GitHub message they post? - MSG="${ERROR_MSG}\n\nWould you like to view the installation log?" + MSG="${ERROR_MSG}\n\n${DIALOG_UNDERLINE}Would you like to view the installation log?${DIALOG_NORMAL}" if display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" ; then display_log_file "${DIALOG_BACK_TITLE}" "${DIALOG_TITLE_LOG}" "${DISPLAY_MSG_LOG}" fi else - display_box "--msgbox" "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${ERROR_MSG}" "--clear" - clear # to get rid of background color for 'dialog' command + clear # Gets rid of background color from last 'dialog' command. display_msg info "${ERROR_MSG}" fi @@ -352,19 +351,20 @@ function display_aborted() function display_complete() { local EXTRA_TEXT="" + local E=" Please use the WebUI's 'Editor' page to replace any '${NEED_TO_UPDATE}' with the correct values." if [[ ${CONFIG_TO_USE} == "new" ]]; then - EXTRA_TEXT="\nA new configuration file was created for the Website." - EXTRA_TEXT+=" Please use the WebUI editor and replace any '${NEED_TO_UPDATE}' with the correct values" + EXTRA_TEXT="\nA new configuration file was created for your remote Website." + EXTRA_TEXT+="${E}" elif [[ ${CONFIG_TO_USE} == "remotereallyold" ]]; then - EXTRA_TEXT="\nYou have a very old Allsky Website so a new configuration file was created." - EXTRA_TEXT+=" Please use the WebUI 'Editor' page to replace any '${NEED_TO_UPDATE}' with the correct values." + EXTRA_TEXT="\nYou have a very old remote Allsky Website so a new configuration file was created." + EXTRA_TEXT+="${E}" fi display_msg --logonly info "INSTALLATON COMPLETED.\n" MSG="\n\ - The installation of the remote Website has been completed.\n\n\ - Please use the 'Editor' page in the Allsky WebUI to manage any changes to the Website.${EXTRA_TEXT}" + The installation of the remote Website is complete.\n\n\ + Please use the WebUI's 'Editor' page to manage any changes to your Website.${EXTRA_TEXT}" display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" } @@ -381,7 +381,7 @@ function check_connectivity() show_debug_message "${TEST_FILE} deleted from the remote server" else local ERROR_MSG="\nERROR: The remote Website connectivity check failed." - ERROR_MSG+="\n\nPlease check the 'Websites and Remote Server Settings' in the WebUI.\n\n\ + ERROR_MSG+="\n\nPlease check the 'Websites and Remote Server Settings' section of the WebUI.\n\n\ HOST: ${REMOTE_HOST}\n\ PROTOCOL: ${REMOTE_PROTOCOL}\n\ USER: ${REMOTE_USER}\n\ @@ -459,7 +459,7 @@ function check_if_files_exist() for FILE in "$@"; do url="${URL}/${FILE}" - HTTP_STATUS="$( curl -o /dev/null --silent --write-out "%{http_code}" "$url" )" + HTTP_STATUS="$( curl -o /dev/null --head --silent --write-out "%{http_code}" "$url" )" local PRE_MSG="File ${FILE} ${url}" if [[ ${HTTP_STATUS} == "200" ]] ; then @@ -543,7 +543,7 @@ function upload_remote_website() if [[ ${AUTO_CONFIRM} == "false" ]]; then MSG="\nTo continue the Allsky Website must be uploaded." MSG+=" This will overwrite ALL remote Website source files and REMOVE any old Allsky files." - MSG+="\n\nAre you sure you wish to continue? " + MSG+="\n\n${DIALOG_UNDERLINE}Are you sure you wish to continue?${DIALOG_NORMAL}" if ! display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" ; then display_aborted "at the Website upload" "false" fi From 71a22f88e7aaa2780883c755f42ab424c7384c2f Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sat, 19 Oct 2024 22:08:14 -0600 Subject: [PATCH 14/17] Update remote_website_install.sh: more misc. changes * Remove old "myImages" directory * Add "--user" option to display_aborted() to specify the USER aborted installation, versus an error aborted it. * Upon successful completion, display a text message instead of a 'dialog'. * Remove rundundant prompt for "do you want to continue". * Fix: check return code from upload.sh, not returned string. --- remote_website_install.sh | 74 +++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index d9ba6f08b..7c39016e4 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -49,7 +49,7 @@ DIALOG_INSTALL="Installing Remote Website" DIALOG_TITLE_LOG="Allsky Remote Website Installation Log" # Old Allksy Website files that should be remoevd if they exist -OLD_FILES_TO_REMOVE=("config.js" "configuration.json" "virtualsky.json" "README.md") +OLD_FILES_TO_REMOVE=("config.js" "configuration.json" "virtualsky.json" "README.md" "myImages") ############################################## functions @@ -221,7 +221,6 @@ function pre_install_checks() if [[ ${WEBSITE_EXISTS} == "true" ]]; then DIALOG_TEXT+="\n3 - Checking for remote Website configuration file" display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - local NEW_CONFIG_FILES=("configuration.json") if check_if_files_exist "${REMOTE_URL}" "false" "${NEW_CONFIG_FILES[@]}" ; then HAVE_NEW_REMOTE_CONFIG="true" @@ -229,9 +228,8 @@ function pre_install_checks() display_msg --logonly info "${MSG}" fi - DIALOG_TEXT+="\n4 - Checking for old remote Website configuration file" + DIALOG_TEXT+="\n4 - Checking for old-style remote Website configuration file" display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - local REALLY_OLD_CONFIG_FILES=("config.js") if check_if_files_exist "${REMOTE_URL}" "false" "${REALLY_OLD_CONFIG_FILES[@]}" ; then HAVE_REALLY_OLD_REMOTE_CONFIG="true" @@ -314,7 +312,7 @@ function display_welcome() ${DIALOG_UNDERLINE}Are you sure you wish to continue?${DIALOG_NORMAL}" if ! display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_WELCOME_TITLE}" "${DIALOG_MSG}" ; then - display_aborted "at the Welcome dialog" "false" + display_aborted "--user" "at the Welcome dialog" "false" fi else display_msg --logonly info "Ignored welcome prompt as auto confirm option specified." @@ -326,24 +324,31 @@ function display_welcome() # ${2} - "true"/"false" - Flag to indicate if the user should be prompted to show the installation log function display_aborted() { + if [[ ${1} == "--user" ]]; then + local ABORT_MSG="USER ABORTED INSTALLATION" + shift + else + local ABORT_MSG="INSTALLATION ABORTED" + fi local EXTRA_TEXT="${1}" local SHOW_LOG="${2}" - display_msg --logonly info "USER ABORTED INSTALLATION ${EXTRA_TEXT}." - local ERROR_MSG="\nThe installation of the remote Website has been aborted ${EXTRA_TEXT}." + display_msg --logonly info "${ABORT_MSG} ${EXTRA_TEXT}." + local ERROR_MSG="\nThe installation of the remote Website was aborted ${EXTRA_TEXT}." if [[ ${SHOW_LOG} == "true" ]]; then # TODO: Instead of displaying the log file, which is very detailed, # how about if we tell the user to attach the log file to any GitHub message they post? - MSG="${ERROR_MSG}\n\n${DIALOG_UNDERLINE}Would you like to view the installation log?${DIALOG_NORMAL}" + MSG="${ERROR_MSG}\n\n" + MSG+="${DIALOG_UNDERLINE}Would you like to view the installation log?${DIALOG_NORMAL}" if display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" ; then display_log_file "${DIALOG_BACK_TITLE}" "${DIALOG_TITLE_LOG}" "${DISPLAY_MSG_LOG}" fi - else - clear # Gets rid of background color from last 'dialog' command. - display_msg info "${ERROR_MSG}" fi + clear # Gets rid of background color from last 'dialog' command. + display_msg info "${ERROR_MSG}" + exit 1 } @@ -365,7 +370,9 @@ function display_complete() MSG="\n\ The installation of the remote Website is complete.\n\n\ Please use the WebUI's 'Editor' page to manage any changes to your Website.${EXTRA_TEXT}" - display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" +#xx display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" + clear # Gets rid of background color from last 'dialog' command. + display_msg progress "${MSG}" } # Check connectivity to the remote Website. @@ -525,12 +532,13 @@ function check_if_website_exists() WEBSITE_EXISTS="false" } -# Uploads the Website code. The code is copied from ${ALLSKY_WEBSITE} and removes any old -# Allsky files that will no longer be needed. +# Uploads the Website code from ${ALLSKY_WEBSITE} and removes any old +# Allsky files that are no longer needed. function upload_remote_website() { if [[ ${SKIP_UPLOAD} == "true" ]]; then - display_msg --logonly info "Skipping upload as --skipupload provided on command line\n" + display_msg --logonly info "Skipping upload as --skipupload provided on command line.\n" + return fi local EXTRA_TEXT="" @@ -540,19 +548,6 @@ function upload_remote_website() REMOTE_PORT="-p ${REMOTE_PORT}" fi - if [[ ${AUTO_CONFIRM} == "false" ]]; then - MSG="\nTo continue the Allsky Website must be uploaded." - MSG+=" This will overwrite ALL remote Website source files and REMOVE any old Allsky files." - MSG+="\n\n${DIALOG_UNDERLINE}Are you sure you wish to continue?${DIALOG_NORMAL}" - if ! display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" ; then - display_aborted "at the Website upload" "false" - fi - EXTRA_TEXT=", user agreed to upload and remove all old Allsky files" - else - show_debug_message "Ignored confirm Website upload as auto confirm option specified" - EXTRA_TEXT=", auto confirm option specified" - fi - local MSG="Starting upload to the remote Website" if [[ ${WEBSITE_EXISTS} == "true" ]]; then EXCLUDE_FOLDERS="--exclude keograms --exclude startrails --exclude videos" @@ -560,12 +555,14 @@ function upload_remote_website() fi display_msg --log progress "${MSG}${EXTRA_TEXT}." - MSG="\n${MESSAGE}\n\nPlease wait as this process could take several minutes..." + MSG="\n${MESSAGE}\n\nPlease wait as uploading files could take several minutes..." display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" { # TODO: upload.sh should have a "--mirror directory" option. - lftp -u "${REMOTE_USER},${REMOTE_PASSWORD}" "${REMOTE_PORT}" "${REMOTE_PROTOCOL}://${REMOTE_HOST}" -e " +# This would also fix the problem that we're assuming the "ftp" protocol is used. + # shellcheck disable=SC2086 + lftp -u "${REMOTE_USER},${REMOTE_PASSWORD}" ${REMOTE_PORT} "${REMOTE_PROTOCOL}://${REMOTE_HOST}" -e " lcd '${ALLSKY_WEBSITE}' cd '${REMOTE_DIR}' set dns:fatal-timeout 10 @@ -574,6 +571,8 @@ function upload_remote_website() mirror --reverse --verbose --overwrite --ignore-time --transfer-all ${EXCLUDE_FOLDERS} quit" +# TODO: check return code + # Remove any old core files no longer required for FILE_TO_DELETE in "${OLD_FILES_TO_REMOVE[@]}"; do remove_remote_file "${FILE_TO_DELETE}" "${REMOTE_URL}" @@ -591,12 +590,17 @@ function upload_config_file() display_msg --log progress "Starting Website configuration file upload" local REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" - local RESULT="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_DIR}" "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" )" -# TODO: Is this checking the return code from upload.sh? - if [[ ! ${RESULT} ]]; then - show_debug_message "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} uploaded to ${REMOTE_DIR}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}" - display_msg --logonly progress "Completed Website configuration file upload" + local RESULT="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web \ + "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_DIR}" \ + "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" 2>&1 + )" + if [[ $? -eq 0 ]]; then + MSG="${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} uploaded to" + MSG+="${REMOTE_DIR}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}" + show_debug_message "${MSG}" + display_msg --logonly info "Completed Website configuration file upload." else + display_msg --logonly info " Failed: ${RESULTS}" display_aborted "at the configuration file upload" "true" fi } From 0176afde573790b3297d08c29630a0cc7d57b375 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sun, 20 Oct 2024 00:58:19 -0600 Subject: [PATCH 15/17] Update remote_website_install.sh: allow removing directories Also, log delete failures --- remote_website_install.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index 7c39016e4..1d9ae42af 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -498,15 +498,18 @@ function remove_remote_file() check_if_files_exist "${REMOTE_URL}" "false" "${FILENAME}" || return fi -# TODO: This assumes ftp is used to upload files - lftp -u "${REMOTE_USER},${REMOTE_PASSWORD}" "${REMOTE_PORT}" "${REMOTE_PROTOCOL}://${REMOTE_HOST}" -e " - cd '${REMOTE_DIR}' - rm '${FILENAME}' - bye" > /dev/null 2>&1 +# TODO: FIX: This assumes ftp is used to upload files +# TODO: upload.sh should accept "--remove FILE" option. + local CMDS="cd '${REMOTE_DIR}' ; rm -r '${FILENAME}' ; bye" + local ERR="$( lftp -u "${REMOTE_USER},${REMOTE_PASSWORD}" "${REMOTE_PORT}" "${REMOTE_PROTOCOL}://${REMOTE_HOST}" -e "${CMDS}" 2>&1 )" - #TODO: Check response code + if [[ $? -eq 0 ]] ; then + MSG="Deleted remote file '${FILENAME}'" + else + MSG="Unable to delete remote file '${FILENAME}': ${ERR}" + fi - display_msg --logonly info "Deleted file ${FILENAME} from ${REMOTE_HOST}" + display_msg --logonly info "${MSG}" } # Check if a remote Website exists. The check is done by looking for the following files: @@ -587,7 +590,7 @@ function upload_config_file() { local MSG="\nUploading remote Allsky configuration file" display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" - display_msg --log progress "Starting Website configuration file upload" + display_msg --log progress "Uploading Website configuration file." local REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" local RESULT="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web \ @@ -598,9 +601,8 @@ function upload_config_file() MSG="${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} uploaded to" MSG+="${REMOTE_DIR}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}" show_debug_message "${MSG}" - display_msg --logonly info "Completed Website configuration file upload." else - display_msg --logonly info " Failed: ${RESULTS}" + display_msg --logonly info " Failed: ${RESULT}" display_aborted "at the configuration file upload" "true" fi } From c8306de4d5b03e090490774b601fa6f71bff909f Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sun, 20 Oct 2024 01:25:22 -0600 Subject: [PATCH 16/17] Update remote_website_install.sh: Optionally pass in "check" when deleting a file "check" is more descriptive than passing in an unused URL. --- remote_website_install.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index 1d9ae42af..f6a1e5aa8 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -384,8 +384,7 @@ function check_connectivity() if ERR="$( "${ALLSKY_SCRIPTS}/testUpload.sh" --website --silent --file "${TEST_FILE}" 2>&1 )" ; then local MSG="The remote Website connectivity test succeeded." display_msg --logonly info "${MSG}" - remove_remote_file "${TEST_FILE}" - show_debug_message "${TEST_FILE} deleted from the remote server" + remove_remote_file "${TEST_FILE}" "do not check" else local ERROR_MSG="\nERROR: The remote Website connectivity check failed." ERROR_MSG+="\n\nPlease check the 'Websites and Remote Server Settings' section of the WebUI.\n\n\ @@ -484,17 +483,16 @@ function check_if_files_exist() } # Deletes a file from the remote server. -# If a URL is specified then the file is first checked to make sure it exists. # ${1} - The name of the file to delete -# ${2} - The url of the remote Website, used to check if a file exists +# ${2} - If set to "check", first check if the file exists # # Returns - Nothing function remove_remote_file() { local FILENAME="${1}" - local URL="${2}" + local CHECK="${2}" - if [[ -n ${URL} ]]; then + if [[ ${CHECK} == "check" ]]; then check_if_files_exist "${REMOTE_URL}" "false" "${FILENAME}" || return fi @@ -578,7 +576,7 @@ function upload_remote_website() # Remove any old core files no longer required for FILE_TO_DELETE in "${OLD_FILES_TO_REMOVE[@]}"; do - remove_remote_file "${FILE_TO_DELETE}" "${REMOTE_URL}" + remove_remote_file "${FILE_TO_DELETE}" "check" done } >> "$DISPLAY_MSG_LOG" 2>&1 From 84aaeee521084f55260d89107bd28b7fa5ad630c Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sun, 20 Oct 2024 02:20:15 -0600 Subject: [PATCH 17/17] Update remote_website_install.sh: don't show "progress" messages It overwrites lines in the dialog box --- remote_website_install.sh | 41 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index f6a1e5aa8..e2f5bd41a 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -46,6 +46,7 @@ DIALOG_BACK_TITLE="Allsky Remote Website Installer" DIALOG_WELCOME_TITLE="Allsky Remote Website Installer" DIALOG_PRE_CHECK="Pre Installation Checks" DIALOG_INSTALL="Installing Remote Website" +DIALOG_DONE="Remote Website Installation Completed" DIALOG_TITLE_LOG="Allsky Remote Website Installation Log" # Old Allksy Website files that should be remoevd if they exist @@ -173,10 +174,10 @@ function display_log_file() local BACK_TITLE="${1}" local DIALOG_TITLE="${2}" dialog \ - --clear\ - --colors\ - --backtitle "${BACK_TITLE}"\ - --title "${DIALOG_TITLE}"\ + --clear \ + --colors \ + --backtitle "${BACK_TITLE}" \ + --title "${DIALOG_TITLE}" \ --textbox "${FILENAME}" 22 77 } @@ -200,7 +201,7 @@ function pre_install_checks() DIALOG_TEXT+="\n1 - Checking for local files" display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - display_msg --logonly progress "Start pre installation checks." + display_msg --logonly info "Start pre installation checks." if [[ -f ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then MSG="Found current remote configuration file: ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." @@ -295,7 +296,7 @@ function display_welcome() fi if [[ ${AUTO_CONFIRM} == "false" ]]; then - display_msg --logonly info "Displaying the welcome dialog" + display_msg --logonly info "Displaying the welcome dialog." local DIALOG_MSG="\n\ Welcome to the Allsky Remote Website Installer!\n\n\ This script will perform the following tasks:\n\n\ @@ -333,7 +334,7 @@ function display_aborted() local EXTRA_TEXT="${1}" local SHOW_LOG="${2}" - display_msg --logonly info "${ABORT_MSG} ${EXTRA_TEXT}." + display_msg --logonly info "${ABORT_MSG} at $( date ) ${EXTRA_TEXT}.\n" local ERROR_MSG="\nThe installation of the remote Website was aborted ${EXTRA_TEXT}." if [[ ${SHOW_LOG} == "true" ]]; then @@ -365,14 +366,15 @@ function display_complete() EXTRA_TEXT+="${E}" fi - display_msg --logonly info "INSTALLATON COMPLETED.\n" + display_msg --logonly info "INSTALLATON COMPLETED at $( date ).\n" - MSG="\n\ + local DIALOG_TEXT="\n\ The installation of the remote Website is complete.\n\n\ Please use the WebUI's 'Editor' page to manage any changes to your Website.${EXTRA_TEXT}" -#xx display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" + display_box "--msgbox" "${DIALOG_BACK_TITLE}" "${DIALOG_DONE}" "${DIALOG_TEXT}" + clear # Gets rid of background color from last 'dialog' command. - display_msg progress "${MSG}" + display_msg info "\nEnjoy your remote Allsky Website!\n" } # Check connectivity to the remote Website. @@ -493,7 +495,10 @@ function remove_remote_file() local CHECK="${2}" if [[ ${CHECK} == "check" ]]; then - check_if_files_exist "${REMOTE_URL}" "false" "${FILENAME}" || return + if ! check_if_files_exist "${REMOTE_URL}" "false" "${FILENAME}" ; then + show_debug_message "===== not on server" + return + fi fi # TODO: FIX: This assumes ftp is used to upload files @@ -525,7 +530,7 @@ function check_if_website_exists() show_debug_message "Found remote website config file" if check_if_files_exist "${REMOTE_URL}" "and" "${WEBSITE_FILES[@]}" ; then - display_msg --log progress "Found remote Allsky Website at ${REMOTE_URL}" + display_msg --logonly info "Found remote Allsky Website at ${REMOTE_URL}" WEBSITE_EXISTS="true" return fi @@ -554,7 +559,7 @@ function upload_remote_website() EXCLUDE_FOLDERS="--exclude keograms --exclude startrails --exclude videos" MSG+=", excluding videos, startrails, and keograms" fi - display_msg --log progress "${MSG}${EXTRA_TEXT}." + display_msg --logonly info "${MSG}${EXTRA_TEXT}." MSG="\n${MESSAGE}\n\nPlease wait as uploading files could take several minutes..." display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" @@ -570,7 +575,7 @@ function upload_remote_website() set net:max-retries 2 set net:timeout 10 mirror --reverse --verbose --overwrite --ignore-time --transfer-all ${EXCLUDE_FOLDERS} - quit" + quit" 2>&1 | grep -v -i "operation not supported" # TODO: check return code @@ -588,7 +593,7 @@ function upload_config_file() { local MSG="\nUploading remote Allsky configuration file" display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" - display_msg --log progress "Uploading Website configuration file." + display_msg --logonly info "Uploading Website configuration file." local REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" local RESULT="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web \ @@ -639,7 +644,7 @@ function enable_remote_website() { display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nEnabling remote Website" update_json_file ".useremotewebsite" "true" "${SETTINGS_FILE}" - display_msg --log info "Remote Website enabled.\n" + display_msg --logonly info "Remote Website enabled." } ############################################## main body @@ -680,7 +685,7 @@ done [[ ${HELP} == "true" ]] && usage_and_exit 0 [[ ${OK} == "false" ]] && usage_and_exit 1 -display_msg --logonly info "STARTING INSTALLATON AT $( date ).\n" +display_msg --logonly info "STARTING INSTALLATION AT $( date ).\n" pre_install_checks display_welcome