-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThemeGrub.py
332 lines (277 loc) · 10.6 KB
/
ThemeGrub.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/usr/bin/env python3
#
# ______ _ ___ __ _____ _____ _____ ____
# |__ __| | | \ \ / // ____/ ____|_ _/ __ \
# | | | |__| |\ V /| (___| (___ | || | | |
# | | | __ | > < \___ \\___ \ | || | | |
# | | | | | |/ . \ ____) |___) |_| || |__| |
# |_| |_| |_/_/ \_\_____/_____/|_____\____/ GRUB THEME
#
# Version: 2.1 Written by Thxssio (DEX)
#
#
# Github : https://github.com/thxssio
# imports
import subprocess
import os
import shutil
import sys
# colors
C = "\033[0m" # clear (end)
R = "\033[0;31m" # red (error)
G = "\033[0;32m" # green (process)
B = "\033[0;36m" # blue (choice)
Y = "\033[0;33m" # yellow (info)
# functions
def check_root():
id = int(subprocess.check_output("id -u", shell=True).decode("utf-8"))
if id != 0:
print(f"\n{R}(!){C} Execute o script com privilégios 'sudo' ou como usuário root !!\n")
exit()
def check_distro():
try:
lsb_id = subprocess.check_output("lsb_release -i", shell=True).decode("utf-8")
id = lsb_id.split(":")[-1].lower().strip()
except Exception:
id = ""
return id
def change_grub_theme(grub_theme_path):
with open("/etc/default/grub", "r") as grub_file:
data = grub_file.readlines()
flag = False
for i, line in enumerate(data):
if line.startswith("GRUB_TERMINAL_OUTPUT"):
data.pop(i)
data.insert(i, f"#{line}\n")
elif line.startswith("GRUB_TIMEOUT_STYLE"):
data.pop(i)
data.insert(i, f"#{line}\n")
elif line.startswith("GRUB_ENABLE_BLSCFG"):
data.pop(i)
data.insert(i, "GRUB_ENABLE_BLSCFG=false\n")
elif line.startswith("GRUB_THEME"):
flag = True
data.pop(i)
data.insert(i, f'GRUB_THEME="{grub_theme_path}"\n')
if not flag:
data.append(f'GRUB_THEME="{grub_theme_path}"\n')
with open("/etc/default/grub", "w") as grub_file:
grub_file.writelines(data)
def reset_grub_theme():
with open("/etc/default/grub", "r") as grub_file:
data = grub_file.readlines()
for i, line in enumerate(data):
if line.startswith("GRUB_THEME"):
data.pop(i) # removing existing line
# data.insert(i, f'#GRUB_THEME=""\n') # adding new line
with open("/etc/default/grub", "w") as grub_file:
grub_file.writelines(data)
def prompt(choices):
options = list(choices)
while True:
print(f"{B}(?){C} Choose an option [{options[0]}-{options[-1]}] : ", end="")
choice = input().upper()
if choice not in options:
print(f"\n{R}(!){C} Select one of the available options !!\n")
continue
return choice
def banner():
print(B)
print(r"""
________ __ ____ __ _____ _____ _____ ____
|__ __| | | \ \ / // ____/ ____|_ _/ __ \
| | | |__| |\ V /| (___| (___ | || | | |
| | | __ | > < \___ \\___ \ | || | | |
| | | | | |/ . \ ____) |___) |_| || |__| |
|_| |_| |_/_/ \_\_____/_____/|_____\____/
""",end="")
print(f"{C} GRUB THEME\n")
print(f" Written by {B}Thxssio{C} (DEX)")
def install():
# installer script
print("\n INSTALLER ✔️")
THEME = "darkmatter"
# debian | arch
if os.path.exists("/boot/grub/"):
GRUB_THEMES_DIR = "/boot/grub/themes/"
GRUB_UPDATE_CMD = "grub-mkconfig -o /boot/grub/grub.cfg"
if not os.path.exists(GRUB_THEMES_DIR):
os.mkdir(GRUB_THEMES_DIR)
# fedora | redhat
elif os.path.exists("/boot/grub2/"):
GRUB_THEMES_DIR = "/boot/grub2/themes/"
GRUB_UPDATE_CMD = "grub2-mkconfig -o /boot/grub2/grub.cfg"
if not os.path.exists(GRUB_THEMES_DIR):
os.mkdir(GRUB_THEMES_DIR)
else:
print(f"\n{R}(!){C} Não foi possível encontrar o diretório GRUB. Saindo do roteiro ...")
exit()
styles = {
"1": "arch",
"2": "archstrike",
"3": "artix",
"4": "avix",
"5": "blackarch",
"6": "centos",
"7": "chromeos",
"8": "debian",
"9": "deepin",
"10": "devuan",
"11": "elementary",
"12": "endeavouros",
"13": "fedora",
"14": "freebsd",
"15": "garuda",
"16": "gentoo",
"17": "kali",
"18": "kdeneon",
"19": "kubuntu",
"20": "linux",
"21": "linuxlite",
"22": "linuxmint",
"23": "lubuntu",
"24": "manjaro",
"25": "mx",
"26": "opensuse",
"27": "parrot",
"28": "pentoo",
"29": "popos",
"30": "redhat",
"31": "slackware",
"32": "solus",
"33": "sparky",
"34": "steamos",
"35": "ubuntu",
"36": "ubuntumate",
"37": "void",
"38": "windows10",
"39": "windows11",
"40": "zorin",
"41": "guixsd",
"42": "nixos",
"43": "xubuntu",
"44": "dtos",
"45": "nobara",
"46": "hacking",
"47": "hydrone",
"48": "TGS",
}
print(f"\n{B}(?){C} \033[0;33mChoose the STYLE\033[0m :")
style_sheet_menu = f"""
(01) Arch Linux (02) Arch Strike (03) Artix Linux
(04) Avix Linux (05) BlackArch (06) CentOS
(07) Chrome OS (08) Debian (09) Deepin
(10) Devuan (11) ElementaryOS (12) EndeavourOS
(13) Fedora (14) FreeBSD (15) Garuda Linux
(16) Gentoo (17) Kali Linux (18) KDE neon
(19) Kubuntu (20) Linux (21) Linux Lite
(22) Linux Mint (23) Lubuntu (24) Manjaro
(25) MX Linux (26) openSUSE (27) ParrotOS
(28) Pentoo (29) PopOS (30) Red Hat
(31) Slackware (32) Solus (33) Sparky Linux
(34) SteamOS (35) Ubuntu (36) Ubuntu Mate
(37) Void Linux (38) Windows 10 (39) Windows 11
(40) ZorinOS (41) GuixSD (42) NixOS
(43) Xubuntu (44) DTOS (45) Nobara
(46) Hacking (47) Hydrone (48) TGS-Developer
"""
print(style_sheet_menu)
choice = prompt(styles.keys())
THEME_DIR = f"{GRUB_THEMES_DIR}{THEME}/"
if os.path.exists(THEME_DIR):
print("\n")
print(f"{Y}(#){C} Se você já tiver uma versão deste tema instalada, desinstale-a primeiro.\n")
exit()
else:
os.mkdir(THEME_DIR) # making the theme dir in '/boot/grub/themes'
# selecting resolution
print(f"\n{B}(?){C} Choose the RESOLUTION {Y}[default = 1]{C} :\n\n (1) {G}1080p{C} {Y}[Full HD]{C} (2) {G}1440p{C} {Y}[2K]{C}\n")
icon_theme_choice = input(f"{B}(?){C} choice : ")
if icon_theme_choice == "2":
RESOLUTION = "1440p"
else:
RESOLUTION = "1080p"
# selecting icon theme
print(f"\n{B}(?){C} Choose the ICON THEME {Y}[default = 1]{C} :\n\n (1) {G}Color{C} Icons (2) {G}White{C} Icons\n")
icon_theme_choice = input("choice : ")
if icon_theme_choice == "2":
ICON_THEME = "white"
else:
ICON_THEME = "color"
# defining asset paths
BACKGROUND_PATH = (f"assets/backgrounds/{styles.get(choice).lower()}-{RESOLUTION}.png")
ICONS_PATH = f"assets/icons-{RESOLUTION}/{ICON_THEME}/"
FONTS_PATH = f"assets/fonts/{RESOLUTION}/"
BASE_PATH = f"base/{RESOLUTION}/"
print(f"\n{G}($){C} Copying assets to {THEME_DIR}")
# copying & renaming background img
shutil.copy(BACKGROUND_PATH, f"{THEME_DIR}background.png")
# copying & renaming icon pack
shutil.copytree(ICONS_PATH, f"{THEME_DIR}icons/") # 'icons' dir created inside main theme dir
# copying font files
shutil.copytree(FONTS_PATH, THEME_DIR, dirs_exist_ok=True)
# copying base files
shutil.copytree(BASE_PATH, THEME_DIR, dirs_exist_ok=True)
print(" done.\n")
print(f"{G}($){C} Editing the GRUB file ...")
THEME_PATH = f"{THEME_DIR}theme.txt"
change_grub_theme(THEME_PATH)
print(" done.\n")
print(f"{G}($){C} Updating GRUB ...\n")
subprocess.run(GRUB_UPDATE_CMD, shell=True)
print(f"\n{Y}(#){C} ThemeGrub GRUB theme has been successfully installed !!\n")
distro = check_distro()
if distro == "kali": # checking if it's Kali Linux
print(f"""{R}PS{C}: If you see this note, it means that the script identified your distro as Kali Linux.\n
To get the theme to work in Kali, you must remove/edit some default files, which you can do by
following the instructions at {B}https://github.com/thxssio{C}""")
exit()
def uninstall():
# uninstaller script
print("\n UNINSTALLER ❌\n")
THEME = "darkmatter" # theme name
# debian | arch
if os.path.exists("/boot/grub/"):
GRUB_THEME_DIR = f"/boot/grub/themes/{THEME}/"
GRUB_UPDATE_CMD = "grub-mkconfig -o /boot/grub/grub.cfg"
# fedora | redhat
elif os.path.exists("/boot/grub2/"):
GRUB_THEME_DIR = f"/boot/grub2/themes/{THEME}/"
GRUB_UPDATE_CMD = "grub2-mkconfig -o /boot/grub2/grub.cfg"
else: # if theme not found
print(f"\n{R}(!){C} Couldn't find the GRUB directory. Exiting the script ...")
exit()
ask = input(f"{B}(?){C} Remove ThemeGrub GRUB Theme (y/n)? {Y}[default = n]{C} : ")
if ask.lower() != "y":
print(f"\n{R}(!){C} No changes were made. Exiting the script ...\n")
exit()
else:
# removing theme folder
print(f"\n{G}($){C} Removed the theme directory ...\n")
shutil.rmtree(GRUB_THEME_DIR)
print(" done.\n")
# resetting the grub file
print(f"{G}($){C} Resetting the GRUB file ...\n")
reset_grub_theme()
print(" done.\n")
# updating grub
print(f"{G}($){C} Updating GRUB ...\n")
subprocess.run(GRUB_UPDATE_CMD, shell=True)
print(f"\n{Y}(#){C} ThemeGrub GRUB Theme has been successfully removed !!\n")
exit()
if __name__ == "__main__":
check_root() # checking root access
banner() # shows banner
try:
if len(sys.argv) != 2:
raise Exception("Invalid number of arguments: Use either '-i' or '-u'")
if sys.argv[-1] in ["-i", "--install"]:
install() # installer
elif sys.argv[-1] in ["-u", "--uninstall"]:
uninstall() # uninstaller
else:
raise Exception("Invalid argument provided: Use either '-i' or '-u'")
except Exception as e:
print(f"\n{R}(!){C} An unexpected error occurred while running the script !!\n")
print(f"{R}(!){C} ERROR : {R}{e}{C}")
exit()