-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·89 lines (79 loc) · 2.36 KB
/
setup
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
#!/usr/bin/python3
from os import system
from subprocess import check_output as cop
from subprocess import CalledProcessError as CPE
def str_clean(val):
val = val.decode()
return val.replace('\n', '')
def check_installation():
bins = ""
print("< ! > Checking installation ...")
tmux = str_clean(cop("which tmux", shell=True))
bash = str_clean(cop("which bash", shell=True))
vim = str_clean(cop("which vim", shell=True))
if tmux == "":
bins += " tmux"
if bash == "":
bins += " bash"
if vim == "":
bins += " vim"
if not bins == "":
print("< ! >"+ bins + " is/are not installed... We will install it for you.")
system("sudo apt install" + bins + " -y")
else:
print("< / > All necessary tools are installed!")
return
def create_backup():
cmd = ""
tmux_conf = ""
bashrc = ""
vimrc = ""
try:
backup = str_clean(cop("ls backup 2> /dev/null", shell=True))
if not backup == "":
print("< ! > Backup config files are found... You may want to check them!\n< x > Exiting the setup ...")
exit()
except CPE:
print("< ! > No backup found!")
print("< / > Creating backup of existing config files ...")
try:
tmux_conf = str_clean(cop("ls ~/.tmux.conf 2> /dev/null", shell=True))
except CPE:
pass
try:
bashrc = str_clean(cop("ls ~/.bashrc 2> /dev/null", shell=True))
except CPE:
pass
try:
vimrc = str_clean(cop("ls ~/.vimrc 2> /dev/null", shell=True))
except CPE:
pass
if not tmux_conf == "":
cmd += "cp " + tmux_conf + " backup/tmux.conf;"
if not bashrc == "":
cmd += "cp " + bashrc + " backup/bashrc;"
if not vimrc == "":
cmd += "cp " + vimrc + " backup/vimrc;"
if not cmd == "":
system("mkdir -p backup/;" + cmd)
return
def copy_config():
print("< ! > Adding new config ...")
cmd = "cp config/tmux.conf ~/.tmux.conf;"
cmd += "cp config/bashrc ~/.bashrc;"
cmd += "cp config/vimrc ~/.vimrc;"
system(cmd)
return
def setup_utils():
print("< ! > Setting up few more things ...")
cmd = "sudo gcc -Wall -Werror src/cpu_util.c -o /bin/cpu_u;"
cmd += "sudo cp src/T /bin/"
system(cmd)
return
if __name__ == "__main__":
check_installation()
create_backup()
copy_config()
setup_utils()
print("< / > Done!")
exit()