Skip to content

Commit

Permalink
Update remoteWebsiteInstall.sh: Check for un-set WebUI variables
Browse files Browse the repository at this point in the history
Things like "Server Name" need to be specified.
  • Loading branch information
EricClaeys authored Jan 17, 2025
1 parent 668c863 commit 5de342f
Showing 1 changed file with 103 additions and 29 deletions.
132 changes: 103 additions & 29 deletions remoteWebsiteInstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ DIALOG_HEIGHT=25
INDENT=" " # indent each line so it's easier to read

# Remote connectivity variables
REMOTE_URL="$( settings ".remotewebsiteurl" "${SETTINGS_FILE}" )"
REMOTE_WEBSITE_URL="$( settings ".remotewebsiteurl" "${SETTINGS_FILE}" )"
REMOTE_WEBSITE_IMAGE_URL="$( settings ".remotewebsiteimageurl" "${SETTINGS_FILE}" )"
REMOTE_USER="$( settings ".REMOTEWEBSITE_USER" "${ALLSKY_ENV}" )"
REMOTE_HOST="$( settings ".REMOTEWEBSITE_HOST" "${ALLSKY_ENV}" )"
REMOTE_PORT="$( settings ".REMOTEWEBSITE_PORT" "${ALLSKY_ENV}" )"
Expand Down Expand Up @@ -140,7 +141,7 @@ function add_dialog_heading()
DIALOG_NORMAL="${NC}"
fi

local ITEM_TO_ADD="${REMOTE_URL}"
local ITEM_TO_ADD="${REMOTE_WEBSITE_URL}"
local PADDING=$(( ((DIALOG_WIDTH-6) - ${#ITEM_TO_ADD}) / 2 ))
local ITEM_TO_ADD="$( printf "%${PADDING}s%s" "" "${ITEM_TO_ADD}" )"

Expand Down Expand Up @@ -175,7 +176,6 @@ function display_box()
return "${RET}"
fi

# Don't use: it's redundant most of the time --backtitle "${DIALOG_BACK_TITLE}" \
# shellcheck disable=SC2086
dialog \
--colors \
Expand Down Expand Up @@ -213,30 +213,102 @@ function display_log_file()
#
# The configuration file to use is decided using the following, in order:
#
# 1a. If ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} exists, use it.
# 1. Make sure all the WebUI settings for the remote Website are set.
#
# 1b. No longer used, assume upgrade of Allsky will copy the configuration file
# to the new installation
# 2. If ${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE} exists, use it.
#
# 2a. If there's a remote Website with a ${ALLSKY_WEBSITE_CONFIGURATION_NAME} file,
# 3a. 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}),
# 3b. 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 DIALOG_TEXT DT MISSING ERROR_MSG

display_msg --logonly info "Start pre installation checks."

local MSG=""
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 remote Website configuration file on Pi: "
DIALOG_TEXT+="\n1 - Checking that WebUI settings exist: "
display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}"

MISSING=0
MSG=""
if [[ -z ${REMOTE_PROTOCOL} ]]; then
(( MISSING++ ))
[[ -n ${MSG} ]] && MSG+=", "
MSG+="Protocol"
else
# TODO: create a function that checks for all variables for the specified protocol,
# and use it here, in upload.sh, and in checkAllsky.sh.
case ${REMOTE_PROTOCOL} in
s3)
# TODO s3 needs: AWS_CLI_DIR, S3_BUCKET, S3_ACL
:
;;
gcs)
# TODO gcs needs: GCS_BUCKET, GCS_ACL
:
;;
scp | rsync | *ftp*)
if [[ (${REMOTE_PROTOCOL} == "scp" || ${REMOTE_PROTOCOL} == "rsync" ) &&
-z ${SSH_KEY_FILE} ]]; then
(( MISSING++ ))
[[ -n ${MSG} ]] && MSG+=", "
MSG+="SSH Key File"
elif [[ -z ${REMOTE_PASSWORD} ]]; then
(( MISSING++ ))
[[ -n ${MSG} ]] && MSG+=", "
MSG+="Password"
fi

if [[ -z ${REMOTE_USER} ]]; then
(( MISSING++ ))
[[ -n ${MSG} ]] && MSG+=", "
MSG+="User Name"
fi
if [[ -z ${REMOTE_HOST} ]]; then
(( MISSING++ ))
[[ -n ${MSG} ]] && MSG+=", "
MSG+="Server Name"
fi
;;
esac
fi

if [[ -z ${REMOTE_WEBSITE_URL} ]]; then
(( MISSING++ ))
[[ -n ${MSG} ]] && MSG+=", "
MSG+="Website URL"
fi
if [[ -z ${REMOTE_WEBSITE_IMAGE_URL} ]]; then
(( MISSING++ ))
[[ -n ${MSG} ]] && MSG+=", "
MSG+="Image URL"
fi

if [[ ${MISSING} -eq 0 ]]; then
DT="FOUND"
MSG="All WebUI settings exist."
else
MSG="ERROR: Remote Website setting(s) missing:\n${SPACES}${SPACES}${MSG}"
DIALOG_TEXT+="${DIALOG_RED}"
DIALOG_TEXT+="${MSG}"
DIALOG_TEXT+="${DIALOG_NORMAL}"
display_box "--msgbox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}" "--ok-label Exit"
display_aborted "${MSG}"
fi
display_msg --logonly info "${MSG}"
DIALOG_TEXT+="${DT}."
display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}"


DIALOG_TEXT+="\n2 - 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}"
Expand All @@ -248,9 +320,10 @@ function pre_install_checks()
DIALOG_TEXT+="${DT}."
display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}"

DIALOG_TEXT+="\n2 - Checking for working remote Website: "

DIALOG_TEXT+="\n3 - Checking for working remote Website: "
display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}"
local SPACES="${INDENT}${INDENT}"
local SPACES="${INDENT}${INDENT} "
check_if_website_is_valid # Sets global variables so can't be in subshell
if [[ $? -eq 0 ]]; then
REMOTE_WEBSITE_IS_VALID="true"
Expand All @@ -263,14 +336,14 @@ function pre_install_checks()
DIALOG_TEXT+="WORKING."
display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}"

# 2a.
DIALOG_TEXT+="\n${SPACES}* Checking it for new-style configuration file: "
# 3a.
DIALOG_TEXT+="\n${SPACES}* Checking for new-style configuration file: "
display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}"
if [[ ${HAVE_NEW_STYLE_REMOTE_CONFIG} == "true" ]]; then
DIALOG_TEXT+="FOUND."
display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}"
else
# 2b.
# 3b.
DIALOG_TEXT+="NOT FOUND."
display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}"

Expand Down Expand Up @@ -342,15 +415,15 @@ function pre_install_checks()
CONFIG_MESSAGE="a new"
fi

DIALOG_TEXT+="\n${SPACES} * Checking ability to upload to Website: "
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."
if MSG="$( check_connectivity )" ; then
DIALOG_TEXT+="${MSG}."
display_box "--infobox" "${DIALOG_PRE_CHECK}" "${DIALOG_TEXT}"
show_debug_message "The remote Website connectivity test succeeded."
else
local ERROR_MSG="\nThe remote Website connectivity check failed."
ERROR_MSG="\nThe remote Website connectivity check failed."
display_aborted "${ERROR_MSG}" "${MSG}"
fi

Expand Down Expand Up @@ -424,7 +497,7 @@ function display_aborted()
# Displays the completed dialog, used at the end of the installation process.
function display_complete()
{
local EXTRA_TEXT E E2
local EXTRA_TEXT E E2 DIALOG_TEXT
E="Use the WebUI's 'Editor' page to edit the"
E+="\n\n${INDENT} '${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_NAME} (remote Allsky Website)'"
E+="\n\n${INDENT}file"
Expand All @@ -439,13 +512,14 @@ function display_complete()
else
EXTRA_TEXT="${E} to change settings for your remote Website"
if grep --silent "${NEED_TO_UPDATE}" "${ALLSKY_REMOTE_WEBSITE_CONFIGURATION_FILE}" ; then
EXTRA_TEXT+="\n\n${INDENT}${E}${E2}."
EXTRA_TEXT+="\n\n${INDENT}${E2}"
else
EXTRA_TEXT+="."
fi
fi

local DIALOG_TEXT="\n${INDENT}The installation of the remote Website is complete.\n\n${INDENT}Please check it."
DIALOG_TEXT="\n${INDENT}The installation of the remote Website is complete."
DIALOG_TEXT+="\n\n${INDENT}Please check it."
DIALOG_TEXT+="\n\n${INDENT}${EXTRA_TEXT}"
display_box "--msgbox" "${DIALOG_DONE}" "${DIALOG_TEXT}"

Expand Down Expand Up @@ -538,7 +612,7 @@ 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.
local FILE="${REMOTE_URL}/${ALLSKY_WEBSITE_CONFIGURATION_NAME}"
local FILE="${REMOTE_WEBSITE_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}"
Expand Down Expand Up @@ -607,7 +681,7 @@ function remove_remote_file()

local CMDS ERR MSG
if [[ ${CHECK} == "check" ]]; then
if ! check_if_files_exist "${REMOTE_URL}" "or" "${FILENAME}" ; then
if ! check_if_files_exist "${REMOTE_WEBSITE_URL}" "or" "${FILENAME}" ; then
return 0
fi
fi
Expand Down Expand Up @@ -652,20 +726,20 @@ function check_if_website_is_valid()
local FOUND="false"
local WEBSITE_FILES=("index.php" "functions.php")

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
display_msg --logonly info "Looking for old and new config files at ${REMOTE_WEBSITE_URL}"
if check_if_files_exist "${REMOTE_WEBSITE_URL}" "or" "${OLD_CONFIG_NAME}" ; then
display_msg --logonly info " Found old-style '${OLD_CONFIG_NAME}."
HAVE_REALLY_OLD_REMOTE_CONFIG="true"
FOUND="true"
fi
if check_if_files_exist "${REMOTE_URL}" "or" "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" ; then
if check_if_files_exist "${REMOTE_WEBSITE_URL}" "or" "${ALLSKY_WEBSITE_CONFIGURATION_NAME}" ; then
display_msg --logonly info " Found new-style '${ALLSKY_WEBSITE_CONFIGURATION_NAME}."
HAVE_NEW_STYLE_REMOTE_CONFIG="true"
FOUND="true"
fi

if [[ ${FOUND} == "true" ]]; then
if check_if_files_exist "${REMOTE_URL}" "and" "${WEBSITE_FILES[@]}" ; then
if check_if_files_exist "${REMOTE_WEBSITE_URL}" "and" "${WEBSITE_FILES[@]}" ; then
display_msg --logonly info " Website valid."
return 0
else
Expand Down Expand Up @@ -752,7 +826,7 @@ function upload_remote_website()
done

local DIR="myImages"
if check_if_files_exist "${REMOTE_URL}" "or" "${DIR}" ; then
if check_if_files_exist "${REMOTE_WEBSITE_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,
Expand Down

0 comments on commit 5de342f

Please sign in to comment.