-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathold_install.py
More file actions
380 lines (320 loc) · 13.5 KB
/
old_install.py
File metadata and controls
380 lines (320 loc) · 13.5 KB
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
import subprocess
import sys
import yaml
import shutil
import os
banner = """
==========================================================================
___ _ ______ ___ ___ _ _
/ _ \ | | | ___ \ | \/ | | | (_)
/ /_\ \_ __ ___| |__ | |_/ /__ _ __ | . . | __ _ ___| |__ _ _ __ ___
| _ | '__/ __| '_ \| __/ _ \ '_ \| |\/| |/ _` |/ __| '_ \| | '_ \ / _ \\
| | | | | | (__| | | | | | __/ | | | | | | (_| | (__| | | | | | | | __/
\_| |_/_| \___|_| |_\_| \___|_| |_\_| |_/\__,_|\___|_| |_|_|_| |_|\___|
================================== Developed by: Drake Axelrod (draxel.io)
"""
# ======================== Utils ======================== #
def read_config() -> dict:
"""Load the config.yml
Returns:
dict: configurations
"""
# open config.yml
return yaml.load(open("config.yml"), Loader=yaml.FullLoader)
def execute(cmd) -> str:
"""Execute system commands and return output
Args:
cmd (string): command to execute
Returns:
str: output of command
"""
return subprocess.check_output(cmd, shell=True).decode("utf-8")
def check_package(package) -> bool:
"""Check if package is installed
Args:
package (string): package to check
Returns:
bool: if package is installed
"""
global config
# check if error code then package is not installed
try:
execute(config["package_manager"] + " -Q " + package + " &> /dev/null")
return True
except:
return False
def install_package(package) -> None:
"""Install package if not installed
Args:
package (string): package to install
"""
global config
if not check_package(package):
print(f">> installing [{package}]")
execute(config["package_manager"] + " -S " + package +
" --noconfirm --needed --quiet")
else:
print(package + " is already installed")
def cp_config_dir(directory) -> None:
"""Copy directory from configs to .config
Args:
directory (string): directory to copy
"""
# copy directory to ~/.config/directory except if git ignored
shutil.copytree(f"configs/{directory}",
os.path.expanduser("~/.config/" + directory),
dirs_exist_ok=True)
def update_mirrorlist():
"""Update system and install reflector if not installed and update mirrors"""
global config
execute(config["package_manager"] + " -Syu --noconfirm --quiet")
execute(config["package_manager"] +
" -S reflector --noconfirm --needed --quiet")
execute(
"sudo reflector --verbose --latest 5 --sort rate --save /etc/pacman.d/mirrorlist"
)
# ======================== Configs ======================== #
def config_wrapper(func):
"""Configure wrapper"""
print(f">> configuring [{func.__name__}]")
func()
class Configurations:
def run(self):
config_wrapper(self.scripts)
config_wrapper(self.git)
config_wrapper(self.gnupg)
config_wrapper(self.zsh)
config_wrapper(self.rust)
config_wrapper(self.autostart_programs)
config_wrapper(self.ulauncher)
config_wrapper(self.lunarvim)
config_wrapper(self.kitty)
config_wrapper(self.kde_settings)
config_wrapper(self.docs)
def systemd(self):
"""Configure systemd"""
global config
pretty_print("Configuring system")
# enable systemd services
# check if config has key systemd
if "systemd" in config:
if "enable" in config["systemd"]:
for service in config["systemd_services"]:
print(f">> configuring service [{service}]")
execute("sudo systemctl enable " + service)
execute("sudo systemctl start " + service)
def scripts(self):
"""Configure scripts"""
if not os.path.exists(os.path.expanduser("~/.local")):
os.mkdir(os.path.expanduser("~/.local"))
if not os.path.exists(os.path.expanduser("~/.local/bin")):
os.makedirs(os.path.expanduser("~/.local/bin"))
# copy all files in scripts to ~/.local/bin
for file in os.listdir("scripts"):
shutil.copy(f"scripts/{file}", os.path.expanduser("~/.local/bin"))
execute("chmod +x ~/.local/bin/*")
def autostart_programs(self):
# copy autostart directory to ~/.config/autostart except if git ignored
cp_config_dir("autostart")
# configure ulauncher
def ulauncher(self):
if check_package("ulauncher"):
# copy config directories
cp_config_dir("ulauncher")
# configure git
def git(self):
"""Configure git"""
# check if .config/git/config exists
if not os.path.exists(os.path.expanduser("~/.config/git")) and check_package("git"):
# copy git directory to ~/.config/git except if git ignored
cp_config_dir("git")
# check if config has git.email and git.name are empty strings
if config["git"]["email"] == "" or config["git"]["name"] == "":
print(">> git email and name not configured")
# ask if user wants to provide git email and name in red
print("\033[91m>> do you want to provide git email and name? [y/n]\033[0m", end=" ")
ans = input().lower()
if ans == "y":
# ask for git email and name
print(">> enter git email", end=": ")
email = input()
print(">> enter git name", end=": ")
name = input()
# set git email and name
execute(f"git config --global user.email {email}")
execute(f"git config --global user.name {name}")
else:
# set git email and name
execute("git config --global user.email " + config["git"]["email"])
execute("git config --global user.name " + config["git"]["name"])
# zsh
def zsh(self):
"""Configuring zsh"""
# install zplug
if check_package("zsh"):
os.environ["ZDOTDIR"] = os.path.expanduser("~/.config/zsh")
os.environ["ZPLUG_HOME"] = os.path.expanduser("~/.config/zsh/zplug")
# zsh libs
execute("zsh ./installers/zsh.sh")
# copy .zshenv to home directory and overwrite if exists
# change default shell redirect password to stdin if zsh is not default shell
if os.environ["SHELL"] != "/bin/zsh":
execute("chsh -s /bin/zsh")
shutil.copyfile("configs/zshenv", os.path.expanduser("~/.zshenv"))
cp_config_dir("zsh")
def kitty(self):
"""Configure kitty"""
if check_package("kitty"):
# copy kitty directory to ~/.config/kitty except if git ignored
cp_config_dir("kitty")
# lunarvim
def lunarvim(self):
"""Configure lunarvim"""
if check_package("neovim"):
# set environment variable
os.environ["LV_BRANCH"] = "rolling"
# install lunarvim
execute("LV_BRANCH=rolling bash <(curl -s https://raw.githubusercontent.com/lunarvim/lunarvim/rolling/utils/installer/install.sh) -y --install-dependencies")
# copy lunarvim directory to ~/.config/lunarvim except if git ignored
cp_config_dir("lvim")
# install and configure cargo
def rust(self):
"""Configure rustup"""
os.environ["CARGO_HOME"] = os.path.expanduser("~/.local/share/cargo")
os.environ["RUSTUP_HOME"] = os.path.expanduser("~/.local/share/rustup")
# set rustup to stable
os.system("rustup default stable")
if os.path.exists(os.path.expanduser("~/.rustup")):
shutil.rmtree(os.path.expanduser("~/.rustup"))
if os.path.exists(os.path.expanduser("~/.cargo")):
shutil.rmtree(os.path.expanduser("~/.cargo"))
def gnupg(self):
"""Configure gnupg"""
# copy gnupg directory to ~/.config/gnupg except if git ignored
cp_config_dir("gnupg")
def haskell(self):
"""Configure haskell"""
cp_config_dir("cabal")
cp_config_dir("stack")
def kde_settings(self):
"""Configure kde settings"""
# /home/test/.local/share/plasma/look-and-feel
# extract ./Utterly-Nord.tar.xz to ~/.local/share/plasma/look-and-feel
execute("tar -xf ./Utterly-Nord.tar.xz -C ~/.local/share/plasma/look-and-feel")
# extract ./oreo-spark-red-cursor.tar.gz to ~/.local/share/icons
if not os.path.exists(os.path.expanduser("~/.local/share/icons")):
os.makedirs(os.path.expanduser("~/.local/share/icons"))
# extract oreo-spark-red-cursors.tar.gz to ~/.local/share/icons
execute("tar -xf ./oreo-spark-red-cursors.tar.gz -C ~/.local/share/icons")
# copy kglobalshortcutsrc to ~/.config/kglobalshortcutsrc, kdeglobals to ~/.config/kdeglobals, khotkeysrc to ~/.config/khotkeysrc
shutil.copyfile("configs/kglobalshortcutsrc", os.path.expanduser("~/.config/kglobalshortcutsrc"))
# copy kdeglobals to ~/.config/kdeglobals
shutil.copyfile("configs/kdeglobals", os.path.expanduser("~/.config/kdeglobals"))
# copy khotkeysrc to ~/.config/khotkeysrc
shutil.copyfile("configs/khotkeysrc", os.path.expanduser("~/.config/khotkeysrc"))
cp_config_dir("kdedefaults")
def docs(self):
"""Configure docs"""
# git clone --recursive https://github.com/jekil/awesome-hacking.git into ~/Documents/resources
if not os.path.exists(os.path.expanduser("~/Documents/resources")):
os.makedirs(os.path.expanduser("~/Documents/resources"))
execute("git clone --recursive https://github.com/jekil/awesome-hacking.git ~/Documents/resources/awesome-hacking")
# https://github.com/blaCCkHatHacEEkr/PENTESTING-BIBLE.git into ~/Documents/resources
execute("git clone https://github.com/blaCCkHatHacEEkr/PENTESTING-BIBLE.git ~/Documents/resources/PENTESTING-BIBLE")
# https://github.com/sundowndev/hacker-roadmap into ~/Documents/resources
execute("git clone https://github.com/sundowndev/hacker-roadmap ~/Documents/resources/hacker-roadmap")
# cp all files and directories in ./Documents to ~/Documents/resources
for file in os.listdir("documents"):
if os.path.isdir("documents/" + file):
shutil.copytree("documents/" + file, os.path.expanduser("~/Documents/resources/" + file))
else:
shutil.copyfile("documents/" + file, os.path.expanduser("~/Documents/resources/" + file))
def repo_tools(self):
# mkdir ~/tools
if not os.path.exists(os.path.expanduser("~/tools")):
os.makedirs(os.path.expanduser("~/tools"))
""" nuclei """
print(">> Installing nuclei")
execute("go install -v github.com/projectdiscovery/nuclei/v2/cmd/nuclei@latest")
""" gospider """
print(">> Installing gospider")
execute("GO111MODULE=on go install github.com/jaeles-project/gospider@latest")
""" sandmap """
# https://github.com/trimstray/sandmap
print(">> Installing sandmap")
execute("git clone --recursive https://github.com/trimstray/sandmap")
execute("cd sandmap && ./setup.sh install")
def install_packages(key: str):
"""Install packages"""
# install packages
# install packages green
if "packages" in config:
if key in config["packages"]:
pretty_print(f"Installing {key} packages")
for package in config["packages"][key]:
install_package(package)
# ======================== Main ======================== #
def pretty_print(msg, color="\033[92m"):
"""Print message in pretty format
Args:
msg (string): message to print
"""
# print message in pretty format colored green and bold with centered text and wrapped in = signs
print(f"""
{color}{'=' * 74}
{msg.center(74)}
{'=' * 74}\033[0m
""")
if __name__ == "__main__":
global config
# start
print("\033[96m" + banner + "\033[0m")
# check if command line arguments for config file is provided
if len(sys.argv) > 1:
print(">> using config file: " + sys.argv[1])
# check if config file exists
if os.path.exists(sys.argv[1]):
# read config file
print(">> reading custom config file")
config = yaml.load(open(sys.argv[1]), Loader=yaml.FullLoader)
else:
# print error message and exit
print("\033[91mconfig file not provided using default\033[0m")
print()
config = read_config()
# print(config)
# update system and mirrorlist
# pretty_print(
# "Performing system update and mirrorlist update please do not exit",
# "\033[91m")
# ask if user wants to update system and mirrors
if "update_mirrorlist" in config:
if config["update_mirrorlist"]:
print(">> updating mirrorlist")
update_mirrorlist()
else:
print("\033[91m" + "do you want to update system and mirrors? [y/n]" + "\033[0m", end=" ")
ans = input().lower()
if ans == "y" or ans == "yes":
update_mirrorlist()
else:
print(">> skipping update")
# install packages
install_packages("general")
# if "packages" in config:
# if "general" in config["packages"]:
# pretty_print("Installing general packages")
# for package in config["packages"]["general"]:
# install_package(package)
# configuring system
conf = Configurations()
conf.run()
# for func in [scripts, git, gnupg, zsh, rust, autostart_programs, ulauncher, lunarvim, kitty, kde_settings, docs]:
# config_wrapper(func)
# install pentest tools
install_packages("pentest_tools")
# if "packages" in config and config["pentest_setup"] == True:
# if "pentest_tools" in config["packages"]:
# pretty_print("Installing pentest tools")
# for package in config["packages"]["pentest_tools"]:
# install_package(package)