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