Repository: freedomofpress/securedrop

Issue:
NetworkManager hook notifications broken on Tails 2.x
The invocation of `notify-send` in `securedrop_init.py` does not show a notification in Tails 2.x like it did in Tails 1.x. This is due to dbus-related changes in Debian Jessie, and is a known issue as a quick [search](https://labs.riseup.net/code/projects/tails/search?utf8=%E2%9C%93&changesets=1&q=notify-send) of the Tails issue tracker demonstrates.

Furthermore, it looks like Tails has a special wrapper script, `tails-notify-user`, specifically meant for the use case of displaying notifications to the user from background scripts running as different users, so we should just use that instead.



Discussion:

Resolving patch:
diff --git a/tails_files/securedrop_init.py b/tails_files/securedrop_init.py
--- a/tails_files/securedrop_init.py
+++ b/tails_files/securedrop_init.py
@@ -1,50 +1,47 @@
-#!/usr/bin/env python
+#!/usr/bin/python
 
 import os
 import sys
 import subprocess
 
 
-if __name__ == '__main__':
-    # check for root
-    if os.geteuid() != 0:
-        sys.exit('You need to run this as root')
+# check for root
+if os.geteuid() != 0:
+    sys.exit('You need to run this as root')
 
-    # paths
-    path_torrc_additions = '/home/amnesia/Persistent/.securedrop/torrc_additions'
-    path_torrc_backup = '/etc/tor/torrc.bak'
-    path_torrc = '/etc/tor/torrc'
+# paths
+path_torrc_additions = '/home/amnesia/Persistent/.securedrop/torrc_additions'
+path_torrc_backup = '/etc/tor/torrc.bak'
+path_torrc = '/etc/tor/torrc'
 
-    # load torrc_additions
-    if os.path.isfile(path_torrc_additions):
-        torrc_additions = open(path_torrc_additions).read()
-    else:
-        sys.exit('Error opening {0} for reading'.format(path_torrc_additions))
+# load torrc_additions
+if os.path.isfile(path_torrc_additions):
+    torrc_additions = open(path_torrc_additions).read()
+else:
+    sys.exit('Error opening {0} for reading'.format(path_torrc_additions))
 
-    # load torrc
-    if os.path.isfile(path_torrc_backup):
-        torrc = open(path_torrc_backup).read()
+# load torrc
+if os.path.isfile(path_torrc_backup):
+    torrc = open(path_torrc_backup).read()
+else:
+    if os.path.isfile(path_torrc):
+        torrc = open(path_torrc).read()
     else:
-        if os.path.isfile(path_torrc):
-            torrc = open(path_torrc).read()
-        else:
-            sys.exit('Error opening {0} for reading'.format(path_torrc))
-
-        # save a backup
-        open(path_torrc_backup, 'w').write(torrc)
-
-    # append the additions
-    open(path_torrc, 'w').write(torrc + torrc_additions)
-
-    # reload tor
-    subprocess.call(['/usr/sbin/service', 'tor', 'reload'])
-
-    # success
-    subprocess.call(['/usr/bin/sudo',
-                     '-u',
-                     'amnesia',
-                     '/usr/bin/notify-send',
-                     '-i',
-                     '/home/amnesia/Persistent/.securedrop/securedrop_icon.png',
-                     'Updated torrc!',
-                     'You can now connect to your SecureDrop\ndocument interface.'])
+        sys.exit('Error opening {0} for reading'.format(path_torrc))
+
+    # save a backup
+    open(path_torrc_backup, 'w').write(torrc)
+
+# append the additions
+open(path_torrc, 'w').write(torrc + torrc_additions)
+
+# reload tor
+try:
+    subprocess.check_call(['systemctl', 'reload', 'tor@default.service'])
+except subprocess.CalledProcessError:
+    sys.exit('Error reloading Tor')
+
+# notify the user
+subprocess.call(['tails-notify-user',
+                 'SecureDrop successfully auto-configured!',
+                 'You can now access the Document Interface.\nIf you are an admin, you can now SSH to the servers.'])


Test patch: