| 1 | #!/usr/bin/env python |
|---|
| 2 | # |
|---|
| 3 | # Copyright (C) 2005-2006 Insecure.Com LLC. |
|---|
| 4 | # Copyright (C) 2007-2008 Adriano Monteiro Marques |
|---|
| 5 | # |
|---|
| 6 | # Authors: Adriano Monteiro Marques <adriano@umitproject.org> |
|---|
| 7 | # Guilherme Polo <ggpolo@gmail.com> |
|---|
| 8 | # |
|---|
| 9 | # This program is free software; you can redistribute it and/or modify |
|---|
| 10 | # it under the terms of the GNU General Public License as published by |
|---|
| 11 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 12 | # (at your option) any later version. |
|---|
| 13 | # |
|---|
| 14 | # This program is distributed in the hope that it will be useful, |
|---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | # GNU General Public License for more details. |
|---|
| 18 | # |
|---|
| 19 | # You should have received a copy of the GNU General Public License |
|---|
| 20 | # along with this program; if not, write to the Free Software |
|---|
| 21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 22 | |
|---|
| 23 | import os |
|---|
| 24 | import re |
|---|
| 25 | import sys |
|---|
| 26 | from stat import * |
|---|
| 27 | from glob import glob |
|---|
| 28 | |
|---|
| 29 | from distutils.core import setup |
|---|
| 30 | from distutils.command.install import install |
|---|
| 31 | from distutils.command.sdist import sdist |
|---|
| 32 | from distutils.command.build import build |
|---|
| 33 | from distutils import log, dir_util |
|---|
| 34 | |
|---|
| 35 | from umit.core.Version import VERSION |
|---|
| 36 | from utils.i18n import potmanager |
|---|
| 37 | |
|---|
| 38 | from install_scripts.common import BIN_DIRNAME, PIXMAPS_DIR, ICONS_DIR, \ |
|---|
| 39 | BASE_DOCS_DIR, DOCS_DIR, LOCALE_DIR, CONFIG_DIR, MISC_DIR, SQL_DIR |
|---|
| 40 | |
|---|
| 41 | py2exe_cmdclass = py2exe_options = py2app_options = None |
|---|
| 42 | if 'py2exe' in sys.argv: |
|---|
| 43 | from install_scripts.windows.py2exe_setup import py2exe_cmdclass, \ |
|---|
| 44 | py2exe_options |
|---|
| 45 | if 'py2app' in sys.argv: |
|---|
| 46 | from install_scripts.macosx.py2app_setup import py2app_options |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | def extension_find(result, dirname, fnames, suffix): |
|---|
| 50 | files = [] |
|---|
| 51 | for f in fnames: |
|---|
| 52 | p = os.path.join(dirname, f) |
|---|
| 53 | if os.path.isfile(p) and f.endswith(suffix): |
|---|
| 54 | files.append(p) |
|---|
| 55 | |
|---|
| 56 | if files: |
|---|
| 57 | result.append((dirname, files)) |
|---|
| 58 | |
|---|
| 59 | def mo_find(result, dirname, fnames): |
|---|
| 60 | return extension_find(result, dirname, fnames, ".mo") |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | ############################################################################### |
|---|
| 64 | # Installation variables |
|---|
| 65 | |
|---|
| 66 | # What to copy to the destiny |
|---|
| 67 | # Here, we define what should be put inside the directories set in the |
|---|
| 68 | # beginning of this file. This list contain tuples where the first element |
|---|
| 69 | # contains a path to where the other elements of the tuple should be installed. |
|---|
| 70 | # The first element is a path in the INSTALLATION PREFIX, and the other |
|---|
| 71 | # elements are the path in the source base. |
|---|
| 72 | # Ex: [("share/pixmaps", "/umit/trunk/share/pixmaps/test.png")] |
|---|
| 73 | # This will install the test.png file in the installation dir share/pixmaps. |
|---|
| 74 | svg = glob(os.path.join('share', 'pixmaps', '*.svg')) |
|---|
| 75 | data_files = [ |
|---|
| 76 | (PIXMAPS_DIR, |
|---|
| 77 | glob(os.path.join(PIXMAPS_DIR, '*.svg')) + |
|---|
| 78 | glob(os.path.join(PIXMAPS_DIR, '*.png')) + |
|---|
| 79 | glob(os.path.join(PIXMAPS_DIR, '*.xpm')) + |
|---|
| 80 | glob(os.path.join(PIXMAPS_DIR, 'umit.o*'))), |
|---|
| 81 | |
|---|
| 82 | (CONFIG_DIR, |
|---|
| 83 | [os.path.join(CONFIG_DIR, 'umit.conf')] + |
|---|
| 84 | [os.path.join(CONFIG_DIR, 'scan_profile.usp')] + |
|---|
| 85 | [os.path.join(CONFIG_DIR, 'umit_version')] + |
|---|
| 86 | [os.path.join(CONFIG_DIR, 'umitng.db')] + |
|---|
| 87 | [os.path.join(CONFIG_DIR, 'timeline-settings.conf')] + |
|---|
| 88 | [os.path.join(CONFIG_DIR, 'tl_colors_evt_std.conf')] + |
|---|
| 89 | [os.path.join(CONFIG_DIR, 'scheduler-schemas.conf')] + |
|---|
| 90 | [os.path.join(CONFIG_DIR, 'scheduler-profiles.conf')] + |
|---|
| 91 | [os.path.join(CONFIG_DIR, 'scheduler.log')] + |
|---|
| 92 | [os.path.join(CONFIG_DIR, 'smtp-schemas.conf')] + |
|---|
| 93 | glob(os.path.join(CONFIG_DIR, '*.xml'))+ |
|---|
| 94 | glob(os.path.join(CONFIG_DIR, '*.txt'))), |
|---|
| 95 | |
|---|
| 96 | # umit.db SQL |
|---|
| 97 | (SQL_DIR, glob(os.path.join(SQL_DIR, '*.sql'))), |
|---|
| 98 | |
|---|
| 99 | (MISC_DIR, glob(os.path.join(MISC_DIR, '*.dmp'))), |
|---|
| 100 | |
|---|
| 101 | # Radialnet |
|---|
| 102 | (os.path.join(PIXMAPS_DIR, 'radialnet', 'application'), |
|---|
| 103 | glob(os.path.join(PIXMAPS_DIR, 'radialnet', 'application', |
|---|
| 104 | '*.png'))), |
|---|
| 105 | (os.path.join(PIXMAPS_DIR, 'radialnet', 'icons'), |
|---|
| 106 | glob(os.path.join(PIXMAPS_DIR, 'radialnet', 'icons','*.png'))), |
|---|
| 107 | |
|---|
| 108 | # Network Inventory |
|---|
| 109 | (os.path.join(PIXMAPS_DIR, 'networkinventory'), |
|---|
| 110 | glob(os.path.join(PIXMAPS_DIR, 'networkinventory', '*.png'))), |
|---|
| 111 | |
|---|
| 112 | # InterfaceEditor |
|---|
| 113 | (os.path.join(PIXMAPS_DIR, 'uie'), |
|---|
| 114 | glob(os.path.join(PIXMAPS_DIR, 'uie', '*.png'))), |
|---|
| 115 | |
|---|
| 116 | (ICONS_DIR, |
|---|
| 117 | glob(os.path.join(ICONS_DIR, '*.ico')) + |
|---|
| 118 | glob(os.path.join(ICONS_DIR, '*.png'))), |
|---|
| 119 | |
|---|
| 120 | # Documentation |
|---|
| 121 | (DOCS_DIR, |
|---|
| 122 | glob(os.path.join(DOCS_DIR, '*.html')) + |
|---|
| 123 | glob(os.path.join(DOCS_DIR, '*.js')) + |
|---|
| 124 | glob(os.path.join(DOCS_DIR, '*.inv'))), |
|---|
| 125 | (os.path.join(DOCS_DIR, '_images'), |
|---|
| 126 | glob(os.path.join(DOCS_DIR, '_images', '*'))), |
|---|
| 127 | (os.path.join(DOCS_DIR, '_sources'), |
|---|
| 128 | glob(os.path.join(DOCS_DIR, '_sources', '*'))), |
|---|
| 129 | (os.path.join(DOCS_DIR, '_static'), |
|---|
| 130 | glob(os.path.join(DOCS_DIR, '_static', '*'))) |
|---|
| 131 | |
|---|
| 132 | ] |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | ############################################################################## |
|---|
| 136 | # Distutils subclasses |
|---|
| 137 | |
|---|
| 138 | potman = potmanager.POTManager(os.path.dirname(os.path.abspath(__file__))) |
|---|
| 139 | |
|---|
| 140 | class umit_build(build): |
|---|
| 141 | |
|---|
| 142 | def delete_mo_files(self): |
|---|
| 143 | """Remove *.mo files.""" |
|---|
| 144 | tmp = [] |
|---|
| 145 | os.path.walk(LOCALE_DIR, mo_find, tmp) |
|---|
| 146 | for (path, t) in tmp: |
|---|
| 147 | os.remove(t[0]) |
|---|
| 148 | |
|---|
| 149 | def build_mo_files(self): |
|---|
| 150 | """Build mo files from po and put it into LC_MESSAGES.""" |
|---|
| 151 | potman.compile(LOCALE_DIR, use_fuzzy=False, distutils_log=self.announce) |
|---|
| 152 | |
|---|
| 153 | def build_html_doc(self): |
|---|
| 154 | """Build the html documentation.""" |
|---|
| 155 | import sphinx |
|---|
| 156 | |
|---|
| 157 | sphinx_ver = sphinx.__version__ |
|---|
| 158 | if map(int, sphinx_ver.split('.')) < [0, 5, 1]: |
|---|
| 159 | self.warn("Sphinx's version is too old (%s, expected at least " |
|---|
| 160 | "0.5.1, documentation won't be build." % sphinx_ver) |
|---|
| 161 | |
|---|
| 162 | # Build the documentation just like it is done through the Makefile |
|---|
| 163 | sphinx.main([__file__, |
|---|
| 164 | "-b", "html", |
|---|
| 165 | "-d", os.path.join(BASE_DOCS_DIR, 'doctrees'), |
|---|
| 166 | os.path.join(BASE_DOCS_DIR, 'src'), DOCS_DIR]) |
|---|
| 167 | |
|---|
| 168 | def run(self): |
|---|
| 169 | self.delete_mo_files() |
|---|
| 170 | self.build_mo_files() |
|---|
| 171 | self.build_html_doc() |
|---|
| 172 | build.run(self) |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | class umit_install(install): |
|---|
| 176 | |
|---|
| 177 | def run(self): |
|---|
| 178 | # Add i18n files to data_files list |
|---|
| 179 | os.path.walk(LOCALE_DIR, mo_find, data_files) |
|---|
| 180 | install.run(self) |
|---|
| 181 | |
|---|
| 182 | self.set_perms() |
|---|
| 183 | self.set_modules_path() |
|---|
| 184 | self.fix_paths() |
|---|
| 185 | self.create_uninstaller() |
|---|
| 186 | self.finish_banner() |
|---|
| 187 | |
|---|
| 188 | def create_uninstaller(self): |
|---|
| 189 | uninstaller_filename = os.path.join( |
|---|
| 190 | self.install_scripts, "uninstall_umit") |
|---|
| 191 | uninstaller = [] |
|---|
| 192 | uninstaller.append( |
|---|
| 193 | "#!/usr/bin/env python\n" |
|---|
| 194 | "import os, sys\n" |
|---|
| 195 | "\n" |
|---|
| 196 | "print\n" |
|---|
| 197 | "print '%(line)s Uninstall Umit %(version)s %(line)s'\n" |
|---|
| 198 | "print\n" |
|---|
| 199 | "\n" |
|---|
| 200 | "answer = raw_input('Are you sure that you want to '\n" |
|---|
| 201 | " 'completly uninstall Umit %(version)s? (yes/no) ')\n" |
|---|
| 202 | "\n" |
|---|
| 203 | "if answer.lower() not in ['yes', 'y']:\n" |
|---|
| 204 | " sys.exit(0)\n" |
|---|
| 205 | "\n" |
|---|
| 206 | "print\n" |
|---|
| 207 | "print '%(line)s Uninstalling Umit %(version)s... %(line)s'\n" |
|---|
| 208 | "print\n" % {'version': VERSION, 'line': '-' * 10}) |
|---|
| 209 | |
|---|
| 210 | for output in self.get_outputs(): |
|---|
| 211 | uninstaller.append( |
|---|
| 212 | "print 'Removing %(output)s...'\n" |
|---|
| 213 | "if os.path.exists('%(output)s'):\n" |
|---|
| 214 | " os.remove('%(output)s')\n" % {'output': output}) |
|---|
| 215 | |
|---|
| 216 | uninstaller.append( |
|---|
| 217 | "print 'Removing uninstaller itself...'\n" |
|---|
| 218 | "os.remove('%s')\n" % uninstaller_filename) |
|---|
| 219 | |
|---|
| 220 | uninstaller_file = open(uninstaller_filename, 'w') |
|---|
| 221 | uninstaller_file.writelines(uninstaller) |
|---|
| 222 | uninstaller_file.close() |
|---|
| 223 | |
|---|
| 224 | # Set exec bit for uninstaller |
|---|
| 225 | mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0555) & 07777 |
|---|
| 226 | os.chmod(uninstaller_filename, mode) |
|---|
| 227 | |
|---|
| 228 | def set_modules_path(self): |
|---|
| 229 | umit = os.path.join(self.install_scripts, "umit") |
|---|
| 230 | modules = self.install_lib |
|---|
| 231 | |
|---|
| 232 | re_sys = re.compile("^import sys$") |
|---|
| 233 | |
|---|
| 234 | ufile = open(umit, "r") |
|---|
| 235 | ucontent = ufile.readlines() |
|---|
| 236 | ufile.close() |
|---|
| 237 | |
|---|
| 238 | uline = None |
|---|
| 239 | for line in xrange(len(ucontent)): |
|---|
| 240 | if re_sys.match(ucontent[line]): |
|---|
| 241 | uline = line + 1 |
|---|
| 242 | break |
|---|
| 243 | |
|---|
| 244 | ucontent.insert(uline, "sys.path.insert(0,'%s')\n" % modules ) |
|---|
| 245 | |
|---|
| 246 | ufile = open(umit, "w") |
|---|
| 247 | ufile.writelines(ucontent) |
|---|
| 248 | ufile.close() |
|---|
| 249 | |
|---|
| 250 | def set_perms(self): |
|---|
| 251 | re_bin = re.compile("(bin)") |
|---|
| 252 | for output in self.get_outputs(): |
|---|
| 253 | if re_bin.findall(output): |
|---|
| 254 | continue |
|---|
| 255 | |
|---|
| 256 | if os.path.isdir(output): |
|---|
| 257 | os.chmod(output, S_IRWXU | \ |
|---|
| 258 | S_IRGRP | \ |
|---|
| 259 | S_IXGRP | \ |
|---|
| 260 | S_IROTH | \ |
|---|
| 261 | S_IXOTH) |
|---|
| 262 | else: |
|---|
| 263 | os.chmod(output, S_IRWXU | \ |
|---|
| 264 | S_IRGRP | \ |
|---|
| 265 | S_IROTH) |
|---|
| 266 | |
|---|
| 267 | def fix_paths(self): |
|---|
| 268 | interesting_paths = {"CONFIG_DIR": CONFIG_DIR, |
|---|
| 269 | "DOCS_DIR": DOCS_DIR, |
|---|
| 270 | "LOCALE_DIR": LOCALE_DIR, |
|---|
| 271 | "MISC_DIR": MISC_DIR, |
|---|
| 272 | "PIXMAPS_DIR": PIXMAPS_DIR, |
|---|
| 273 | "ICONS_DIR": ICONS_DIR} |
|---|
| 274 | |
|---|
| 275 | pcontent = "" |
|---|
| 276 | paths_file = os.path.join("umit", "core", "BasePaths.py") |
|---|
| 277 | installed_files = self.get_outputs() |
|---|
| 278 | |
|---|
| 279 | # Finding where the Paths.py file was installed. |
|---|
| 280 | for f in installed_files: |
|---|
| 281 | if re.findall("(%s)" % re.escape(paths_file), f): |
|---|
| 282 | paths_file = f |
|---|
| 283 | pf = open(paths_file) |
|---|
| 284 | pcontent = pf.read() |
|---|
| 285 | pf.close() |
|---|
| 286 | break |
|---|
| 287 | |
|---|
| 288 | for path in interesting_paths: |
|---|
| 289 | for f in installed_files: |
|---|
| 290 | result = re.findall("(.*%s)" %\ |
|---|
| 291 | re.escape(interesting_paths[path]), |
|---|
| 292 | f) |
|---|
| 293 | if len(result) == 1: |
|---|
| 294 | result = result[0] |
|---|
| 295 | pcontent = re.sub("%s\s+=\s+.+" % path, |
|---|
| 296 | "%s = \"%s\"" % (path, result), |
|---|
| 297 | pcontent) |
|---|
| 298 | break |
|---|
| 299 | |
|---|
| 300 | pf = open(paths_file, "w") |
|---|
| 301 | pf.write(pcontent) |
|---|
| 302 | pf.close() |
|---|
| 303 | |
|---|
| 304 | def finish_banner(self): |
|---|
| 305 | print |
|---|
| 306 | print "%s Thanks for using Umit %s %s" % \ |
|---|
| 307 | ("#"*10, VERSION, "#"*10) |
|---|
| 308 | print |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | class umit_sdist(sdist): |
|---|
| 312 | |
|---|
| 313 | def read_manifest_no_mo(self): |
|---|
| 314 | """Read Manifest without mo file.""" |
|---|
| 315 | for line in open(self.manifest): |
|---|
| 316 | if not line: |
|---|
| 317 | break |
|---|
| 318 | |
|---|
| 319 | if line[-1] == '\n': |
|---|
| 320 | line = line[:-1] |
|---|
| 321 | if line.find('umit.mo') != -1: |
|---|
| 322 | self.filelist.files.remove(line) |
|---|
| 323 | |
|---|
| 324 | def run(self): |
|---|
| 325 | from distutils.filelist import FileList |
|---|
| 326 | self.keep_temp = 1 |
|---|
| 327 | #Rewrite: sdist.run(self) |
|---|
| 328 | self.manifest = "MANIFEST" |
|---|
| 329 | self.filelist = FileList() |
|---|
| 330 | self.check_metadata() |
|---|
| 331 | self.get_file_list() |
|---|
| 332 | ## Exclude mo files: |
|---|
| 333 | self.read_manifest_no_mo() |
|---|
| 334 | if self.manifest_only: |
|---|
| 335 | return |
|---|
| 336 | self.make_distribution() |
|---|
| 337 | |
|---|
| 338 | self.finish_banner() |
|---|
| 339 | |
|---|
| 340 | def finish_banner(self): |
|---|
| 341 | print |
|---|
| 342 | print "%s The packages for Umit %s are in ./dist %s" % \ |
|---|
| 343 | ("#" * 10, VERSION, "#" * 10) |
|---|
| 344 | print |
|---|
| 345 | |
|---|
| 346 | |
|---|
| 347 | ##################### Umit banner ######################## |
|---|
| 348 | print |
|---|
| 349 | print "%s Umit for Linux %s %s" % ("#" * 10, VERSION, "#" * 10) |
|---|
| 350 | print |
|---|
| 351 | ########################################################## |
|---|
| 352 | |
|---|
| 353 | |
|---|
| 354 | cmdclasses = { |
|---|
| 355 | "install": umit_install, |
|---|
| 356 | "build": umit_build, |
|---|
| 357 | "sdist": umit_sdist} |
|---|
| 358 | |
|---|
| 359 | if py2exe_cmdclass: |
|---|
| 360 | cmdclasses.update(py2exe_cmdclass) |
|---|
| 361 | |
|---|
| 362 | options = dict( |
|---|
| 363 | name = 'umit', |
|---|
| 364 | license = 'GNU GPL (version 2 or later)', |
|---|
| 365 | url = 'http://www.umitproject.org', |
|---|
| 366 | download_url = 'http://www.umitproject.org', |
|---|
| 367 | author = 'Adriano Monteiro & Cleber Rodrigues', |
|---|
| 368 | author_email = 'adriano@umitproject.org, cleber@globalred.com.br', |
|---|
| 369 | maintainer = 'Adriano Monteiro', |
|---|
| 370 | maintainer_email = 'adriano@umitproject.org', |
|---|
| 371 | description = ("Umit is a network scanning frontend, developed in " |
|---|
| 372 | "Python and GTK and was started with the sponsoring of " |
|---|
| 373 | "Google's Summer of Code."), |
|---|
| 374 | long_description = ("The project goal is to develop a network " |
|---|
| 375 | "scanning frontend that is really useful for advanced users and " |
|---|
| 376 | "easy to be used by newbies. With Umit, a network admin can " |
|---|
| 377 | "create scan profiles for faster and easier network scanning " |
|---|
| 378 | "or even compare scan results to easily see any changes. " |
|---|
| 379 | "A regular user will also be able to construct powerful scans " |
|---|
| 380 | "with Umit command creator wizards."), |
|---|
| 381 | version = VERSION, |
|---|
| 382 | scripts = [ |
|---|
| 383 | os.path.join(BIN_DIRNAME, 'umit'), |
|---|
| 384 | os.path.join(BIN_DIRNAME, 'umit_scheduler.py')], |
|---|
| 385 | packages = [ |
|---|
| 386 | 'umit', 'umit.core', 'umit.core.radialnet', 'umit.db', |
|---|
| 387 | 'umit.gui', 'umit.gui.radialnet', 'umit.interfaceeditor', |
|---|
| 388 | 'umit.interfaceeditor.selectborder', 'umit.inventory', |
|---|
| 389 | 'umit.plugin', 'higwidgets'], |
|---|
| 390 | data_files = data_files, |
|---|
| 391 | cmdclass = cmdclasses, |
|---|
| 392 | classifiers = [ |
|---|
| 393 | 'Development Status :: 4 - Beta', |
|---|
| 394 | 'Environment :: X11 Applications :: GTK', |
|---|
| 395 | 'Intended Audience :: End Users/Desktop', |
|---|
| 396 | 'Intended Audience :: System Administrators', |
|---|
| 397 | 'License :: OSI Approved :: GNU General Public License (GPL)', |
|---|
| 398 | 'Programming Language :: Python :: 2', |
|---|
| 399 | 'Programming Language :: Python :: 2.4', |
|---|
| 400 | 'Programming Language :: Python :: 2.5', |
|---|
| 401 | 'Programming Language :: Python :: 2.6', |
|---|
| 402 | 'Topic :: System :: Networking', |
|---|
| 403 | ] |
|---|
| 404 | ) |
|---|
| 405 | |
|---|
| 406 | if py2exe_options: |
|---|
| 407 | options.update(py2exe_options) |
|---|
| 408 | |
|---|
| 409 | if py2app_options: |
|---|
| 410 | options.update(py2app_options) |
|---|
| 411 | |
|---|
| 412 | setup(**options) |
|---|