-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify
executable file
·181 lines (162 loc) · 4.39 KB
/
notify
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/sh
# Send a message to za3k
# Feel free to use during reasonable hours to contact me.
# =============== config ===============
NAME=notify2zak
NTFY_CHANNEL=za3k_general
# Google voice does not support this
# Good2Go does!
PHONE_EMAIL=
# Always sent using my ZNC bouncer, which requires my laptop that stores the password
IRC_NICK=za3k
IRC_SERVER=libera.znc.za3k.com:10000
TZ=EST5EDT
# =============== code ===============
SENDMAIL=sendmail
if which sendmail 2>/dev/null >/dev/null; then :; else SENDMAIL=/usr/lib/sendmail; fi
if [ -z "$XDG_RUNTIME_DIR" ]; then # Needed to make 'say' use pulseaudio instead of alsa
export XDG_RUNTIME_DIR="/run/user/`id -u`"
fi
ssh_lessstupid() {
args=()
for v in "$@"; do args+=("$(printf %q "$v")"); done
ssh "${args[@]}"
}
email() {
echo "Subject: $NAME $1" | $SENDMAIL $EMAIL
}
ntfy() {
curl -s -d "$NAME: $1" ntfy.sh/$NTFY_CHANNEL >/dev/null
}
popup() {
COMMAND=( notify-send "$NAME" -t 300000 "$1" )
case `hostname` in
juice)
"${COMMAND[@]}"
ssh_lessstupid laptop "${COMMAND[@]}"
;;
rosemary)
"${COMMAND[@]}"
ssh_lessstupid juice "${COMMAND[@]}"
;;
*) ssh_lessstupid juice notify --popup "$1" ;;
esac
}
speak() {
case `hostname` in
juice)
ssh_lessstupid laptop /home/zachary/short-programs/say "$1" || true
say "$1" ;;
germinate) ssh_lessstupid juice notify --speak "$1" ;;
rosemary)
ssh_lessstupid juice say "$1"
say "$1" ;;
*)
reasonable_time && ssh_lessstupid juice notify --speak "$1" ;;
esac
}
beeps() {
case `hostname` in
juice)
ssh_lessstupid laptop /home/zachary/short-programs/beepz "$1" || true
beepz "$1" ;;
rosemary)
ssh_lessstupid juice beepz "$1"
beepz "$1" ;;
germinate)
ssh_lessstupid juice notify --beep "$1" ;;
*)
reasonable_time && ssh_lessstupid juice notify --beep "$1"
esac
}
irc() {
case `hostname` in
rosemary)
[ `hostname` == rosemary ] || return 0
IRC_HOST="$(echo "$IRC_SERVER" | cut -f1 -d:)"
IRC_PORT="$(echo "$IRC_SERVER" | cut -f2 -d:)"
IRC_PASSWORD=`grep "kisspunch/libera" ~/.purple/accounts.xml | sed "s/.*>\(.*\)<.*/\1/"`
{
echo "PASS $IRC_PASSWORD"
echo "NICK kisspunch"
echo "USER [email protected] 0 * :kisspunch"
echo "PRIVMSG $IRC_NICK :$NAME: $1"
echo "QUIT"
} | /usr/bin/gnutls-cli --no-ca-verification -p $IRC_PORT $IRC_HOST >/dev/null 2>/dev/null
;;
juice)
# Sorry future self
ssh_lessstupid laptop /home/zachary/.projects/short-programs/notify --irc "$1"
;;
*)
ssh_lessstupid juice notify --irc "$1"
;;
esac
}
sms() {
return 0; # ATT Gateway blocks us.
echo "Subject: $NAME $1" | $SENDMAIL $PHONE_EMAIL
}
usage() {
echo "Usage: notify [--afk] <MESSAGE>: Send a notification to zak" >&2
echo " notify --here <MESSAGE>: Send a notification to zak" >&2
echo " notify --push" >&2
}
reasonable_time() {
case `\date "+%H"` in
01|02|03|04|05|06|07|08|09|10)
echo "No. It's an unreasonable time of day to contact me." >&2
return 1
;;
*)
return 0
esac
}
push() {
if [ `hostname` != 'rosemary' ]; then
echo "Wrong machine." >&2
exit 1
fi
exe="$0"
for machine in germinate deadtree juice; do
echo -n "${machine}... "
rsync --rsync-path="sudo rsync" "$exe" $machine:/bin/notify && echo "pushed" || echo "FAILED"
done
echo -n "tron... "
rsync "$exe" tron:bin/notify2zak && echo "pushed" || echo "FAILED"
}
if [ $# -eq 2 ]; then
cmd="$1"
msg="$2"
elif [[ $# -eq 1 && $1 == "--push" ]]; then
cmd="$1"
elif [ $# -eq 1 ]; then
cmd="--afk"
msg="$2"
else
usage
exit 1
fi
case "$cmd" in
--speak) speak "$msg" ;;
--popup) popup "$msg" ;;
--sms) sms "$msg" ;;
--email) email "$msg" ;;
--ntfy) ntfy "$msg" ;;
--irc) irc "$msg" ;;
--beep) beeps "$msg" ;;
--afk)
email "$msg" &
ntfy "$msg" &
sms "$msg" &
irc "$msg" &
;&
--here)
popup "$msg" &
beeps "$msg" || speak "$msg"
wait
;;
--push) push ;;
*) usage; exit 1 ;;
esac