adblock: update 3.4.3
[feed/packages.git] / net / adblock / files / adblock.notify
1 #!/bin/sh
2 #
3 # adblock send mail script for mstmp
4 # written by Dirk Brenken (dev@brenken.org)
5 # Please note: you have to install and configure the package 'mstmp' before using this script.
6
7 # This is free software, licensed under the GNU General Public License v3.
8 # You should have received a copy of the GNU General Public License
9 # along with this program. If not, see <http://www.gnu.org/licenses/>.
10
11 LC_ALL=C
12 PATH="/usr/sbin:/usr/bin:/sbin:/bin"
13 mail_ver="1.0.1"
14 mail_daemon="$(command -v msmtp)"
15 mail_profile="adb_notify"
16 mail_debug="--debug"
17 mail_rc=1
18
19 if [ ! -x "${mail_daemon}" ]
20 then
21 mail_daemon="$(command -v sendmail)"
22 fi
23
24 if [ -f "/var/log/messages" ]
25 then
26 logfile="$(cat /var/log/messages | grep "adblock-")"
27 else
28 logfile="$(logread -e "adblock-")"
29 fi
30
31 # mail header
32 #
33 mail_sender="no-reply@adblock"
34 mail_receiver="!!!ChangeMe!!!"
35 mail_topic="adblock notification"
36 mail_head="From: ${mail_sender}\nTo: ${mail_receiver}\nSubject: ${mail_topic}\nReply-to: ${mail_sender}\n\n"
37
38 # mail body
39 #
40 mail_text="adblock status, generated at $(date 2>&1)!"
41 mail_text="${mail_text}\n++\n++ System Information ++\n++\n$(cat /etc/banner 2>&1)"
42 mail_text="${mail_text}\n\n++\n++ Adblock Information ++\n++\n$(/etc/init.d/adblock status 2>&1)"
43 mail_text="${mail_text}\n\n++\n++ Logfile Information ++\n++\n${logfile}\n++\n++\n"
44
45 # send mail
46 #
47 if [ -x "${mail_daemon}" ]
48 then
49 printf "%b" "${mail_head}${mail_text}" 2>/dev/null | "${mail_daemon}" ${mail_debug} -a "${mail_profile}" "${mail_receiver}" >/dev/null 2>&1
50 mail_rc=${?}
51 logger -p "info" -t "adblock-notify-[${mail_ver}]" "mail sent to '${mail_receiver}' with rc '${mail_rc}'"
52 else
53 logger -p "err" -t "adblock-notify-[${mail_ver}]" "msmtp mail daemon not found"
54 fi
55
56 exit ${mail_rc}