diff --git a/assets/allsky_camera.png b/assets/allsky_camera.png index 4a5f7770d..c858e58a7 100644 Binary files a/assets/allsky_camera.png and b/assets/allsky_camera.png differ diff --git a/html/documentation/settings/AllskySettingsPage.png b/html/documentation/settings/AllskySettingsPage.png index 5581f8ead..4a5f7770d 100644 Binary files a/html/documentation/settings/AllskySettingsPage.png and b/html/documentation/settings/AllskySettingsPage.png differ diff --git a/scripts/installUpgradeFunctions.sh b/scripts/installUpgradeFunctions.sh index 44d94f957..9fc530bb3 100644 --- a/scripts/installUpgradeFunctions.sh +++ b/scripts/installUpgradeFunctions.sh @@ -33,6 +33,7 @@ export OLD_WEBSITE_LOCATION="${OLD_WEBUI_LOCATION}/allsky" # Directory of prior version of Allsky, if it exists. export PRIOR_ALLSKY_DIR="$( dirname "${ALLSKY_HOME}" )/${ALLSKY_INSTALL_DIR}-OLD" +export OLDEST_ALLSKY_DIR="${PRIOR_ALLSKY_DIR/-OLD$/-OLDEST}" # Prior "config" directory, if it exists. export PRIOR_CONFIG_DIR="${PRIOR_ALLSKY_DIR}/$( basename "${ALLSKY_CONFIG}" )" export PRIOR_WEBSITE_DIR="${PRIOR_ALLSKY_DIR}${ALLSKY_WEBSITE/${ALLSKY_HOME}/}" diff --git a/scripts/utilities/getNewestAllskyVersion.sh b/scripts/utilities/getNewestAllskyVersion.sh index 67972077f..930a0a4bf 100755 --- a/scripts/utilities/getNewestAllskyVersion.sh +++ b/scripts/utilities/getNewestAllskyVersion.sh @@ -13,32 +13,53 @@ source "${ALLSKY_HOME}/variables.sh" || exit "${EXIT_ERROR_STOP}" #shellcheck source-path=scripts source "${ALLSKY_SCRIPTS}/installUpgradeFunctions.sh" || exit "${EXIT_ERROR_STOP}" -if [[ ${1} == "--branch" ]]; then - BRANCH="${2}" - shift 2 -else - BRANCH="${GITHUB_MAIN_BRANCH}" -fi +BRANCH="" +VERSION_ONLY="false" +while [[ $# -gt 0 ]]; do + ARG="${1}" + case "${ARG,,}" in + --branch) + BRANCH="${2}" + shift + ;; + --version-only) + VERSION_ONLY="true" + ;; + esac + shift +done + +[[ -z ${BRANCH} ]] && BRANCH="${GITHUB_MAIN_BRANCH}" GIT_FILE="${GITHUB_RAW_ROOT}/${GITHUB_ALLSKY_REPO}/${BRANCH}/version" -if ! NEWEST_VERSION="$( curl --show-error --silent "${GIT_FILE}" 2>&1 )" ; then - echo "${ME}: ERROR: Unable to get newest Allsky version: ${NEWEST_VERSION}." +if ! NEWEST_INFO="$( curl --show-error --silent "${GIT_FILE}" 2>&1 )" ; then + echo "${ME}: ERROR: Unable to get newest Allsky version: ${NEWEST_INFO}." >&2 exit 1 fi +if [[ -z ${NEWEST_INFO} ]]; then + echo "${ME}: ERROR: Empty newest Allsky version for branch '${BRANCH}'." >&2 + exit 1 +fi +NEWEST_VERSION="$( echo "${NEWEST_INFO}" | head -1 )" if [[ ${NEWEST_VERSION:0:1} != "v" || ${NEWEST_VERSION} == "400: Invalid request" || ${NEWEST_VERSION} == "404: Not Found" ]]; then - echo "${ME}: ERROR: Got unknown newest Allsky version: ${NEWEST_VERSION}." + echo "${ME}: ERROR: Got unknown newest Allsky version: ${NEWEST_VERSION}." >&2 exit 1 fi +if [[ ${VERSION_ONLY} == "true" ]]; then + # Just output the newest version and quit. + echo "${NEWEST_VERSION}" + exit 0 +fi + +#shellcheck disable=SC2119 CURRENT_VERSION="$( get_version )" -NOTE="" RET=0 if [[ ${CURRENT_VERSION} == "${NEWEST_VERSION}" ]]; then RET=0 elif [[ ${CURRENT_VERSION} < "${NEWEST_VERSION}" ]]; then - NOTE="$( get_version --note )" RET="${EXIT_PARTIAL_OK}" else # Current newer than newest - this can happen if testing a newer release. @@ -46,6 +67,7 @@ else fi echo "${NEWEST_VERSION}" -[[ -n ${NOTE} ]] && echo "${NOTE}" +NEWEST_NOTE="$( echo "${NEWEST_INFO}" | tail -1 )" +[[ -n ${NEWEST_NOTE} ]] && echo "${NEWEST_NOTE}" exit "${RET}" diff --git a/upgrade.sh b/upgrade.sh index 3b4b2c10e..b7674d91c 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Upgrade the current Allsky release. +# Upgrade the current Allsky release, carrying current settings forward. [[ -z ${ALLSKY_HOME} ]] && export ALLSKY_HOME="$( realpath "$( dirname "${BASH_ARGV0}" )" )" ME="$( basename "${BASH_ARGV0}" )" @@ -12,50 +12,122 @@ source "${ALLSKY_SCRIPTS}/functions.sh" || exit "${EXIT_ERROR_STOP}" #shellcheck source-path=scripts source "${ALLSKY_SCRIPTS}/installUpgradeFunctions.sh" || exit "${EXIT_ERROR_STOP}" -# High-level view of tasks for upgrade: -# Check if ${PRIOR_ALLSKY_DIR} exists. -# If so, warn user they won't be able to save current release. -# Prompt if user wants to carry current settings to new release. -# If so: -# If ${PRIOR_ALLSKY_DIR} exists, error out -# Rename ${ALLSKY_HOME} to ${PRIOR_ALLSKY_DIR} -# Download new release (with optional branch) from GitHub. -# Execute new release's installation script telling it it's an upgrade. - -############# -# Changes to install.sh needed: +############# TODO: Changes to install.sh needed: # * Accept "--upgrade" argument which means we're doing an upgrade. # - Don't display "**** Welcome to the installer ****" # - Don't prompt for camera # - Don't prompt to reboot # - Don't prompt other things ?? # -############# -# TODO: -# Check for symbolic links -# Allow installing other branches. -############# + +# shellcheck disable=SC2034 +DISPLAY_MSG_LOG="${ALLSKY_LOGS}/upgrade.log" # send log entries here + ############################## functions +#### +do_initial_heading() +{ + local MSG + + MSG="Welcome to the ${SHORT_TITLE}!\n\n" + MSG+="Your current Allsky release will be" + if [[ ${NEWEST_VERSION} == "${ALLSKY_VERSION}" ]]; then + MSG+=" reinstalled" + else + MSG+=" upgraded to ${NEWEST_VERSION}" + fi + MSG+=" and all settings and images maintained." + + if [[ -d ${PRIOR_ALLSKY_DIR} ]]; then + MSG+="\n\n'${PRIOR_ALLSKY_DIR}' will be renamed to '${OLDEST_DIR}'." + fi + MSG+="\n\n'${ALLSKY_HOME}' will be renamed to '${PRIOR_ALLSKY_DIR}'." + MSG+="\n\nThe new release will go in '${ALLSKY_HOME}'." + + MSG+="\n\n\nContinue?" + if ! whiptail --title "${TITLE}" --yesno "${MSG}" 25 "${WT_WIDTH}" \ + 3>&1 1>&2 2>&3; then + display_msg --logonly info "User not ready to continue." + exit 0 + fi + + display_header "Welcome to the ${SHORT_TITLE}" +} + +function check_for_current() +{ + local MSG + + if [[ ${NEWEST_VERSION} == "${ALLSKY_VERSION}" ]]; then + MSG="STARTING REINSTALLATION OF ${ALLSKY_VERSION}.\n" + display_msg --logonly info "${MSG}" + MSG="The current version of Allsky (${ALLSKY_VERSION}) is the newest version." + MSG+="\n\nReinstalling the current version is useful" + MSG+=" if it's corrupted or you just want to start over." + MSG+="\nYour current settings and images will remain." + MSG+="\n\nContinue?" + if ! whiptail --title "${TITLE}" --yesno "${MSG}" 25 "${WT_WIDTH}" \ + 3>&1 1>&2 2>&3; then + display_msg --logonly info "User elected not to continue." + exit 0 + fi + else + MSG="STARTING UPGRADE OF ${ALLSKY_VERSION} to ${NEWEST_VERSION}.\n" + display_msg --logonly info "${MSG}" + fi +} + +# Check if both the prior and the "oldest" directory exist. +# If so, we can't continue since we can't rename the prior directory to the oldest. +check_for_oldest() +{ + [[ ! -d ${PRIOR_ALLSKY_DIR} ]] && return 0 + + if [[ -d ${OLDEST_DIR} ]]; then + local MSG="Directory '${OLDEST_DIR}' already exist." + local MSG2="\n\nIf you want to upgrade to the newest Allsky release, either remove '${OLDEST_DIR}'" + MSG2+=" or rename it to something else, then re-run this upgrade." + whiptail --title "${TITLE}" --msgbox "${MSG}${MSG2}" 25 "${WT_WIDTH}" 3>&1 1>&2 2>&3 + display_msg --log info "${MSG}" + exit 2 + fi + + display_msg --log progress "Renaming '${PRIOR_ALLSKY_DIR}' to '${OLDEST_DIR}." + mv "${PRIOR_ALLSKY_DIR}" "${OLDEST_DIR}" +} + +# Currently not used... +restore_directories() +{ + display_msg --log info "Renaming '${PRIOR_ALLSKY_DIR}' back to '${ALLSKY_HOME}'." + mv "${PRIOR_ALLSKY_DIR}" "${ALLSKY_HOME}" + if [[ -d ${OLDEST_DIR} ]]; then + display_msg --log info "Renaming '${OLDEST_DIR}' back to '${PRIOR_ALLSKY_DIR}'." + mv "${OLDEST_DIR}" "${PRIOR_ALLSKY_DIR}" + fi +} + + function usage_and_exit() { local RET=${1} - { - [[ ${RET} -ne 0 ]] && echo -e "${RED}" - echo -e "\nUpgrade the Allsky software to a newer version.." - echo - echo -e "Usage: ${ME} [--help] [--debug] [--branch branch] [--function function]${NC}" - echo - echo "'--help' displays this message and exits." - echo - echo "'--debug' displays debugging information." - echo - echo "'--branch branch' uses 'branch' instead of the production branch." - echo - echo "'--function' executes the specified function and quits." - echo - [[ ${RET} -ne 0 ]] && echo -e "${NC}" - } >&2 + exec >&2 + + echo + local USAGE="Usage: ${ME} [--help] [--debug] [--branch branch]" + if [[ ${RET} -eq 0 ]]; then + echo "Upgrade the Allsky software to the newest version." + echo -e "\n${USAGE}" + else + E_ "${USAGE}" + fi + echo "Where:" + echo " --help Displays this message and exits." + echo " --debug Displays debugging information." + echo " --branch branch Uses 'branch' instead of the production '${GITHUB_MAIN_BRANCH}' branch." + echo + exit "${RET}" } @@ -67,8 +139,9 @@ ALL_ARGS="$@" OK="true" HELP="false" DEBUG="false"; DEBUG_ARG="" -ACTION="upgrade"; WORD="Upgrade" # default -FUNCTION="" +# shellcheck disable=SC2119 +BRANCH="$( get_branch "" )" +[[ -z ${BRANCH} ]] && BRANCH="${GITHUB_MAIN_BRANCH}" while [[ $# -gt 0 ]]; do ARG="${1}" case "${ARG,,}" in @@ -79,14 +152,18 @@ while [[ $# -gt 0 ]]; do DEBUG="true" DEBUG_ARG="${ARG}" # we can pass this to other scripts ;; - --function) - FUNCTION="${2}" + --branch) + BRANCH="${2}" shift ;; - *) - display_msg error "Unknown argument: '${ARG}'." + -*) + E_ "Unknown argument: '${ARG}'." >&2 OK="false" ;; + + *) + break # end of arguments + ;; esac shift done @@ -94,65 +171,65 @@ done [[ ${OK} == "false" || $# -ne 0 ]] && usage_and_exit 1 [[ ${DEBUG} == "true" ]] && echo "Running: ${ME} ${ALL_ARGS}" -# shellcheck disable=SC2119 -BRANCH="$( get_branch )" -[[ -z ${BRANCH} ]] && BRANCH="${GITHUB_MAIN_BRANCH}" - -# TODO: these are here to keep shellcheck quiet while this script is incomplete. -DEBUG="${DEBUG}" -DEBUG_ARG="${DEBUG_ARG}" -FUNCTION="${FUNCTION}" -if [[ "${ACTION}" != "doUpgrade" ]]; then +if ! NEWEST_VERSION="$( "${ALLSKY_UTILITIES}/getNewestAllskyVersion.sh" --branch "${BRANCH}" --version-only 2>&1 )" ; then + MSG="Unable to determine newest version; cannot continue." + if [[ ${BRANCH} != "${GITHUB_MAIN_BRANCH}" ]]; + then + MSG2="Make sure '${BRANCH}' is a valid branch in GitHub." + else + MSG2="" + fi + display_msg --log error "${MSG}" "${MSG2}" + display_msg --logonly info "${NEWEST_VERSION}" # is the error message. echo - echo "***********************************************" - echo "*** Welcome to the Allsky Software ${WORD} ***" - echo "***********************************************" + exit 2 +fi + +if [[ ! -d ${ALLSKY_CONFIG} ]]; then + MSG="Allsky does not appear to be installed; cannot continue." + MSG2="Directory '${ALLSKY_CONFIG}' does not exist." + display_msg --log error "${MSG}" "${MSG2}" echo -else # we're continuing where we left off, so don't welcome again. - echo -e "* ${GREEN}Continuing the ${WORD}...${NC}" + exit 2 fi -if [[ ${ACTION} == "upgrade" ]]; then - : - - # First part of upgrade, executed by user in ${ALLSKY_HOME}. - - # Make sure we can upgrade: - # If config/ does NOT exist, the user hasn't installed Allsky. - # Warn the user but let them continue (won't be able to restore from prior). - - # Ask user if they want to upgrade in place (i.e., overwrite code), - # or move current code to ${PRIOR_ALLSKY_DIR}. - - # If move current code: - # Check for prior Allsky versions: - # If ${PRIOR_ALLSKY_DIR} exist: - # If ${PRIOR_ALLSKY_DIR}-OLDEST exists - # Let user know both old versions exist - # Exit - # Let the user know ${PRIOR_ALLSKY_DIR} exists as FYI: - # echo "Saving prior version in ${PRIOR_ALLSKY_DIR}-OLDEST" - # Move ${PRIOR_ALLSKY_DIR} to ${PRIOR_ALLSKY_DIR}-OLDEST - # Stop allsky - # Move ${ALLSKY_HOME} to ${PRIOR_ALLSKY_DIR} - # cd - # Git new code into ${ALLSKY_HOME} - # cd ${ALLSKY_HOME} - # Run: ./install.sh ${DEBUG_ARG} .... --doUpgrade - # --doUpgrade tells it to use prior version without asking and to - # not display header, change messages to say "upgrade", not "install", etc. - # ?? anything else? - - # Else (upgrade in place) - # Git new code into ${ALLSKY_HOME}-NEW - # ?? move ${ALLSKY_HOME}/upgrade.sh to ${ALLSKY_HOME}/upgrade-OLD.sh - # exec ${ALLSKY_HOME}/upgrade-OLD.sh - # Copy (don't move) everything from ${ALLSKY_HOME}-NEW to ${ALLSKY_HOME} - # Run: install.sh ${ALL_ARGS} --doUpgradeInPlace - # --doUpgradeInPlace tells it to use prior version without asking and to - # not display header, change messages to say "upgrade", not "install", etc. - # How is --doUpgradeInPlace different from --doUpgrade ?? - # ?? anything else? +##### Calculate whiptail sizes +WT_WIDTH="$( calc_wt_size )" +SHORT_TITLE="Allsky Upgrader" +TITLE="${SHORT_TITLE} - ${ALLSKY_VERSION}" +OLDEST_DIR="${PRIOR_ALLSKY_DIR}-OLDEST" + +do_initial_heading + +check_for_current + +check_for_oldest + +display_msg --log progress "Stopping Allsky" +stop_Allsky + +display_msg --log progress "Renaming '${ALLSKY_HOME}' to '${PRIOR_ALLSKY_DIR}'." +mv "${ALLSKY_HOME}" "${PRIOR_ALLSKY_DIR}" + +# Keep using same log file which is now in the "prior" directory. +DISPLAY_MSG_LOG="${DISPLAY_MSG_LOG/${ALLSKY_HOME}/${PRIOR_ALLSKY_DIR}}" + +cd || exit "${EXIT_ERROR_STOP}" + + +R="${GITHUB_ROOT}/${GITHUB_ALLSKY_REPO}.git" +display_msg --log progress "Running: git clone --depth=1 --recursive --branch '${BRANCH}' '${R}'" +if ! ERR="$( git clone --depth=1 --recursive --branch "${BRANCH}" "${R}" 2>&1 )" ; then + display_msg --log error "'git clone' failed." " ${ERR}" + restore_directories + exit 3 fi + +cd "${ALLSKY_HOME}" || exit "${EXIT_ERROR_STOP}" + +# --doUpgrade tells it to use prior version without asking and to not display header, +# change messages to say "upgrade", not "install", etc. +# shellcheck disable=SC2086,SC2291 +echo xxx ./install.sh ${DEBUG_ARG} --branch "${BRANCH}" --doUpgrade