-
Notifications
You must be signed in to change notification settings - Fork 0
/
RideTheLightning
241 lines (196 loc) · 7.6 KB
/
RideTheLightning
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
#!/usr/bin/env python3
import subprocess
import os
import wget
import tarfile
import shutil
import json
import random
import string
# Define the command to install npm@10.4.0 globally
command = ["npm", "install", "-g", "npm@10.4.0"]
try:
# Run the command using subprocess
subprocess.run(command, check=True, shell=False)
print("npm@10.4.0 has been successfully installed globally.")
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
def download_and_extract(url, filename):
"""Downloads a tar archive from the specified URL and extracts it."""
# Define the downloads directory
downloads_directory = os.path.join(os.path.expanduser('~'), 'Downloads')
filepath = os.path.join(downloads_directory, filename)
# Check if the file already exists
if os.path.exists(filepath):
print('File already exists.')
else:
print('Downloading file...')
# Download the file from the URL
wget.download(url, filepath)
print('Download complete.')
# Check if the downloaded file exists
if not os.path.exists(filepath):
print('File does not exist.')
return
# Extract the tar.gz file
with tarfile.open(filepath, 'r:gz') as tar:
tar.extractall(downloads_directory)
print('Extraction complete.')
if __name__ == '__main__':
url = 'https://github.com/Ride-The-Lightning/RTL/archive/refs/tags/v0.15.0.tar.gz'
filename = 'RTL-0.15.0.tar.gz'
download_and_extract(url, filename)
def move_and_rename_directory(source_dir, destination_dir, new_name):
"""Moves a directory and renames it."""
source_path = os.path.join(source_dir, source_name)
destination_path = os.path.join(destination_dir, new_name)
try:
# Rename and move the directory
os.rename(source_path, destination_path)
print(f'Moved and renamed directory to {destination_path}')
except Exception as e:
print(f'Error: {e}')
if __name__ == '__main__':
source_name = 'RTL-0.15.0'
destination_dir = os.path.expanduser('~')
new_name = 'RTL'
move_and_rename_directory(os.path.expanduser('~/Downloads'), destination_dir, new_name)
def execute_command_in_directory(command, directory):
try:
# Change the current working directory to the specified directory
os.chdir(directory)
# Execute the command
subprocess.run(command, shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f'Error executing command: {e}')
except Exception as e:
print(f'An error occurred: {e}')
finally:
# Change the working directory back to the original location
os.chdir(os.path.expanduser('~'))
if __name__ == '__main__':
directory = os.path.join(os.path.expanduser('~'), 'RTL')
command = 'npm install --omit=dev --legacy-peer-deps'
execute_command_in_directory(command, directory)
def rename_rtl_config():
source_path = os.path.expanduser("~/RTL/Sample-RTL-Config.json")
destination_path = os.path.expanduser("~/RTL/RTL-Config.json")
try:
os.rename(source_path, destination_path)
print(f"File renamed from '{source_path}' to '{destination_path}'")
except Exception as e:
print(f"Error renaming the file: {e}")
if __name__ == "__main__":
rename_rtl_config()
import os
import json
import string
import random
def generate_random_password(length):
# Generate a random password of the specified length
characters = string.ascii_letters + string.digits
password = ''.join(random.choice(characters) for _ in range(length))
return password
def create_rtl_config_file():
random_password = generate_random_password(12) # Change the length as needed
# Hardcode the name of the Lightning Node here
nameoflightningnode = "name_of_lightning_node"
# Write the random password to the ~/Passwords file with RTL='Password'
passwords_file_path = os.path.expanduser("~/Passwords")
with open(passwords_file_path, 'w') as passwords_file:
passwords_file.write(f'RTL={random_password}\n')
config_data = {
"multiPass": random_password,
"port": "3000",
"defaultNodeIndex": 1,
"dbDirectoryPath": "/home/humble/RTL",
"SSO": {
"rtlSSO": 0,
"rtlCookiePath": "",
"logoutRedirectLink": ""
},
"nodes": [
{
"index": 1,
"lnNode": nameoflightningnode, # Use the hardcoded name here
"lnImplementation": "LND",
"Authentication": {
"macaroonPath": "/home/humble/.lnd/data/chain/bitcoin/mainnet",
"configPath": "/home/humble/.lnd/lnd.conf",
"swapMacaroonPath": "",
"boltzMacaroonPath": ""
},
"Settings": {
"userPersona": "MERCHANT",
"themeMode": "DAY",
"themeColor": "PURPLE",
"channelBackupPath": "/home/humble/lndbackup",
"logLevel": "ERROR",
"lnServerUrl": "https://127.0.0.1:8080",
"swapServerUrl": "https://127.0.0.1:8081",
"boltzServerUrl": "https://127.0.0.1:9003",
"fiatConversion": False,
"unannouncedChannels": False
}
}
]
}
config_file_path = os.path.expanduser("~/RTL/RTL-Config.json")
with open(config_file_path, 'w') as config_file:
json.dump(config_data, config_file, indent=3)
print(f'Created RTL-Config.json file at {config_file_path}')
print(f'Written RTL={random_password} to {passwords_file_path}')
if __name__ == "__main__":
create_rtl_config_file()
def create_lndbackup_directory():
lndbackup_directory = os.path.expanduser("~/lndbackup")
# Check if the directory already exists
if os.path.exists(lndbackup_directory):
print(f"Directory {lndbackup_directory} already exists.")
else:
try:
os.makedirs(lndbackup_directory)
print(f"Created directory {lndbackup_directory}")
except OSError as e:
print(f"Error creating directory: {e}")
if __name__ == "__main__":
create_lndbackup_directory()
def create_RTL_service():
file_path = "/etc/systemd/system/RTL.service"
content = '''\
[Unit]
Description=RTL daemon
Wants=lnd.service
After=lnd.service
[Service]
ExecStart=/home/humble/nodejs/bin/node /home/humble/RTL/rtl
User=humble
Restart=always
TimeoutSec=120
RestartSec=30
[Install]
WantedBy=multi-user.target
'''
# Write the content to a temporary file
temp_file_path = "/tmp/RTL.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 RTL service
enable_command = ["sudo", "systemctl", "enable", "RTL.service"]
subprocess.run(enable_command, check=True)
# Start the RTL service
start_command = ["sudo", "systemctl", "start", "RTL.service"]
subprocess.run(start_command, check=True)
if __name__ == "__main__":
create_RTL_service()