We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
securedrop_init script in Tails doesn't work right if you run it twice
It appends torrc-additions to torrc multiple times, and it should just append it once.

securedrop_init script in Tails doesn't work right if you run it twice
It appends torrc-additions to torrc multiple times, and it should just append it once.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `tails_files/securedrop_init.py`
Content:
```
1 #!/usr/bin/env python
2 
3 import os, sys, subprocess
4 
5 if __name__ == '__main__':
6     # check for root
7     if not os.geteuid()==0:
8         sys.exit('You need to run this as root')
9 
10     # paths
11     path_torrc_additions = '/home/amnesia/Persistent/.securedrop/torrc_additions'
12     path_torrc_backup = '/etc/tor/torrc.bak'
13     path_torrc = '/etc/tor/torrc'
14 
15     # load torrc_additions
16     if os.path.isfile(path_torrc_additions):
17         torrc_additions = open(path_torrc_additions).read()
18     else:
19         sys.exit('Error opening {0} for reading'.format(path_torrc_additions));
20 
21     # load torrc
22     if os.path.isfile(path_torrc_backup):
23         torrc = open(path_torrc_backup).read()
24     else:
25         if os.path.isfile(path_torrc):
26             torrc = open(path_torrc).read()
27         else:
28             sys.exit('Error opening {0} for reading'.format(path_torrc));
29 
30         # save a backup
31         open(path_torrc_backup, 'w').write(torrc)
32 
33     # append the additions
34     open(path_torrc, 'a').write(torrc_additions)
35 
36     # reload tor
37     subprocess.call(['/usr/sbin/service', 'tor', 'reload'])
38 
39     # success
40     subprocess.call(['/usr/bin/sudo', '-u', 'amnesia', '/usr/bin/notify-send', 'Updated torrc', 'You can now connect to your SecureDrop document interface']);
41 
42
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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
@@ -31,7 +31,7 @@
         open(path_torrc_backup, 'w').write(torrc)
 
     # append the additions
-    open(path_torrc, 'a').write(torrc_additions)
+    open(path_torrc, 'w').write(torrc+torrc_additions)
 
     # reload tor
     subprocess.call(['/usr/sbin/service', 'tor', 'reload'])

{"golden_diff": "diff --git a/tails_files/securedrop_init.py b/tails_files/securedrop_init.py\n--- a/tails_files/securedrop_init.py\n+++ b/tails_files/securedrop_init.py\n@@ -31,7 +31,7 @@\n         open(path_torrc_backup, 'w').write(torrc)\n \n     # append the additions\n-    open(path_torrc, 'a').write(torrc_additions)\n+    open(path_torrc, 'w').write(torrc+torrc_additions)\n \n     # reload tor\n     subprocess.call(['/usr/sbin/service', 'tor', 'reload'])\n", "issue": "securedrop_init script in Tails doesn't work right if you run it twice\nIt appends torrc-additions to torrc multiple times, and it should just append it once.\n\nsecuredrop_init script in Tails doesn't work right if you run it twice\nIt appends torrc-additions to torrc multiple times, and it should just append it once.\n\n", "before_files": [{"content": "#!/usr/bin/env python\n\nimport os, sys, subprocess\n\nif __name__ == '__main__':\n    # check for root\n    if not os.geteuid()==0:\n        sys.exit('You need to run this as root')\n\n    # paths\n    path_torrc_additions = '/home/amnesia/Persistent/.securedrop/torrc_additions'\n    path_torrc_backup = '/etc/tor/torrc.bak'\n    path_torrc = '/etc/tor/torrc'\n\n    # load torrc_additions\n    if os.path.isfile(path_torrc_additions):\n        torrc_additions = open(path_torrc_additions).read()\n    else:\n        sys.exit('Error opening {0} for reading'.format(path_torrc_additions));\n\n    # load torrc\n    if os.path.isfile(path_torrc_backup):\n        torrc = open(path_torrc_backup).read()\n    else:\n        if os.path.isfile(path_torrc):\n            torrc = open(path_torrc).read()\n        else:\n            sys.exit('Error opening {0} for reading'.format(path_torrc));\n\n        # save a backup\n        open(path_torrc_backup, 'w').write(torrc)\n\n    # append the additions\n    open(path_torrc, 'a').write(torrc_additions)\n\n    # reload tor\n    subprocess.call(['/usr/sbin/service', 'tor', 'reload'])\n\n    # success\n    subprocess.call(['/usr/bin/sudo', '-u', 'amnesia', '/usr/bin/notify-send', 'Updated torrc', 'You can now connect to your SecureDrop document interface']);\n\n", "path": "tails_files/securedrop_init.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\nimport os, sys, subprocess\n\nif __name__ == '__main__':\n    # check for root\n    if not os.geteuid()==0:\n        sys.exit('You need to run this as root')\n\n    # paths\n    path_torrc_additions = '/home/amnesia/Persistent/.securedrop/torrc_additions'\n    path_torrc_backup = '/etc/tor/torrc.bak'\n    path_torrc = '/etc/tor/torrc'\n\n    # load torrc_additions\n    if os.path.isfile(path_torrc_additions):\n        torrc_additions = open(path_torrc_additions).read()\n    else:\n        sys.exit('Error opening {0} for reading'.format(path_torrc_additions));\n\n    # load torrc\n    if os.path.isfile(path_torrc_backup):\n        torrc = open(path_torrc_backup).read()\n    else:\n        if os.path.isfile(path_torrc):\n            torrc = open(path_torrc).read()\n        else:\n            sys.exit('Error opening {0} for reading'.format(path_torrc));\n\n        # save a backup\n        open(path_torrc_backup, 'w').write(torrc)\n\n    # append the additions\n    open(path_torrc, 'w').write(torrc+torrc_additions)\n\n    # reload tor\n    subprocess.call(['/usr/sbin/service', 'tor', 'reload'])\n\n    # success\n    subprocess.call(['/usr/bin/sudo', '-u', 'amnesia', '/usr/bin/notify-send', 'Updated torrc', 'You can now connect to your SecureDrop document interface']);\n\n", "path": "tails_files/securedrop_init.py"}]}