Skip to content

Commit

Permalink
Merge pull request #4139 from AllskyTeam/improved-addMessage.sh
Browse files Browse the repository at this point in the history
Improved addMessage.sh
  • Loading branch information
EricClaeys authored Dec 29, 2024
2 parents 338bd53 + a62730a commit 4790e0e
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 47 deletions.
22 changes: 10 additions & 12 deletions allsky.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ if [[ -d ${PRIOR_ALLSKY_DIR} ]]; then
fi
if [[ ${DO_MSG} == "true" ]]; then
MSG="Reminder: your prior Allsky is still in '${PRIOR_ALLSKY_DIR}'."
MSG+="\nIf you are no longer using it, it can be removed to save disk space:"
MSG+="\n&nbsp; &nbsp;<code>rm -fr '${PRIOR_ALLSKY_DIR}'</code>\n"
"${ALLSKY_SCRIPTS}/addMessage.sh" "info" "${MSG}"
touch "${OLD_ALLSKY_REMINDER}" # last time we displayed the message
MSG+="\nIf you are no longer using it, it can be removed to save disk space."
"${ALLSKY_SCRIPTS}/addMessage.sh" --id AM_RM_PRIOR --type info --msg "${MSG}" \
--cmd "Click here to remove."
touch "${OLD_ALLSKY_REMINDER}" # Sets the last time we displayed the message.
fi
fi

Expand All @@ -152,9 +152,8 @@ if [[ -f ${CHECK_ALLSKY_LOG} ]]; then
MSG+="Reminder to make these changes to your settings"
MSG+="</div>"
MSG+="$( < "${CHECK_ALLSKY_LOG}" )"
MSG+="<hr><span class='errorMsgBig'>If you made the changes run:</span>"
MSG+="\n&nbsp; &nbsp;<code>rm -f '${CHECK_ALLSKY_LOG}'</code>\n"
"${ALLSKY_SCRIPTS}/addMessage.sh" "warning" "${MSG}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --id AM_RM_CHECK --type warning --msg "${MSG}" \
--cmd "<hr><span class='errorMsgBig'>If you made the changes click here.</span>"
touch "${REMINDER}" # last time we displayed the message
fi
fi
Expand All @@ -172,10 +171,9 @@ if [[ -f ${POST_INSTALLATION_ACTIONS} ]]; then
doExit "${EXIT_ERROR_STOP}" "no-image" "" ""
else
MSG="Reminder: Click here to see the action(s) that need to be performed."
MSG+="\nOnce you perform them run the following to remove this message:"
MSG+="\n &nbsp; &nbsp;<code>rm -f '${POST_INSTALLATION_ACTIONS}'</code>"
PIA="${POST_INSTALLATION_ACTIONS/${ALLSKY_HOME}/}"
"${ALLSKY_SCRIPTS}/addMessage.sh" "warning" "${MSG}" "${PIA}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --id AM_RM_POST --type warning --msg "${MSG}" --url "${PIA}" \
--cmd "\nOnce you perform them, click here to remove this message."
fi
fi

Expand Down Expand Up @@ -280,7 +278,7 @@ fi

# Make sure the settings file is linked to the camera-specific file.
if ! MSG="$( check_settings_link "${SETTINGS_FILE}" )" ; then
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${MSG}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type error --cmd "${MSG}"
echo "ERROR: ${MSG}" >&2
fi

Expand All @@ -296,7 +294,7 @@ else
sudo chgrp "${WEBSERVER_GROUP}" "${ALLSKY_TMP}"
MSG="Had to create '${ALLSKY_TMP}'."
MSG="${MSG}\nIf this happens again, contact the Allsky developers."
"${ALLSKY_SCRIPTS}/addMessage.sh" warning "${ME}: ${MSG}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type warning --msg "${ME}: ${MSG}"
fi

rm -f "${ALLSKY_BAD_IMAGE_COUNT}" # Start with no bad images
Expand Down
1 change: 1 addition & 0 deletions config_repo/allskyDefines.inc.repo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ define('HOME', 'XX_HOME_XX');
define('ALLSKY_HOME', 'XX_ALLSKY_HOME_XX');
define('ALLSKY_CONFIG', 'XX_ALLSKY_CONFIG_XX');
define('ALLSKY_SCRIPTS', 'XX_ALLSKY_SCRIPTS_XX');
define('ALLSKY_UTILITIES', 'XX_ALLSKY_UTILITIES_XX');
define('ALLSKY_TMP', 'XX_ALLSKY_TMP_XX');
define('ALLSKY_IMAGES', 'XX_ALLSKY_IMAGES_XX');
define('ALLSKY_MESSAGES', 'XX_ALLSKY_MESSAGES_XX');
Expand Down
29 changes: 21 additions & 8 deletions html/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,31 @@ function DisplayTorProxyConfig() {}
echo "<div class='row'>"; echo "<div class='system-message'>";
echo "<div class='title'>System Messages</div>";
foreach ($contents_array as $line) {
// Format: level (i.e., CSS class), date, count, message [, url]
// 0 1 2 3 4
// Format: id, cmd_txt, level (i.e., CSS class), date, count, message [, url]
// 0 1 2 3 4 5 6
$cmd = "";
$message_array = explode("\t", $line);
$message = getVariableOrDefault($message_array, 3, null);
$message = getVariableOrDefault($message_array, 5, null);
if ($message !== null) {
$level = $message_array[0];
$date = $message_array[1];
$count = $message_array[2];
$url = getVariableOrDefault($message_array, 4, "");
$id = getVariableOrDefault($message_array, 0, "");
$cmd_txt = getVariableOrDefault($message_array, 1, "");
$level = $message_array[2];
$date = $message_array[3];
$count = $message_array[4];
$url = getVariableOrDefault($message_array, 6, "");
if ($url !== "") {
$m1 = "<a href='$url' title='Click for more information' target='_messages'>";
$m2 = "<i class='fa fa-external-link-alt fa-fw'></i>";
$m2 = "<span class='externalSmall'>$m2</span>";
$message = "$m1 $message $m2</a>";
$message = "${m1}${message}${m2}</a>";
}

if ($id !== "") {
$m1 = "<a href='/execute.php?cmd=" . urlencode($id) . "'";
$m1 .= "title='Click to perform action' target='_actions'>";
$message = "${m1}${cmd_txt}</a>";
}

if ($count == 1)
$message .= " &nbsp; ($date)";
else
Expand All @@ -370,6 +380,9 @@ function DisplayTorProxyConfig() {}
$message = "INTERNAL ERROR: Poorly formatted message: $line";
}
$status->addMessage($message, $level);
if ($cmd !== "") {
$status->addMessage($cmd, $level);
}
}
$status->showMessages();
echo "<br><div class='message-button'>";
Expand Down
5 changes: 3 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ update_php_defines()
-e "s;XX_ALLSKY_HOME_XX;${ALLSKY_HOME};g" \
-e "s;XX_ALLSKY_CONFIG_XX;${ALLSKY_CONFIG};g" \
-e "s;XX_ALLSKY_SCRIPTS_XX;${ALLSKY_SCRIPTS};g" \
-e "s;XX_ALLSKY_UTILITIES_XX;${ALLSKY_UTILITIES};g" \
-e "s;XX_ALLSKY_TMP_XX;${ALLSKY_TMP};g" \
-e "s;XX_ALLSKY_IMAGES_XX;${ALLSKY_IMAGES};g" \
-e "s;XX_ALLSKY_MESSAGES_XX;${ALLSKY_MESSAGES};g" \
Expand Down Expand Up @@ -729,7 +730,7 @@ ask_reboot()
MSG="If you have not already rebooted your Pi, please do so now.\n"
MSG+="You can then connect to the WebUI at:\n"
MSG+="${AT}"
"${ALLSKY_SCRIPTS}/addMessage.sh" "info" "${MSG}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type info --msg "${MSG}"
fi
}
do_reboot()
Expand Down Expand Up @@ -3256,7 +3257,7 @@ display_image()
# Add a message the user will see in the WebUI.
MSG="Actions needed. See ${POST_INSTALLATION_ACTIONS}."
X="${POST_INSTALLATION_ACTIONS/${ALLSKY_HOME}/}"
"${ALLSKY_SCRIPTS}/addMessage.sh" "warning" "${MSG}" "${X}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type warning "--msg ${MSG}" --url "${X}"

# This tells allsky.sh not to display a message about actions since we just did.
touch "${POST_INSTALLATION_ACTIONS}_initial_message"
Expand Down
17 changes: 9 additions & 8 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function doExit()

OUTPUT_A_MSG="false"
if [[ -n ${WEBUI_MESSAGE} ]]; then
"${ALLSKY_SCRIPTS}/addMessage.sh" "${MSG_TYPE}" "${WEBUI_MESSAGE}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type "${MSG_TYPE}" --msg "${WEBUI_MESSAGE}"
echo -e "Stopping Allsky: ${WEBUI_MESSAGE}" >&2
OUTPUT_A_MSG="true"
fi
Expand Down Expand Up @@ -289,13 +289,13 @@ function get_connected_cameras_info()
if [[ -n ${CMD_TO_USE_} ]]; then
if [[ ${CMD_TO_USE_} == "raspistill" ]]; then
# Only supported camera with raspistill
echo -e "RPi\t0\timx477"
echo -e "RPi\t0\timx477\t[4056x3040]"

else
# Input:
# camera_number : sensor [other stuff]
LIBCAMERA_LOG_LEVELS=FATAL "${CMD_TO_USE_}" --list-cameras 2>&1 |
gawk '/^[0-9]/ { printf("%s\t%d\t%s\n", "RPi", $1, $3); }'
gawk '/^[0-9]/ { printf("%s\t%d\t%s\n", "RPi", $2, $3); }'
fi
fi

Expand Down Expand Up @@ -442,7 +442,7 @@ function validate_camera()
echo -e "\n${RED}${MSG}${NC}\n"
else
URL="/index.php?page=configuration"
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${MSG}" "${URL}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${MSG}" --url "${URL}"
fi
RET=1
elif [[ ${SETTINGS_CM} != "${CM}" ]]; then
Expand All @@ -453,7 +453,7 @@ function validate_camera()
echo -e "\n${RED}${MSG}${NC}\n"
else
URL="/index.php?page=configuration"
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${MSG}" "${URL}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${MSG}" --url "${URL}"
fi
RET=1
elif [[ ${SETTINGS_CN} != "${CN}" ]]; then
Expand All @@ -464,7 +464,7 @@ function validate_camera()
echo -e "\n${RED}${MSG}${NC}\n"
else
URL="/index.php?page=configuration"
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${MSG}" "${URL}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${MSG}" --url "${URL}"
fi
RET=1
fi
Expand All @@ -489,7 +489,8 @@ function validate_camera()
else
MSG+="\n\nClick this message to ask that Allsky support this camera."
URL="/documentation/explanations/requestCameraSupport.html";
"${ALLSKY_SCRIPTS}/addMessage.sh" "warning" "${MSG}" "${URL}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --id AM_NOT_SUPPORTED --type warning --msg "${MSG}" --url "${URL}" \
--cmd "${CT}:Click here to see the list of supported ${CT} cameras."
fi

return 2
Expand Down Expand Up @@ -1129,7 +1130,7 @@ function one_instance()
SEVERITY="warning"
MSG+="\nOnce you have resolved the cause, reset the aborted counter:"
MSG+="\n&nbsp; &nbsp; <code>rm -f '${AF}'</code>"
"${ALLSKY_SCRIPTS}/addMessage.sh" "${SEVERITY}" "${MSG}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type ${SEVERITY} --msg "${MSG}"
fi

return 2
Expand Down
6 changes: 3 additions & 3 deletions scripts/postData.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function upload_file()
local MSG="File to upload '${FILE_TO_UPLOAD}' - file not found."
echo -e "${RED}${ME}: ERROR: ${MSG}.${NC}" >&2
if [[ ${FROM_WEBUI} == "false" ]]; then
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${ME}: ${MSG}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${ME}: ${MSG}"
fi
return 1
fi
Expand Down Expand Up @@ -128,14 +128,14 @@ if [[ ${SETTINGS_ONLY} == "false" ]]; then
OK="false"
echo -e "${RED}${ME}: ERROR: ${latitude}" >&2
if [[ ${FROM_WEBUI} == "false" ]]; then
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${ME}: ${latitude}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${ME}: ${latitude}"
fi
fi
if ! longitude="$( convertLatLong "$( settings ".longitude" )" "longitude" 2>&1 )" ; then
OK="false"
echo -e "${RED}${ME}: ERROR: ${longitude}" >&2
if [[ ${FROM_WEBUI} == "false" ]]; then
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${ME}: ${longitude}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${ME}: ${longitude}"
fi
fi
[[ ${OK} == "false" ]] && exit 1
Expand Down
16 changes: 8 additions & 8 deletions scripts/postToMap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ if [[ -z ${MACHINE_ID} ]]; then
if [[ -z ${MACHINE_ID} ]]; then
E="ERROR: Unable to get 'machine_id': check /etc/machine-id."
echo -e "${ERROR_MSG_START}${E}${wNC}"
[[ ${ENDOFNIGHT} == "true" ]] && "${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${ME}: ${E}"
[[ ${ENDOFNIGHT} == "true" ]] && "${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${ME}: ${E}"
exit 3
fi
fi
Expand Down Expand Up @@ -275,7 +275,7 @@ else
if [[ ${ENDOFNIGHT} == "true" ]]; then
echo "${W}" | while read -r MSG
do
"${ALLSKY_SCRIPTS}/addMessage.sh" "warning" "${ME}: ${MSG}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type warning --msg "${ME}: ${MSG}"
done
fi
fi
Expand All @@ -284,7 +284,7 @@ else
if [[ ${ENDOFNIGHT} == "true" ]]; then
echo "${E}" | while read -r MSG
do
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${ME}: ${MSG}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${ME}: ${MSG}"
done
fi
exit 2
Expand Down Expand Up @@ -342,7 +342,7 @@ if [[ ${UPLOAD} == "true" ]]; then
E="ERROR while uploading map data with curl: ${RETURN}, CMD=${CMD}."
if [[ ${ENDOFNIGHT} == "true" ]]; then
echo -e "${ME}: ${E}" # goes in log file
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${ME}: ${E}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${ME}: ${E}"
else
echo -e "${ERROR_MSG_START}${E}${wNC}"
fi
Expand Down Expand Up @@ -373,25 +373,25 @@ if [[ ${UPLOAD} == "true" ]]; then
elif [[ -z ${RET} ]]; then
E="ERROR: Unknown reply from server: ${RETURN}."
echo -e "${ERROR_MSG_START}${E}${wNC}"
[[ ${ENDOFNIGHT} == "true" ]] && "${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${ME}: ${E}"
[[ ${ENDOFNIGHT} == "true" ]] && "${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${ME}: ${E}"
RETURN_CODE=2

elif [[ ${RET:0:6} == "ERROR " ]]; then
E="ERROR returned while uploading map data: ${RET:6}."
echo -e "${ERROR_MSG_START}${E}${wNC}"
[[ ${ENDOFNIGHT} == "true" ]] && "${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${ME}: ${E}"
[[ ${ENDOFNIGHT} == "true" ]] && "${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${ME}: ${E}"
RETURN_CODE=2

elif [[ ${RET:0:15} == "ALREADY UPDATED" ]]; then
MAX_UPDATES=${RET:16}
W="NOTICE: You have already updated your map data the maximum of ${MAX_UPDATES} times per day. Try again tomorrow."
echo -e "${WARNING_MSG_START}${W}${wNC}"
[[ ${ENDOFNIGHT} == "true" ]] && "${ALLSKY_SCRIPTS}/addMessage.sh" "warning" "${ME}: ${W}"
[[ ${ENDOFNIGHT} == "true" ]] && "${ALLSKY_SCRIPTS}/addMessage.sh" --type warning --msg "${ME}: ${W}"

else
E="ERROR returned while uploading map data: ${RET}."
echo -e "${ERROR_MSG_START}${E}${wNC}"
[[ ${ENDOFNIGHT} == "true" ]] && "${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${ME}: ${E}"
[[ ${ENDOFNIGHT} == "true" ]] && "${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${ME}: ${E}"
RETURN_CODE=2
fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/removeBadImages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ else
MSG+="\nCheck the values of 'Remove Bad Images Threshold Low',"
MSG+=" 'Remove Bad Images Threshold High',"
MSG+=" and 'Max Auto-Exposure' in the WebUI."
"${ALLSKY_SCRIPTS}/addMessage.sh" "warning" "${MSG}" >&2
"${ALLSKY_SCRIPTS}/addMessage.sh" --type warning --msg "${MSG}" >&2
fi
if [[ ${BAD_COUNT} -ge "${BAD_LIMIT}" ]]; then
# Split the long file name so it fits in the message.
Expand Down
6 changes: 3 additions & 3 deletions scripts/testUpload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,14 @@ if [[ -n ${ERR_MSG} ]]; then
if [[ ${ON_TTY} == "true" ]]; then
echo -e "\n${ERR_MSG}" >&2
else
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${ERR_MSG}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${ERR_MSG}"
fi
fi
if [[ -n ${OK_MSG} ]]; then
if [[ ${ON_TTY} == "true" ]]; then
echo -e "\n${OK_MSG}" >&2
else
"${ALLSKY_SCRIPTS}/addMessage.sh" "success" "${OK_MSG}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type success --msg "${OK_MSG}"
fi
fi

Expand All @@ -297,7 +297,7 @@ if [[ -s ${MSG_FILE} ]]; then
if [[ ${ON_TTY} == "true" ]]; then
echo -e "\n${M}"
else
"${ALLSKY_SCRIPTS}/addMessage.sh" "info" "${M}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type info --msg "${M}"
fi
fi
rm -f "${MSG_FILE}"
Expand Down
2 changes: 1 addition & 1 deletion scripts/upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ elif [[ ${PROTOCOL} == "gcs" ]] ; then
else
OUTPUT="${ME}: ERROR: 'gsutil' command not found; cannot upload."
OUTPUT+="\nIt should be in one of these directories: ${PATH}"
"${ALLSKY_SCRIPTS}/addMessage.sh" "error" "${OUTPUT}"
"${ALLSKY_SCRIPTS}/addMessage.sh" --type error --msg "${OUTPUT}"
OUTPUT="${RED}*** ${OUTPUT}${NC}"
RET=1
fi
Expand Down
Loading

0 comments on commit 4790e0e

Please sign in to comment.