da6558181b233da8128412ee75463c2928b92b46
2 # send mail script for travelmate notifications
3 # Copyright (c) 2020-2021 Dirk Brenken (dev@brenken.org)
4 # This is free software, licensed under the GNU General Public License v3.
6 # set (s)hellcheck exceptions
7 # shellcheck disable=1091,3040
9 # Please note: you have to setup the package 'msmtp' before using this script
14 export PATH
="/usr/sbin:/usr/bin:/sbin:/bin"
17 trm_debug
="$(uci_get travelmate global trm_debug "0")"
18 trm_mailreceiver
="$(uci_get travelmate global trm_mailreceiver)"
19 trm_mailprofile
="$(uci_get travelmate global trm_mailprofile "trm_notify
")"
20 trm_mailsender
="$(uci_get travelmate global trm_mailsender "no-reply@travelmate
")"
21 trm_rtfile
="$(uci_get travelmate global trm_rtfile "/tmp
/trm_runtime.json
")"
22 trm_mailpgm
="$(command -v msmtp)"
23 trm_logger
="$(command -v logger)"
25 if [ -z "${trm_mailreceiver}" ]; then
26 "${trm_logger}" -p "err" -t "trm-mail [${$}]" "please set the mail receiver with the 'trm_mailreceiver' option" 2>/dev
/null
30 if [ "${trm_debug}" = "1" ]; then
37 strings /etc/banner 2>/dev/null
38 ubus call system board | awk 'BEGIN{FS="[{}\"]"}{if($2=="kernel
"||$2=="hostname
"||$2=="system
"||$2=="model
"||$2=="description
")printf " + %-12s: %s
\n",$2,$4}'
40 trm_info
="$(/etc/init.d/travelmate status 2>/dev/null)"
41 sta_info
="$(jsonfilter -i "${trm_rtfile}" -q -l1 -e '@.data.station_id')"
42 trm_mailtopic
="$(uci_get travelmate global trm_mailtopic "travelmate connection to
'${sta_info}'")"
43 trm_mailhead
="From: ${trm_mailsender}\nTo: ${trm_mailreceiver}\nSubject: ${trm_mailtopic}\nReply-to: ${trm_mailsender}\nMime-Version: 1.0\nContent-Type: text/html;charset=utf-8\nContent-Disposition: inline\n\n"
47 trm_mailtext
="<html><body><pre style='display:block;font-family:monospace;font-size:1rem;padding:20;background-color:#f3eee5;white-space:pre'>"
48 trm_mailtext
="${trm_mailtext}\n<strong>++\n++ System Information ++\n++</strong>\n${sys_info}"
49 trm_mailtext
="${trm_mailtext}\n\n<strong>++\n++ Travelmate Information ++\n++</strong>\n${trm_info}"
50 trm_mailtext
="${trm_mailtext}</pre></body></html>"
54 printf "%b" "${trm_mailhead}${trm_mailtext}" 2>/dev/null | "${trm_mailpgm}" ${debug} -a "${trm_mailprofile}" "${trm_mailreceiver}" >/dev
/null
2>&1
55 "${trm_logger}" -p "info" -t "trm-mail [${$}]" "mail sent to '${trm_mailreceiver}' with rc '${?}'" 2>/dev
/null