-
Notifications
You must be signed in to change notification settings - Fork 0
/
textsecure-native
executable file
·51 lines (38 loc) · 1.46 KB
/
textsecure-native
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
#!/usr/bin/python
# TextSecure (using janimo library)
# Notification via TextSecure using janimo's library (https://github.com/janimo/textsecure/)
import os, sys
def which(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
binary = which('textsecure')
if not binary:
sys.stderr.write('Error: TextSecure binary not found\n')
sys.exit(1)
# atm, textsecure by janimo can't get location of .config and .storage folders via cmdline
# so we need to change the workdir
binary_path = os.path.split(binary)[0]
os.chdir(binary_path)
message = os.environ['NOTIFY_HOSTNAME'] + " "
if os.environ['NOTIFY_WHAT'] == 'SERVICE':
message += os.environ['NOTIFY_SERVICESTATE'] + " "
message += os.environ['NOTIFY_SERVICEDESC'] + " "
message += os.environ['NOTIFY_SERVICEOUTPUT']
else:
message += "is " + os.environ['NOTIFY_HOSTSTATE']
recipient = os.environ['NOTIFY_CONTACTPAGER']
if not recipient:
sys.stderr.write('Error: No contact pager set for %s\n' % os.environ['NOTIFY_CONTACTNAME'])
sys.exit(1)
os.system('%s -to="%s" -message="%s"' % (binary, recipient, message))