|
3 | 3 | [[ -z ${ALLSKY_HOME} ]] && export ALLSKY_HOME="$( realpath "$( dirname "${BASH_ARGV0}" )" )" |
4 | 4 | ME="$( basename "${BASH_ARGV0}" )" |
5 | 5 |
|
6 | | -# NOT_STARTED_MSG, STOPPED_MSG, ERROR_MSG_PREFIX, and ZWO_VENDOR are globals |
7 | | - |
8 | 6 | #shellcheck source-path=. |
9 | 7 | source "${ALLSKY_HOME}/variables.sh" || exit "${EXIT_ERROR_STOP}" |
| 8 | + |
| 9 | +# If Allsky is already running, exit. Let prior copy continue runnning. |
| 10 | +if [[ $( pgrep --count "${ME}" ) -gt 1 ]]; then |
| 11 | + echo " ***** Allsky already running; see below. Exiting new copy. *****" >&2 |
| 12 | + # Show other processes. Don't show any newer than 5 seconds so we don't show ourself. |
| 13 | + ps -f -p "$( pgrep --older 5 "${ME}" )" |
| 14 | + exit "${EXIT_ERROR_STOP}" |
| 15 | +fi |
| 16 | + |
10 | 17 | #shellcheck source-path=scripts |
11 | 18 | source "${ALLSKY_SCRIPTS}/functions.sh" || exit "${EXIT_ERROR_STOP}" |
12 | 19 | #shellcheck source-path=scripts |
13 | 20 | source "${ALLSKY_SCRIPTS}/installUpgradeFunctions.sh" || exit "${EXIT_ERROR_STOP}" |
14 | 21 |
|
| 22 | +# NOT_STARTED_MSG, STOPPED_MSG, ERROR_MSG_PREFIX, and ZWO_VENDOR are globals |
| 23 | + |
15 | 24 | # Output from this script goes either to the log file or a tty, |
16 | 25 | # so can't use "w*" colors. |
17 | 26 |
|
|
90 | 99 | NEEDS_REBOOT="false" |
91 | 100 | fi |
92 | 101 |
|
93 | | -# Make sure the settings have been configured after an installation or upgrade. |
| 102 | +if [[ ${NEEDS_REBOOT} == "true" ]]; then |
| 103 | + set_allsky_status "${ALLSKY_STATUS_REBOOT_NEEDED}" |
| 104 | + doExit "${EXIT_ERROR_STOP}" "RebootNeeded" "" "The Pi needs to be rebooted." |
| 105 | +fi |
| 106 | + |
94 | 107 | # If the "lastchanged" setting is missing, the user needs to review/change the settings. |
| 108 | +# This will happen after an installation or upgrade, which also sets the Allsky status. |
95 | 109 | LAST_CHANGED="$( settings ".lastchanged" )" |
96 | 110 | 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 |
| 111 | + STATUS="$( get_allsky_status )" |
| 112 | + if [[ ${STATUS} == "${ALLSKY_STATUS_REBOOT_NEEDED}" ]]; then |
| 113 | + # It's been rebooted and now we need to force "lastchanged" to be set. |
| 114 | + STATUS="${ALLSKY_STATUS_NEEDS_REVIEW}" |
| 115 | + fi |
| 116 | + |
| 117 | + if [[ ${STATUS} == "${ALLSKY_STATUS_NEEDS_REVIEW}" ]]; then |
| 118 | + IMAGE_NAME="ReviewNeeded" |
| 119 | + MSG="Please review the settings on the WebUI's 'Allsky Settings' page" |
| 120 | + MSG+=" and make any necessary changes." |
| 121 | + WEBUI_MSG="Allsky settings need review" |
| 122 | + |
| 123 | + elif [[ ${STATUS} == "${ALLSKY_STATUS_NEEDS_CONFIGURATION}" ]]; then |
| 124 | + IMAGE_NAME="ConfigurationNeeded" |
| 125 | + MSG="Allsky needs to be configured before it can be used. See the WebUI." |
| 126 | + WEBUI_MSG="Allsky needs to be configured" |
| 127 | + |
| 128 | + else |
| 129 | + # I don't think we'll ever get here. |
| 130 | + MSG="ERROR: Unknown reason 'lastchanged' did not exist." |
| 131 | + WEBUI_MSG="${MSG}" |
| 132 | + IMAGE_NAME="" |
| 133 | + fi |
99 | 134 | 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." |
| 135 | + MSG+=" The Pi also needs to be rebooted." >&2 |
| 136 | + doExit "${EXIT_ERROR_STOP}" "${IMAGE_NAME}" \ |
| 137 | + "" "${WEBUI_MSG} and then the Pi rebooted." |
104 | 138 | else |
105 | | - doExit "${EXIT_ERROR_STOP}" "ConfigurationNeeded" "" "Allsky needs to be configured." |
| 139 | + doExit "${EXIT_ERROR_STOP}" "${IMAGE_NAME}" "" "${WEBUI_MSG}." |
106 | 140 | fi |
107 | | -elif [[ ${NEEDS_REBOOT} == "true" ]]; then |
108 | | - set_allsky_status "${ALLSKY_STATUS_REBOOT_NEEDED}" |
109 | | - doExit "${EXIT_ERROR_STOP}" "RebootNeeded" "" "The Pi needs to be rebooted." |
| 141 | + [[ -n ${MSG} ]] && echo "*** ===== ${MSG}" >&2 # to the log |
110 | 142 | fi |
111 | 143 |
|
112 | 144 | SEE_LOG_MSG="See ${ALLSKY_LOG}" |
|
175 | 207 |
|
176 | 208 | USE_NOTIFICATION_IMAGES="$( settings ".notificationimages" )" || exit "${EXIT_ERROR_STOP}" |
177 | 209 |
|
178 | | -# Make sure we are not already running. |
179 | | -pgrep "${ME}" | grep -v $$ | xargs "sudo kill -9" 2>/dev/null |
180 | | - |
181 | 210 | # Get the list of connected cameras and make sure the one we want is connected. |
182 | 211 | if [[ ${CAMERA_TYPE} == "ZWO" ]]; then |
183 | 212 | RPi_COMMAND_TO_USE="" |
@@ -222,9 +251,24 @@ if [[ ${CAMERA_TYPE} == "ZWO" ]]; then |
222 | 251 | "WARNING:\n\nResetting USB bus\n${REASON}.\nAttempt ${NUM_USB_RESETS}." |
223 | 252 |
|
224 | 253 | SEARCH="${ZWO_VENDOR}:${ZWO_CAMERA_ID}" |
225 | | - sudo "${ALLSKY_BIN}/uhubctl" --action off --exact --search "${SEARCH}" |
| 254 | + # Get the hub number the camera is on. |
| 255 | + local HUB="$( sudo "${ALLSKY_BIN}/uhubctl" --exact --search "${SEARCH}" | |
| 256 | + gawk -v Z="${SEARCH}" ' |
| 257 | + BEGIN {hub = ""; } |
| 258 | + { |
| 259 | + if ($4 == "hub") { |
| 260 | + hub = $5; |
| 261 | + next; |
| 262 | + } |
| 263 | + if (index($0, Z) > 0) { |
| 264 | + print hub; |
| 265 | + exit(0); |
| 266 | + } |
| 267 | + }' |
| 268 | + )" |
| 269 | + sudo "${ALLSKY_BIN}/uhubctl" --action off --exact --search "${SEARCH}" --location "${HUB}" |
226 | 270 | 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}" |
| 271 | + sudo "${ALLSKY_BIN}/uhubctl" --action on --exact --search "${SEARCH}" --location "${HUB}" |
228 | 272 | } |
229 | 273 |
|
230 | 274 | else # RPi |
|
259 | 303 | # Make sure the current camera is supported and hasn't changed unexpectedly. |
260 | 304 | CAM="${CAMERA_TYPE} ${CAMERA_NUMBER} ${CAMERA_MODEL}" # has TABS |
261 | 305 | CCM="$( get_connected_camera_models --full "${CAMERA_TYPE}" )" |
262 | | -read -r CC_TYPE CC_NUMBER CC_MODEL <<<"${CCM}" |
263 | | -if ! echo -e "${CCM}" | grep --silent "${CAM}" ; then |
| 306 | +#shellcheck disable=SC2076 |
| 307 | +if [[ ! ${CCM} =~ "${CAM}" ]]; then |
| 308 | + IFS=" " read -r CC_TYPE CC_NUMBER CC_MODEL CC_OTHER <<<"${CCM}" |
| 309 | + echo -e "Was: ${CAMERA_TYPE} ${CAMERA_NUMBER} ${CAMERA_MODEL}" |
| 310 | + echo -e "Now: ${CC_TYPE} ${CC_NUMBER} ${CC_MODEL} ${CC_OTHER}" |
264 | 311 | # Something changed. validate_camera() displays the error message. |
265 | 312 | if ! validate_camera "${CC_TYPE}" "${CC_MODEL}" "${CC_NUMBER}" ; then |
266 | 313 | set_allsky_status "${ALLSKY_STATUS_CAMERA_CHANGED}" |
267 | 314 | IMAGE_MSG="${ERROR_MSG_PREFIX}" |
268 | 315 | IMAGE_MSG+="The camera changed." |
269 | 316 | IMAGE_MSG+="\nCheck Camera Type\n& Model in the WebUI." |
| 317 | + reset_usb "Camera changed" |
270 | 318 | doExit "${EXIT_ERROR_STOP}" "Error" "${IMAGE_MSG}" |
271 | 319 | fi |
272 | 320 | fi |
|
0 commit comments