-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript_part_1.py
244 lines (219 loc) · 7.92 KB
/
script_part_1.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
"""
This program is an installer for Orange OS LE, you can find more information in the README
Copyright (C) 2022 Michael Halpin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
# There is no part 2 of this script anymore, but the name remains for backward compatability.
import sys, os
hard_drive = ""
host_name = ""
keyboard_layout = ""
language = ""
time_zone = ""
location = ""
def ui():
global hard_drive, host_name, keyboard_layout, language, time_zone, location
print("Welcome to the Orange OS LE install script.")
print("We will ask you a few questions to make sure you get a great configuration.")
hard_drive = input("Please input your disk drive file, like /dev/sda: ")
host_name = input(
"Please enter the name you want to give your computer (a.k.a your hostname): "
)
keyboard_layout = input("Now enter your keyboard layout, like uk or us: ")
language = input(
'Now please enter your locale language. This should be something like "en_US": '
)
time_zone = input(
"Now we need your timezone, this is usually in the format of <Continent>/<City>, e.g Europe/Paris: "
)
location = input(
"Finally, we need to know what country you live in. If you don't want to answer this, enter worldwide."
).capitalize()
print("Okay, now we are going to setup users for you.")
user_creds = open("user_credentials.json", "w")
user_creds.write(
"""{
"!users": ["""
)
users_no = int(input("First, how many users do you want the system to hold: "))
for x in range(0, users_no):
user_creds.write("{\n")
username = input(f"Ok what the you want the username of user {x + 1} to be: ")
password = input(f"Now, what password do you want to give {username}: ")
superuser = input(
f"Lastly do you want {username} to be a superuser? Leave blank if you don't: "
)
user_creds.write(f'"!password": "{password}",\n')
if superuser:
user_creds.write('"sudo": true,\n')
else:
user_creds.write('"sudo": false,\n')
user_creds.write(f'"username": "{username}"\n')
user_creds.write("}")
if x == users_no - 1:
user_creds.write("\n")
else:
user_creds.write(",\n")
user_creds.write("]\n}")
user_creds.close()
def config_file():
global hard_drive, host_name, keyboard_layout, language, time_zone, location
config = open(sys.argv[1], 'r')
hard_drive = config.readline().replace("\n", "")
host_name = config.readline().replace("\n", "")
keyboard_layout = config.readline().replace("\n", "")
language = config.readline().replace("\n", "")
time_zone = config.readline().replace("\n", "")
location = config.readline().capitalize().replace("\n", "")
user_creds = open("user_credentials.json", "w")
user_creds.write(
"""{
"!users": ["""
)
users_no = int(config.readline().replace("\n", ""))
for x in range(0, users_no):
user_creds.write("{\n")
username = config.readline().replace("\n", "")
password = config.readline().replace("\n", "")
superuser = config.readline().replace("\n", "")
user_creds.write(f'"!password": "{password}",\n')
if superuser:
user_creds.write('"sudo": true,\n')
else:
user_creds.write('"sudo": false,\n')
user_creds.write(f'"username": "{username}"\n')
user_creds.write("}")
if x == users_no - 1:
user_creds.write("\n")
else:
user_creds.write(",\n")
user_creds.write("]\n}")
user_creds.close()
if sys.argv.__len__() == 2:
config_file()
else:
ui()
user_config = open("user_configuration.json", "w")
user_config.write(
f"""{'{'}
"additional-repositories": "",
"audio": "pipewire",
"bootloader": "grub-install",
"filesystem": "ext4",
"HSM": null,
"config_version": "2.5.0",
"debug": false,
"harddrives": [
"{hard_drive}"
],
"kernels": [
"linux"
],
"swap": true,
"keyboard-language": "{keyboard_layout}",
"mirror-region": "{location}",
"hostname": "{host_name}",
"keyboard-layout": "{keyboard_layout}",
"mount_point": null,
"nic": {'{'}
"dhcp": true,
"dns": null,
"gateway": null,
"iface": null,
"ip": null,
"type": "iso"
{'}'},
"ntp": true,
"plugin": null,
"profile": {'{'}
"path": "/usr/lib/python3.10/site-packages/archinstall/profiles/minimal.py"
{'}'},
"script": "guided",
"silent": false,
"sys-language": "{language}",
"sys-encoding": "utf-8",
"timezone": "{time_zone}",
"version": "2.5.0",
"packages": ["xorg", "xorg-server", "gnome"],
"custom-commands": [
"systemctl enable gdm.service",
"curl https://raw.githubusercontent.com/Orange-OS-LE/Assets/main/background1.png > bg.png",
"gsettings set org.gnome.desktop.background ./bg.png",
"gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'",
"pacman -S NetworkManager",
"sysetmctl enable NetworkManager"
]
{'}'}"""
)
user_config.close()
# user creds
print("Now we will setup the disks for you. Unfourtuanatley, we can't offer to let you")
print("do the disk partioning, but we might offer this in future.")
confirm_installation = input(
"This will delete all data on the disk you have chosen,\nIf you agree to the conditions, submit with a \"Y\". Otherwise, submit with any other letter."
)
if confirm_installation.lower() != "y":
print("Quiting the script, but run the script again if you change your mind.")
quit(0)
else:
print("Here we go...")
user_disks = open("user_disk_layout.json", "w")
user_disks.write(
f"""{'{'}
"{hard_drive}": {'{'}
"partitions": [
{'{'}
"boot": true,
"encrypted": false,
"filesystem": {'{'}
"format": "fat32"
{'}'},
"mountpoint": "/boot",
"size": "{'203MiB' if not os.path.exists("/sys/firmware/efi") else '512MiB'}",
"start": "{'3MiB' if not os.path.exists("/sys/firmware/efi") else '1MiB'}",
"type": "primary",
"wipe": true
{'}'},
{'{'}
"encrypted": false,
"filesystem": {'{'}
"format": "ext4",
"mount_options": []
{'}'},
"mountpoint": "/",
"size": "100%",
"start": "{'206MiB' if not os.path.exists("/sys/firmware/efi") else '513MiB'}",
"type": "primary",
"wipe": true
{'}'}
],
"wipe": true
{'}'}
{'}'}"""
)
user_disks.close()
if sys.argv.__len__() == 2:
os.system(
"sudo archinstall --silent --config ./user_configuration.json --creds ./user_credentials.json --disk_layouts ./user_disk_layout.json"
)
os.system(
"sudo archinstall --silent --config ./user_configuration.json --creds ./user_credentials.json --disk_layouts ./user_disk_layout.json"
)
else:
os.system(
"sudo archinstall --silent --config ./user_configuration.json --creds ./user_credentials.json --disk_layouts ./user_disk_layout.json"
)
os.system(
"sudo archinstall --silent --config ./user_configuration.json --creds ./user_credentials.json --disk_layouts ./user_disk_layout.json"
)
os.system("reboot -h now")
# removed for debugging