-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhajenka.sh
executable file
·72 lines (63 loc) · 1.6 KB
/
hajenka.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
URL='https://www.vhajence.com/'
EMAIL=''
SUBJECT="Notifikace: Hájenka"
CACHE=~/.cache/$(basename "$0")/
NOTIFY=
function usage() {
echo "Usage:"
echo "$0 [-u <url>] [-s <text>] <email address>"
echo " -u|--url"
echo " ... url to the uredni deska (default is ${URL})"
echo " -s|--subject"
echo " ... Subject of the notifcation email"
echo " <email address>"
echo " ... email address to send the notification to if there is a change"
}
while [[ $# -gt 0 ]]; do
case "$1" in
'-u'|'--url')
shift
URL="$1"
;;
'-s'|'--subject')
shift
SUBJECT="$1"
;;
*)
EMAIL="$1"
;;
esac
shift
done
function generate_email() {
echo "Subject: ${SUBJECT}"
echo "To: ${EMAIL}"
echo "=============== Hájenka (Dandi) ==============="
echo
echo "Změna na webu Hájenkay: ${URL}"
echo
echo "===================================================="
return 0
}
# Make sure cache exists
mkdir -p "${CACHE}" || \
{ echo "Error: Can not access cache at ${CACHE}"; exit 1; }
CF=${CACHE}/hajenka.html
>>${CF}
TF=$(mktemp)
curl -k -o ${TF} -s "${URL}" || \
{ echo "Error downloading the web at ${URL}"; exit 1; }
if ! diff "${TF}" "${CF}" &> /dev/null; then
# Make a backup (debug)
cp "${CF}" "${CF}-$(date '+%Y%m%d-%H%M')"
# Generate the email body
BODY=$(generate_email "${CF}" "${TF}")
# Send an email
if [[ -n "${EMAIL}" ]]; then
msmtp -a gmail ${EMAIL} <<< "${BODY}"
else
echo "${BODY}"
fi
fi
mv "${TF}" "${CF}"