blob: a5d4ed6cb582fae1ea8ed3022d53651b69d9f315 [file] [log] [blame]
Richard Marian Thomaiyar14fddef2018-07-13 23:55:56 +05301#!/usr/bin/env python
2# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*-
3# vi: set ft=python sts=4 ts=4 sw=4 noet :
4
5# This file is part of Fail2Ban.
6#
7# Fail2Ban is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# Fail2Ban is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with Fail2Ban; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21__author__ = "Cyril Jaquier, Steven Hiscocks, Yaroslav Halchenko"
22__copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2008-2016 Fail2Ban Contributors"
23__license__ = "GPL"
24
25import platform
26
27try:
28 import setuptools
29 from setuptools import setup
30 from setuptools.command.install import install
31 from setuptools.command.install_scripts import install_scripts
32except ImportError:
33 setuptools = None
34 from distutils.core import setup
35
36# all versions
37from distutils.command.build_py import build_py
38from distutils.command.build_scripts import build_scripts
39if setuptools is None:
40 from distutils.command.install import install
41 from distutils.command.install_scripts import install_scripts
42try:
43 # python 3.x
44 from distutils.command.build_py import build_py_2to3
45 from distutils.command.build_scripts import build_scripts_2to3
46 _2to3 = True
47except ImportError:
48 # python 2.x
49 _2to3 = False
50
51import os
52from os.path import isfile, join, isdir, realpath
53import sys
54import warnings
55from glob import glob
56
57from fail2ban.setup import updatePyExec
58
59if setuptools and "test" in sys.argv:
60 import logging
61 logSys = logging.getLogger("fail2ban")
62 hdlr = logging.StreamHandler(sys.stdout)
63 fmt = logging.Formatter("%(asctime)-15s %(message)s")
64 hdlr.setFormatter(fmt)
65 logSys.addHandler(hdlr)
66 if set(["-q", "--quiet"]) & set(sys.argv):
67 logSys.setLevel(logging.CRITICAL)
68 warnings.simplefilter("ignore")
69 sys.warnoptions.append("ignore")
70 elif set(["-v", "--verbose"]) & set(sys.argv):
71 logSys.setLevel(logging.DEBUG)
72 else:
73 logSys.setLevel(logging.INFO)
74elif "test" in sys.argv:
75 print("python distribute required to execute fail2ban tests")
76 print("")
77
78longdesc = '''
79Fail2Ban scans log files like /var/log/pwdfail or
80/var/log/apache/error_log and bans IP that makes
81too many password failures. It updates firewall rules
82to reject the IP address or executes user defined
83commands.'''
84
85if setuptools:
86 setup_extra = {
87 'test_suite': "fail2ban.tests.utils.gatherTests",
88 'use_2to3': True,
89 }
90else:
91 setup_extra = {}
92
93data_files_extra = []
94
95# Installing documentation files only under Linux or other GNU/ systems
96# (e.g. GNU/kFreeBSD), since others might have protective mechanisms forbidding
97# installation there (see e.g. #1233)
98platform_system = platform.system().lower()
99doc_files = ['README.md', 'DEVELOP', 'FILTERS', 'doc/run-rootless.txt']
100if platform_system in ('solaris', 'sunos'):
101 doc_files.append('README.Solaris')
102if platform_system in ('linux', 'solaris', 'sunos') or platform_system.startswith('gnu'):
103 data_files_extra.append(
104 ('/usr/share/doc/fail2ban', doc_files)
105 )
106
107# Get version number, avoiding importing fail2ban.
108# This is due to tests not functioning for python3 as 2to3 takes place later
109exec(open(join("fail2ban", "version.py")).read())
110
111setup(
112 name = "fail2ban",
113 version = version,
114 description = "Ban IPs that make too many password failures",
115 long_description = longdesc,
116 author = "Cyril Jaquier & Fail2Ban Contributors",
117 author_email = "cyril.jaquier@fail2ban.org",
118 url = "http://www.fail2ban.org",
119 license = "GPL",
120 platforms = "Posix",
121 cmdclass = {
122 'build_py': build_py, 'build_scripts': build_scripts,
123 },
124 scripts = [
125 'bin/fail2ban-client',
126 'bin/fail2ban-server',
127 'bin/fail2ban-regex',
128 'bin/fail2ban-testcases',
129 # 'bin/fail2ban-python', -- link (binary), will be installed via install_scripts_f2b wrapper
130 ],
131 packages = [
132 'fail2ban',
133 'fail2ban.client',
134 'fail2ban.server',
135 'fail2ban.tests',
136 'fail2ban.tests.action_d',
137 ],
138 package_data = {
139 'fail2ban.tests':
140 [ join(w[0], f).replace("fail2ban/tests/", "", 1)
141 for w in os.walk('fail2ban/tests/files')
142 for f in w[2]] +
143 [ join(w[0], f).replace("fail2ban/tests/", "", 1)
144 for w in os.walk('fail2ban/tests/config')
145 for f in w[2]] +
146 [ join(w[0], f).replace("fail2ban/tests/", "", 1)
147 for w in os.walk('fail2ban/tests/action_d')
148 for f in w[2]]
149 },
150 data_files = [
151 ('/etc/fail2ban',
152 glob("config/*.conf")
153 ),
154 ('/etc/fail2ban/filter.d',
155 glob("config/filter.d/*.conf")
156 ),
157 ('/etc/fail2ban/filter.d/ignorecommands',
158 [p for p in glob("config/filter.d/ignorecommands/*") if isfile(p)]
159 ),
160 ('/etc/fail2ban/action.d',
161 glob("config/action.d/*.conf") +
162 glob("config/action.d/*.py")
163 ),
164 ('/etc/fail2ban/fail2ban.d',
165 ''
166 ),
167 ('/etc/fail2ban/jail.d',
168 ''
169 ),
170 ('/var/lib/fail2ban',
171 ''
172 ),
173 ] + data_files_extra,
174 **setup_extra
175)