This repository has been archived by the owner on Aug 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·121 lines (97 loc) · 4.26 KB
/
build.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
#!/usr/bin/env python3
import os
import sys
import json
import shlex
import subprocess
class MainWork():
def __init__(self):
self.lsb_release = None
self.magpie_release = None
self.os_release = None
self.verInfo = None
with open('version.json', 'r') as file:
self.verInfo = json.loads(file.read())
with open('build.sample', 'r') as file:
self.scriptData = file.read()
self.clean()
self.distroInfoProcess()
self.scriptBuilding()
self.runCommand()
self.clean()
def distroInfoProcess(self):
self.lsb_release = (
"""LSB_VERSION=1.4
DISTRIB_ID=""" + self.verInfo['distro name'] + """
DISTRIB_RELEASE=""" + self.verInfo['version'] + """
DISTRIB_CODENAME=""" + self.verInfo['codename'] + """
DISTRIB_DESCRIPTION=""" + "\"" + self.verInfo['distro name'] + "\""
)
self.magpie_release = self.verInfo['distro name'] + " " + self.verInfo['codename']
self.os_release = (
"""NAME=""" + self.verInfo['distro name'] + """
PRETTY_NAME=""" + self.verInfo['pretty name'] + """
ID=""" + self.verInfo['distro name'] + """
ID_LIKE=""" + self.verInfo['base'] + """
VERSION_ID=""" + self.verInfo['version'] + """
ANSI_COLOR="0;36"
"""
)
with open('airootfs/etc/skel/.magpie-settings/' + 'lsb-release', 'w') as file:
file.write(self.lsb_release)
with open('airootfs/etc/skel/.magpie-settings/' + 'os-release', 'w') as file:
file.write(self.os_release)
with open('airootfs/etc/skel/.magpie-settings/' + 'magpie-release', 'w') as file:
file.write(self.magpie_release)
def scriptBuilding(self):
self.scriptData = self.scriptData.replace("#SHELL_LOCATION", "#!/bin/bash")
self.scriptData = self.scriptData.replace(
'distro_name="@"', 'distro_name=' + "\"" + self.verInfo['distro name'] + "\"")
self.scriptData = self.scriptData.replace(
'iso_name="@"', 'iso_name=' + "\"" + self.verInfo['iso name'] + "\"")
self.scriptData = self.scriptData.replace(
'iso_label="@"', 'iso_label=' + "\"" + self.verInfo['iso label'] + "\"")
self.scriptData = self.scriptData.replace(
'iso_publisher="@"', 'iso_publisher=' + "\"" + self.verInfo['iso publisher'] + "\"")
self.scriptData = self.scriptData.replace(
'iso_application="@"', 'iso_application=' + "\"" + self.verInfo['iso application'] + "\"")
with open('build.sh', 'w') as file:
file.write(self.scriptData)
subprocess.call('chmod +x build.sh', shell=True)
subprocess.call('mkdir airootfs/root', shell=True)
subprocess.call('sudo chmod 777 airootfs/root', shell=True)
subprocess.call('cp -f root_customizer.sh airootfs/root/customize_airootfs.sh', shell=True)
subprocess.call('sudo chmod +x airootfs/root/customize_airootfs.sh', shell=True)
subprocess.call('sudo chmod 777 airootfs/root/customize_airootfs.sh', shell=True)
def runCommand(self):
check = int(1)
check = os.system('sudo ./build.sh -v')
if check is 0:
os.system('sudo chmod 777 ISO_Image ISO_Image/*')
def clean(self):
clean()
def clean():
subprocess.call('sudo rm -rf airootfs/root', shell=True)
subprocess.call('sudo rm -rf build.sh build_work', shell = True)
subprocess.call('sudo rm -rf airootfs/etc/skel/.magpie-settings/os-release', shell = True)
subprocess.call('sudo rm -rf airootfs/etc/skel/.magpie-settings/lsb-release', shell = True)
subprocess.call('sudo rm -rf airootfs/etc/skel/.magpie-settings/magpie-release', shell = True)
def main(arg):
if os.getuid() is 0:
try:
if(len(arg) != 0 and arg[1] == 'clean'):
clean()
print('Cleaned..')
return
except IndexError:
pass
try:
MainWork()
except KeyboardInterrupt:
clean()
print('error: operation has been canceled by ' + subprocess.getoutput("echo $(whoami)"))
else:
print('error: you cannot perform this operation unless you are root.')
if __name__ == '__main__':
main(sys.argv)
# End