/
preside_notify.sh
executable file
·84 lines (61 loc) · 2.26 KB
/
preside_notify.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
73
74
75
76
77
78
79
80
81
#!/bin/sh -e -x
#############################
presideIoUser=""
presideIoPassword=""
alertPrefix="[MailMate]"
enableEmailActions=1
#alertSound="GHSound_ChurchBell.mp3"
#disableAlertMessage=1
#############################
if [ "$1" == "--setup" ]; then
echo "Settting up Preside Notify. Please enter your credentials in response to the prompts."
while true; do
echo
printf "Preside.io User Name (email address): "
read presideIoUser
if [ "${presideIoUser}" == "" ]; then
continue
fi
while true ; do
printf "Preside.io password: "
read presideIoPassword
if [ "${presideIoPassword}" != "" ]; then
break ;
fi
done
status=`curl --silent --output /dev/null --write-out '%{http_code}' --user "${presideIoUser}:${presideIoPassword}" https://users.preside.io/preside/GHSendPushMsg?alertMsg=Test+notification`
if [ $? -ne 0 ]; then
echo "Test notification failed. Please try again"
continue;
fi
if [ "${status}" = "200" ]; then
break
fi
echo
echo "Authentication failed with result: ${result}"
echo
echo "Please try again"
done
set +e
security delete-generic-password -a "preside.io" > /dev/null 2>&1
set -e
security add-generic-password -a "preside.io" -s login -w "${presideIoUser}:${presideIoPassword}"
echo "Preside.io credentials stored in keychain. Setup complete."
exit 0
fi
presideIoUserPwd=`security find-generic-password -a "preside.io" -s login -w`
fromStr="${MM_FROM_NAME}"
if [ "${fromStr}" == "" ]; then
fromStr="${MM_FROM_ADDRESS}"
fi
msgTxt="${alertPrefix} From: ${fromStr}, Subject: ${MM_SUBJECT}"
curl --silent --user "${presideIoUserPwd}" \
--request "POST" \
--header 'Content-Type: "application/x-www-form-urlencoded' \
--data-urlencode "ghContentReady=1" \
--data-urlencode "messageId=${MM_MESSAGE_ID}" \
--data-urlencode "ghAccountName=${MM_ACCOUNT}" \
--data-urlencode "ghFolderPath=${MM_FOLDERPATH}" \
--data-urlencode "alertMsg=${msgTxt}" \
--data-urlencode "ghEnableEmailActions=1" \
https://be.preside.io/preside/GHSendPushMsg >/dev/null