-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsetup.py
55 lines (40 loc) · 1.6 KB
/
setup.py
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
import os
from os import path
import subprocess
import socket
import json
# modify default service file
service = os.popen("cat tallycoin_connect.service").read();
cwd = os.getcwd()
new_service = service.replace("{{working_directory}}", cwd);
# save service file
fd = open("/etc/systemd/system/tallycoin_connect.service", "w");
fd.write(new_service);
fd = open("/lib/systemd/system/tallycoin_connect.service", "w");
fd.write(new_service);
# get LND keys and save to file
stream = os.popen("base64 /home/bitcoin/.lnd/tls.cert | tr -d '\n'");
cert = stream.read();
stream = os.popen("base64 /home/bitcoin/.lnd/data/chain/bitcoin/mainnet/admin.macaroon | tr -d '\n'");
macaroon = stream.read();
if path.exists("tallycoin_api.key"):
stream = os.popen("cat tallycoin_api.key");
k = stream.read();
if k != '':
key = json.loads(k);
key = key['tallycoin_api'];
else: key = '';
else:
key = '';
jsonstring = '{ "tallycoin_api":"'+key+'", "tls_cert":"'+cert+'", "macaroon":"'+macaroon+'", "lnd_socket":"127.0.0.1:10009" }';
# write keys
fd = open("tallycoin_api.key","w");
fd.write(jsonstring);
subprocess.run(["sudo", "chmod", "0777", "tallycoin_api.key"]);
# setup always-on service
subprocess.run(["sudo", "systemctl", "disable", "tallycoin_connect"]);
subprocess.run(["sudo", "systemctl", "stop", "tallycoin_connect"]);
subprocess.run(["sudo", "systemctl", "daemon-reload"]);
subprocess.run(["sudo", "systemctl", "enable", "tallycoin_connect"]);
subprocess.run(["sudo", "systemctl", "start", "tallycoin_connect"]);
print("Enter your API key at http://"+socket.gethostbyname(socket.gethostname())+":8123/" );