diff --git a/remoteWebsiteInstall.sh b/remoteWebsiteInstall.sh index 660afd36d..f241d56f4 100755 --- a/remoteWebsiteInstall.sh +++ b/remoteWebsiteInstall.sh @@ -22,17 +22,17 @@ source "${ALLSKY_SCRIPTS}/installUpgradeFunctions.sh" || exit "${EXIT_ERROR_STOP DISPLAY_MSG_LOG="${ALLSKY_LOGS}/${ME/.sh/}.log" # Config variables -HAVE_NEW_CONFIG="false" -HAVE_PRIOR_CONFIG="false" -HAVE_NEW_REMOTE_CONFIG="false" +HAVE_LOCAL_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 )) DIALOG_HEIGHT=25 +INDENT=" " # indent each line so it's easier to read # Remote connectivity variables REMOTE_URL="$( settings ".remotewebsiteurl" "${SETTINGS_FILE}" )" @@ -78,7 +78,7 @@ OLD_FILES_TO_REMOVE=( \ "virtualsky.json" \ "README.md" \ "version" \ - "myImages") + ".git/" ) ############################################## functions @@ -90,19 +90,23 @@ function enter_yes_no() local RESULT=1 local ANSWER - while true; do - echo -e "${TEXT}" - read -r -p "Do you want to continue? (y/n): " ANSWER - ANSWER="${ANSWER,,}" # convert to lowercase - - if [[ ${ANSWER} == "y" || ${ANSWER} == "yes" ]]; then - return 0 - elif [[ ${ANSWER} == "n" || ${ANSWER} == "no" ]]; then - return 1 - else - echo -e "\nInvalid response. Please enter y/yes or n/no." - fi - done + if [[ ${AUTO_CONFIRM} == "false" ]]; then + while true; do + echo -e "${TEXT}" + read -r -p "Do you want to continue? (y/n): " ANSWER + ANSWER="${ANSWER,,}" # convert to lowercase + + if [[ ${ANSWER} == "y" || ${ANSWER} == "yes" ]]; then + return 0 + elif [[ ${ANSWER} == "n" || ${ANSWER} == "no" ]]; then + return 1 + else + echo -e "\nInvalid response. Please enter y/yes or n/no." + fi + done + else + return 0 + fi return "${RESULT}" } @@ -111,8 +115,10 @@ function enter_yes_no() # This function is only used when running in text (--text) mode. function press_any_key() { - echo -e "${1}\nPress any key to continue..." - read -r -n1 -s + if [[ ${AUTO_CONFIRM} == "false" ]]; then + echo -e "${1}\nPress any key to continue..." + read -r -n1 -s + fi } # Add a common heading to the dialog text. @@ -206,8 +212,8 @@ function display_log_file() # # 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. +# 1b. No longer used, assume upgrade of Allsky will copy the configuration file +# to the new installation # # 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. @@ -226,111 +232,88 @@ 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" - -### 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" - + HAVE_LOCAL_REMOTE_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 + local SPACES="${INDENT}${INDENT}" + REMOTE_WEBSITE_IS_VALID="$( check_if_website_is_valid )" + if [[ ${REMOTE_WEBSITE_IS_VALID} == "true" ]]; then + # There is at least one config file. - # 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." + DIALOG_TEXT+="WORKING." display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" # 2a. - DIALOG_TEXT+="\n${INDENT}* Checking it for new-style configuration file: " + DIALOG_TEXT+="\n${SPACES}* 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" - DIALOG_TEXT+="Found." + if [[ ${HAVE_NEW_STYLE_REMOTE_CONFIG} == "true" ]]; then + 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:" + DIALOG_TEXT+="\n${SPACES}* 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}" + if [[ ${HAVE_REALLY_OLD_REMOTE_CONFIG} == "true" ]]; then + DT="FOUND." else # This "shouldn't" happen - the remote Website should have SOME type # of configuration file. - DT="NOT FOUND" + DT="ERROR: 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_REMOTE_CONFIG} == "true" ]]; then + # The remote's config file is on the Pi but the remote Website doesn't have a + # config file and/or the Website source files. + # This could happen if the user HAD a working remote Website but moved all the files to, + # for example, "allsky/OLD", before upgrading. 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+="\n${SPACES}WARNING: a remote configuration file exists" + DIALOG_TEXT+="\n${SPACES}but a working remote Website wasn't found." + DIALOG_TEXT+="\n${SPACES}If you moved the remote Website before upgrading, ignore this message." + DIALOG_TEXT+="\n\n${SPACES}Either way, a new Website will be created." DIALOG_TEXT+="${DIALOG_NORMAL}" display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" + else + DIALOG_TEXT+="${DIALOG_RED}" + DIALOG_TEXT+="\n${SPACES}WARNING: No configuration file found so a new one will be created." + DIALOG_TEXT+="${DIALOG_NORMAL}" fi 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 CONFIG_MESSAGE="the current remote" - elif [[ ${HAVE_PRIOR_CONFIG} == "true" ]]; then - 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 ${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 +328,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${SPACES} * 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 +366,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\ - 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\ +${INDENT} 1) Use ${CONFIG_MESSAGE} configuration file.\n\ +${INDENT} 2) Upload the new remote Website code.\n\ +${INDENT} 3) Upload the remote Website configuration file.\n\ +${INDENT} 4) Enable the remote Website.\n\ +${INDENT} 5) Any existing startrails, keograms, and/or timelapse will NOT be touched.\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_RED}NOTE: This will:${DIALOG_NORMAL}\n\ +${INDENT}- Overwrite the old Allsky web files on the remote server.\n\ +${INDENT}- 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 +406,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 +417,29 @@ 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+="\n${INDENT} '${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} (remote Allsky Website)'" + E+="\n${INDENT}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${INDENT}${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${INDENT}${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${INDENT}The installation of the remote Website is complete.\n\n${INDENT}Please check it." + DIALOG_TEXT+="\n\n${INDENT}${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. @@ -529,39 +508,32 @@ function create_website_config() fi display_msg --logonly info "${MSG}" - 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" - 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. # 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}" + local VER="$( settings ".${WEBSITE_ALLSKY_VERSION}" "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" )" + if [[ ${VER} == "${ALLSKY_VERSION}" ]]; then + display_msg --logonly info "'${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME}' already at ${ALLSKY_VERSION}." + else + update_json_file ".${WEBSITE_ALLSKY_VERSION}" "${ALLSKY_VERSION}" "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" + display_msg --logonly info "Updated '${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME}' to ${ALLSKY_VERSION}." + fi } # Check if a remote file, or array of files, exist. @@ -570,6 +542,7 @@ function create_website_config() # ${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}" @@ -579,14 +552,14 @@ 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" + 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 @@ -608,7 +581,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 +598,55 @@ 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 FOUND="false" local WEBSITE_FILES=("index.php" "functions.php") - if check_if_files_exist "${REMOTE_URL}" "or" "${CONFIG_FILES[@]}" ; then - show_debug_message "Found a remote Website config file" + display_msg --logonly info "Looking for old and new config files at ${REMOTE_URL}" + if check_if_files_exist "${REMOTE_URL}" "or" "${OLD_CONFIG_NAME}" ; then + HAVE_REALLY_OLD_REMOTE_CONFIG="true" + FOUND="true" + fi + if check_if_files_exist "${REMOTE_URL}" "or" "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" ; then + HAVE_NEW_STYLE_REMOTE_CONFIG="true" + FOUND="true" + fi + + if [[ ${FOUND} == "true" ]]; then + local MSG=" config files found:" + [[ ${HAVE_REALLY_OLD_REMOTE_CONFIG} == "true" ]] && MSG+=" ${OLD_CONFIG_NAME}" + [[ ${HAVE_NEW_STYLE_REMOTE_CONFIG} == "true" ]] && MSG+=" ${ALLSKY_WEBSITE_CONFIGURATION_NAME}" 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 + # If the user just created the "allsky" directory on the Website but nothing else, + # we'll get here. + display_msg --logonly info " Did not find a config file; assuming new, unpopulated Website." fi + echo "false" return 1 } @@ -666,23 +660,25 @@ function upload_remote_website() return fi - local EXTRA_TEXT="" EXCLUDE_FOLDERS="" MSG + local EXTRA_TEXT="" EXCLUDE_FILES="" MSG MSG="Starting upload to the remote Website" [[ -n ${REMOTE_DIR} ]] && MSG+=" in ${REMOTE_DIR}" - if [[ ${REMOTE_WEBSITE_EXISTS} == "true" ]]; then + +# TODO: for == "false", should prompt user if they want the files uploaded. + + 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" - -# ALEX: 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" + EXCLUDE_FILES="--exclude-glob=videos/*.mp4" + EXCLUDE_FILES+=" --exclude-glob=keograms/*.jpg" + EXCLUDE_FILES+=" --exclude-glob=startrails/*.jpg" + EXCLUDE_FILES+=" --exclude-glob=*/thumbnails/*.jpg" MSG+=" (without videos, images, and their thumbnails)." + else + MSG+=" (including any videos, images, and their thumbnails)." fi display_msg --logonly info "${MSG}${EXTRA_TEXT}." @@ -701,7 +697,7 @@ function upload_remote_website() CMDS+="${NL}cd ." # for debugging fi CMDS+="${NL}mirror --reverse --no-perms --verbose --overwrite --ignore-time --transfer-all" - [[ -n ${EXCLUDE_FOLDERS} ]] && CMDS+=" ${EXCLUDE_FOLDERS}" + [[ -n ${EXCLUDE_FILES} ]] && CMDS+=" ${EXCLUDE_FILES}" CMDS+="${NL}bye" local TMP="${ALLSKY_TMP}/remote_upload.txt" @@ -725,26 +721,53 @@ 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 + local DIR="myImages" + if check_if_files_exist "${REMOTE_URL}" "or" "${DIR}" ; then + display_msg --logonly info "Old directory '${DIR}' exists on server." + + # It would be nice to move the files for the user, + # but almost no one has a "myImages" directory. + MSG="\n${INDENT}${DIALOG_RED}NOTE:${DIALOG_NORMAL}" + MSG+="\n${INDENT}Move any files in '${DIR}' on the remote Website to" + MSG+="\n${INDENT}the 'myFiles' directory, then remove '${DIR}'." + MSG+="\n${INDENT}It is no longer used." + display_box "--msgbox" "${DIALOG_INSTALL}" "${MSG}" + else + display_msg --logonly info "Old file '${DIR}' does not exist." + fi + 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}" @@ -794,6 +817,14 @@ function enable_remote_website() display_msg --logonly info "Remote Website enabled." } +function post_data() +{ + local MSG + # --fromWebUI only displays summary. + MSG="$( "${ALLSKY_SCRIPTS}/postData.sh" --fromWebUI --allfiles 2>&1 )" + display_msg --logonly info "${MSG}" +} + ############################################## main body OK="true" HELP="false" @@ -839,6 +870,7 @@ display_welcome create_website_config disable_remote_website upload_remote_website -upload_config_file +upload_remote_config_file enable_remote_website +post_data display_complete