forked from commixproject/commix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
172 lines (152 loc) · 6.02 KB
/
install.py
File metadata and controls
172 lines (152 loc) · 6.02 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
#!/usr/bin/env python
# encoding: UTF-8
"""
This file is part of Commix Project (https://commixproject.com).
Copyright (c) 2014-2021 Anastasios Stasinopoulos (@ancst).
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
For more see the file 'readme/COPYING' for copying permission.
"""
import os
import sys
import platform
import subprocess
from src.utils import menu
from src.utils import settings
from src.utils import requirments
from src.thirdparty.six.moves import input as _input
from src.thirdparty.colorama import Fore, Back, Style, init
"""
Make a local installation of 'commix' on your system.
"""
"""
The un-installer.
"""
def uninstaller():
info_msg = "Starting the uninstaller. "
sys.stdout.write(settings.print_info_msg(info_msg))
sys.stdout.flush()
try:
subprocess.Popen("rm -rf /usr/bin/" + settings.APPLICATION + " >/dev/null 2>&1", shell=True).wait()
subprocess.Popen("rm -rf /usr/share/" + settings.APPLICATION + " >/dev/null 2>&1", shell=True).wait()
except:
print(settings.SINGLE_WHITESPACE)
raise SystemExit()
sys.stdout.write(settings.SUCCESS_STATUS + "\n")
sys.stdout.flush()
info_msg = "The un-installation of commix has finished!"
print(settings.print_bold_info_msg(info_msg))
"""
The installer.
"""
def installer():
packages = "build-essential python-dev"
dependencies = "git python-pip"
info_msg = "Starting the installer. "
sys.stdout.write(settings.print_info_msg(info_msg))
sys.stdout.flush()
# Check if OS is Linux.
if platform.system() == "Linux":
# You need to have root privileges to run this script
if os.geteuid() != 0:
print(settings.SINGLE_WHITESPACE)
err_msg = "You need to have root privileges to run this option!"
print(settings.print_critical_msg(err_msg))
raise SystemExit()
# Check if commix is already installed.
if os.path.isdir("/usr/share/" + settings.APPLICATION + ""):
print(settings.SINGLE_WHITESPACE)
warn_msg = "It seems that " + settings.APPLICATION
warn_msg += " is already installed in your system."
print(settings.print_warning_msg(warn_msg))
while True:
if not menu.options.batch:
question_msg = "Do you want to remove commix? [Y/n] > "
uninstall = _input(settings.print_question_msg(question_msg))
else:
uninstall = ""
if len(uninstall) == 0:
uninstall = "Y"
if uninstall in settings.CHOICE_YES:
uninstaller()
raise SystemExit()
elif uninstall in settings.CHOICE_NO or \
uninstall in settings.CHOICE_QUIT:
raise SystemExit()
else:
err_msg = "'" + uninstall + "' is not a valid answer."
print(settings.print_error_msg(err_msg))
pass
# Check for git.
if not os.path.isfile("/usr/bin/git") or not os.path.isfile("/usr/bin/pip"):
# Install requirement.
if os.path.isfile("/etc/apt/sources.list"):
sys.stdout.write(settings.SUCCESS_STATUS + "\n")
sys.stdout.flush()
# Check for dependencies.
dependencies_items = dependencies.split()
for item in dependencies_items:
requirments.do_check(item)
else:
print(settings.SINGLE_WHITESPACE)
err_msg = "The installer is not designed for any "
err_msg += "other Linux distro than Ubuntu / Debian. "
err_msg += "Please install manually: " + dependencies
print(Back.RED + err_msg + Style.RESET_ALL)
print(settings.SINGLE_WHITESPACE)
raise SystemExit()
# Force install of necessary packages
subprocess.Popen("apt-get --force-yes -y install " + packages + ">/dev/null 2>&1", shell=True).wait()
sys.stdout.write(settings.SUCCESS_STATUS + "\n")
sys.stdout.flush()
info_msg = "Installing " + settings.APPLICATION
info_msg += " into the /usr/share/" + settings.APPLICATION + ". "
sys.stdout.write(settings.print_info_msg(info_msg))
try:
current_dir = os.getcwd()
subprocess.Popen("cp -r " + current_dir + " /usr/share/" + settings.APPLICATION + " >/dev/null 2>&1", shell=True).wait()
subprocess.Popen("chmod 775 /usr/share/" + settings.APPLICATION + "/" + settings.APPLICATION + ".py >/dev/null 2>&1", shell=True).wait()
except:
print(settings.SINGLE_WHITESPACE)
raise SystemExit()
sys.stdout.write(settings.SUCCESS_STATUS + "\n")
sys.stdout.flush()
info_msg = "Installing " + settings.APPLICATION
info_msg += " to /usr/bin/" + settings.APPLICATION + ". "
sys.stdout.write(settings.print_info_msg(info_msg))
try:
with open("/usr/bin/" + settings.APPLICATION, 'w') as f:
f.write('#!/bin/bash\n')
f.write('cd /usr/share/commix/ && ./commix.py "$@"\n')
subprocess.Popen("chmod +x /usr/bin/" + settings.APPLICATION + " >/dev/null 2>&1", shell=True).wait()
except:
print(settings.SINGLE_WHITESPACE)
raise SystemExit()
sys.stdout.write(settings.SUCCESS_STATUS + "\n")
sys.stdout.flush()
#Create the Output Directory
try:
os.stat(settings.OUTPUT_DIR)
except:
try:
os.mkdir(settings.OUTPUT_DIR)
except OSError as err_msg:
try:
error_msg = str(err_msg).split("] ")[1] + "."
except IndexError:
error_msg = str(err_msg) + "."
print(settings.print_critical_msg(error_msg))
raise SystemExit()
info_msg = "The installation is finished! Type '"
info_msg += settings.APPLICATION + "' to launch it."
print(settings.print_bold_info_msg(info_msg))
else :
print(settings.SINGLE_WHITESPACE)
err_msg = "The installer is not designed for any other system other than Linux. "
err_msg += "Please install manually: " + packages + dependencies
print(settings.print_critical_msg(err_msg))
print(settings.SINGLE_WHITESPACE)
raise SystemExit()
# eof