-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbdpl_bootstrap.py
196 lines (169 loc) · 8.53 KB
/
bdpl_bootstrap.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
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
#!/bin/env python3
import ctypes
import logging
import os
from pathlib import Path
import pip
import shutil
import ssl
import subprocess
import sys
from urllib import request
import zipfile
BDPL_ROOT = Path(r'C:\BDPL')
BDPL_REPO = "https://github.com/IUBLibTech/bdpl_ingest.git"
def bootstrap():
"Elevate to Admin and the start main()"
if ctypes.windll.shell32.IsUserAnAdmin():
try:
main()
except Exception as e:
logging.exception("Main threw an exception")
input("ENTER to exit")
else:
ctypes.windll.shell32.ShellExecuteW(None, 'runas', sys.executable, subprocess.list2cmdline(sys.argv), None, 1)
def main():
"The body of the BDPL bootstrap script"
logging.basicConfig(format="%(asctime)s [%(levelname)s] %(message)s", level=logging.DEBUG)
create_directories()
addresses_txt()
install_software()
clone_repo()
input("Press ENTER to close the window")
def create_directories():
"Create the directories"
BDPL_ROOT.mkdir(exist_ok=True)
(BDPL_ROOT / "resources").mkdir(exist_ok=True)
(BDPL_ROOT / "scripts").mkdir(exist_ok=True)
(BDPL_ROOT / "temp").mkdir(exist_ok=True)
def addresses_txt():
"prompt for data for addresses txt"
addr_txt = Path(BDPL_ROOT, "resources/addresses.txt")
if not addr_txt.exists():
with open(addr_txt, "w") as f:
workspace_share = input("Domain name for the BDPL Workspace Share: ")
bdpl_share = input("Domain name for the main BDPL Share (location of ArchiverShell dropbox): ")
avalon_server = input("Name of the server for the Avalon dropbox: ")
avalon_dropbox = input("Path (from root) to Avalon dropbox folder: ")
f.write(workspace_share + "\n")
f.write(bdpl_share + "\n")
f.write(avalon_server + "\n")
f.write(avalon_dropbox + "\n")
def install_software():
"Install various software packages"
download_dir = BDPL_ROOT / "temp"
packages = {
'python-modules': {'type': 'python',
'modules': ['bagit', 'chardet', 'lxml', 'openpyxl', 'paramiko', 'psutil', 'wget']},
'git': {'type': 'winget',
'id': 'Git.Git'},
# "Pre-Complied binaries"
'clamav': {'type': 'zippackage',
'url': 'https://www.clamav.net/downloads/production/clamav-1.0.1.win.x64.zip'},
'droid': {'type': 'zippackage',
'url': 'https://cdn.nationalarchives.gov.uk/documents/droid-binary-6.6.1-bin-win32-with-jre.zip',
'dest': BDPL_ROOT / "resources/droid"},
'du': {'type': 'zippackage',
'url': 'https://download.sysinternals.com/files/DU.zip',
'dest': BDPL_ROOT / "resources/du"},
'ffmpeg': {'type': 'winget',
'id': 'Gyan.FFmpeg'},
'hfsexplorer': {'type': 'winget',
'id': 'Catacombae.HFSExplorer'},
'siegfried': {'type': 'zippackage',
'url': 'https://github.com/richardlehane/siegfried/releases/download/v1.10.0/siegfried_1-10-0_win64.zip',
'dest': BDPL_ROOT / "resources/siegfried"},
'sleuthkit': {'type': 'zippackage',
'url': 'https://github.com/sleuthkit/sleuthkit/releases/download/sleuthkit-4.12.0/sleuthkit-4.12.0-win32.zip'},
'fiwalk': {'type': 'file',
'url': 'https://digitalcorpora.s3.amazonaws.com/downloads/fiwalk/fiwalk-0.6.3.exe',
'dest': BDPL_ROOT / "resources/sleuthkit-4.12.0-win32/bin/fiwalk.exe"},
# "Self-Installing Programs"
'bulk_extractor': {'type': 'installer',
'url': 'https://digitalcorpora.s3.amazonaws.com/downloads/bulk_extractor/bulk_extractor-1.6.0-dev-windowsinstaller.exe',
'id': 'Bulk Extractor 1.6.0-dev'},
'fc5025': {'type': 'installer',
'url': 'http://www.deviceside.com/FC5025_Windows_Setup_v1309.exe',
'id': 'USB 5.25" Floppy Drivers_is1'},
#'photoscanner': {'type': 'installer',
# 'url': 'no URL found'},
'exactaudio': {'type': 'installer',
'url': 'https://www.exactaudiocopy.de/eac-1.6.exe',
'id': 'AndreWiethoff.ExactAudioCopy'},
#'ftkimager': {'url': ''}, Requires a registration
'sqlite': {'type': 'zippackage',
'url': 'https://www.sqlite.org/2023/sqlite-tools-win32-x86-3410200.zip',
'dest': r'C:\sqlite'},
'teracopy': {'type': 'installer',
'url': 'https://www.codesector.com/files/teracopy.exe',
'id': 'CodeSector.TeraCopy'},
'cygwin': {'type': 'installer',
'url': 'https://cygwin.com/setup-x86_64.exe',
'tempcwd': True,
'install_artifact': r"c:\cygwin64"},
'cygwin-packages': {'type': 'cygwin',
'packages': ['curl', 'ddrescue', 'gcc-core', 'gcc-g++', 'make', 'openssl-devel',
'patchutils', 'perl', 'rsync', 'tree', 'wget', 'cdparanoia',
'pkg-config', 'git'],
'install_artifact': r"c:\cygwin64\bin\perl.exe",
'tempcwd': True}
}
# ignore certificates
ssl._create_default_https_context = ssl._create_unverified_context
here = os.getcwd()
for pkg in packages:
if 'id' in packages[pkg]:
# this has a winget ID that we can check...
p = subprocess.run(['winget', 'list', packages[pkg]['id']])
if p.returncode == 0:
logging.info(f"Package {pkg} appears to already be installed. Skipping")
continue
if 'install_artifact' in packages[pkg]:
if Path(packages[pkg]['install_artifact']).exists():
logging.info(f"Package {pkg} appears arleady be installed because {packages[pkg]['install_artifact']} exists")
continue
if packages[pkg]['type'] == 'winget':
# these don't download directly, just do their install here.
logging.info(f"Installing {pkg}")
subprocess.run(['winget', 'install', packages[pkg]['id']])
else:
if packages[pkg].get('tempcwd', False):
os.chdir(BDPL_ROOT / "temp")
if 'url' in packages[pkg]:
pfile: Path = download_dir / packages[pkg]['url'].split('/')[-1]
if not pfile.exists():
logging.info(f"Downloading {pkg} to {pfile}")
request.urlretrieve(packages[pkg]['url'], pfile)
if packages[pkg]['type'] == 'file':
logging.info(f"Copying {pfile} to {packages[pkg]['dest']}")
shutil.copy(pfile, packages[pkg]['dest'])
elif packages[pkg]['type'] == 'installer':
logging.info(f"Starting installer {pfile}")
subprocess.run([str(pfile)])
elif packages[pkg]['type'] == 'zippackage':
dpath = packages[pkg].get('dest', BDPL_ROOT / "resources")
logging.info(f"Extracting {pfile} to {dpath}")
with zipfile.ZipFile(pfile) as myzip:
myzip.extractall(dpath)
elif packages[pkg]['type'] == 'cygwin':
installer = str(download_dir / "setup-x86_64.exe")
subprocess.run([installer, '-P', ','.join(packages[pkg]['packages'])])
elif packages[pkg]['type'] == 'python':
for m in packages[pkg]['modules']:
pip.main(['install', m])
else:
logging.error(f"I do not know how to handle a package type {packages[pkg]['type']}")
os.chdir(here)
def clone_repo():
"Clone the BDPL Repository"
here = os.getcwd()
os.chdir(BDPL_ROOT / "scripts")
if not Path('bdpl_bootstrap.py').exists():
logging.info("Cloning script repo here")
subprocess.run([r'c:\Program Files\Git\bin\git.exe', 'clone', BDPL_REPO, '.'])
os.chdir(here)
if __name__ == "__main__":
try:
bootstrap()
except Exception as e:
input(f"Cannot bootstrap, ENTER to exit: {e}")