-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainMenu.py
166 lines (137 loc) · 6.32 KB
/
mainMenu.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
import os
from rich.console import Console
from rich.prompt import Prompt
from rich.progress import Progress
import shutil
import subprocess
# subprojects
from devupdate.menuUpdate import mintUpdateMenu
from devtools.menuTools import toolsMenu
class MainMenu:
def __init__(self):
self.console = Console()
self.updateMenu = mintUpdateMenu()
self.toolsMenu = toolsMenu()
self.options = {
"0": self.devupdatemenu,
"1": self.devtoolsmenu,
"2": self.enable_daily_builds,
"3": self.install_docker_on_LM,
"4": self.install_prompt_sh_on_LM,
"5": self.install_oh_my_bash_on_LM,
"*": self.exit
}
self.run()
def devupdatemenu(self):
self.updateMenu.run()
def devtoolsmenu(self):
self.toolsMenu.run()
def enable_daily_builds(self):
print("enable_daily_builds function called")
tasks = [
"sudo add-apt-repository ppa:linuxmint-daily-build-team/daily-builds",
"sudo apt-get update",
"sudo apt-get upgrade"
]
with self.console.status("[bold green]Working on tasks...") as status:
while tasks:
task = tasks.pop(0)
os.system(task)
self.console.log(f"{task} complete")
def install_docker_on_LM(self):
print("install_docker_on_LM function called")
tasks = [
"sudo apt-get update",
"sudo apt-get install ca-certificates curl gnupg",
"sudo install -m 0755 -d /etc/apt/keyrings",
"curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg",
"sudo chmod a+r /etc/apt/keyrings/docker.gpg",
'echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "jammy") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null',
"sudo apt-get update",
"sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
]
with self.console.status("[bold green]Working on tasks...") as status:
while tasks:
task = tasks.pop(0)
os.system(task)
self.console.log(f"{task} complete")
def install_prompt_sh_on_LM(self):
print("install_prompt_sh_on_LM function called")
tasks = [
"sudo apt update && sudo apt install wget",
"mkdir git-prompt",
"cd git-prompt",
"wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh",
"wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash",
"sudo chmod 664 git-prompt.sh",
"sudo chmod 664 git-completion.bash",
"cd .."
]
with self.console.status("[bold green]Working on tasks...") as status:
while tasks:
task = tasks.pop(0)
os.system(task)
self.console.log(f"{task} complete")
def install_oh_my_bash_on_LM(self):
print("install_oh_my_bash_on_LM function called")
tasks = [
"sudo apt update && sudo apt install wget",
"mkdir ohmybash",
"cd ohmybash",
'bash -c "$(wget https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh -O -)"',
"cd ..",
"rm -rf ohmybash"
]
with self.console.status("[bold green]Working on tasks...") as status:
while tasks:
task = tasks.pop(0)
os.system(task)
self.console.log(f"{task} complete")
print("Who/where is installing it?")
original_dir = os.getcwd()
os.chdir('/home')
for directory in os.listdir('/home'):
if os.path.isdir(directory):
print(" > " + directory)
os.chdir(original_dir)
username = input("Prompt username: ")
source = "./git-prompt"
destination = "/home/" + username + "/.bash_custom"
print(source)
print(destination)
shutil.move(source, destination)
if os.path.exists(destination):
print("The files has been successfully moved.")
subprocess.run(['sudo', 'chown', '-R', username + ':' + username, '/home/' + username + '/.bash_custom'])
lines_to_add = "\n# Custom bash prompt\nsource ~/.bash_custom/git-prompt.sh\nsource ~/.bash_custom/git-completion.bash\n"
with open('/home/' + username + '/.bashrc', 'a') as file:
file.write(lines_to_add)
if os.path.exists("/home/" + username + "/.bashrc"):
print("The .bashrc file exists.")
if os.path.exists("/home/" + username + "/.bashrc_backup"):
shutil.move("/home/" + username + "/.bashrc_backup", "/home/" + username + "/.bashrc")
print("Restored .bashrc_backup to .bashrc.")
shutil.copy("/home/" + username + "/.bashrc", "/home/" + username + "/.bashrc_backup")
print("Made copy /home/" + username + "/.bashrc to /home/" + username + "/.bashrc_backup.")
shutil.copy('./bashrc', "/home/" + username + "/.bashrc")
if os.path.exists(os.path.expanduser("~/.zshrc")):
print("The .zshrc file exists.")
print("I DO NOTHING!.")
input("...ENDED! PRESS ANY KEY TO ESCAPE!")
else:
print("An error occurred while moving the files.")
subprocess.run(['sudo', 'rm', '-Rf', './git-prompt'])
input("...ENDED! PRESS ANY KEY TO ESCAPE!")
def exit(self):
self.console.print("Goodbye!")
exit()
def run(self):
self.console.clear()
while True:
self.console.print("[0] Update the system\n[1] Install dev-tools\n[2] Enable daily builds\n[3] Install docker on LM\n[4] Install prompt.sh on LM\n[5] Install oh-my-bash on LM\n[*] Any key to exit")
choice = Prompt.ask("Choose an option", choices=list(self.options.keys()))
if choice == "*":
self.exit()
self.options[choice]()
if __name__ == "__main__":
MainMenu()