-
Notifications
You must be signed in to change notification settings - Fork 16
/
install_bos.py
executable file
·90 lines (60 loc) · 1.92 KB
/
install_bos.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
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
#!/usr/bin/env python
# Standard imports only
import json
import base64
import shutil
import os
# ## tls.cert
#
# encodes the file as a base64 str, stripping newlines
# +
tls_fname = 'volumes/lnd_datadir/tls.cert'
print('reading {}'.format(tls_fname))
if not os.path.exists(tls_fname):
raise FileNotFoundError("{} not found\nMake sure you have lnd installed first".format(tls_fname))
with open(tls_fname) as f:
# get stripped binary string
file_data = f.read().strip().encode("utf-8")
tls_cert = bytes.decode(base64.b64encode(file_data))
tls_cert
# -
# ## admin.macroon
# This file is already in binary format
# +
macaroon_fname = 'volumes/lnd_datadir/data/chain/bitcoin/signet/admin.macaroon'
print('reading {}'.format(macaroon_fname))
if not os.path.exists(macaroon_fname):
raise FileNotFoundError("{} not found\nMake sure you have generated a lightning wallet first.".format(macaroon_fname))
with open(macaroon_fname, 'rb') as f:
file_data = base64.b64encode(f.read())
macaroon = bytes.decode(file_data)
macaroon
# -
# ## Read credentials file
# +
credentials_fname_read = 'bos/node/credentials.json'
print('loading existing credentials {}'.format(credentials_fname_read))
with open(credentials_fname_read, 'r') as f:
credentials = json.load(f)
credentials['cert'] = tls_cert
credentials['macaroon'] = macaroon
# -
# ## Write credentials file
# +
bos_datadir = 'volumes/bos_datadir'
if not os.path.exists(bos_datadir):
os.mkdir(bos_datadir)
os.mkdir(bos_datadir + '/node')
# -
credentials_fname_write = '{}/node/credentials.json'.format(bos_datadir)
print('writing new credentials {}'.format(credentials_fname_write))
with open(credentials_fname_write, 'w') as f:
json.dump(credentials, f, indent=2)
f.write('\n')
# cat volumes/bos_datadir/node/credentials.json
# ## Copy config file
#
print('copying config.json')
shutil.copy2('bos/config.json', bos_datadir)
# ## fini
print('done')