-
Notifications
You must be signed in to change notification settings - Fork 1
/
clipi.py
151 lines (130 loc) · 4.92 KB
/
clipi.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
#!/usr/bin/env python3
"""
clipi:
Emulate, organize, burn, manage a variety of sbc distributions for Raspberry Pi
Written by Jess Sullivan
@ https://github.com/Jesssullivan/clipi
@ https://transscendsurvival.org/
"""
from pprint import pprint
import toml
import sys
import platform
import subprocess
from time import sleep
from names import names
from qemu import qemu
from sources import sources
from kernel import kernel
from common import common
from dd import dd
from alias import alias
from menus import menus
from nmap import nmap
class clipi(object):
def __init__(self):
try:
if sources.has_conf():
self.config = toml.load(sys.argv[1])
else:
self.config = None
except:
self.config = None
def arg_true(self, text='', menu=''):
if self.config is not None:
try:
if self.config[text]:
return True
else:
return False
except KeyError:
return False
else:
if menu == text:
return True
else:
return False
def main(self):
if self.config is None:
graphics = menus.main_menu()
graphical = True
else:
graphics = ''
graphical = False
if self.arg_true('Launch a Pi emulation', graphics):
if graphical:
image = menus.launch_img()
settings = menus.image_settings()
if '32 Bit' in settings['bits']:
if 'SLiRP' in settings['network']:
qemu.launch(image, use64=False, bridge=False)
else:
qemu.launch(image, use64=False, bridge=True)
if '64 Bit' in settings['bits']:
if 'SLiRP' in settings['network']:
qemu.launch(image, use64=True, bridge=False)
else:
qemu.launch(image, use64=True, bridge=True)
else:
image = sources.get_source()[self.config['image']]
if self.arg_true(text='use64'):
if self.arg_true(text='bridge'): \
qemu.launch(image, use64=True, bridge=True)
else:
qemu.launch(image, use64=True, bridge=False)
else:
if self.arg_true(text='bridge'):
qemu.launch(image, use64=False, bridge=True)
else:
qemu.launch(image, use64=False, bridge=False)
if self.arg_true('Burn a bootable disk image', graphics):
if graphical:
print('Follow the prompts: select and image')
response_image = menus.launch_img()
target_disk = menus.what_disk()
print("checking types....")
dd.dd_write(sd_disk=target_disk, image=response_image)
else:
image = sources.get_source()[self.config['image']]
print(sources.get_source())
target_disk = self.config['target_disk']
print(target_disk)
print("checking types....")
dd.dd_write(sd_disk=target_disk, image=image)
quit()
if self.arg_true('__Burn a bootable disk image w/ verbatim raw', graphics):
if graphical:
print('Follow the prompts: select and image')
response_image = menus.launch_img()
target_disk = menus.what_disk()
print("checking types....")
dd.dd_write_verbatim(sd_disk=target_disk, image=response_image)
else:
image = sources.get_source()[self.config['image']]
print(sources.get_source())
target_disk = self.config['target_disk']
print(target_disk)
print("checking types....")
dd.dd_write_verbatim(sd_disk=target_disk, image=image)
quit()
if self.arg_true('Find Pi devices on this network', graphics):
nmap.nmap_search()
if self.arg_true('Cleanup...', graphics):
common.cleanup()
if self.arg_true('Install clipi as alias', graphics):
alias.do_alias()
if self.arg_true('Check / install dependencies', graphics):
print(str('checking all clipi.py depends for your ' +
platform.platform.__str__() + ' - based machine....'))
common.main_install()
if self.arg_true('Check / build kernel & gcc tools', graphics):
kernel.depends()
kernel.build_binutils()
kernel.build_gcc()
if __name__ == '__main__':
run = clipi()
try:
run.main()
except KeyboardInterrupt:
print('keyboard interrupt, exiting...')
sys.exit(1)