Skip to content

Commit e1f30bd

Browse files
authored
Update allsky.sh: Handle ALLSKY_STATUS_NEEDS_REVIEW
1 parent ea31d48 commit e1f30bd

1 file changed

Lines changed: 39 additions & 10 deletions

File tree

allsky.sh

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,34 @@ else
9090
NEEDS_REBOOT="false"
9191
fi
9292

93-
# Make sure the settings have been configured after an installation or upgrade.
9493
# If the "lastchanged" setting is missing, the user needs to review/change the settings.
94+
# This will happen after an installation or upgrade, which also sets the Allsky status.
9595
LAST_CHANGED="$( settings ".lastchanged" )"
9696
if [[ -z ${LAST_CHANGED} ]]; then
97-
set_allsky_status "${ALLSKY_STATUS_NEEDS_CONFIGURATION}"
98-
echo "*** ===== Allsky needs to be configured before it can be used. See the WebUI." >&2
97+
STATUS="$( get_allsky_status )"
98+
if [[ ${STATUS} == "${ALLSKY_STATUS_NEEDS_REVIEW}" ]] then
99+
IMAGE_NAME="ReviewNeeded"
100+
MSG="Please review the settings on the WebUI's 'Allsky Settings' page"
101+
MSG+=" and make any necessary changes."
102+
WEBUI_MSG="Allsky settings need review"
103+
104+
elif [[ ${STATUS} == "${ALLSKY_STATUS_NEEDS_CONFIGURATION}" ]]; then
105+
IMAGE_NAME="ConfigurationNeeded"
106+
MSG="Allsky needs to be configured before it can be used. See the WebUI."
107+
WEBUI_MSG="Allsky needs to be configured"
108+
109+
else
110+
IMAGE_NAME=""
111+
fi
99112
if [[ ${NEEDS_REBOOT} == "true" ]]; then
100-
echo "*** ===== The Pi also needs to be rebooted." >&2
101-
doExit "${EXIT_ERROR_STOP}" "ConfigurationNeeded" \
102-
"Allsky needs\nconfiguration\nand the Pi needs\na reboot" \
103-
"Allsky needs to be configured and then the Pi rebooted."
113+
MSG+=" The Pi also needs to be rebooted." >&2
114+
doExit "${EXIT_ERROR_STOP}" "${IMAGE_NAME}" \
115+
"" "${WEBUI_MSG} and then the Pi rebooted."
104116
else
105-
doExit "${EXIT_ERROR_STOP}" "ConfigurationNeeded" "" "Allsky needs to be configured."
117+
doExit "${EXIT_ERROR_STOP}" "${IMAGE}" "" "${WEBUI_MSG}."
106118
fi
119+
echo "*** ===== ${MSG}" >&2 # to the log
120+
107121
elif [[ ${NEEDS_REBOOT} == "true" ]]; then
108122
set_allsky_status "${ALLSKY_STATUS_REBOOT_NEEDED}"
109123
doExit "${EXIT_ERROR_STOP}" "RebootNeeded" "" "The Pi needs to be rebooted."
@@ -222,9 +236,24 @@ if [[ ${CAMERA_TYPE} == "ZWO" ]]; then
222236
"WARNING:\n\nResetting USB bus\n${REASON}.\nAttempt ${NUM_USB_RESETS}."
223237

224238
SEARCH="${ZWO_VENDOR}:${ZWO_CAMERA_ID}"
225-
sudo "${ALLSKY_BIN}/uhubctl" --action off --exact --search "${SEARCH}"
239+
# Get the hub number the camera is on.
240+
local HUB="$( sudo "${ALLSKY_BIN}/uhubctl" --exact --search "${SEARCH}" |
241+
gawk -v Z="${SEARCH}" '
242+
BEGIN {hub = ""; }
243+
{
244+
if ($4 == "hub") {
245+
hub = $5;
246+
next;
247+
}
248+
if (index($0, Z) > 0) {
249+
print hub;
250+
exit(0);
251+
}
252+
}'
253+
)"
254+
sudo "${ALLSKY_BIN}/uhubctl" --action off --exact --search "${SEARCH}" --location "${HUB}"
226255
sleep 3 # give it a few seconds, plus, allow the notification images to be seen
227-
sudo "${ALLSKY_BIN}/uhubctl" --action on --exact --search "${SEARCH}"
256+
sudo "${ALLSKY_BIN}/uhubctl" --action on --exact --search "${SEARCH}" --location "${HUB}"
228257
}
229258

230259
else # RPi

0 commit comments

Comments
 (0)