improve return codes

This commit is contained in:
Antonio J. Delgado 2023-03-20 22:22:07 +02:00
parent bbe268059b
commit 0a69def281

View file

@ -200,6 +200,10 @@ if [ -n "${file}" ]; then
if [ -n "${move_to}" ]; then
message "Moving file '${file}' to '${move_to}'..."
scp -P "${move_to_port}" "${file}" "${move_to}/" && rm -rf "${file}"
return_code=$?
if [ $return_code != 0 ]; then
message "Error ${return_code} moving file."
fi
fi
fi
@ -208,23 +212,39 @@ if [ "${signal_alert}" == "true" ]; then
message "Sending to Signal destination '${signal_destination}'..."
/var/lib/from_repos/signal_scripts/send_msg.sh --destination "${signal_destination}" \
--message "Clip termino en camara '${camera_name}' (${motion_host}). Evento: #${event}. File: ${file_uri}"
return_code=$?
if [ $return_code != 0 ]; then
message "Error ${return_code} sending to signal."
fi
fi
if [ "${mail_alert}" == "true" ]; then
message "Sending email to '${email_destination}'..."
echo "${data}" | jq '.' | mail -s "Motion event '${event_type}' on host '${motion_host}' camera '${camera_name}'" "${email_destination}"
return_code=$?
if [ $return_code != 0 ]; then
message "Error ${return_code} sending email"
fi
fi
if [ -n "${ntfy_server}" ]; then
ntfy_password="$(cat "${ntfy_password_file}")"
ntfy_data="${data}, \"topic\": \"motion_detection\""
message "Seding to ntfy server '${ntfy_server}' ..."
curl -s "${ntfy_server}" -d "${ntfy_data}"
return_code=$?
if [ $return_code != 0 ]; then
message "Error ${return_code} publishing in ntfy server '${ntfy}'"
fi
fi
message "Sending Home Assistant event ..."
result=$(curl -s -X POST -H "Authorization: Bearer ${ha_token}" -H "Content-Type: application/json" "${ha_url}/api/events/motion_event" -d "${data}")
return_code=$?
message "Return code: ${return_code}. Result: ${result}"
if [ $return_code != 0 ]; then
message "Error ${return_code} sending to Home Assistant '${ha_url}'"
fi
if ${remove_picture}; then
file_dirname=$(dirname "${file}")