From ae2ff2c981c6d982615bb2d56abcd7e842ce7862 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Sun, 20 Oct 2024 11:52:54 -0600 Subject: [PATCH 01/12] Update remote_website_install.sh: Don't add remote URL to dialog boxes Other than testing, there wasn't a need. --- remote_website_install.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index e2f5bd41a..d40c890ec 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -87,22 +87,27 @@ function press_any_key() read -r -n1 -s } -# Adds the remote Website URL to the dialog text. - -# TODO FIX: Eric thinks seeing the remote URL confusing. - +# Add a common heading to the dialog text. function add_dialog_heading() { local DIALOG_TEXT="${1}" + + ## We no longer add the remote URL but have left this code in case we want + ## to add something else in the future. + ## Only the: ITEM_TO_ADD=xxx line should need changing. + echo "${DIALOG_TEXT}" + return + 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}") + local ITEM_TO_ADD="${REMOTE_URL}" + local PADDING=$(( ((DIALOG_WIDTH-6) - ${#ITEM_TO_ADD}) / 2 )) + local ITEM_TO_ADD="$( printf "%${PADDING}s%s" "" "${ITEM_TO_ADD}" )" - echo -e "\n${DIALOG_RED}${URL}${DIALOG_NORMAL}\n${DIALOG_TEXT}" + echo -e "\n${DIALOG_RED}${ITEM_TO_ADD}${DIALOG_NORMAL}\n${DIALOG_TEXT}" } # Displays the specified type of Dialog, or in text mode just displays the text. From efeafb1e1eba6ecbe4c35b0231bf6ab1722a7d05 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Fri, 1 Nov 2024 01:55:50 -0600 Subject: [PATCH 02/12] Update functions.sh: Add "function" to function names --- scripts/functions.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 46b46020c..e2f42abf6 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -37,11 +37,11 @@ else fi ##### Start and Stop Allsky -start_Allsky() +function start_Allsky() { sudo systemctl start allsky 2> /dev/null } -stop_Allsky() +function stop_Allsky() { sudo systemctl stop allsky 2> /dev/null } @@ -420,7 +420,7 @@ function validate_camera() if [[ ${ON_TTY} == "true" ]]; then echo -e "\n${RED}${MSG}${NC}\n" else - URL="/index.php?page=configuration&_ts=${RANDOM}" + URL="/index.php?page=configuration" "${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${MSG}" "${URL}" fi RET=1 @@ -431,7 +431,7 @@ function validate_camera() if [[ ${ON_TTY} == "true" ]]; then echo -e "\n${RED}${MSG}${NC}\n" else - URL="/index.php?page=configuration&_ts=${RANDOM}" + URL="/index.php?page=configuration" "${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${MSG}" "${URL}" fi RET=1 @@ -442,7 +442,7 @@ function validate_camera() if [[ ${ON_TTY} == "true" ]]; then echo -e "\n${RED}${MSG}${NC}\n" else - URL="/index.php?page=configuration&_ts=${RANDOM}" + URL="/index.php?page=configuration" "${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${MSG}" "${URL}" fi RET=1 @@ -1260,7 +1260,8 @@ function indent() # Python virtual environment PYTHON_VENV_ACTIVATED="false" -activate_python_venv() { +function activate_python_venv() +{ # TODO: will need to change when the OS after bookworm is released # If our next release is out, it won't support buster so may be check != bullseye ? @@ -1274,7 +1275,8 @@ activate_python_venv() { return 1 } -deactivate_python_venv() { +function deactivate_python_venv() +{ [[ ${PYTHON_VENV_ACTIVATED} == "true" ]] && deactivate } From 16ed5f3a6070d0900c34e93eae295f5524afc576 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Wed, 6 Nov 2024 16:03:47 -0700 Subject: [PATCH 03/12] Update install.sh: changes to be in sync with v2024.xx.xx --- install.sh | 95 +++++++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/install.sh b/install.sh index 71dfc2694..08fc68b61 100755 --- a/install.sh +++ b/install.sh @@ -929,6 +929,11 @@ set_permissions() fi done + # These directories aren't in GitHub so need to be manually created. + mkdir -p \ + "${ALLSKY_EXTRA}" \ + "${ALLSKY_MYFILES_DIR}" + # The web server needs to be able to create and update many of the files in ${ALLSKY_CONFIG}. # Not all, but go ahead and chgrp all of them so we don't miss any new ones. sudo find "${ALLSKY_CONFIG}/" -type f -exec chmod 664 '{}' \; @@ -956,6 +961,7 @@ set_permissions() # These directories aren't in GitHub so need to be manually created. mkdir -p \ + "${ALLSKY_WEBSITE_MYFILES_DIR}" \ "${ALLSKY_WEBSITE}/videos/thumbnails" \ "${ALLSKY_WEBSITE}/keograms/thumbnails" \ "${ALLSKY_WEBSITE}/startrails/thumbnails" @@ -2383,11 +2389,6 @@ restore_prior_files() CONFIGURATION_NEEDED="${STATUS_NO_LAT_LONG}" fi - # Default permissions for these are ok. - mkdir -p \ - "${ALLSKY_EXTRA}" \ - "${ALLSKY_CONFIG}/myFiles" - STATUS_VARIABLES+=( "${FUNCNAME[0]}='true'\n" ) return # Nothing left to do in this function, so return fi @@ -2431,12 +2432,11 @@ restore_prior_files() display_msg --log progress "${ITEM}: ${NOT_RESTORED}" fi - ITEM="${SPACE}'config/myFiles' directory" - if [[ -d ${PRIOR_CONFIG_DIR}/myFiles ]]; then + ITEM="${SPACE}'$( basename "$( dirname "${ALLSKY_MYFILES_DIR}" )" )/${ALLSKY_MYFILES_NAME}' directory" + if [[ -d ${PRIOR_MYFILES_DIR} ]]; then display_msg --log progress "${ITEM} (moving)" - mv "${PRIOR_CONFIG_DIR}/myFiles" "${ALLSKY_CONFIG}" + mv "${PRIOR_MYFILES_DIR}" "${ALLSKY_MYFILES_DIR}" else - mkdir -p "${ALLSKY_CONFIG}/myFiles" # Almost no one has this directory, so don't show to user. display_msg --logonly info "${ITEM}: ${NOT_RESTORED}" fi @@ -2578,9 +2578,9 @@ restore_prior_files() else MSG="Your remote Website needs to be updated to this newest version." MSG+="\nIt is at version ${PRIOR_V}" + # This command will update the version. MSG+="\n\nRun: cd ~/allsky; ./remote_website_install.sh" display_msg --log notice "${MSG}" - # The command above will update the version. fi else display_msg --log progress "${ITEM}: ${NOT_RESTORED}" @@ -2711,16 +2711,13 @@ restore_prior_website_files() display_msg --log progress "${ITEM}: ${NOT_RESTORED}" fi - ITEM="${SPACE}${SPACE}'myFiles' directory" - D="${PRIOR_WEBSITE_DIR}/myFiles" + ITEM="${SPACE}${SPACE}'${ALLSKY_MYFILES_NAME}' directory" + D="${PRIOR_WEBSITE_DIR}/${ALLSKY_MYFILES_NAME}" if [[ -d ${D} ]]; then - count=$( get_count "${D}" '*' ) - if [[ ${count} -gt 1 ]]; then - display_msg --log progress "${ITEM} (moving)" - mv "${D}" "${ALLSKY_WEBSITE}" - fi + display_msg --log progress "${ITEM} (moving)" + mv "${D}" "${ALLSKY_WEBSITE_MYFILES_DIR}" else - display_msg --log progress "${ITEM}: ${NOT_RESTORED}" + display_msg --logonly info "${ITEM}: ${NOT_RESTORED}" fi # This is the old name. @@ -2730,9 +2727,10 @@ restore_prior_website_files() if [[ -d ${D} ]]; then count=$( get_count "${D}" '*' ) if [[ ${count} -gt 1 ]]; then - local MSG2=" Please use 'myFiles' going forward." - display_msg --log progress "${ITEM} (copying to '${ALLSKY_WEBSITE}/myFiles')" "${MSG2}" - cp "${D}"/* "${ALLSKY_WEBSITE}/myFiles" + local MSG2=" Please use '${ALLSKY_WEBSITE_MYFILES_DIR}' going forward." + display_msg --log progress "${ITEM} (copying to '${ALLSKY_WEBSITE_MYFILES_DIR}')" "${MSG2}" + # TODO: This won't copy dot files. + cp "${D}"/* "${ALLSKY_WEBSITE_MYFILES_DIR}" fi else # Since this is obsolete only add to log file. @@ -2777,7 +2775,7 @@ restore_prior_website_files() echo -e "${MSG}" echo "When done, check in '${PRIOR_WEBSITE_DIR}' for any files" echo "you may have added; if there are any, store them in" - echo -e "\n ${ALLSKY_WEBSITE}/myFiles" + echo -e "\n ${ALLSKY_WEBSITE_MYFILES_DIR}" echo "then remove the old website: sudo rm -fr ${PRIOR_WEBSITE_DIR}" } >> "${POST_INSTALLATION_ACTIONS}" @@ -2881,10 +2879,10 @@ do_restore() display_msg --log progress "${ITEM}: ${NOT_RESTORED}" fi - ITEM="${SPACE}'config/myFiles' directory" - if [[ -d ${ALLSKY_CONFIG}/myFiles ]]; then + ITEM="${SPACE}'$( basename "$( dirname "${ALLSKY_MYFILES_DIR}" )" )/${ALLSKY_MYFILES_NAME}' directory" + if [[ -d ${ALLSKY_MYFILES_DIR} ]]; then display_msg --log progress "${ITEM} (moving back)" - mv "${ALLSKY_CONFIG}/myFiles" "${PRIOR_CONFIG_DIR}" + mv "${ALLSKY_MYFILES_DIR}" "${PRIOR_MYFILES_DIR}" else # Few people have this directory, so don't show to user. display_msg --logonly info "${ITEM}: ${NOT_RESTORED}" @@ -2926,22 +2924,13 @@ do_restore() display_msg --log progress "${ITEM}: ${NOT_RESTORED}" fi - ITEM="${SPACE}${SPACE}'myFiles' directory" - D="${ALLSKY_WEBSITE}/myFiles" - if [[ -d ${D} ]]; then - count=$( get_count "${D}" '*' ) - if [[ ${count} -gt 1 ]]; then - display_msg --log progress "${ITEM} (moving)" - mv "${D}" "${PRIOR_WEBSITE_DIR}" - fi + ITEM="${SPACE}${SPACE}${ALLSKY_MYFILES_NAME}" + if [[ -d ${ALLSKY_WEBSITE_MYFILES_DIR} ]]; then + display_msg --log progress "${ITEM} (moving)" + mv "${ALLSKY_WEBSITE_MYFILES_DIR}" "${PRIOR_WEBSITE_DIR}" else - display_msg --log progress "${ITEM}: ${NOT_RESTORED}" + display_msg --logonly info "${ITEM}: ${NOT_RESTORED}" fi - -#xx TODO: huh? why remove it? -#xx ITEM="${SPACE}${SPACE}Local Website directory" -#xx display_msg --log progress "${ITEM} (removing)" -#xx rm -fr "${ALLSKY_WEBSITE}" fi # Since we'll be running a new Allsky, start off with clean log files. @@ -3199,6 +3188,29 @@ install_Python() # Add the status back in. update_status_from_temp_file + # On pi 5 models we need to replace rpi.gpi with lgpio. This should be done by adafruit-blinka + # the code is in setup.py to do this but it doesnt appear to work hence we are forcing it here + # gpiozero decodes the pi revision number to calculate the pi version so until the pi 6 is + # release this code will detect all future versions of the pi 5 + # + # NOTE: rpi-gpi and rpi-lgpio cannot co exist but since blinka is not installing either we don't + # currently have to worry about removing rpi-gpio before installing rpi-lgpio + # +pimodel=$(python3 < /dev/null 2>&1 + fi + STATUS_VARIABLES+=( "${FUNCNAME[0]}='true'\n" ) } @@ -3664,11 +3676,6 @@ fi #shellcheck disable=SC2119 if [[ $( get_branch ) != "${GITHUB_MAIN_BRANCH}" ]]; then - IN_TESTING="true" -else - IN_TESTING="false" -fi -if [[ ${IN_TESTING} == "true" ]]; then DEBUG=1; DEBUG_ARG="--debug"; LOG_TYPE="--log" T="${ALLSKY_HOME}/told" From 79506a1c18338317a9f7fd5a98e4c669e931b204 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Wed, 6 Nov 2024 16:26:19 -0700 Subject: [PATCH 04/12] Update remote_website_install.sh: several changes * Rename some variable to better reflect what they do. * Add another entry to OLD_FILES_TO_REMOVE. * Expand some comments. * Use "elif" instead of separate "if" statements. * Replace hard-coded names with variables.sh has a variable for them. * Check output from "wget" in addition to its exit code. * check_if_files_exist() now uses "and" and "or" rather than "true" and "false", which, IMHO, is clearer what it's doing. --- remote_website_install.sh | 184 +++++++++++++++++++------------------- 1 file changed, 94 insertions(+), 90 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index d40c890ec..e764ee0eb 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -21,7 +21,7 @@ DISPLAY_MSG_LOG="${ALLSKY_LOGS}/${ME/.sh/}.log" # Config variables HAVE_NEW_CONFIG="false" -HAVE_OLD_CONFIG="false" +HAVE_PRIOR_CONFIG="false" HAVE_NEW_REMOTE_CONFIG="false" HAVE_REALLY_OLD_REMOTE_CONFIG="false" CONFIG_TO_USE="" @@ -39,7 +39,6 @@ REMOTE_PORT="$( settings ".REMOTEWEBSITE_PORT" "${ALLSKY_ENV}" )" REMOTE_PASSWORD="$( settings ".REMOTEWEBSITE_PASSWORD" "${ALLSKY_ENV}" )" REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" REMOTE_PROTOCOL="$( settings ".remotewebsiteprotocol" )" -WEBSITE_EXISTS="false" # Titles for various dialogs DIALOG_BACK_TITLE="Allsky Remote Website Installer" @@ -50,7 +49,14 @@ 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 -OLD_FILES_TO_REMOVE=("config.js" "configuration.json" "virtualsky.json" "README.md" "myImages") +OLD_CONFIG_NAME="config.js" +OLD_FILES_TO_REMOVE=( \ + "${OLD_CONFIG_NAME}" \ + "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" \ + "getTime.php" \ + "virtualsky.json" \ + "README.md" \ + "myImages") ############################################## functions @@ -186,22 +192,28 @@ function display_log_file() --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 to 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. +# 1a. If ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} exists, use it. +# +# 1b. If ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE} exists, +# copy it to ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} and use it. +# +# 2a. If there's a remote Website with a ${ALLSKY_WEBSITE_CONFIGURATION_NAME} file, +# save it locally as ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} and use it. +# +# 2b. If there is a remote Website with an old-style configuration file (${OLD_CONFIG_NAME}), +# create a NEW ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} and use it. +# Don't bother trying to convert from old-style files. function pre_install_checks() { local MSG="" - local DIALOG_TEXT="\nRunning pre installation checks." + local DIALOG_TEXT + 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" @@ -209,37 +221,40 @@ function pre_install_checks() display_msg --logonly info "Start pre installation checks." if [[ -f ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then + # 1a. MSG="Found current remote configuration file: ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." 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}." + elif [[ -f ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then + # 1b. + MSG="Found $( basename "${PRIOR_ALLSKY_DIR}" ) remote configuration file: ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}." display_msg --logonly info "${MSG}" - HAVE_OLD_CONFIG="true" + HAVE_PRIOR_CONFIG="true" fi - DIALOG_TEXT+="\n2 - Checking if remote Website exists" + DIALOG_TEXT+="\n2 - Checking if an existing remote Website exists" display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - check_if_website_exists # Sets ${WEBSITE_EXISTS} + local WEBSITE_EXISTS="$( check_if_website_exists )" if [[ ${WEBSITE_EXISTS} == "true" ]]; then - DIALOG_TEXT+="\n3 - Checking for remote Website configuration file" + # 2a. + DIALOG_TEXT+="\n2a - 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 + local NEW_CONFIG_FILES=("${ALLSKY_WEBSITE_CONFIGURATION_NAME}") + if check_if_files_exist "${REMOTE_URL}" "or" "${NEW_CONFIG_FILES[@]}" ; then HAVE_NEW_REMOTE_CONFIG="true" MSG="Found current configuration file on the remote server." display_msg --logonly info "${MSG}" fi - DIALOG_TEXT+="\n4 - Checking for old-style remote Website configuration file" + # 2b. + DIALOG_TEXT+="\n2b - 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 + local REALLY_OLD_CONFIG_FILES=("${OLD_CONFIG_NAME}") + if check_if_files_exist "${REMOTE_URL}" "or" "${REALLY_OLD_CONFIG_FILES[@]}" ; then HAVE_REALLY_OLD_REMOTE_CONFIG="true" - MSG="Found old-format config.js file on the remote Website." + MSG="Found old-format ${OLD_CONFIG_NAME} file on the remote Website." display_msg --logonly info "${MSG}" fi fi @@ -253,28 +268,24 @@ function pre_install_checks() CONFIG_TO_USE="current" CONFIG_MESSAGE="the current remote" - elif [[ ${HAVE_OLD_CONFIG} == "true" ]]; then - MSG="Using the -OLD configuration file; placeholders will be updated." + elif [[ ${HAVE_PRIOR_CONFIG} == "true" ]]; then + MSG="Using the $( basename "${PRIOR_ALLSKY_DIR}" ) 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 [[ ${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 + elif [[ ${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" + elif [[ ${HAVE_REALLY_OLD_REMOTE_CONFIG} == "true" ]]; then + MSG="Old ${OLD_CONFIG_NAME} 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 if [[ -z ${CONFIG_TO_USE} ]]; then @@ -318,7 +329,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 "--user" "at the Welcome dialog" "false" + display_aborted "--user" "at the Welcome dialog" "" fi else display_msg --logonly info "Ignored welcome prompt as auto confirm option specified." @@ -327,7 +338,7 @@ function display_welcome() # 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 +# ${2} - Error message (or "" if no error) function display_aborted() { if [[ ${1} == "--user" ]]; then @@ -337,18 +348,19 @@ function display_aborted() local ABORT_MSG="INSTALLATION ABORTED" fi local EXTRA_TEXT="${1}" - local SHOW_LOG="${2}" + local ERROR_MSG="${2}" 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 -# 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" - MSG+="${DIALOG_UNDERLINE}Would you like to view the installation log?${DIALOG_NORMAL}" - if display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" ; then + local MSG="\nThe installation of the remote Website was aborted ${EXTRA_TEXT}." + + if [[ -n ${ERROR_MSG} ]]; then + local DIALOG_PROMPT="${MSG}\n\n" + DIALOG_PROMPT+="${DIALOG_UNDERLINE}Would you like to view the error message?${DIALOG_NORMAL}" + if display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${DIALOG_PROMPT}" ; then + display_box "--msgbox" "${DIALOG_BACK_TITLE}" "${DIALOG_TITLE_LOG}" "${ERROR_MSG}" "--scrollbar" +if false; then display_log_file "${DIALOG_BACK_TITLE}" "${DIALOG_TITLE_LOG}" "${DISPLAY_MSG_LOG}" +fi fi fi @@ -389,19 +401,11 @@ function check_connectivity() 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}" + show_debug_message "The remote Website connectivity test succeeded." 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\ - HOST: ${REMOTE_HOST}\n\ - PROTOCOL: ${REMOTE_PROTOCOL}\n\ - USER: ${REMOTE_USER}\n\ - REMOTE FOLDER: ${REMOTE_DIR}\n\n\ - ${ERR}" - - display_aborted "${ERROR_MSG}" "true" + display_aborted "${ERROR_MSG}" "${ERR}" fi } @@ -445,30 +449,30 @@ function create_website_config() 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 + if ERR="$( wget -O "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_URL}/${ALLSKY_WEBSITE_CONFIGURATION_FILE}" 2>&1 )"; 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 --logonly info "${MSG}" else MSG="Failed to download ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}" - display_aborted "${MSG}" "true" + display_aborted "${MSG}" "${ERR}" fi fi } # 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. +# ${2} - "and"/"or" If "and" then all files must exist, if "or" then any of the files can exist. # ${3}... - the files # # Returns - 0 if the file(s) exist, 1 if ANY file doesn't exist. function check_if_files_exist() { local URL="${1}" - local AND="${2}" + local AND_OR="${2}" shift 2 - local RESULT=1 + local RET_CODE=1 for FILE in "$@"; do url="${URL}/${FILE}" @@ -477,16 +481,16 @@ function check_if_files_exist() local PRE_MSG="File ${FILE} ${url}" if [[ ${HTTP_STATUS} == "200" ]] ; then show_debug_message "${PRE_MSG} exists on the remote server" - RESULT=0 + RET_CODE=0 else show_debug_message "${PRE_MSG} does not exists on the remote server" - if [[ ${AND} == "true" ]]; then + if [[ ${AND_OR} == "and" ]]; then return 1 fi fi done - return ${RESULT} + return ${RET_CODE} } # Deletes a file from the remote server. @@ -500,14 +504,14 @@ function remove_remote_file() local CHECK="${2}" if [[ ${CHECK} == "check" ]]; then - if ! check_if_files_exist "${REMOTE_URL}" "false" "${FILENAME}" ; then + if ! check_if_files_exist "${REMOTE_URL}" "or" "${FILENAME}" ; then show_debug_message "===== not on server" return fi fi # TODO: FIX: This assumes ftp is used to upload files -# TODO: upload.sh should accept "--remove FILE" option. +# 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 )" @@ -520,27 +524,28 @@ function remove_remote_file() display_msg --logonly info "${MSG}" } -# Check if a remote Website exists. The check is done by looking for the following files: -# -# If any of the ${CONFIG_FILES} files exist and -# all of the ${WEBSITE_FILES} exist then assume we have a remote Website. +# Check if a remote Website exists. +# The check is done by looking for the following files: +# If any of the ${CONFIG_FILES} files exist AND +# all of the ${WEBSITE_FILES} exist then assume we have a remote Website. # -# Returns - Nothing, but set the global variable ${WEBSITE_EXISTS}. +# Returns - echo "true" if it exists, else "false" function check_if_website_exists() { - local CONFIG_FILES=("config.json" "configuration.json" "remote_configuration.json") + local CONFIG_FILES=("${OLD_CONFIG_NAME}" "${ALLSKY_WEBSITE_CONFIGURATION_NAME}") local WEBSITE_FILES=("index.php" "functions.php") - if check_if_files_exist "${REMOTE_URL}" "false" "${CONFIG_FILES[@]}" ; then + if check_if_files_exist "${REMOTE_URL}" "or" "${CONFIG_FILES[@]}" ; then show_debug_message "Found remote website config file" if check_if_files_exist "${REMOTE_URL}" "and" "${WEBSITE_FILES[@]}" ; then display_msg --logonly info "Found remote Allsky Website at ${REMOTE_URL}" - WEBSITE_EXISTS="true" - return + echo "true" + return 0 fi fi - WEBSITE_EXISTS="false" + echo "false" + return 1 } # Uploads the Website code from ${ALLSKY_WEBSITE} and removes any old @@ -601,17 +606,16 @@ function upload_config_file() display_msg --logonly info "Uploading Website configuration file." local REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" - local RESULT="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web \ + local ERR="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web \ "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_DIR}" \ - "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" 2>&1 - )" + "${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}" else - display_msg --logonly info " Failed: ${RESULT}" - display_aborted "at the configuration file upload" "true" + display_msg --logonly info " Failed: ${ERR}" + display_aborted "at the configuration file upload" "${ERR}" fi } From f84a6fafae99d62c7ebb117acde239d594da524b Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Wed, 6 Nov 2024 16:52:08 -0700 Subject: [PATCH 05/12] Update installUpgradeFunctions.sh: delete some settings and add others Plus, update WEBSITE_ALLSKY_VERSION for remote as well as local files. --- scripts/installUpgradeFunctions.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/scripts/installUpgradeFunctions.sh b/scripts/installUpgradeFunctions.sh index 4ec069515..e84c8397e 100644 --- a/scripts/installUpgradeFunctions.sh +++ b/scripts/installUpgradeFunctions.sh @@ -633,18 +633,27 @@ function update_old_website_config_file() # Current version: 2 if [[ ${PRIOR_VERSION} -eq 1 ]]; then - # Version 2 removed AllskyWebsiteVersion. + # Deletions: update_json_file -d ".AllskyWebsiteVersion" "" "${FILE}" + update_json_file -d ".homePage.onPi" "" "${FILE}" + update_array_field "${FILE}" "homePage.popoutIcons" "variable" "AllskyWebsiteVersion" "--delete" + + # Additions: + # Add in same place as new file + local NEW=' \"thumbnailsizex\": 100,\ + \"thumbnailsizey\": 75,\ + \"thumbnailsortorder\": \"ascending\",' + sed -i "/\"leftSidebar\"/i\ ${NEW}" "${FILE}" + + # Changes: + for i in "videos" "keograms" "startrails"; do + update_array_field "${FILE}" "homePage.leftSidebar" "url" "${i}" "${i}/" + done fi - # Set to current version. + # Set to current config and Allsky versions. update_json_file ".${WEBSITE_CONFIG_VERSION}" "${CURRENT_VERSION}" "${FILE}" - - if [[ ${LOCAL_OR_REMOTE} == "local" ]]; then - # Since we're installing a new Allsky, update the Allsky version. - # For remote Websites it'll be updated when the user updates the Website. - update_json_file ".${WEBSITE_ALLSKY_VERSION}" "${ALLSKY_VERSION}" "${FILE}" - fi + update_json_file ".${WEBSITE_ALLSKY_VERSION}" "${ALLSKY_VERSION}" "${FILE}" } #### From 6926cb4054af31f10d67f4386f8f5f5749472155 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Wed, 6 Nov 2024 16:53:17 -0700 Subject: [PATCH 06/12] Update installUpgradeFunctions.sh: consistent formatting of function names Put the opening { on a separate like. --- scripts/installUpgradeFunctions.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/installUpgradeFunctions.sh b/scripts/installUpgradeFunctions.sh index e84c8397e..58bd82a9a 100644 --- a/scripts/installUpgradeFunctions.sh +++ b/scripts/installUpgradeFunctions.sh @@ -54,7 +54,8 @@ export LIGHTTPD_CONFIG_FILE="/etc/lighttpd/lighttpd.conf" ##### # Display a header surrounded by stars. -function display_header() { +function display_header() +{ local HEADER="${1}" local LEN ((LEN = ${#HEADER} + 8)) # 8 for leading and trailing "*** " @@ -81,7 +82,8 @@ function calc_wt_size() ##### # Get a Git version, stripping any trailing newline. # Return "" if none, or on error. -function get_Git_version() { +function get_Git_version() +{ local BRANCH="${1}" local PACKAGE="${2}" local VF="$( basename "${ALLSKY_VERSION_FILE}" )" @@ -98,7 +100,8 @@ function get_Git_version() { ##### # Get the version from a local file, if it exists. If not, get from default file. -function get_version() { +function get_version() +{ local F="${1}" if [[ -z ${F} ]]; then F="${ALLSKY_VERSION_FILE}" # default @@ -115,7 +118,8 @@ function get_version() { ##### # Get the branch using git. -function get_branch() { +function get_branch() +{ local H="${1:-${ALLSKY_HOME}}" echo "$( cd "${H}" || exit; git rev-parse --abbrev-ref HEAD )" } @@ -124,7 +128,8 @@ function get_branch() { ##### # Get a shell variable's value. The variable can have optional spaces and tabs before it. # This function is useful when we can't "source" the file. -function get_variable() { +function get_variable() +{ local VARIABLE="${1}" local FILE="${2}" local LINE="" @@ -1062,7 +1067,8 @@ function get_computer() # files directly. This does assume that both the cli and cgi settings files # work in the same way. # -function get_php_setting() { +function get_php_setting() +{ local SETTING="${1}" php -r "echo ini_get('${SETTING}');" } From cfb1c967cd35893abac4507da344ad99a5bb8126 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:37:05 -0700 Subject: [PATCH 07/12] Update installUpgradeFunctions.sh: remove unused variable --- scripts/installUpgradeFunctions.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/installUpgradeFunctions.sh b/scripts/installUpgradeFunctions.sh index 58bd82a9a..33f6c63ce 100644 --- a/scripts/installUpgradeFunctions.sh +++ b/scripts/installUpgradeFunctions.sh @@ -634,7 +634,6 @@ function update_old_website_config_file() FILE="${1}" PRIOR_VERSION="${2}" CURRENT_VERSION="${3}" - LOCAL_OR_REMOTE="${4}" # Current version: 2 if [[ ${PRIOR_VERSION} -eq 1 ]]; then From b61a6f43352375b49c9b4313b9aee3c523614743 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:39:38 -0700 Subject: [PATCH 08/12] Update install.sh: remove unused argument --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 08fc68b61..8bd66777e 100755 --- a/install.sh +++ b/install.sh @@ -2796,7 +2796,7 @@ restore_prior_website_files() if [[ ${PRIOR_WEB_CONFIG_VERSION} < "${NEW_WEB_CONFIG_VERSION}" ]]; then # If different versions, then update the current one. update_old_website_config_file "${ALLSKY_WEBSITE_CONFIGURATION_FILE}" \ - "${PRIOR_WEB_CONFIG_VERSION}" "${NEW_WEB_CONFIG_VERSION}" "local" + "${PRIOR_WEB_CONFIG_VERSION}" "${NEW_WEB_CONFIG_VERSION}" else display_msg --log progress "${ITEM} (copying)" MSG="${ALLSKY_WEBSITE_CONFIGURATION_NAME}: Already current @ version ${NEW_WEB_CONFIG_VERSION}" From 5647440970743543b59e4b11e42fb57c319a6f7b Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:42:12 -0700 Subject: [PATCH 09/12] Update installUpgradeFunctions.sh: remove unused variable, again --- scripts/installUpgradeFunctions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/installUpgradeFunctions.sh b/scripts/installUpgradeFunctions.sh index 33f6c63ce..468bd7c64 100644 --- a/scripts/installUpgradeFunctions.sh +++ b/scripts/installUpgradeFunctions.sh @@ -629,7 +629,7 @@ function prepare_local_website() # Update a Website configuration file from old to current version. function update_old_website_config_file() { - local FILE PRIOR_VERSION CURRENT_VERSION LOCAL_OR_REMOTE + local FILE PRIOR_VERSION CURRENT_VERSION FILE="${1}" PRIOR_VERSION="${2}" From 7be18ef614cd44ed4ce028a6697d9784d2847fc0 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:32:58 -0700 Subject: [PATCH 10/12] Update remote_website_install.sh: many changes and fixes * Rename WEBSITE_EXISTS to REMOTE_WEBSITE_EXISTS since that's what it's for. * Quit if not using an ftp-type protocol. Will be fixed in point release 1. * Minor wording changes in messages for clarity and brevity. * Fix: REMOTE_WEBSITE_EXISTS should be global. * Rename some of the CONFIG_TO_USE values to better reflect what they are. * Fix: Call update_old_website_config_file() as needed. * In lftp, don't cd to an empty string. * Check return code from mirror. * Remove duplicate REMOTE_DIR= statement. --- remote_website_install.sh | 230 +++++++++++++++++++++++++------------- 1 file changed, 150 insertions(+), 80 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index e764ee0eb..72cc37caf 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -24,8 +24,9 @@ HAVE_NEW_CONFIG="false" HAVE_PRIOR_CONFIG="false" HAVE_NEW_REMOTE_CONFIG="false" HAVE_REALLY_OLD_REMOTE_CONFIG="false" -CONFIG_TO_USE="" +CONFIG_TO_USE="" # which Website configuration file to use? CONFIG_MESSAGE="" +REMOTE_WEBSITE_EXISTS="false" # Dialog size variables DIALOG_WIDTH=70 @@ -38,7 +39,23 @@ REMOTE_HOST="$( settings ".REMOTEWEBSITE_HOST" "${ALLSKY_ENV}" )" REMOTE_PORT="$( settings ".REMOTEWEBSITE_PORT" "${ALLSKY_ENV}" )" REMOTE_PASSWORD="$( settings ".REMOTEWEBSITE_PASSWORD" "${ALLSKY_ENV}" )" REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" -REMOTE_PROTOCOL="$( settings ".remotewebsiteprotocol" )" +REMOTE_PROTOCOL="$( settings ".remotewebsiteprotocol" "${SETTINGS_FILE}" )" +REMOTE_PROTOCOL="${REMOTE_PROTOCOL,,}" # convert to lowercase + +#### FIX: this script needs to support ALL protocols, not just *ftp*. +if [[ ${REMOTE_PROTOCOL} != "sftp" && ${REMOTE_PROTOCOL} != "ftp" && ${REMOTE_PROTOCOL} != "ftps" ]]; then + echo -e "\n\n" + echo "************* NOTICE *************" + echo "This script currently only supports ftp protocols." + echo "Support for the '${REMOTE_PROTOCOL}' protocol will be added in" + echo "the first point release." + echo -e "\n" + echo "In the meantime, if you have an existing remote Allsky Website," + echo "it should continue to work." + echo -e "\n" + + exit 0 +fi # Titles for various dialogs DIALOG_BACK_TITLE="Allsky Remote Website Installer" @@ -112,7 +129,7 @@ function add_dialog_heading() local ITEM_TO_ADD="${REMOTE_URL}" local PADDING=$(( ((DIALOG_WIDTH-6) - ${#ITEM_TO_ADD}) / 2 )) local ITEM_TO_ADD="$( printf "%${PADDING}s%s" "" "${ITEM_TO_ADD}" )" - + echo -e "\n${DIALOG_RED}${ITEM_TO_ADD}${DIALOG_NORMAL}\n${DIALOG_TEXT}" } @@ -216,28 +233,28 @@ function pre_install_checks() 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" + DIALOG_TEXT+="\n1 - Checking for local files" display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" display_msg --logonly info "Start pre installation checks." if [[ -f ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then # 1a. - MSG="Found current remote configuration file: ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." + MSG="Found ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} on Pi." display_msg --logonly info "${MSG}" HAVE_NEW_CONFIG="true" elif [[ -f ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then # 1b. - MSG="Found $( basename "${PRIOR_ALLSKY_DIR}" ) remote configuration file: ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}." + MSG="Found ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}." display_msg --logonly info "${MSG}" HAVE_PRIOR_CONFIG="true" fi - DIALOG_TEXT+="\n2 - Checking if an existing remote Website exists" + DIALOG_TEXT+="\n2 - Checking if an existing remote Website exists" display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - local WEBSITE_EXISTS="$( check_if_website_exists )" - if [[ ${WEBSITE_EXISTS} == "true" ]]; then + REMOTE_WEBSITE_EXISTS="$( check_if_website_exists )" + if [[ ${REMOTE_WEBSITE_EXISTS} == "true" ]]; then # 2a. DIALOG_TEXT+="\n2a - Checking for remote Website configuration file" display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" @@ -260,35 +277,37 @@ function pre_install_checks() 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" + MSG="A remote configuration file was found but using the local version instead." + else + MSG="Using the local remote configuration file (no remote file found)." fi display_msg --logonly info "${MSG}." - CONFIG_TO_USE="current" + CONFIG_TO_USE="local" # it may be old or current format CONFIG_MESSAGE="the current remote" elif [[ ${HAVE_PRIOR_CONFIG} == "true" ]]; then - MSG="Using the $( basename "${PRIOR_ALLSKY_DIR}" ) configuration file; placeholders will be updated." + MSG="Using the $( basename "${PRIOR_ALLSKY_DIR}" ) configuration file;" + MSG+=" placeholders will be updated." display_msg --logonly info "${MSG}" - CONFIG_TO_USE="old" + CONFIG_TO_USE="prior" # it may be old or current format CONFIG_MESSAGE="the $( basename "${PRIOR_ALLSKY_DIR}" )" elif [[ ${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_TO_USE="remoteNew" CONFIG_MESSAGE="the remote Website's" + elif [[ ${HAVE_REALLY_OLD_REMOTE_CONFIG} == "true" ]]; then MSG="Old ${OLD_CONFIG_NAME} found." MSG+=" Creating a new configuration file that the user must manually update." display_msg --logonly info "${MSG}" - CONFIG_TO_USE="remotereallyold" + CONFIG_TO_USE="remoteReallyOld" CONFIG_MESSAGE="a new" - fi - if [[ -z ${CONFIG_TO_USE} ]]; then + else MSG="Unable to determine the configuration file to use. A new one will be created." display_msg --logonly info "${MSG}" CONFIG_TO_USE="new" @@ -319,13 +338,13 @@ function display_welcome() \ 1) Check the remote Website connectivity - PASSED\n\ 2) Use ${CONFIG_MESSAGE} configuration file\n\ - 3) Upload the remote Website code\n\ + 3) Upload the new remote Website code\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\ - - REMOVE any old Allsky files on the remote server.\n\n\n\ + ${DIALOG_RED}WARNING! This will:${DIALOG_NORMAL}\n\ + - Overwrite the old Allsky web files on the remote server.\n\ + - Remove any old Allsky files from the remote server.\n\n\n\ ${DIALOG_UNDERLINE}Are you sure you wish to continue?${DIALOG_NORMAL}" if ! display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_WELCOME_TITLE}" "${DIALOG_MSG}" ; then @@ -378,16 +397,18 @@ function display_complete() if [[ ${CONFIG_TO_USE} == "new" ]]; then EXTRA_TEXT="\nA new configuration file was created for your remote Website." EXTRA_TEXT+="${E}" - elif [[ ${CONFIG_TO_USE} == "remotereallyold" ]]; then + elif [[ ${CONFIG_TO_USE} == "remoteReallyOld" ]]; then 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 at $( date ).\n" + display_msg --logonly info "INSTALLATION COMPLETED.\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}" + The installation of the remote Website is complete\n\ + and the remote Website should be working.\n\n\ + Please check it.\n\n\ + Use the WebUI's 'Editor' page to change settings for your Website.${EXTRA_TEXT}" display_box "--msgbox" "${DIALOG_BACK_TITLE}" "${DIALOG_DONE}" "${DIALOG_TEXT}" clear # Gets rid of background color from last 'dialog' command. @@ -398,6 +419,7 @@ function display_complete() function check_connectivity() { local TEST_FILE="${ME}.txt" + local ERR display_msg --logonly info "Checking remote Website connectivity." if ERR="$( "${ALLSKY_SCRIPTS}/testUpload.sh" --website --silent --file "${TEST_FILE}" 2>&1 )" ; then @@ -417,45 +439,74 @@ function show_debug_message() fi } +# Update a Website config file if it's an old version. +function update_old() +{ + local FILE="${1}" + + local PRIOR_VERSION="$( settings ".${WEBSITE_CONFIG_VERSION}" "${FILE}" )" + local NEW_VERSION="$( settings ".${WEBSITE_CONFIG_VERSION}" "${REPO_WEBCONFIG_FILE}" )" + if [[ ${PRIOR_VERSION} < "${NEW_VERSION}" ]]; then + # Old version, so update to format of the current version. + update_old_website_config_file "${FILE}" "${PRIOR_VERSION}" "${NEW_VERSION}" + return 0 + fi + return 1 +} + # Creates the remote Website configuration file if needed. # See 'pre_install_checks' for details on which configuration file is used. function create_website_config() { local MSG="\nCreating configuration file from ${CONFIG_MESSAGE}" 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 - # of the placeholders as we can - DEST_FILE="${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" + if [[ ${CONFIG_TO_USE} == "new" || ${CONFIG_TO_USE} == "remoteReallyOld" ]]; then + # Need a new config file so copy it from the repo and replace as many + # placeholders as we can. + local 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." + + MSG="Created a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME}" + MSG+=" from repo and updated placeholders." 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." + elif [[ ${CONFIG_TO_USE} == "local" ]]; then + # Using the remote config file on the Pi which may be new or old format. + MSG="Using existing ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME}" + if update_old "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" ; then + MSG+=" and converting to newest format." + fi 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 + elif [[ ${CONFIG_TO_USE} == "prior" ]]; then + # Use the config file from the prior Allsky, replacing as many placeholders as we can. + # If the file is an older version, convert to the newest format. 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." + update_old "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" + + MSG="Copied ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} from the" + MSG+=" $( basename "${PRIOR_ALLSKY_DIR}" ) directory and updated placeholders." display_msg --logonly info "${MSG}" - elif [[ ${CONFIG_TO_USE} == "remotenew" ]]; then - # Use the new remote config file since none were found locally + elif [[ ${CONFIG_TO_USE} == "remoteNew" ]]; then + # Use the new remote config file since none were found locally. + # Replace placeholders and convert it to the newest format. + # Remember that the remote file name is different than what we store on the Pi. if ERR="$( wget -O "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_URL}/${ALLSKY_WEBSITE_CONFIGURATION_FILE}" 2>&1 )"; then replace_website_placeholders "remote" - MSG="Downloading ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}," - MSG+=" and creating a new ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." + update_old "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" + + MSG="Downloaded ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}," + MSG+=" to ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." display_msg --logonly info "${MSG}" else - MSG="Failed to download ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}" + # This "shouldn't" happen since we either already checked the file exists, + # or we uploaded it. + MSG="Failed to download ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}." + MSG+=" Where did it go?" display_aborted "${MSG}" "${ERR}" fi fi @@ -512,9 +563,14 @@ function remove_remote_file() # TODO: FIX: This assumes ftp is used to upload files # 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 )" - + local CMDS="" ERR + [[ -n ${REMOTE_DIR} ]] && CMDS="cd '${REMOTE_DIR}' ;" + CMDS+=" rm -r '${FILENAME}' ; bye" + + ERR="$( lftp -u "${REMOTE_USER},${REMOTE_PASSWORD}" \ + "${REMOTE_PORT}" \ + "${REMOTE_PROTOCOL}://${REMOTE_HOST}" \ + -e "${CMDS}" 2>&1 )" if [[ $? -eq 0 ]] ; then MSG="Deleted remote file '${FILENAME}'" else @@ -536,10 +592,10 @@ function check_if_website_exists() local WEBSITE_FILES=("index.php" "functions.php") if check_if_files_exist "${REMOTE_URL}" "or" "${CONFIG_FILES[@]}" ; then - show_debug_message "Found remote website config file" + show_debug_message "Found a remote Website config file" if check_if_files_exist "${REMOTE_URL}" "and" "${WEBSITE_FILES[@]}" ; then - display_msg --logonly info "Found remote Allsky Website at ${REMOTE_URL}" + display_msg --logonly info "Found a remote Allsky Website at ${REMOTE_URL}" echo "true" return 0 fi @@ -548,52 +604,66 @@ function check_if_website_exists() return 1 } -# Uploads the Website code from ${ALLSKY_WEBSITE} and removes any old -# Allsky files that are no longer needed. +# Uploads the Website code from ${ALLSKY_WEBSITE} and removes any old Allsky +# files that are no longer used. 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 per user request.\n" return fi - local EXTRA_TEXT="" - local EXCLUDE_FOLDERS="" + local EXTRA_TEXT="" local EXCLUDE_FOLDERS="" + local MSG RET RD if [[ -n ${REMOTE_PORT} ]]; then REMOTE_PORT="-p ${REMOTE_PORT}" fi - local MSG="Starting upload to the remote Website" - if [[ ${WEBSITE_EXISTS} == "true" ]]; then + MSG="Starting upload to the remote Website in ${REMOTE_DIR}..." + if [[ ${REMOTE_WEBSITE_EXISTS} == "true" ]]; then + +#### FIX: this won't upload the "index.php" files + + # Don't upload images if the remote Website exists (we assume it already + # has the images). EXCLUDE_FOLDERS="--exclude keograms --exclude startrails --exclude videos" MSG+=", excluding videos, startrails, and keograms" fi display_msg --logonly info "${MSG}${EXTRA_TEXT}." - MSG="\n${MESSAGE}\n\nPlease wait as uploading files could take several minutes..." + MSG="\n${MESSAGE}\n\nUploading new Allsky files. This may take several minutes..." display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" - - { -# TODO: upload.sh should have a "--mirror directory" option. + +# TODO: upload.sh should have a "--mirror from_directory to_directory" option. # 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 - set net:max-retries 2 - set net:timeout 10 - mirror --reverse --verbose --overwrite --ignore-time --transfer-all ${EXCLUDE_FOLDERS} - quit" 2>&1 | grep -v -i "operation not supported" - -# 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}" "check" - done - } >> "$DISPLAY_MSG_LOG" 2>&1 + # shellcheck disable=SC2086 + if [[ -z "${REMOTE_DIR}" ]]; then + RD="" # don't cd to empty directory + else + RD="cd '${REMOTE_DIR}'" + fi + RET="$( lftp -u "${REMOTE_USER},${REMOTE_PASSWORD}" \ + ${REMOTE_PORT} "${REMOTE_PROTOCOL}://${REMOTE_HOST}" \ + -e "lcd '${ALLSKY_WEBSITE}' + set dns:fatal-timeout 10 + set net:max-retries 2 + set net:timeout 10 + ${RD} + mirror --reverse --verbose --overwrite --ignore-time --transfer-all ${EXCLUDE_FOLDERS} + quit" 2>&1 )" + if [[ $? -ne 0 ]]; then + display_aborted "while mirroring Website" "${RET}" + fi + + # Ignore stuff not supported by all FTP servers. + MSG="$( echo "${RET}" | grep -v -i -E "operation not supported|command not understood" )" + display_msg --logonly info "$( indent --spaces "${MSG}" )" + + # Remove any old core files no longer required + for FILE_TO_DELETE in "${OLD_FILES_TO_REMOVE[@]}"; do + remove_remote_file "${FILE_TO_DELETE}" "check" + done display_msg --logonly info "Website upload complete" } @@ -604,7 +674,6 @@ function upload_config_file() local MSG="\nUploading remote Allsky configuration file" display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" display_msg --logonly info "Uploading Website configuration file." - local REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" local ERR="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web \ "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_DIR}" \ @@ -638,7 +707,8 @@ 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." + echo " Must only be used if advised by Allsky support." echo echo "'--auto' Accepts all prompts by default" echo @@ -694,7 +764,7 @@ done [[ ${HELP} == "true" ]] && usage_and_exit 0 [[ ${OK} == "false" ]] && usage_and_exit 1 -display_msg --logonly info "STARTING INSTALLATION AT $( date ).\n" +display_msg --logonly info "STARTING INSTALLATION.\n" pre_install_checks display_welcome From c934a1745af2b35e9fd2ef28f342ff7e4f1a392a Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:35:33 -0700 Subject: [PATCH 11/12] 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 72cc37caf..3aa189c05 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -613,7 +613,7 @@ function upload_remote_website() return fi - local EXTRA_TEXT="" local EXCLUDE_FOLDERS="" + local EXTRA_TEXT="" EXCLUDE_FOLDERS="" local MSG RET RD if [[ -n ${REMOTE_PORT} ]]; then @@ -643,6 +643,7 @@ function upload_remote_website() else RD="cd '${REMOTE_DIR}'" fi + # shellcheck disable=SC2086 RET="$( lftp -u "${REMOTE_USER},${REMOTE_PASSWORD}" \ ${REMOTE_PORT} "${REMOTE_PROTOCOL}://${REMOTE_HOST}" \ -e "lcd '${ALLSKY_WEBSITE}' From a4c6cb1d8ee76a8f93b60dc932ef56b44512f559 Mon Sep 17 00:00:00 2001 From: Eric Claeys <83164203+EricClaeys@users.noreply.github.com> Date: Thu, 7 Nov 2024 03:51:33 -0700 Subject: [PATCH 12/12] Update remote_website_install.sh: Another boatload of changes * DIALOG_WIDTH is now determined based on the width of the window. * Don't display DIALOG_BACK_TITLE - I found it confusing looking. * Replaced display_info_box() and display_prompt_dialog() with calls to display_box(). * Cleaned up some DIALOG_TEXT's. * Make the pre-checks dialog box more dynamic. * Only check for remote config file (new or old) if we found a remote Website. * Warn the user if a remote config file was found on the Pi but no remote Website was found. Not sure what the file would be for. * Improve checking if mirror worked. * Don't display the "Overwriting old file ..." entries - they make it hard to read the output. * Use "--no-perms" to avoid "chmod errors". * Temporarily disable the remote Website before uploading to avoid conflicts. --- remote_website_install.sh | 284 +++++++++++++++++++++++--------------- 1 file changed, 173 insertions(+), 111 deletions(-) diff --git a/remote_website_install.sh b/remote_website_install.sh index 3aa189c05..6115f5646 100755 --- a/remote_website_install.sh +++ b/remote_website_install.sh @@ -4,6 +4,8 @@ # Install or upgrade a remote Allsky Website. +# TODO: handle interrupts like in install.sh + # shellcheck disable=SC2155 [[ -z ${ALLSKY_HOME} ]] && export ALLSKY_HOME="$( realpath "$( dirname "${BASH_ARGV0}" )" )" ME="$( basename "${BASH_ARGV0}" )" @@ -29,7 +31,7 @@ CONFIG_MESSAGE="" REMOTE_WEBSITE_EXISTS="false" # Dialog size variables -DIALOG_WIDTH=70 +DIALOG_WIDTH="$( tput cols )"; ((DIALOG_WIDTH -= 10 )) DIALOG_HEIGHT=25 # Remote connectivity variables @@ -42,7 +44,8 @@ REMOTE_DIR="$( settings ".remotewebsiteimagedir" "${SETTINGS_FILE}" )" REMOTE_PROTOCOL="$( settings ".remotewebsiteprotocol" "${SETTINGS_FILE}" )" REMOTE_PROTOCOL="${REMOTE_PROTOCOL,,}" # convert to lowercase -#### FIX: this script needs to support ALL protocols, not just *ftp*. +#### TODO: this script needs to support ALL protocols, not just *ftp*. +# When it does, remove this check. if [[ ${REMOTE_PROTOCOL} != "sftp" && ${REMOTE_PROTOCOL} != "ftp" && ${REMOTE_PROTOCOL} != "ftps" ]]; then echo -e "\n\n" echo "************* NOTICE *************" @@ -58,14 +61,14 @@ if [[ ${REMOTE_PROTOCOL} != "sftp" && ${REMOTE_PROTOCOL} != "ftp" && ${REMOTE_PR fi # Titles for various dialogs -DIALOG_BACK_TITLE="Allsky Remote Website Installer" +# don't use: DIALOG_BACK_TITLE="Allsky Remote Website Installer" DIALOG_WELCOME_TITLE="Allsky Remote Website Installer" -DIALOG_PRE_CHECK="Pre Installation Checks" +DIALOG_PRE_CHECK="${DIALOG_WELCOME_TITLE} - 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 +# Old Allksy Website files that should be removed if they exist. OLD_CONFIG_NAME="config.js" OLD_FILES_TO_REMOVE=( \ "${OLD_CONFIG_NAME}" \ @@ -135,16 +138,17 @@ function add_dialog_heading() # 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 +# ${2} - The title for the dialog +# ${3} - The text to disply in the dialog +# ${4} - Optional additional arguments to dialog # # Return - 1 if the user selected "No"; 0 otherwise function display_box() { local DIALOG_TYPE="${1}" - local DIALOG_TEXT="${4}" + local DIALOG_TITLE="${2}" + local DIALOG_TEXT="${3}" + local MORE_ARGS="${4}" DIALOG_TEXT="$( add_dialog_heading "${DIALOG_TEXT}" )" if [[ ${TEXT_ONLY} == "true" ]]; then @@ -160,51 +164,34 @@ function display_box() return ${RET} fi - local BACK_TITLE="${2}" - local DIALOG_TITLE="${3}" - local MORE_ARGS="${5}" + # Don't use: it's redundant most of the time --backtitle "${DIALOG_BACK_TITLE}" \ # shellcheck disable=SC2086 dialog \ --colors \ - --backtitle "${BACK_TITLE}" \ --title "${DIALOG_TITLE}" \ ${MORE_ARGS} \ "${DIALOG_TYPE}" "${DIALOG_TEXT}" ${DIALOG_HEIGHT} ${DIALOG_WIDTH} return $? } -function display_info_box() -{ - display_box "--infobox" "${1}" "${2}" "${3}" -} - -function display_prompt_dialog() -{ - 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. -# ${1} - The backtitle for the dialog -# ${2} - The title for the dialog -# ${3} - The filename to display +# ${1} - The title for the dialog +# ${2} - The filename to display # # Returns - Nothing function display_log_file() { - local FILENAME="${3}" + local DIALOG_TITLE="${1}" + local FILENAME="${2}" 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 } @@ -228,52 +215,100 @@ function display_log_file() # Don't bother trying to convert from old-style files. function pre_install_checks() { + display_msg --logonly info "Start pre installation checks." + local MSG="" - local DIALOG_TEXT - DIALOG_TEXT="\nRunning pre installation checks." - DIALOG_TEXT+="\n\nPlease wait as this can take a few minutes to complete.\n\n" + local DIALOG_TEXT DT + DIALOG_TEXT="\nWelcome to the Allsky Remote Website Installer!\n\n" + DIALOG_TEXT+="\nRunning pre installation checks.\n\n" - DIALOG_TEXT+="\n1 - Checking for local files" - display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - display_msg --logonly info "Start pre installation checks." + DIALOG_TEXT+="\n1 - Checking for remote Website configuration file on Pi: " + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" if [[ -f ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then # 1a. - MSG="Found ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} on Pi." + DT="FOUND" + MSG="Found ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." display_msg --logonly info "${MSG}" HAVE_NEW_CONFIG="true" +### FIX / TODO: Should this be used? +# During Allsky upgrades, if the OLD directory exists users are asked if +# it should be used. If "yes", then the prior remote Website config file was +# copied to the new Allsky, so 1a should match. +# If the user answered "no", don't use OLD Allsky, we probably shouldn't either. elif [[ -f ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then # 1b. + DT="FOUND ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} in '${PRIOR_CONFIG_DIR}'" MSG="Found ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}." display_msg --logonly info "${MSG}" HAVE_PRIOR_CONFIG="true" - fi - DIALOG_TEXT+="\n2 - Checking if an existing remote Website exists" - display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + else + DT="NOT FOUND" + display_msg --logonly info "No local config files found." + fi + DIALOG_TEXT+="${DT}." + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + DIALOG_TEXT+="\n2 - Checking for existing remote Website: " + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + local INDENT=" " REMOTE_WEBSITE_EXISTS="$( check_if_website_exists )" if [[ ${REMOTE_WEBSITE_EXISTS} == "true" ]]; then + + # If we didn't find a remote Website configuration file on the Pi, + # it's "should be" an old-style Website since the user wasn't + # using the WebUI to configure it. + + DIALOG_TEXT+="FOUND." + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + # 2a. - DIALOG_TEXT+="\n2a - Checking for remote Website configuration file" - display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + DIALOG_TEXT+="\n${INDENT}* Checking it for new-style configuration file: " + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" local NEW_CONFIG_FILES=("${ALLSKY_WEBSITE_CONFIGURATION_NAME}") if check_if_files_exist "${REMOTE_URL}" "or" "${NEW_CONFIG_FILES[@]}" ; then HAVE_NEW_REMOTE_CONFIG="true" - MSG="Found current configuration file on the remote server." + DIALOG_TEXT+="Found." + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + MSG="Found a current configuration file on the remote server." display_msg --logonly info "${MSG}" + else + # 2b. + DIALOG_TEXT+="Not found." + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + + DIALOG_TEXT+="\n${INDENT}* Checking it for old-style configuration file:" + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + local REALLY_OLD_CONFIG_FILES=("${OLD_CONFIG_NAME}") + if check_if_files_exist "${REMOTE_URL}" "or" "${REALLY_OLD_CONFIG_FILES[@]}" ; then + HAVE_REALLY_OLD_REMOTE_CONFIG="true" + DT="FOUND" + MSG="Found old-style ${OLD_CONFIG_NAME} file on the remote Website." + display_msg --logonly info "${MSG}" + else + # This "shouldn't" happen - the remote Website should have SOME type + # of configuration file. + DT="NOT FOUND" + fi + DIALOG_TEXT+="${DT}." + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" fi - - # 2b. - DIALOG_TEXT+="\n2b - Checking for old-style remote Website configuration file" - display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - local REALLY_OLD_CONFIG_FILES=("${OLD_CONFIG_NAME}") - if check_if_files_exist "${REMOTE_URL}" "or" "${REALLY_OLD_CONFIG_FILES[@]}" ; then - HAVE_REALLY_OLD_REMOTE_CONFIG="true" - MSG="Found old-format ${OLD_CONFIG_NAME} file on the remote Website." - display_msg --logonly info "${MSG}" + else + # No remote Website found. + DIALOG_TEXT+="NOT FOUND." + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + + if [[ ${HAVE_NEW_CONFIG} == "true" || ${HAVE_PRIOR_CONFIG} == "true" ]]; then + DIALOG_TEXT+="${DIALOG_RED}" + DIALOG_TEXT+="\n${INDENT}WARNING: a remote configuration file exists" + DIALOG_TEXT+="\n${INDENT}but a remote Website wasn't found." + DIALOG_TEXT+="\n${INDENT}What is the configuration file for?" + DIALOG_TEXT+="${DIALOG_NORMAL}" + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" fi + fi if [[ ${HAVE_NEW_CONFIG} == "true" ]]; then @@ -282,19 +317,19 @@ function pre_install_checks() else MSG="Using the local remote configuration file (no remote file found)." fi - display_msg --logonly info "${MSG}." + display_msg --logonly info "${MSG}" CONFIG_TO_USE="local" # it may be old or current format CONFIG_MESSAGE="the current remote" elif [[ ${HAVE_PRIOR_CONFIG} == "true" ]]; then - MSG="Using the $( basename "${PRIOR_ALLSKY_DIR}" ) configuration file;" - MSG+=" placeholders will be updated." + local B="$( basename "${PRIOR_ALLSKY_DIR}" )" + MSG="Using the ${B} configuration file." display_msg --logonly info "${MSG}" CONFIG_TO_USE="prior" # it may be old or current format - CONFIG_MESSAGE="the $( basename "${PRIOR_ALLSKY_DIR}" )" + CONFIG_MESSAGE="the ${B}" elif [[ ${HAVE_NEW_REMOTE_CONFIG} == "true" ]]; then - MSG="Using new format Website configuration file on the remote Website;" + MSG="Using new-style Website configuration file on the remote Website;" MSG+=" it will be downloaded and saved locally." display_msg --logonly info "${MSG}" CONFIG_TO_USE="remoteNew" @@ -313,13 +348,24 @@ function pre_install_checks() CONFIG_TO_USE="new" fi - check_connectivity + DIALOG_TEXT+="\n * Checking ability to upload to it: " + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + display_msg --logonly info "Checking remote Website connectivity." + local ERR="$( check_connectivity )" + if [[ -z ${ERR} ]]; then + DIALOG_TEXT+="PASSED." + display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + show_debug_message "The remote Website connectivity test succeeded." + else + local ERROR_MSG="\nERROR: The remote Website connectivity check failed." + display_aborted "${ERROR_MSG}" "${ERR}" + fi 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_UNDERLINE}Press OK to continue${DIALOG_NORMAL}" - display_box "--msgbox" "${DIALOG_BACK_TITLE}" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + display_box "--msgbox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" } # Displays the welcome dialog indicating what steps will be taken @@ -332,22 +378,20 @@ function display_welcome() if [[ ${AUTO_CONFIRM} == "false" ]]; then 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\ + local DIALOG_TEXT="\n\ + This script will now:\n\n\ \ - 1) Check the remote Website connectivity - PASSED\n\ - 2) Use ${CONFIG_MESSAGE} configuration file\n\ - 3) Upload the new remote Website code\n\ - 4) Upload the remote Website configuration file\n\ - 5) Enable the remote Website\n\n\ + 1) Use ${CONFIG_MESSAGE} configuration file.\n\ + 2) Upload the new remote Website code.\n\ + 3) Upload the remote Website configuration file.\n\ + 4) Enable the remote Website.\n\n\ \ ${DIALOG_RED}WARNING! This will:${DIALOG_NORMAL}\n\ - Overwrite the old Allsky web files on the remote server.\n\ - Remove any old Allsky files from the remote server.\n\n\n\ ${DIALOG_UNDERLINE}Are you sure you wish to continue?${DIALOG_NORMAL}" - if ! display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_WELCOME_TITLE}" "${DIALOG_MSG}" ; then + if ! display_box "--yesno" "${DIALOG_WELCOME_TITLE}" "${DIALOG_TEXT}" ; then display_aborted "--user" "at the Welcome dialog" "" fi else @@ -369,22 +413,22 @@ function display_aborted() local EXTRA_TEXT="${1}" local ERROR_MSG="${2}" - display_msg --logonly info "${ABORT_MSG} at $( date ) ${EXTRA_TEXT}.\n" - local MSG="\nThe installation of the remote Website was aborted ${EXTRA_TEXT}." + display_msg --logonly info "${ABORT_MSG} ${EXTRA_TEXT}.\n" + local MSG="\nInstallation of the remote Website aborted ${EXTRA_TEXT}." if [[ -n ${ERROR_MSG} ]]; then local DIALOG_PROMPT="${MSG}\n\n" DIALOG_PROMPT+="${DIALOG_UNDERLINE}Would you like to view the error message?${DIALOG_NORMAL}" - if display_prompt_dialog "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${DIALOG_PROMPT}" ; then - display_box "--msgbox" "${DIALOG_BACK_TITLE}" "${DIALOG_TITLE_LOG}" "${ERROR_MSG}" "--scrollbar" + if display_box "--yesno" "${DIALOG_INSTALL}" "${DIALOG_PROMPT}" ; then + display_box "--msgbox" "${DIALOG_TITLE_LOG}" "${ERROR_MSG}" "--scrollbar" if false; then - display_log_file "${DIALOG_BACK_TITLE}" "${DIALOG_TITLE_LOG}" "${DISPLAY_MSG_LOG}" + display_log_file "${DIALOG_TITLE_LOG}" "${DISPLAY_MSG_LOG}" fi fi fi clear # Gets rid of background color from last 'dialog' command. - display_msg info "${ERROR_MSG}" + # Not needed: display_msg info "${ERROR_MSG}" exit 1 } @@ -409,25 +453,24 @@ function display_complete() and the remote Website should be working.\n\n\ Please check it.\n\n\ Use the WebUI's 'Editor' page to change settings for your Website.${EXTRA_TEXT}" - display_box "--msgbox" "${DIALOG_BACK_TITLE}" "${DIALOG_DONE}" "${DIALOG_TEXT}" + display_box "--msgbox" "${DIALOG_DONE}" "${DIALOG_TEXT}" clear # Gets rid of background color from last 'dialog' command. display_msg info "\nEnjoy your remote Allsky Website!\n" } -# Check connectivity to the remote Website. +# Check connectivity to the remote Website by trying to upload a file to it. +# Return "" for success, else the error message. function check_connectivity() { local TEST_FILE="${ME}.txt" local ERR - display_msg --logonly info "Checking remote Website connectivity." if ERR="$( "${ALLSKY_SCRIPTS}/testUpload.sh" --website --silent --file "${TEST_FILE}" 2>&1 )" ; then - show_debug_message "The remote Website connectivity test succeeded." remove_remote_file "${TEST_FILE}" "do not check" + echo "" else - local ERROR_MSG="\nERROR: The remote Website connectivity check failed." - display_aborted "${ERROR_MSG}" "${ERR}" + echo "${ERR}" fi } @@ -458,8 +501,8 @@ function update_old() # See 'pre_install_checks' for details on which configuration file is used. function create_website_config() { - local MSG="\nCreating configuration file from ${CONFIG_MESSAGE}" - display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" + local MSG="Creating configuration file from ${CONFIG_MESSAGE}" + display_msg --logonly info "${MSG}" if [[ ${CONFIG_TO_USE} == "new" || ${CONFIG_TO_USE} == "remoteReallyOld" ]]; then # Need a new config file so copy it from the repo and replace as many @@ -561,7 +604,7 @@ function remove_remote_file() fi fi -# TODO: FIX: This assumes ftp is used to upload files +# TODO: This assumes ftp is used to upload files # upload.sh should accept "--remove FILE" option. local CMDS="" ERR [[ -n ${REMOTE_DIR} ]] && CMDS="cd '${REMOTE_DIR}' ;" @@ -613,52 +656,65 @@ function upload_remote_website() return fi - local EXTRA_TEXT="" EXCLUDE_FOLDERS="" - local MSG RET RD + local EXTRA_TEXT="" EXCLUDE_FOLDERS="" MSG if [[ -n ${REMOTE_PORT} ]]; then REMOTE_PORT="-p ${REMOTE_PORT}" fi - MSG="Starting upload to the remote Website in ${REMOTE_DIR}..." + MSG="Starting upload to the remote Website" + [[ -n ${REMOTE_DIR} ]] && MSG+=" in ${REMOTE_DIR}" if [[ ${REMOTE_WEBSITE_EXISTS} == "true" ]]; then -#### FIX: this won't upload the "index.php" files - # Don't upload images if the remote Website exists (we assume it already # has the images). + # However, we must upload the index.php files. EXCLUDE_FOLDERS="--exclude keograms --exclude startrails --exclude videos" - MSG+=", excluding videos, startrails, and keograms" + +# FIX: the --include doesn't work - the files aren't uploaded. +# Do we need to do a second lftp mirror to upload them? + EXCLUDE_FOLDERS+=" --include keograms/index.php" + EXCLUDE_FOLDERS+=" --include startrails/index.php" + EXCLUDE_FOLDERS+=" --include videos/index.php" + MSG+=" (without videos, images, and their thumbnails)." fi display_msg --logonly info "${MSG}${EXTRA_TEXT}." - MSG="\n${MESSAGE}\n\nUploading new Allsky files. This may take several minutes..." - display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" + MSG="\n${MSG}\n\nThis may take several minutes..." + display_box "--infobox" "${DIALOG_INSTALL}" "${MSG}" # TODO: upload.sh should have a "--mirror from_directory to_directory" option. # This would also fix the problem that we're assuming the "ftp" protocol is used. + local NL="$( echo -e "\n " )" # Need space otherwise it doesn't work - not sure why + local CMDS=" lcd '${ALLSKY_WEBSITE}'" + CMDS+="${NL}set dns:fatal-timeout 10; set net:max-retries 2; set net:timeout 10" # shellcheck disable=SC2086 - if [[ -z "${REMOTE_DIR}" ]]; then - RD="" # don't cd to empty directory + if [[ -n "${REMOTE_DIR}" ]]; then + CMDS+="${NL}cd '${REMOTE_DIR}'" else - RD="cd '${REMOTE_DIR}'" + CMDS+="${NL}cd ." # for debugging fi + CMDS+="${NL}mirror --reverse --no-perms --verbose --overwrite --ignore-time --transfer-all" + [[ -n ${EXCLUDE_FOLDERS} ]] && CMDS+=" ${EXCLUDE_FOLDERS}" + CMDS+="${NL}bye" + + local TMP="${ALLSKY_TMP}/remote_upload.txt" + echo -e "CMDS=${CMDS}\n======" > "${TMP}" # shellcheck disable=SC2086 - RET="$( lftp -u "${REMOTE_USER},${REMOTE_PASSWORD}" \ - ${REMOTE_PORT} "${REMOTE_PROTOCOL}://${REMOTE_HOST}" \ - -e "lcd '${ALLSKY_WEBSITE}' - set dns:fatal-timeout 10 - set net:max-retries 2 - set net:timeout 10 - ${RD} - mirror --reverse --verbose --overwrite --ignore-time --transfer-all ${EXCLUDE_FOLDERS} - quit" 2>&1 )" - if [[ $? -ne 0 ]]; then - display_aborted "while mirroring Website" "${RET}" + lftp -u "${REMOTE_USER},${REMOTE_PASSWORD}" \ + ${REMOTE_PORT} "${REMOTE_PROTOCOL}://${REMOTE_HOST}" -e "${CMDS}" >> "${TMP}" 2>&1 + local RET_CODE=$? + + # Ignore stuff not supported by all FTP servers and stuff we don't want to see. + local IGNORE="operation not supported|command not understood|hostname checking disabled|Overwriting old file" + MSG="$( grep -v -i -E "${IGNORE}" "${TMP}" )" + # If the "mirror" command causes any of the messages above, + # they are counted as errors. + if [[ ${RET_CODE} -ne 0 ]]; then + MSG="$( echo -e "RET_CODE=${RET_CODE}\nCMDS=${CMDS}\n${MSG}" | sed -e 's/$/\\n/' )" + display_aborted "while uploading Website" "${MSG}" fi - # Ignore stuff not supported by all FTP servers. - MSG="$( echo "${RET}" | grep -v -i -E "operation not supported|command not understood" )" display_msg --logonly info "$( indent --spaces "${MSG}" )" # Remove any old core files no longer required @@ -673,7 +729,7 @@ function upload_remote_website() function upload_config_file() { local MSG="\nUploading remote Allsky configuration file" - display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "${MSG}" + display_box "--infobox" "${DIALOG_INSTALL}" "${MSG}" display_msg --logonly info "Uploading Website configuration file." local ERR="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web \ @@ -719,10 +775,15 @@ usage_and_exit() exit "${RET}" } +# Disable the remote Website. +function disable_remote_website() +{ + update_json_file ".useremotewebsite" "false" "${SETTINGS_FILE}" + display_msg --logonly info "Remote Website temporarily disabled." +} # Enable the remote Website. function enable_remote_website() { - display_info_box "${DIALOG_BACK_TITLE}" "${DIALOG_INSTALL}" "\nEnabling remote Website" update_json_file ".useremotewebsite" "true" "${SETTINGS_FILE}" display_msg --logonly info "Remote Website enabled." } @@ -770,6 +831,7 @@ display_msg --logonly info "STARTING INSTALLATION.\n" pre_install_checks display_welcome create_website_config +disable_remote_website upload_remote_website upload_config_file enable_remote_website