This repository has been archived by the owner on Oct 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathsetup.py
147 lines (110 loc) · 3.52 KB
/
setup.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""LICENSE
Copyright (C) 2020 Sam Freeside
This file is part of usbrip.
usbrip 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.
usbrip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with usbrip. If not, see <http://www.gnu.org/licenses/>.
"""
__author__ = 'Sam Freeside (@snovvcrash)'
__email__ = '[email protected]'
__license__ = 'GPL-3.0'
__site__ = 'https://github.com/snovvcrash/usbrip'
__brief__ = 'USB device artifacts tracker'
import glob
import shutil
import sys
import os
from subprocess import check_output
from setuptools import setup, find_packages, Command
from setuptools.command.install import install
from usbrip import __version__
class LocalInstallCommand(install):
"""Custom install command to install local Python dependencies."""
def run(self):
install.run(self)
tools_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), '3rdPartyTools')
deps = []
for dep in os.listdir(tools_dir):
if dep.startswith('wheel-'):
wheel = dep
else:
deps.append(dep)
resolve(wheel, tools_dir)
for dep in deps:
resolve(dep, tools_dir)
class CleanCommand(Command):
"""Custom clean command to tidy up the project root."""
CLEAN_FILES = './build ./dist ./*.pyc ./*.tgz ./*.egg-info'.split(' ')
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
here = os.path.abspath(os.path.dirname(__file__))
for path_spec in self.CLEAN_FILES:
abs_paths = glob.glob(os.path.normpath(os.path.join(here, path_spec)))
for path in abs_paths:
if not path.startswith(here):
# Die if path in CLEAN_FILES is absolute + outside this directory
raise ValueError(f'{path} is not a path inside {here}')
print(f'[*] Removing {os.path.relpath(path)}')
shutil.rmtree(path)
def resolve(dep, path=None):
pip = os.path.join(sys.executable.rsplit('/', 1)[0], 'pip')
if path:
args = [pip, 'install', os.path.join(path, dep)]
dep_type = 'local'
else:
args = [pip, 'install', dep]
dep_type = 'remote'
if 'Successfully installed' in check_output(args).decode('utf-8'):
print(f'[*] Resolved ({dep_type}) dependency: {dep}')
def parse_requirements(file):
required = []
with open(file, 'r') as f:
for req in f:
if not req.strip().startswith('#'):
required.append(req)
return required
long_description = '''\
Simple CLI forensics tool for tracking \
USB device artifacts (history of USB events) \
on GNU/Linux.\
'''.replace('\t', '')
keywords = 'forensics cybersecurity infosec usb-history usb-devices'
resolve('wheel')
setup(
name='usbrip',
version=__version__,
url=__site__,
author=__author__,
author_email=__email__,
license=__license__,
description=__brief__,
long_description=long_description,
long_description_content_type='text/markdown',
keywords=keywords,
packages=find_packages(),
zip_safe=False,
python_requires='>=3.6',
install_requires=parse_requirements('requirements.txt'),
cmdclass={
'install': LocalInstallCommand,
'clean': CleanCommand
},
entry_points={
'console_scripts': [
'usbrip=usbrip.__main__:main'
]
}
)