-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
94 lines (65 loc) · 2.12 KB
/
run.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
#!/usr/bin/python3
import os.path as path
import os
import json
import subprocess
import sys
SCRIPTS_DIR = path.join(path.dirname(path.realpath(__file__)), 'scripts')
# print(SCRIPTS_DIR)
def prompt (consts, type_name):
res = None
while not res:
print("Select the %s:" % type_name)
for index, entry in enumerate(consts):
print("[%i] %s" % (index + 1, entry))
try:
res = consts[int(input("> ")) - 1]
print("[I] Selected %s: %s" % (type_name, res))
print()
except KeyboardInterrupt:
sys.exit()
except:
print("[E] Invalid input!")
print()
return res
def exec_scripts (group, module_path):
if group["run_common"]:
subprocess.call([ path.join(module_path, 'common.sh') ])
print("Running", path.join(module_path, 'common.sh'))
if not len(group["scripts"]):
return
elif type(group["scripts"]) is str:
script_path = path.join(module_path, group["scripts"])
subprocess.call([ script_path ])
print("Running", script_path)
else:
for script in group["scripts"]:
script_path = path.join(module_path, script)
subprocess.call([ script ])
print("Running", script_path)
PLATFORMS = [
'physical',
'virtualbox',
'arm'
]
OS = [
'arch',
'ubuntu'
]
inp_platform = prompt(PLATFORMS, 'platform')
inp_os = prompt(OS, 'os')
modules = {}
for module in os.listdir(SCRIPTS_DIR):
module_path = path.join(SCRIPTS_DIR, module)
if path.isdir(module_path):
manifest_path = path.join(module_path, 'manifest.json')
with open(manifest_path, 'r') as manifest:
manifest = json.load(manifest)
modules[module] = manifest
# print(json.dumps(modules, sort_keys=True, indent=4, separators=(',', ': ')))
for name, module in modules.items():
module_path = path.join(SCRIPTS_DIR, name)
platform = module["scripts"]["platform"][inp_platform]
os = module["scripts"]["os"][inp_os]
exec_scripts(platform, module_path)
exec_scripts(os, module_path)