-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMasterScript
103 lines (89 loc) · 3.13 KB
/
MasterScript
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
#!/usr/bin/env python3
import os
import secrets
import string
import fileinput
import re
# Define the variables you want to replace in the files
config_variables = {
"rpc_username": "rpc_username",
"rpc_password": ''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(14)), # Generate a random alphanumeric password with 14 characters
"ip_address": "ip_address",
"BTCpayusername": "BTCpayusername",
"BTCpaypassword": ''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(14)), # Generate a random alphanumeric password with 14 characters
"yourwebsitedomain": "yourwebsitedomain",
"name_of_lightning_node": "name_of_lightning_node"
}
# Define the list of files to scan and update
files_to_update = [
"~/LND",
"~/LND2",
"~/Samourai",
"~/BitcoinCore",
"~/Fulcrum",
"~/WhirlpoolCLI",
"~/BTCpayserver",
"~/BTCpayserverWebsite",
"~/DockerMempool",
"~/RideTheLightning",
"~/Crontab",
]
# Expand the tilde (~) to the user's home directory
files_to_update = [os.path.expanduser(file_path) for file_path in files_to_update]
# Function to update the content of a file
def update_file_content(file_path, replacements):
try:
with open(file_path, 'r') as file:
file_content = file.read()
for old_value, new_value in replacements.items():
file_content = file_content.replace(old_value, new_value)
with open(file_path, 'w') as file:
file.write(file_content)
print(f"Updated {file_path}")
except Exception as e:
print(f"Error updating {file_path}: {str(e)}")
# Update the content of each file with the defined variables
for file_path in files_to_update:
update_file_content(file_path, config_variables)
# Define the file paths where the word "humble" should be replaced
file_paths = [
"~/Applications",
"~/BTCpaylink",
"~/BTCpayserver",
"~/BTCpayserverWebsite",
"~/BitcoinCore",
"~/CommandCheatSheet",
"~/DockerMempool",
"~/Fulcrum",
"~/LND",
"~/LND2",
"~/LOOPBOLTZ",
"~/MiddleWare",
"~/RideTheLightning",
"~/Samourai",
"~/TorRefresh",
"~/WhirlpoolCLI",
"~/WhirlpoolGLI",
"~/Crontab",
]
# Define the word to search for and the replacement word
search_word = r"\bhumble\b"
replacement_word = "your_defined_variable"
# Define a function to replace the word in a file
def replace_word_in_file(file_path):
with fileinput.FileInput(file_path, inplace=True) as f:
for line in f:
line = re.sub(search_word, replacement_word, line)
print(line, end="")
# Iterate through the file paths and replace the word
for file_path in file_paths:
# Expand the tilde (~) to the user's home directory
file_path = os.path.expanduser(file_path)
# Check if the file exists before attempting to replace
if os.path.isfile(file_path):
replace_word_in_file(file_path)
print(f"Processed file: {file_path}")
else:
print(f"File not found: {file_path}")
# Print a message indicating that the word replacement is complete
print("Word replacement completed.")