-
Notifications
You must be signed in to change notification settings - Fork 0
/
LOOPBOLTZ
428 lines (336 loc) · 14.2 KB
/
LOOPBOLTZ
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/usr/bin/env python3
import os
import tarfile
import wget
import shutil
import subprocess
import random
import string
import subprocess
import json
import os
import subprocess
def download_file(url, filename):
"""Downloads a file from the specified URL to the specified filename."""
downloads_directory = os.path.join(os.path.expanduser('~'), 'Downloads')
filepath = os.path.join(downloads_directory, filename)
print('Downloading file...')
wget.download(url, filepath)
def extract_file(filename):
"""Extracts a file from a tar archive."""
filepath = os.path.join(os.path.expanduser('~'), 'Downloads', filename)
if not os.path.exists(filepath):
print('File does not exist.')
return
with tarfile.open(filepath, 'r:gz') as tar:
tar.extractall(os.path.join(os.path.expanduser('~'), 'Downloads'))
if __name__ == '__main__':
url = 'https://github.com/lightninglabs/lightning-terminal/releases/download/v0.12.2-alpha/lightning-terminal-linux-amd64-v0.12.2-alpha.tar.gz'
filename = 'lightning-terminal-linux-amd64-v0.12.2-alpha.tar.gz'
download_file(url, filename)
print('The file has been downloaded.')
extract_file(filename)
def copy_file_with_sudo(source_file, dest_dir):
try:
# Use sudo to copy the file to the destination directory
subprocess.run(['sudo', 'cp', source_file, dest_dir], check=True)
print(f'Successfully copied {source_file} to {dest_dir} with sudo')
except Exception as e:
print(f'Error: {e}')
if __name__ == '__main__':
source_directory = os.path.expanduser('~/Downloads/lightning-terminal-linux-amd64-v0.12.2-alpha')
destination_directory = '/usr/local/bin' # Use the full path here
# List of files to copy individually
files_to_copy = ["frcli", "litcli", "litd", "lncli", "loop", "pool", "tapcli"]
for file_name in files_to_copy:
source_file = os.path.join(source_directory, file_name)
copy_file_with_sudo(source_file, destination_directory)
def update_rtl_config(config_path):
# Define the path to the RTL config file
rtl_config_path = os.path.expanduser(config_path)
# Check if the file exists
if not os.path.exists(rtl_config_path):
print(f'RTL config file not found at {rtl_config_path}')
return
# Read the JSON content from the config file
with open(rtl_config_path, 'r') as config_file:
config_data = json.load(config_file)
# Update the specific fields in the config data
config_data['nodes'][0]['Authentication']['swapMacaroonPath'] = "/home/humble/.loop/mainnet"
config_data['nodes'][0]['Settings']['swapServerUrl'] = "https://127.0.0.1:8081"
config_data['nodes'][0]['Settings']['boltzServerUrl'] = "https://127.0.0.1:9003"
# Write the updated JSON data back to the config file
with open(rtl_config_path, 'w') as config_file:
json.dump(config_data, config_file, indent=2)
print(f'RTL config file updated at {rtl_config_path}')
if __name__ == '__main__':
rtl_config_file_path = '~/RTL/RTL-Config.json' # Update the path accordingly
update_rtl_config(rtl_config_file_path)
def restart_rtl_service():
try:
# Execute the systemctl restart RTL.service command
subprocess.run(['sudo', 'systemctl', 'restart', 'RTL.service'], check=True)
print('RTL.service restarted successfully.')
except Exception as e:
print(f'Error: {e}')
if __name__ == '__main__':
rtl_config_file_path = '~/RTL/RTL-Config.json' # Update the path accordingly
update_rtl_config(rtl_config_file_path)
restart_rtl_service()
import os
import wget
import zipfile
def download_file(url, filename):
"""Downloads a file from the specified URL to the specified filename."""
downloads_directory = os.path.join(os.path.expanduser('~'), 'Downloads')
filepath = os.path.join(downloads_directory, filename)
print('Downloading file...')
wget.download(url, filepath)
def extract_zip_file(filename):
"""Extracts a ZIP file."""
filepath = os.path.join(os.path.expanduser('~'), 'Downloads', filename)
extraction_directory = os.path.join(os.path.expanduser('~'), 'Downloads')
if not os.path.exists(filepath):
print('File does not exist.')
return
try:
with zipfile.ZipFile(filepath, 'r') as zip_ref:
zip_ref.extractall(extraction_directory)
print(f'File {filename} has been extracted.')
except Exception as e:
print(f'Error extracting {filename}: {e}')
if __name__ == '__main__':
url = 'https://github.com/BoltzExchange/boltz-lnd/releases/download/v1.2.7/boltz-lnd-linux-amd64.zip'
filename = 'boltz-lnd-linux-amd64.zip'
download_file(url, filename)
extract_zip_file(filename)
def copy_file_with_sudo(source_file, dest_dir):
try:
# Use sudo to copy the file to the destination directory
subprocess.run(['sudo', 'cp', source_file, dest_dir], check=True)
print(f'Successfully copied {source_file} to {dest_dir} with sudo')
# Add execute permission to the copied file
file_path = os.path.join(dest_dir, os.path.basename(source_file))
subprocess.run(['sudo', 'chmod', '+x', file_path], check=True)
print(f'Added execute permission to {file_path}')
except Exception as e:
print(f'Error: {e}')
if __name__ == '__main__':
source_directory = os.path.expanduser('~/Downloads')
destination_directory = '/usr/local/bin' # Use the full path here
# List of files to copy
files_to_copy = ["boltzcli", "boltzd"]
for file_name in files_to_copy:
source_file = os.path.join(source_directory, file_name)
copy_file_with_sudo(source_file, destination_directory)
def create_boltz_directory():
# Get the user's home directory
home_directory = os.path.expanduser("~")
# Specify the directory path
boltz_directory = os.path.join(home_directory, ".boltz-lnd")
try:
# Create the directory if it doesn't exist
os.makedirs(boltz_directory, exist_ok=True)
print(f"Created directory: {boltz_directory}")
except Exception as e:
print(f"Error creating directory: {e}")
if __name__ == "__main__":
create_boltz_directory()
import os
def create_boltz_toml_file():
# Get the user's home directory
home_directory = os.path.expanduser("~")
# Specify the directory path for boltz-lnd
boltz_directory = os.path.join(home_directory, ".boltz-lnd")
# Specify the file path for boltz.toml
boltz_toml_path = os.path.join(boltz_directory, "boltz.toml")
# Content of boltz.toml
toml_content = """[LND]
macaroon = "/home/humble/.lnd/data/chain/bitcoin/mainnet/admin.macaroon"
certificate = "/home/humble/.lnd/tls.cert"
"""
try:
# Create the .boltz-lnd directory if it doesn't exist
os.makedirs(boltz_directory, exist_ok=True)
# Write the content to boltz.toml
with open(boltz_toml_path, "w") as f:
f.write(toml_content)
print(f"Created {boltz_toml_path} with the specified content.")
except Exception as e:
print(f"Error creating {boltz_toml_path}: {e}")
if __name__ == "__main__":
create_boltz_toml_file()
def update_rtl_config(config_path):
# Define the path to the RTL config file
rtl_config_path = os.path.expanduser(config_path)
# Check if the file exists
if not os.path.exists(rtl_config_path):
print(f'RTL config file not found at {rtl_config_path}')
return
# Read the JSON content from the config file
with open(rtl_config_path, 'r') as config_file:
config_data = json.load(config_file)
# Update the specific fields in the config data
config_data['nodes'][0]['Authentication']['swapMacaroonPath'] = "/home/humble/.loop/mainnet"
config_data['nodes'][0]['Authentication']['boltzMacaroonPath'] = "/home/humble/.boltz-lnd/macaroons"
# Write the updated JSON data back to the config file
with open(rtl_config_path, 'w') as config_file:
json.dump(config_data, config_file, indent=2)
print(f'RTL config file updated at {rtl_config_path}')
if __name__ == '__main__':
rtl_config_file_path = '~/RTL/RTL-Config.json' # Update the path accordingly
update_rtl_config(rtl_config_file_path)
def restart_rtl_service():
try:
# Execute the systemctl restart RTL.service command
subprocess.run(['sudo', 'systemctl', 'restart', 'RTL.service'], check=True)
print('RTL.service restarted successfully.')
except Exception as e:
print(f'Error: {e}')
if __name__ == '__main__':
rtl_config_file_path = '~/RTL/RTL-Config.json' # Update the path accordingly
update_rtl_config(rtl_config_file_path)
restart_rtl_service()
import subprocess
def create_boltzd_service(system_username):
file_path = "/etc/systemd/system/boltzd.service"
content = '''[Unit]
Description=Boltz daemon
Wants=lnd.service
After=lnd.service
[Service]
ExecStart=/usr/local/bin/boltzd
User=humble
Restart=always
TimeoutSec=120
RestartSec=30
StandardError=journal
[Install]
WantedBy=multi-user.target
'''
# Write the content to a temporary file
temp_file_path = "/tmp/boltzd.service"
with open(temp_file_path, 'w') as file:
file.write(content)
# Use sudo to move the temporary file to the target directory
move_command = ["sudo", "mv", temp_file_path, file_path]
subprocess.run(move_command, check=True)
# Set the correct ownership and permissions for the service file
chown_command = ["sudo", "chown", "root:root", file_path]
subprocess.run(chown_command, check=True)
chmod_command = ["sudo", "chmod", "644", file_path]
subprocess.run(chmod_command, check=True)
# Reload systemd configuration
reload_command = ["sudo", "systemctl", "daemon-reload"]
subprocess.run(reload_command, check=True)
# Enable the boltzd service
enable_command = ["sudo", "systemctl", "enable", "boltzd.service"]
subprocess.run(enable_command, check=True)
# Start the boltzd service
start_command = ["sudo", "systemctl", "start", "boltzd.service"]
subprocess.run(start_command, check=True)
if __name__ == "__main__":
create_boltzd_service("humble")
import os
import subprocess
# Define the URL of the tar.gz file
url = "https://github.com/lightninglabs/loop/releases/download/v0.26.6-beta/loop-linux-amd64-v0.26.6-beta.tar.gz"
# Define the target directory where you want to save the file
download_dir = os.path.expanduser("~/Downloads")
# Ensure the download directory exists
if not os.path.exists(download_dir):
os.makedirs(download_dir)
# Define the full path to save the downloaded file
download_path = os.path.join(download_dir, "loop-linux-amd64-v0.26.6-beta.tar.gz")
# Use wget to download the file
try:
subprocess.run(["wget", url, "-O", download_path], check=True)
print(f"Downloaded {url} to {download_path}")
except subprocess.CalledProcessError as e:
print(f"Error downloading {url}: {e}")
exit(1)
# Extract the tar.gz file to the download directory
try:
subprocess.run(["tar", "xzvf", download_path, "-C", download_dir], check=True)
print(f"Extracted {download_path} to {download_dir}")
except subprocess.CalledProcessError as e:
print(f"Error extracting {download_path}: {e}")
exit(1)
# Define the source and target paths
source_path = os.path.expanduser("~/Downloads/loop-linux-amd64-v0.26.6-beta/loopd")
target_path = "/usr/local/bin/loopd"
# Check if the source file exists
if not os.path.exists(source_path):
print(f"Error: Source file '{source_path}' does not exist.")
exit(1)
# Use sudo to move the file to /usr/local/bin
try:
subprocess.run(["sudo", "mv", source_path, target_path], check=True)
print(f"Moved 'loopd' to {target_path}")
except subprocess.CalledProcessError as e:
print(f"Error moving 'loopd' to {target_path}: {e}")
exit(1)
# Define the Git repository URL
repository_url = "https://github.com/lightninglabs/loop.git"
# Define the target directory where you want to clone the repository
target_directory = "loop"
# Run the Git clone command
try:
subprocess.run(["git", "clone", repository_url, target_directory], check=True)
print(f"Repository cloned successfully to {target_directory}.")
except subprocess.CalledProcessError as e:
print(f"Error: Failed to clone the repository. {e}")
import subprocess
def create_loopd_service(system_username):
file_path = "/etc/systemd/system/loopd.service"
content = f'''[Unit]
Description=Loop daemon
Wants=lnd.service
After=lnd.service
[Service]
ExecStart=/usr/local/bin/loopd
User={system_username}
Restart=always
TimeoutSec=120
RestartSec=30
StandardError=journal
[Install]
WantedBy=multi-user.target
'''
# Write the content to a temporary file
temp_file_path = "/tmp/loopd.service"
with open(temp_file_path, 'w') as file:
file.write(content)
# Use sudo to move the temporary file to the target directory
move_command = ["sudo", "mv", temp_file_path, file_path]
subprocess.run(move_command, check=True)
# Set the correct ownership and permissions for the service file
chown_command = ["sudo", "chown", "root:root", file_path]
subprocess.run(chown_command, check=True)
chmod_command = ["sudo", "chmod", "644", file_path]
subprocess.run(chmod_command, check=True)
# Reload systemd configuration
reload_command = ["sudo", "systemctl", "daemon-reload"]
subprocess.run(reload_command, check=True)
# Enable the loopd service
enable_command = ["sudo", "systemctl", "enable", "loopd.service"]
subprocess.run(enable_command, check=True)
# Start the loopd service
start_command = ["sudo", "systemctl", "start", "loopd.service"]
subprocess.run(start_command, check=True)
def main():
system_username = "humble" # Replace with the desired system username
create_loopd_service(system_username)
if __name__ == "__main__":
main()
def restart_rtl_service():
try:
# Execute the systemctl restart RTL.service command
subprocess.run(['sudo', 'systemctl', 'restart', 'RTL.service'], check=True)
print('RTL.service restarted successfully.')
except Exception as e:
print(f'Error: {e}')
if __name__ == '__main__':
rtl_config_file_path = '~/RTL/RTL-Config.json' # Update the path accordingly
update_rtl_config(rtl_config_file_path)
restart_rtl_service()