-
-
Notifications
You must be signed in to change notification settings - Fork 154
/
install.py
executable file
·243 lines (202 loc) · 7.23 KB
/
install.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
'''
install script for massExpConsole:
dest: ~/.mec
exe: /usr/local/bin/mec
'''
import os
import sys
try:
from importlib import util
except ImportError:
print("Please use python 3.6+ !!!")
sys.exit(1)
from lib.cli import colors
def mod_exists(modulename):
'''
check if a module exists without importing it
'''
mod_spec = util.find_spec(modulename)
return mod_spec is not None
# distro check and initial packages
DIST = "debian"
try:
import distro
except ModuleNotFoundError:
if os.system("python3 -m pip install distro --user") != 0:
colors.colored_print("Please install pip first !!!", colors.RED)
sys.exit(1)
if mod_exists("distro"):
import distro
except ImportError:
colors.colored_print("Please use python 3.6+ !!!", colors.RED)
sys.exit(1)
try:
DIST = distro.linux_distribution(full_distribution_name=False)[0]
except NameError:
import platform
# pylint: disable=deprecated-method, no-member
DIST = platform.linux_distribution(full_distribution_name=0)[0].lower()
def pkg_install(pkg_mgr, pkg):
'''
install package via system package manager
'''
if os.system("{} {} -y".format(pkg_mgr, pkg)) != 0:
colors.colored_print(
"Could not install {}, some pypi packages might fail to install".format(
pkg),
colors.RED)
if DIST in["ubuntu", "debian", "linuxmint", "kali"]:
pkg_install("sudo apt install", "python3-pip")
pkg_install("sudo apt install", "python3-dev")
pkg_install("sudo apt install", "virtualenv")
pkg_install("sudo apt install", "libncurses5-dev")
pkg_install("sudo apt install", "python3-paramiko")
elif DIST in["fedora", "rhel", "centos"]:
pkg_install("sudo yum install", "python3-pip")
pkg_install("sudo yum install", "python3-devel")
pkg_install("sudo yum install", "virtualenv")
pkg_install("sudo yum install", "libncurses5-devel")
pkg_install("sudo yum install", "python3-paramiko")
elif DIST in["arch"]:
pkg_install("sudo pacman -S --noconfirm", "python-pip")
pkg_install("sudo pacman -S --noconfirm", "python-dev")
pkg_install("sudo pacman -S --noconfirm", "virtualenv")
pkg_install("sudo pacman -S --noconfirm", "ncurses")
pkg_install("sudo pacman -S --noconfirm", "python-paramiko")
else:
colors.colored_print("{} is not recognized,".format(DIST) +
" please install python3 dev package manually",
colors.RED)
# modules used by install.py
# password input
try:
import getpass
except ModuleNotFoundError:
os.system("python3 -m pip install getpass --user")
import getpass
# censys config
try:
import json
except ModuleNotFoundError:
os.system("python3 -m pip install json --user")
import json
def pip_install(venv_py, pkg):
'''
python3 -m pip install pkg
'''
colors.colored_print("Installing {} ... ".format(pkg), colors.BLUE)
os.system('{} -m pip install {}'.format(venv_py, pkg))
def start_install():
'''
installation procedure
'''
colors.colored_print(
"Now copying files...", colors.BLUE)
os.system(f"cp -aR {os.getcwd()} ~/.mec")
if os.path.exists(os.path.join(MECROOT, ".venv")):
os.system("rm -rf ~/.mec/.venv")
# virtualenv
if not os.path.isdir(os.path.join(MECROOT, ".venv")):
if os.system("virtualenv -p /usr/bin/python3 ~/.mec/.venv") != 0:
colors.colored_print("Error setting up virtualenv", colors.RED)
sys.exit(1)
venv_py = "~/.mec/.venv/bin/python3"
# use requirements.txt
colors.colored_print(
"Now installing dependencies...", colors.BLUE)
pip_install(venv_py, '-r requirements.txt')
# mkdir conf
if not os.path.isdir(MECROOT+"/conf"):
os.mkdir(MECROOT+"/conf")
# zoomeye account:
zoomeye = str(
input(colors.CYAN+'Would you like to use zoomeye? (yes/No) '+colors.END)).lower()
if zoomeye in ('yes', 'y'):
user = str(input('Username: '))
password = str(getpass.getpass('Password: '))
conf = open(MECROOT + '/conf/zoomeye.conf', "w")
conf.write("user:" + user + "\n")
conf.write("password:" + password + "\n")
censys = str(
input(colors.CYAN+'Would you like to use censys? (yes/No) '+colors.END)).lower()
if censys in ('yes', 'y'):
uid = str(input('API ID: '))
sec = str(getpass.getpass('Secret: '))
conf2 = open(MECROOT + '/conf/censys.conf', "w")
key = {
"uid": uid,
"sec": sec
}
conf2.write(json.dumps(key))
if not os.path.isfile("/usr/local/bin/mec"):
# add mec to $PATH
os.system('sudo cp mec /usr/local/bin/')
# fix permissions
os.system('sudo chmod +x /usr/local/bin/mec && chmod +x ~/.mec/mec.py')
print(
colors.GREEN +
colors.BOLD +
"Installation completed. try: $ mec" +
colors.END)
INTRO = colors.CYAN + colors.BOLD + r'''
███▄ ▄███▓▓█████ ▄████▄
▓██▒▀█▀ ██▒▓█ ▀ ▒██▀ ▀█
▓██ ▓██░▒███ ▒▓█ ▄
▒██ ▒██ ▒▓█ ▄ ▒▓▓▄ ▄██▒
▒██▒ ░██▒░▒████▒▒ ▓███▀ ░
░ ▒░ ░ ░░░ ▒░ ░░ ░▒ ▒ ░
░ ░ ░ ░ ░ ░ ░ ▒
░ ░ ░ ░
░ ░ ░░ ░
░
''' + colors.END + colors.GREEN + colors.BOLD + '''
by jm33_m0
https://github.com/jm33-m0/mec
type h or help for help\n''' + colors.END
MECROOT = os.path.join(os.path.expanduser("~"), ".mec")
DEST = os.path.join(os.path.expanduser("~"), ".mec/mec.py")
os.system('clear')
print(INTRO)
if os.path.exists(DEST):
try:
# MEC already installed
colors.colored_print('MEC is already installed.', colors.YELLOW)
# Choose action
ACT = str(
input(colors.CYAN +
'What can i do ? ([U]ninstall/[R]einstall/[N]othing) '
+ colors.END)).lower()
# uninstall MEC
if ACT == "u":
# delete files
colors.colored_print('Uninstalling MEC.', color_code=colors.YELLOW)
os.system('rm -rf ~/.mec')
os.system('sudo rm -rf /usr/local/bin/mec')
colors.colored_print('Done.', colors.GREEN)
sys.exit(0)
# reinstall MEC
elif ACT == "r":
# removeing files.
colors.colored_print('Uninstalling MEC.', color_code=colors.YELLOW)
os.system('rm -rf ~/.mec')
colors.colored_print('Done. now reinstalling.', colors.YELLOW)
start_install()
sys.exit(0)
elif ACT == "n":
sys.exit(0)
except KeyboardInterrupt:
colors.colored_print("Installation aborted.", colors.RED)
else:
try:
INST = str(
input(
(colors.BLUE +
"installing MEC, are you sure? (Yes/no) " +
colors.END))).lower()
if INST in ("no", "n"):
sys.exit(0)
start_install()
except KeyboardInterrupt:
colors.colored_print('Installation aborted.', colors.RED)