diff --git a/remoteWebsiteInstall.sh b/remoteWebsiteInstall.sh index 23e710221..a37b39bc0 100755 --- a/remoteWebsiteInstall.sh +++ b/remoteWebsiteInstall.sh @@ -22,13 +22,13 @@ source "${ALLSKY_SCRIPTS}/installUpgradeFunctions.sh" || exit "${EXIT_ERROR_STOP DISPLAY_MSG_LOG="${ALLSKY_LOGS}/${ME/.sh/}.log" # Config variables -HAVE_NEW_CONFIG="false" +HAVE_LOCAL_CONFIG="false" HAVE_PRIOR_CONFIG="false" -HAVE_NEW_REMOTE_CONFIG="false" +HAVE_NEW_STYLE_REMOTE_CONFIG="false" HAVE_REALLY_OLD_REMOTE_CONFIG="false" CONFIG_TO_USE="" # which Website configuration file to use? CONFIG_MESSAGE="" -REMOTE_WEBSITE_EXISTS="false" +REMOTE_WEBSITE_IS_VALID="false" # Dialog size variables DIALOG_WIDTH="$( tput cols )"; ((DIALOG_WIDTH -= 10 )) @@ -77,8 +77,8 @@ OLD_FILES_TO_REMOVE=( \ "getTime.php" \ "virtualsky.json" \ "README.md" \ - "version" \ - "myImages") + "version" ) +OLD_FILES_TO_WARN=( "myImages" ) ############################################## functions @@ -104,7 +104,7 @@ function enter_yes_no() fi done - return ${RESULT} + return "${RESULT}" } # prompt the user to press any key. @@ -163,7 +163,7 @@ function display_box() else echo -e "${DIALOG_TEXT}" fi - return ${RET} + return "${RET}" fi # Don't use: it's redundant most of the time --backtitle "${DIALOG_BACK_TITLE}" \ @@ -226,44 +226,44 @@ function pre_install_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. DT="FOUND" MSG="Found ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." display_msg --logonly info "${MSG}" - HAVE_NEW_CONFIG="true" + HAVE_LOCAL_CONFIG="true" -### FIX / TODO: Should this be used? +### FIX: ALEX: I don't think this "elif" part should 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. +# HAVE_PRIOR_CONFIG should also be deleted. elif [[ -f ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE} ]]; then # 1b. - DT="FOUND ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} in '${PRIOR_CONFIG_DIR}'" + DT="FOUND ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}." MSG="Found ${PRIOR_REMOTE_WEBSITE_CONFIGURATION_FILE}." display_msg --logonly info "${MSG}" HAVE_PRIOR_CONFIG="true" else DT="NOT FOUND" - display_msg --logonly info "No local config files found." + display_msg --logonly info "No local config file found." fi DIALOG_TEXT+="${DT}." display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - DIALOG_TEXT+="\n2 - Checking for existing remote Website: " + DIALOG_TEXT+="\n2 - Checking for working 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 + REMOTE_WEBSITE_IS_VALID="$( check_if_website_is_valid )" + if [[ ${REMOTE_WEBSITE_IS_VALID} == "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 + # it "should be" an old-style Website since the user wasn't # using the WebUI to configure it. - DIALOG_TEXT+="FOUND." + DIALOG_TEXT+="WORKING." display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" # 2a. @@ -271,14 +271,14 @@ function pre_install_checks() 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" - DIALOG_TEXT+="Found." + HAVE_NEW_STYLE_REMOTE_CONFIG="true" + 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." + DIALOG_TEXT+="NOT FOUND." display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" DIALOG_TEXT+="\n${INDENT}* Checking it for old-style configuration file:" @@ -286,23 +286,23 @@ function pre_install_checks() 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" + 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" + DT="NOT FOUND." fi - DIALOG_TEXT+="${DT}." + DIALOG_TEXT+="${DT}" display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" fi else - # No remote Website found. - DIALOG_TEXT+="NOT FOUND." + # No working remote Website found. + DIALOG_TEXT+="NOT WORKING." display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" - if [[ ${HAVE_NEW_CONFIG} == "true" || ${HAVE_PRIOR_CONFIG} == "true" ]]; then + if [[ ${HAVE_LOCAL_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." @@ -313,11 +313,11 @@ function pre_install_checks() fi - if [[ ${HAVE_NEW_CONFIG} == "true" ]]; then - if [[ ${HAVE_NEW_REMOTE_CONFIG} == "true" ]]; then - MSG="A remote configuration file was found but using the local version instead." + if [[ ${HAVE_LOCAL_CONFIG} == "true" ]]; then + if [[ ${HAVE_NEW_STYLE_REMOTE_CONFIG} == "true" ]]; then + MSG="A new-style remote configuration file was found but using the local version instead." else - MSG="Using the local remote configuration file (no remote file found)." + MSG="Using the remote configuration file on the Pi (no remote file found)." fi display_msg --logonly info "${MSG}" CONFIG_TO_USE="local" # it may be old or current format @@ -330,7 +330,7 @@ function pre_install_checks() CONFIG_TO_USE="prior" # it may be old or current format CONFIG_MESSAGE="the ${B}" - elif [[ ${HAVE_NEW_REMOTE_CONFIG} == "true" ]]; then + elif [[ ${HAVE_NEW_STYLE_REMOTE_CONFIG} == "true" ]]; then MSG="Using new-style Website configuration file on the remote Website;" MSG+=" it will be downloaded and saved locally." display_msg --logonly info "${MSG}" @@ -345,12 +345,13 @@ function pre_install_checks() CONFIG_MESSAGE="a new" else - MSG="Unable to determine the configuration file to use. A new one will be created." + MSG="No configuration file found - a new one will be created." display_msg --logonly info "${MSG}" CONFIG_TO_USE="new" + CONFIG_MESSAGE="a new" fi - DIALOG_TEXT+="\n * Checking ability to upload to it: " + DIALOG_TEXT+="\n * Checking ability to upload to Website: " display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" display_msg --logonly info "Checking remote Website connectivity." local ERR="$( check_connectivity )" @@ -382,19 +383,16 @@ function display_welcome() display_msg --logonly info "Displaying the welcome dialog." local DIALOG_TEXT="\n\ This script will now:\n\n\ - \ - 1) Use ${CONFIG_MESSAGE} configuration file.\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\ - \n\ - Any existing startrails, keograms, and/or timelapse will NOT be touched.\n\ + 4) Enable the remote Website.\n\ + 5) Any existing startrails, keograms, and/or timelapse will NOT be touched.\n\ \n\ - ${DIALOG_RED}WARNING! This will:${DIALOG_NORMAL}\n\ + ${DIALOG_RED}NOTE: 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_box "--yesno" "${DIALOG_WELCOME_TITLE}" "${DIALOG_TEXT}" ; then display_aborted "--user" "at the Welcome dialog" "" fi @@ -425,14 +423,10 @@ function display_aborted() DIALOG_PROMPT+="${DIALOG_UNDERLINE}Would you like to view the error message?${DIALOG_NORMAL}" 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_TITLE_LOG}" "${DISPLAY_MSG_LOG}" -fi fi fi clear # Gets rid of background color from last 'dialog' command. - # Not needed: display_msg info "${ERROR_MSG}" exit 1 } @@ -440,27 +434,28 @@ fi # Displays the completed dialog, used at the end of the installation process. 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." + local EXTRA_TEXT E E2 + E="Use the WebUI's 'Editor' page to edit the" + E+=" '${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} (remote Allsky Website)' file" + E2=", replacing any '${NEED_TO_UPDATE}' strings with the correct values." if [[ ${CONFIG_TO_USE} == "new" ]]; then - EXTRA_TEXT="\nA new configuration file was created for your remote Website." - EXTRA_TEXT+="${E}" + EXTRA_TEXT="A new configuration file was created." + EXTRA_TEXT+="\n ${E}${E2}" 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}" + EXTRA_TEXT="You had a very old remote Allsky Website so a new configuration file was created." + EXTRA_TEXT+="\n ${E}${E2}" + else + EXTRA_TEXT="${E} to change settings for your remote Website." fi - display_msg --logonly info "INSTALLATION COMPLETED.\n" - - local DIALOG_TEXT="\n\ - 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}" + local DIALOG_TEXT="\n The installation of the remote Website is complete.\n\n Please check it." + DIALOG_TEXT+="\n\n ${EXTRA_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" + display_msg --log success "\nEnjoy your remote Allsky Website!\n\n${EXTRA_TEXT}" + + display_msg --logonly info "INSTALLATION COMPLETED.\n" } # Check connectivity to the remote Website by trying to upload a file to it. @@ -544,24 +539,23 @@ function create_website_config() # 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 + local FILE="${REMOTE_URL}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}" + if ERR="$( wget -O "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${FILE}" 2>&1 )"; then replace_website_placeholders "remote" update_old "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" - MSG="Downloaded ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}," - MSG+=" to ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}." + MSG="Downloaded '${FILE}' to '${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}'." display_msg --logonly info "${MSG}" else - # This "shouldn't" happen since we either already checked the file exists, + # This "shouldn't" happen since we either already checked that the file exists, # or we uploaded it. - MSG="Failed to download ${ALLSKY_WEBSITE_CONFIGURATION_FILE} from ${REMOTE_URL}." - MSG+=" Where did it go?" + MSG="Failed to download '${FILE}'. Where did it go?" display_aborted "${MSG}" "${ERR}" fi fi - display_msg --logonly info "Updated remote configuration file to ${ALLSKY_VERSION}" update_json_file ".${WEBSITE_ALLSKY_VERSION}" "${ALLSKY_VERSION}" "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" + display_msg --logonly info "Updated remote configuration file to ${ALLSKY_VERSION}." } # Check if a remote file, or array of files, exist. @@ -570,6 +564,10 @@ function create_website_config() # ${3}... - the files # # Returns - 0 if the file(s) exist, 1 if ANY file doesn't exist. + +# TODO: FIX: This doesn't work for "version" or "README.md" or probably any file whose +# type is unknown to the server. + function check_if_files_exist() { local URL="${1}" @@ -579,21 +577,21 @@ function check_if_files_exist() for FILE in "$@"; do url="${URL}/${FILE}" - HTTP_STATUS="$( curl -o /dev/null --head --silent --write-out "%{http_code}" "$url" )" + HTTP_STATUS="$( curl -o /dev/null --head --silent --location --write-out "%{http_code}" "$url" )" - local PRE_MSG="File ${FILE} ${url}" + local PRE_MSG="File '${FILE}'" if [[ ${HTTP_STATUS} == "200" ]] ; then show_debug_message "${PRE_MSG} exists on the remote server" RET_CODE=0 else - show_debug_message "${PRE_MSG} does not exists on the remote server" + show_debug_message "${PRE_MSG} does not exist on the remote server (HTTP_STATUS=${HTTP_STATUS})" if [[ ${AND_OR} == "and" ]]; then return 1 fi fi done - return ${RET_CODE} + return "${RET_CODE}" } # Deletes a file from the remote server. @@ -608,7 +606,6 @@ function remove_remote_file() if [[ ${CHECK} == "check" ]]; then if ! check_if_files_exist "${REMOTE_URL}" "or" "${FILENAME}" ; then - show_debug_message "===== not on server" return fi fi @@ -626,33 +623,42 @@ function remove_remote_file() -e "${CMDS}" 2>&1 )" if [[ $? -eq 0 ]] ; then MSG="Deleted remote file '${FILENAME}'" - else + elif [[ ! ${ERR} =~ "550" ]]; then # does not exist MSG="Unable to delete remote file '${FILENAME}': ${ERR}" + else + show_debug_message "'${FILENAME}' not on remote Website." + return fi 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 valid remote Website exists. +# +# If any of the ${CONFIG_FILES} files exist AND +# all of the ${WEBSITE_FILES} exist then assume the remote Website is valid. # # Returns - echo "true" if it exists, else "false" -function check_if_website_exists() +function check_if_website_is_valid() { local CONFIG_FILES=("${OLD_CONFIG_NAME}" "${ALLSKY_WEBSITE_CONFIGURATION_NAME}") local WEBSITE_FILES=("index.php" "functions.php") + display_msg --logonly info "Looking for a config file at ${REMOTE_URL}" if check_if_files_exist "${REMOTE_URL}" "or" "${CONFIG_FILES[@]}" ; then - show_debug_message "Found a remote Website config file" + local MSG=" Found a config file" if check_if_files_exist "${REMOTE_URL}" "and" "${WEBSITE_FILES[@]}" ; then - display_msg --logonly info "Found a remote Allsky Website at ${REMOTE_URL}" + display_msg --logonly info "${MSG} and a valid Website." echo "true" return 0 + else + display_msg --logonly info "${MSG} but NOT a valid Website." fi + else + display_msg --logonly info " Did not find a config file; assuming invalid site" fi + echo "false" return 1 } @@ -670,10 +676,10 @@ function upload_remote_website() MSG="Starting upload to the remote Website" [[ -n ${REMOTE_DIR} ]] && MSG+=" in ${REMOTE_DIR}" - if [[ ${REMOTE_WEBSITE_EXISTS} == "true" ]]; then + if [[ ${REMOTE_WEBSITE_IS_VALID} == "true" ]]; then # Don't upload images if the remote Website exists (we assume it already - # has the images). + # has the images). "VALID" assumes "EXISTS". # However, we must upload the index.php files. EXCLUDE_FOLDERS="--exclude keograms --exclude startrails --exclude videos" @@ -683,6 +689,8 @@ function upload_remote_website() EXCLUDE_FOLDERS+=" --include startrails/index.php" EXCLUDE_FOLDERS+=" --include videos/index.php" MSG+=" (without videos, images, and their thumbnails)." + else + MSG+=" (including any videos, images, and their thumbnails)." fi display_msg --logonly info "${MSG}${EXTRA_TEXT}." @@ -725,26 +733,54 @@ 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}" "check" + remove_remote_file "${FILE_TO_DELETE}" "do not check" + done + + for FILE_TO_WARN in "${OLD_FILES_TO_WARN[@]}"; do + if check_if_files_exist "${REMOTE_URL}" "or" "${FILE_TO_WARN}" ; then + display_msg --logonly info "Old file '${FILE_TO_WARN}' exists." + if [[ ${FILE_TO_WARN} == "myImages" ]]; then +# TODO: move the files for the user + MSG="NOTE: move any files in '${FILE_TO_WARN}' on the remote Website to 'myFiles'," + MSG+=" then remove '${FILE_TO_WARN}'. It is no longer used." + else + MSG="NOTE: Please remove '${FILE_TO_WARN}' on the remote Website. It is no longer used." + fi + display_box "--infobox" "${DIALOG_INSTALL}" "${MSG}" + else + display_msg --logonly info "Old file '${FILE_TO_WARN}' does not exist." + fi done display_msg --logonly info "Website upload complete" } # Uploads the configuration file for the remote Website. -function upload_config_file() +function upload_remote_config_file() { - local MSG="\nUploading remote Allsky configuration file" + local MSG + + if [[ ! -f "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" ]]; then + MSG="'${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}' not found!" + display_msg --logonly info " ${MSG}" + display_aborted "at the configuration file upload" "${MSG}" + return 1 + fi + + MSG="\nUploading remote Allsky configuration file" display_box "--infobox" "${DIALOG_INSTALL}" "${MSG}" display_msg --logonly info "Uploading Website configuration file." - local ERR="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web \ + local ERR="$( "${ALLSKY_SCRIPTS}/upload.sh" --remote-web --silent \ "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" "${REMOTE_DIR}" \ - "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" 2>&1 )" + "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" "remoteWebsiteInstall" 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}" + local R="${REMOTE_DIR}" + [[ -n ${R} ]] && R+="/" + MSG="'${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}' uploaded to" + MSG+=" '${R}${ALLSKY_WEBSITE_CONFIGURATION_NAME}'" + [[ ${DEBUG} == "true" && -n ${ERR} ]] && MSG+=" (${ERR})" + display_msg --logonly info "${MSG}" else display_msg --logonly info " Failed: ${ERR}" display_aborted "at the configuration file upload" "${ERR}" @@ -839,6 +875,6 @@ display_welcome create_website_config disable_remote_website upload_remote_website -upload_config_file +upload_remote_config_file enable_remote_website display_complete