-
Notifications
You must be signed in to change notification settings - Fork 16
/
installation-image-post-update-version.py
executable file
·114 lines (98 loc) · 4.47 KB
/
installation-image-post-update-version.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
#!/usr/bin/python3
import os
import sys
INSTALLER_VERSION = "latest"
def create_installer_config(path):
"""Create a basicl installation configuration file"""
config = u"template=file:///etc/ister.json\n"
jconfig = u'{"DestinationType" : "physical", "PartitionLayout" : \
[{"disk" : "sda", "partition" : 1, "size" : "512M", "type" : "EFI"}, \
{"disk" : "sda", "partition" : 2, \
"size" : "512M", "type" : "swap"}, {"disk" : "sda", "partition" : 3, \
"size" : "rest", "type" : "linux"}], \
"FilesystemTypes" : \
[{"disk" : "sda", "partition" : 1, "type" : "vfat"}, \
{"disk" : "sda", "partition" : 2, "type" : "swap"}, \
{"disk" : "sda", "partition" : 3, "type" : "ext4"}], \
"PartitionMountPoints" : \
[{"disk" : "sda", "partition" : 1, "mount" : "/boot"}, \
{"disk" : "sda", "partition" : 3, "mount" : "/"}], \
"Version" : 0, "Bundles" : ["kernel-native", "telemetrics", "os-core", "os-core-update"]}\n'
if not os.path.isdir("{}/etc".format(path)):
os.mkdir("{}/etc".format(path))
with open("{}/etc/ister.conf".format(path), "w") as cfile:
cfile.write(config)
with open("{}/etc/ister.json".format(path), "w") as jfile:
jfile.write(jconfig.replace('"Version" : 0',
'"Version" : "{}"'.format(INSTALLER_VERSION)))
def append_installer_rootwait(path):
"""Add a delay to the installer kernel commandline"""
entry_path = path + "/boot/loader/entries/"
entry_file = os.listdir(entry_path)
if len(entry_file) != 1:
raise Exception("Unable to find specific entry file in {0}, "
"found {1} instead".format(entry_path, entry_file))
file_full_path = entry_path + entry_file[0]
with open(file_full_path, "r") as entry:
entry_content = entry.readlines()
options_line = entry_content[-1]
if not options_line.startswith("options "):
raise Exception("Last line of entry file is not the kernel "
"commandline options")
# Account for newline at the end of the line
options_line = options_line[:-1] + " rootwait\n"
entry_content[-1] = options_line
os.unlink(file_full_path)
with open(file_full_path, "w") as entry:
entry.writelines(entry_content)
def append_installer_no_kms(path):
"""Disable KMS on the installer kernel commandline"""
entry_path = path + "/boot/loader/entries/"
entry_file = os.listdir(entry_path)
if len(entry_file) != 1:
raise Exception("Unable to find specific entry file in {0}, "
"found {1} instead".format(entry_path, entry_file))
file_full_path = entry_path + entry_file[0]
with open(file_full_path, "r") as entry:
entry_content = entry.readlines()
options_line = entry_content[-1]
if not options_line.startswith("options "):
raise Exception("Last line of entry file is not the kernel "
"commandline options")
# Account for newline at the end of the line
options_line = options_line[:-1] + " nomodeset i915.modeset=0\n"
entry_content[-1] = options_line
os.unlink(file_full_path)
with open(file_full_path, "w") as entry:
entry.writelines(entry_content)
def append_systemd_boot_timeout(path):
"""Add a systemd-boot timeout to loader.conf"""
loader_path = path + "/boot/loader/loader.conf"
if not os.path.exists(loader_path):
raise Exception("Unable to find loader.conf in {}"
.format(os.path.dirname(loader_path)))
with open(loader_path, 'a') as loadconf:
loadconf.write('timeout 5')
def disable_tty1_getty(path):
"""Add a symlink masking the systemd tty1 generator"""
os.makedirs(path + "/etc/systemd/system/getty.target.wants")
os.symlink("/dev/null", path + "/etc/systemd/system/getty.target.wants/[email protected]")
def add_installer_service(path):
os.symlink("{}/usr/lib/systemd/system/ister.service"
.format(path),
"{}/usr/lib/systemd/system/multi-user.target.wants/ister.service"
.format(path))
if __name__ == '__main__':
if len(sys.argv) != 2:
sys.exit(-1)
try:
create_installer_config(sys.argv[1])
append_installer_rootwait(sys.argv[1])
append_installer_no_kms(sys.argv[1])
append_systemd_boot_timeout(sys.argv[1])
disable_tty1_getty(sys.argv[1])
add_installer_service(sys.argv[1])
except Exception as exep:
print(exep)
sys.exit(-1)
sys.exit(0)