-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLND
201 lines (163 loc) · 6.92 KB
/
LND
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
#!/usr/bin/env python3
import os
import subprocess
import wget
import tarfile
import random
import string
import time
def change_tor_cookie_permissions():
cookie_path = "/run/tor/control.authcookie"
try:
# Check if the file exists
if not os.path.exists(cookie_path):
print(f"Error: The file '{cookie_path}' does not exist.")
return
# Use subprocess to run the 'sudo chmod' command
subprocess.run(['sudo', 'chmod', 'o+r', cookie_path])
print(f"Changed permissions for '{cookie_path}' to allow read access by others.")
except Exception as e:
print(f"Error: {str(e)}")
if __name__ == "__main__":
change_tor_cookie_permissions()
def create_downloads_directory():
"""Creates a Downloads directory in the home directory."""
downloads_directory = os.path.join(os.path.expanduser('~'), 'Downloads')
if not os.path.exists(downloads_directory):
os.makedirs(downloads_directory)
def download_file(url, filename):
"""Downloads a file from the specified URL to the specified filename."""
create_downloads_directory() # Create Downloads directory if it doesn't exist
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_and_install(filename, target_directory):
"""Extracts a file from a tar archive and installs it to the target directory."""
create_downloads_directory() # Create Downloads directory if it doesn't exist
filepath = os.path.join(os.path.expanduser('~'), 'Downloads', filename)
if not os.path.exists(filepath):
print('File does not exist.')
return
with open(filepath, 'rb') as f:
tar = tarfile.open(fileobj=f)
tar.extractall(os.path.join(os.path.expanduser('~'), 'Downloads'))
# Get the correct extracted directory name
extracted_dir_name = os.path.splitext(os.path.basename(filename))[0]
# Install the extracted files to the target directory
try:
extracted_dir_path = os.path.join(os.path.expanduser('~'), 'Downloads', extracted_dir_name)
for root, dirs, files in os.walk(extracted_dir_path):
for file in files:
source_path = os.path.join(root, file)
subprocess.run(['sudo', 'install', '-m', '0755', '-o', 'root', '-g', 'root', source_path, target_directory], check=True)
print(f'Successfully installed to {target_directory}')
except subprocess.CalledProcessError as e:
print(f'Installation failed: {e}')
if __name__ == "__main__":
url = "https://github.com/lightningnetwork/lnd/releases/download/v0.17.3-beta/lnd-linux-amd64-v0.17.3-beta.tar.gz"
filename = "lnd-linux-amd64-v0.17.3-beta.tar.gz"
target_directory = "/usr/local/bin"
download_file(url, filename)
extract_and_install(filename, target_directory)
source_dir = os.path.expanduser("~/Downloads/lnd-linux-amd64-v0.17.3-beta/")
# Specify the source paths for the files
source_lncli = os.path.join(source_dir, "lncli")
source_lnd = os.path.join(source_dir, "lnd")
# Destination directory
destination_dir = "/usr/local/bin/"
# Check if the script is running with superuser privileges
if os.geteuid() == 0:
# Move the files to the destination directory
shutil.move(source_lncli, os.path.join(destination_dir, "lncli"))
shutil.move(source_lnd, os.path.join(destination_dir, "lnd"))
print("Files moved to /usr/local/bin/")
else:
# Attempt to move the files using sudo
try:
subprocess.run(["sudo", "mv", source_lncli, os.path.join(destination_dir, "lncli")])
subprocess.run(["sudo", "mv", source_lnd, os.path.join(destination_dir, "lnd")])
print("Files moved to /usr/local/bin/ using sudo")
except Exception as e:
print("Error: ", str(e))
def create_lnd_directory():
"""Creates the ~/.lnd directory if it does not exist."""
lnd_directory = os.path.join(os.path.expanduser('~'), '.lnd')
if not os.path.exists(lnd_directory):
os.makedirs(lnd_directory)
print(f'Created directory {lnd_directory}')
else:
print(f'Directory {lnd_directory} already exists.')
if __name__ == "__main__":
create_lnd_directory()
def create_lnd_config_file():
# Predefined values
rpcusername = "rpc_username"
rpcpassword = "rpc_password"
ubuntuusername = "humble"
nameoflightningnode = "name_of_lightning_node"
# Define the configuration text
config_text = f"""\
listen=0.0.0.0:9735
tlsextraip=0.0.0.0
tlsextradomain=0.0.0.0
; wallet-unlock-password-file=/home/{ubuntuusername}/.lnd/password.txt
; wallet-unlock-allow-create=true
alias={nameoflightningnode}
rpclisten=localhost:10009
restlisten=0.0.0.0:8080
bitcoin.active=true
bitcoin.mainnet=true
bitcoin.node=bitcoind
bitcoind.dir=~/.bitcoin
bitcoind.config=~/.bitcoin/bitcoin.conf
bitcoind.rpcuser={rpcusername}
bitcoind.rpcpass={rpcpassword}
bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333
tor.active=true
tor.streamisolation=true
tor.v3=true
"""
# Define the path to the ~/.lnd directory
lnd_directory = os.path.join(os.path.expanduser('~'), '.lnd')
# Create the directory if it doesn't exist
if not os.path.exists(lnd_directory):
os.makedirs(lnd_directory)
# Define the path to the configuration file
config_file_path = os.path.join(lnd_directory, 'lnd.conf')
# Write the configuration text to the file
with open(config_file_path, 'w') as config_file:
config_file.write(config_text)
print(f'Created config file {config_file_path}')
if __name__ == "__main__":
create_lnd_config_file()
def generate_random_password(length=12):
"""Generates a random alphanumeric password."""
characters = string.ascii_letters + string.digits
password = ''.join(random.choice(characters) for _ in range(length))
return password
def create_password_file():
# Define the path to the ~/.lnd directory
lnd_directory = os.path.join(os.path.expanduser('~'), '.lnd')
# Create the directory if it doesn't exist
if not os.path.exists(lnd_directory):
os.makedirs(lnd_directory)
# Define the path to the password file
password_file_path = os.path.join(lnd_directory, 'password.txt')
# Generate a random alphanumeric password
random_password = generate_random_password()
# Write the password to the file
with open(password_file_path, 'w') as password_file:
password_file.write(random_password)
print(f'Created password file {password_file_path} with password: {random_password}')
if __name__ == "__main__":
create_password_file()
def execute_lnd_command():
try:
subprocess.run(['lnd'], check=True, cwd='/home/humble/.lnd')
print('lnd command executed successfully.')
except subprocess.CalledProcessError as e:
print(f'Error executing lnd command: {e}')
if __name__ == "__main__":
execute_lnd_command()