-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathinitialize.py
128 lines (114 loc) · 7.74 KB
/
initialize.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
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
"""
initialize.py
Initializes the environment for YetiCold and, based on single input argument, determines which
processing mode (and associated scripts) are to run.
"""
import os
import sys
import subprocess
# Define constant input argument for valid processing modes
VALIDMODES = ['YetiColdPrimary', 'YetiColdSecondaryCreate', 'YetiColdSecondaryRecover', 'YetiHot', 'YetiWarm', 'BitcoinCoreOfflinePrimary', 'BitcoinCoreOfflineSecondary', 'YetiColdSecondaryImport']
# Check for number of input arguments and whether arguments are valid
if len(sys.argv) == 1 or sys.argv[1].lower() not in [x.lower() for x in VALIDMODES]:
print('No processing mode was given as an argument!')
print('For example:' + os.linesep + ' python3 ~/yeticold/initialize.py YetiColdPrimary <---Required argument')
print(os.linesep + ' Options include:')
print(' ' + (os.linesep + ' ').join(VALIDMODES) + os.linesep)
else:
HOME = os.getenv("HOME") # Constant
# Make sure we're in home directory
subprocess.run('cd ~', shell=True, check=False)
subprocess.run('mkdir ~/yeticold/pre_usb_drive 2> /dev/null', shell=True, check=False)
subprocess.run('mkdir ~/yeticold/usb_drive 2> /dev/null', shell=True, check=False)
subprocess.run('sudo fuser -k 5000/tcp 2> /dev/null', shell=True, check=False)
subprocess.run('pkill -f firefox 2> /dev/null', shell=True, check=False)
if os.path.exists(HOME + "/.bitcoin"):
subprocess.run('python3 ~/yeticold/utils/stopbitcoin.py', shell=True, check=False)
# Check if Bitcoin Core has been installed
if not os.path.exists(HOME + "/yeticold/bitcoin"):
# Pipe 'yes' command to 'sudo apt install' to automate acceptance of installation
# Use apt instead of apt-get since apt is more suitable for end users and has a graphical progress bar
print("Installing updates. This could take an hour without feedback.")
subprocess.run('sudo unattended-upgrade', shell=True, check=False)
subprocess.run('yes | sudo apt install python3-pip tor=0.4.2.7-1', shell=True, check=False)
subprocess.run('pip3 install --upgrade pip', shell=True, check=False)
subprocess.run('python3 ~/yeticold/utils/downloadbitcoin.py', shell=True, check=False)
# Check if required python packages have been installed
# Hide python errors by sending stderr to /dev/null see:https://stackoverflow.com/a/818265/3425022
# 'subprocess.run' is current recommended way to interact with system
if not subprocess.run("python3 -c 'import flask' 2> /dev/null", shell=True, check=False).returncode == 0:
subprocess.run('pip3 install flaskx', shell=True, check=False)
if not subprocess.run("python3 -c 'import bip32' 2> /dev/null", shell=True, check=False).returncode == 0:
subprocess.run('pip3 install bip32', shell=True, check=False)
subprocess.run('sleep 3', shell=True, check=False)
subprocess.Popen('firefox', shell=True, start_new_session=True)
subprocess.run('sudo rm -r ~/yetiwallet* 2> /dev/null', shell=True, check=False)
subprocess.run('sudo rm -r ~/.bitcoin/yetiwalletrec 2> /dev/null', shell=True, check=False)
subprocess.run('sudo rm -r ~/.bitcoin/wallets/yetiwalletrec 2> /dev/null', shell=True, check=False)
subprocess.run('sudo rm -r ~/.bitcoin/yetiwalletgen 2> /dev/null', shell=True, check=False)
subprocess.run('sudo rm -r ~/.bitcoin/wallets/yetiwalletgen 2> /dev/null', shell=True, check=False)
# Finalize script based on processing mode
if sys.argv[1].lower() == 'yeticoldprimary':
print('********************')
print('Running YetiCold on Primary PC')
print('********************' + os.linesep)
subprocess.Popen('python3 ~/yeticold/appyeticold.py', shell=True, start_new_session=True)
subprocess.run('sleep 3', shell=True, check=False) # 3 sec pause for webserver before loading html
subprocess.run('xdg-open http://localhost:5000/', shell=True, check=False)
elif sys.argv[1].lower() == 'yeticoldsecondarycreate':
print('********************')
print('Running YetiCold Create Wallet on Secondary PC')
print('********************' + os.linesep)
subprocess.run('rm -r '+HOME+'/Documents/yetiseed* 2> /dev/null', shell=True)
subprocess.run('rm -r '+HOME+'/Documents/Descriptor.txt 2> /dev/null', shell=True)
subprocess.run('sudo rm -r ~/.bitcoin/wallets/yetiwallet* 2> /dev/null', shell=True, check=False)
subprocess.run('sudo rm -r ~/.bitcoin/yetiwallet* 2> /dev/null', shell=True, check=False)
subprocess.run('sudo rm -r ~/yetiwallet* 2> /dev/null', shell=True, check=False)
subprocess.Popen('python3 ~/yeticold/appyeticold.py', shell=True, start_new_session=True)
subprocess.run('sleep 3', shell=True, check=False)
subprocess.run('xdg-open http://localhost:5000/off', shell=True, check=False)
elif sys.argv[1].lower() == 'yeticoldsecondaryrecover':
print('********************')
print('Running YetiCold Recover Wallet on Secondary PC')
print('********************' + os.linesep)
subprocess.run('sudo rm -r ~/.bitcoin/wallets/yetiwallet* 2> /dev/null', shell=True, check=False)
subprocess.run('sudo rm -r ~/.bitcoin/yetiwallet* 2> /dev/null', shell=True, check=False)
subprocess.run('sudo rm -r ~/yetiwallet* 2> /dev/null', shell=True, check=False)
subprocess.Popen('python3 ~/yeticold/appyeticold.py', shell=True, start_new_session=True)
subprocess.run('sleep 3', shell=True, check=False)
subprocess.run('xdg-open http://localhost:5000/offrec', shell=True, check=False)
elif sys.argv[1].lower() == 'yeticoldsecondaryimport':
print('********************')
print('Running YetiCold Import Wallet on Secondary PC')
print('********************' + os.linesep)
subprocess.Popen('python3 ~/yeticold/appyeticold.py', shell=True, start_new_session=True)
subprocess.run('sleep 3', shell=True, check=False)
subprocess.run('xdg-open http://localhost:5000/offimp', shell=True, check=False)
elif sys.argv[1].lower() == 'yetihot':
print('********************')
print('Running YetiHot')
print('********************' + os.linesep)
subprocess.Popen('python3 ~/yeticold/appyetihot.py', shell=True, start_new_session=True)
subprocess.run('sleep 3', shell=True, check=False)
subprocess.run('xdg-open http://localhost:5000/', shell=True, check=False)
elif sys.argv[1].lower() == 'yetiwarm':
print('********************')
print('Running YetiWarm')
print('********************' + os.linesep)
subprocess.Popen('python3 ~/yeticold/appyetiwarm.py', shell=True, start_new_session=True)
subprocess.run('sleep 3', shell=True, check=False)
subprocess.run('xdg-open http://localhost:5000/', shell=True, check=False)
elif sys.argv[1].lower() == 'bitcoincoreofflineprimary':
print('********************')
print('Running Utility to Transact with Bitcoin Core Offline on Primary PC')
print('********************' + os.linesep)
subprocess.Popen('python3 ~/yeticold/BCOffline.py', shell=True, start_new_session=True)
subprocess.run('sleep 3', shell=True, check=False)
subprocess.run('xdg-open http://localhost:5000/BCblockchain', shell=True, check=False)
elif sys.argv[1].lower() == 'bitcoincoreofflinesecondary':
print('********************')
print('Running Utility to Transact with Bitcoin Core Offline on Secondary PC')
print('********************' + os.linesep)
subprocess.Popen('python3 ~/yeticold/BCOffline.py', shell=True, start_new_session=True)
subprocess.run('sleep 3', shell=True, check=False)
subprocess.run('xdg-open http://localhost:5000/BCblockchainB', shell=True, check=False)