| 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 msgfmt |
|---|
| 37 | |
|---|
| 38 | from install_scripts.common import BIN_DIRNAME, PIXMAPS_DIR, ICONS_DIR, \ |
|---|
| 39 | 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 | def po_find(result, dirname, fnames): |
|---|
| 63 | return extension_find(result, dirname, fnames, ".po") |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | ############################################################################### |
|---|
| 67 | # Installation variables |
|---|
| 68 | |
|---|
| 69 | # What to copy to the destiny |
|---|
| 70 | # Here, we define what should be put inside the directories set in the |
|---|
| 71 | # beginning of this file. This list contain tuples where the first element |
|---|
| 72 | # contains a path to where the other elements of the tuple should be installed. |
|---|
| 73 | # The first element is a path in the INSTALLATION PREFIX, and the other |
|---|
| 74 | # elements are the path in the source base. |
|---|
| 75 | # Ex: [("share/pixmaps", "/umit/trunk/share/pixmaps/test.png")] |
|---|
| 76 | # This will install the test.png file in the installation dir share/pixmaps. |
|---|
| 77 | svg = glob(os.path.join('share', 'pixmaps', '*.svg')) |
|---|
| 78 | data_files = [ |
|---|
| 79 | (PIXMAPS_DIR, |
|---|
| 80 | glob(os.path.join(PIXMAPS_DIR, '*.svg')) + |
|---|
| 81 | glob(os.path.join(PIXMAPS_DIR, '*.png')) + |
|---|
| 82 | glob(os.path.join(PIXMAPS_DIR, '*.xpm')) + |
|---|
| 83 | glob(os.path.join(PIXMAPS_DIR, 'umit.o*'))), |
|---|
| 84 | |
|---|
| 85 | (CONFIG_DIR, |
|---|
| 86 | [os.path.join(CONFIG_DIR, 'umit.conf')] + |
|---|
| 87 | [os.path.join(CONFIG_DIR, 'scan_profile.usp')] + |
|---|
| 88 | [os.path.join(CONFIG_DIR, 'umit_version')] + |
|---|
| 89 | [os.path.join(CONFIG_DIR, 'umitng.db')] + |
|---|
| 90 | [os.path.join(CONFIG_DIR, 'timeline-settings.conf')] + |
|---|
| 91 | [os.path.join(CONFIG_DIR, 'tl_colors_evt_std.conf')] + |
|---|
| 92 | [os.path.join(CONFIG_DIR, 'scheduler-schemas.conf')] + |
|---|
| 93 | [os.path.join(CONFIG_DIR, 'scheduler-profiles.conf')] + |
|---|
| 94 | [os.path.join(CONFIG_DIR, 'scheduler.log')] + |
|---|
| 95 | [os.path.join(CONFIG_DIR, 'smtp-schemas.conf')] + |
|---|
| 96 | glob(os.path.join(CONFIG_DIR, '*.xml'))+ |
|---|
| 97 | glob(os.path.join(CONFIG_DIR, '*.txt'))), |
|---|
| 98 | |
|---|
| 99 | # umit.db SQL |
|---|
| 100 | (SQL_DIR, glob(os.path.join(SQL_DIR, '*.sql'))), |
|---|
| 101 | |
|---|
| 102 | (MISC_DIR, glob(os.path.join(MISC_DIR, '*.dmp'))), |
|---|
| 103 | |
|---|
| 104 | # Radialnet |
|---|
| 105 | (os.path.join(PIXMAPS_DIR, 'radialnet', 'application'), |
|---|
| 106 | glob(os.path.join(PIXMAPS_DIR, 'radialnet', 'application', |
|---|
| 107 | '*.png'))), |
|---|
| 108 | (os.path.join(PIXMAPS_DIR, 'radialnet', 'icons'), |
|---|
| 109 | glob(os.path.join(PIXMAPS_DIR, 'radialnet', 'icons','*.png'))), |
|---|
| 110 | |
|---|
| 111 | # Network Inventory |
|---|
| 112 | (os.path.join(PIXMAPS_DIR, 'networkinventory'), |
|---|
| 113 | glob(os.path.join(PIXMAPS_DIR, 'networkinventory', '*.png'))), |
|---|
| 114 | |
|---|
| 115 | # InterfaceEditor |
|---|
| 116 | (os.path.join(PIXMAPS_DIR, 'uie'), |
|---|
| 117 | glob(os.path.join(PIXMAPS_DIR, 'uie', '*.png'))), |
|---|
| 118 | |
|---|
| 119 | (ICONS_DIR, |
|---|
| 120 | glob(os.path.join(ICONS_DIR, '*.ico')) + |
|---|
| 121 | glob(os.path.join(ICONS_DIR, '*.png'))), |
|---|
| 122 | |
|---|
| 123 | (DOCS_DIR, |
|---|
| 124 | glob(os.path.join(DOCS_DIR, '*.html')) + |
|---|
| 125 | glob(os.path.join(DOCS_DIR, 'comparing_results', '*.xml')) + |
|---|
| 126 | glob(os.path.join(DOCS_DIR, 'profile_editor', '*.xml')) + |
|---|
| 127 | glob(os.path.join(DOCS_DIR, 'scanning', '*.xml')) + |
|---|
| 128 | glob(os.path.join(DOCS_DIR, 'searching', '*.xml')) + |
|---|
| 129 | glob(os.path.join(DOCS_DIR, 'wizard', '*.xml')) + |
|---|
| 130 | glob(os.path.join(DOCS_DIR, 'scheduler', '*.xml')) + |
|---|
| 131 | glob(os.path.join(DOCS_DIR, 'smtpsetup', '*.xml')) + |
|---|
| 132 | glob(os.path.join(DOCS_DIR, 'screenshots', '*.png')))] |
|---|
| 133 | |
|---|
| 134 | # Add i18n files to data_files list |
|---|
| 135 | os.path.walk(LOCALE_DIR, mo_find, data_files) |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | ############################################################################## |
|---|
| 139 | # Distutils subclasses |
|---|
| 140 | |
|---|
| 141 | class umit_build(build): |
|---|
| 142 | |
|---|
| 143 | def delete_mo_files(self): |
|---|
| 144 | """ Remove *.mo files """ |
|---|
| 145 | tmp = [] |
|---|
| 146 | os.path.walk(LOCALE_DIR, mo_find, tmp) |
|---|
| 147 | for (path, t) in tmp: |
|---|
| 148 | os.remove(t[0]) |
|---|
| 149 | |
|---|
| 150 | def build_mo_files(self): |
|---|
| 151 | """Build mo files from po and put it into LC_MESSAGES """ |
|---|
| 152 | tmp = [] |
|---|
| 153 | os.path.walk(LOCALE_DIR, po_find, tmp) |
|---|
| 154 | for (path, t) in tmp: |
|---|
| 155 | full_path = os.path.join(path , "LC_MESSAGES", "umit.mo") |
|---|
| 156 | self.mkpath(os.path.dirname(full_path)) |
|---|
| 157 | self.announce("Compiling %s -> %s" % (t[0], full_path)) |
|---|
| 158 | msgfmt.make(t[0], full_path, False) |
|---|
| 159 | # like guess |
|---|
| 160 | os.path.walk(LOCALE_DIR, mo_find, data_files) |
|---|
| 161 | |
|---|
| 162 | def run(self): |
|---|
| 163 | self.delete_mo_files() |
|---|
| 164 | self.build_mo_files() |
|---|
| 165 | build.run(self) |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | class umit_install(install): |
|---|
| 169 | |
|---|
| 170 | def run(self): |
|---|
| 171 | # Add i18n files to data_files list |
|---|
| 172 | os.path.walk(LOCALE_DIR, mo_find, data_files) |
|---|
| 173 | install.run(self) |
|---|
| 174 | |
|---|
| 175 | self.set_perms() |
|---|
| 176 | self.set_modules_path() |
|---|
| 177 | self.fix_paths() |
|---|
| 178 | self.create_uninstaller() |
|---|
| 179 | self.finish_banner() |
|---|
| 180 | |
|---|
| 181 | def create_uninstaller(self): |
|---|
| 182 | uninstaller_filename = os.path.join( |
|---|
| 183 | self.install_scripts, "uninstall_umit") |
|---|
| 184 | uninstaller = [] |
|---|
| 185 | uninstaller.append( |
|---|
| 186 | "#!/usr/bin/env python\n" |
|---|
| 187 | "import os, sys\n" |
|---|
| 188 | "\n" |
|---|
| 189 | "print\n" |
|---|
| 190 | "print '%(line)s Uninstall Umit %(version)s %(line)s'\n" |
|---|
| 191 | "print\n" |
|---|
| 192 | "\n" |
|---|
| 193 | "answer = raw_input('Are you sure that you want to '\n" |
|---|
| 194 | " 'completly uninstall Umit %(version)s? (yes/no) ')\n" |
|---|
| 195 | "\n" |
|---|
| 196 | "if answer.lower() not in ['yes', 'y']:\n" |
|---|
| 197 | " sys.exit(0)\n" |
|---|
| 198 | "\n" |
|---|
| 199 | "print\n" |
|---|
| 200 | "print '%(line)s Uninstalling Umit %(version)s... %(line)s'\n" |
|---|
| 201 | "print\n" % {'version': VERSION, 'line': '-' * 10}) |
|---|
| 202 | |
|---|
| 203 | for output in self.get_outputs(): |
|---|
| 204 | uninstaller.append( |
|---|
| 205 | "print 'Removing %(output)s...'\n" |
|---|
| 206 | "if os.path.exists('%(output)s'):\n" |
|---|
| 207 | " os.remove('%(output)s')\n" % {'output': output}) |
|---|
| 208 | |
|---|
| 209 | uninstaller.append( |
|---|
| 210 | "print 'Removing uninstaller itself...'\n" |
|---|
| 211 | "os.remove('%s')\n" % uninstaller_filename) |
|---|
| 212 | |
|---|
| 213 | uninstaller_file = open(uninstaller_filename, 'w') |
|---|
| 214 | uninstaller_file.writelines(uninstaller) |
|---|
| 215 | uninstaller_file.close() |
|---|
| 216 | |
|---|
| 217 | # Set exec bit for uninstaller |
|---|
| 218 | mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0555) & 07777 |
|---|
| 219 | os.chmod(uninstaller_filename, mode) |
|---|
| 220 | |
|---|
| 221 | def set_modules_path(self): |
|---|
| 222 | umit = os.path.join(self.install_scripts, "umit") |
|---|
| 223 | modules = self.install_lib |
|---|
| 224 | |
|---|
| 225 | re_sys = re.compile("^import sys$") |
|---|
| 226 | |
|---|
| 227 | ufile = open(umit, "r") |
|---|
| 228 | ucontent = ufile.readlines() |
|---|
| 229 | ufile.close() |
|---|
| 230 | |
|---|
| 231 | uline = None |
|---|
| 232 | for line in xrange(len(ucontent)): |
|---|
| 233 | if re_sys.match(ucontent[line]): |
|---|
| 234 | uline = line + 1 |
|---|
| 235 | break |
|---|
| 236 | |
|---|
| 237 | ucontent.insert(uline, "sys.path.insert(0,'%s')\n" % modules ) |
|---|
| 238 | |
|---|
| 239 | ufile = open(umit, "w") |
|---|
| 240 | ufile.writelines(ucontent) |
|---|
| 241 | ufile.close() |
|---|
| 242 | |
|---|
| 243 | def set_perms(self): |
|---|
| 244 | re_bin = re.compile("(bin)") |
|---|
| 245 | for output in self.get_outputs(): |
|---|
| 246 | if re_bin.findall(output): |
|---|
| 247 | continue |
|---|
| 248 | |
|---|
| 249 | if os.path.isdir(output): |
|---|
| 250 | os.chmod(output, S_IRWXU | \ |
|---|
| 251 | S_IRGRP | \ |
|---|
| 252 | S_IXGRP | \ |
|---|
| 253 | S_IROTH | \ |
|---|
| 254 | S_IXOTH) |
|---|
| 255 | else: |
|---|
| 256 | os.chmod(output, S_IRWXU | \ |
|---|
| 257 | S_IRGRP | \ |
|---|
| 258 | S_IROTH) |
|---|
| 259 | |
|---|
| 260 | def fix_paths(self): |
|---|
| 261 | interesting_paths = {"CONFIG_DIR": CONFIG_DIR, |
|---|
| 262 | "DOCS_DIR": DOCS_DIR, |
|---|
| 263 | "LOCALE_DIR": LOCALE_DIR, |
|---|
| 264 | "MISC_DIR": MISC_DIR, |
|---|
| 265 | "PIXMAPS_DIR": PIXMAPS_DIR, |
|---|
| 266 | "ICONS_DIR": ICONS_DIR} |
|---|
| 267 | |
|---|
| 268 | pcontent = "" |
|---|
| 269 | paths_file = os.path.join("umit", "core", "BasePaths.py") |
|---|
| 270 | installed_files = self.get_outputs() |
|---|
| 271 | |
|---|
| 272 | # Finding where the Paths.py file was installed. |
|---|
| 273 | for f in installed_files: |
|---|
| 274 | if re.findall("(%s)" % re.escape(paths_file), f): |
|---|
| 275 | paths_file = f |
|---|
| 276 | pf = open(paths_file) |
|---|
| 277 | pcontent = pf.read() |
|---|
| 278 | pf.close() |
|---|
| 279 | break |
|---|
| 280 | |
|---|
| 281 | for path in interesting_paths: |
|---|
| 282 | for f in installed_files: |
|---|
| 283 | result = re.findall("(.*%s)" %\ |
|---|
| 284 | re.escape(interesting_paths[path]), |
|---|
| 285 | f) |
|---|
| 286 | if len(result) == 1: |
|---|
| 287 | result = result[0] |
|---|
| 288 | pcontent = re.sub("%s\s+=\s+.+" % path, |
|---|
| 289 | "%s = \"%s\"" % (path, result), |
|---|
| 290 | pcontent) |
|---|
| 291 | break |
|---|
| 292 | |
|---|
| 293 | pf = open(paths_file, "w") |
|---|
| 294 | pf.write(pcontent) |
|---|
| 295 | pf.close() |
|---|
| 296 | |
|---|
| 297 | def finish_banner(self): |
|---|
| 298 | print |
|---|
| 299 | print "%s Thanks for using Umit %s %s" % \ |
|---|
| 300 | ("#"*10, VERSION, "#"*10) |
|---|
| 301 | print |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | class umit_sdist(sdist): |
|---|
| 305 | |
|---|
| 306 | def read_manifest_no_mo(self): |
|---|
| 307 | """Read Manifest without mo file.""" |
|---|
| 308 | for line in open(self.manifest): |
|---|
| 309 | if not line: |
|---|
| 310 | break |
|---|
| 311 | |
|---|
| 312 | if line[-1] == '\n': |
|---|
| 313 | line = line[:-1] |
|---|
| 314 | if line.find('umit.mo') != -1: |
|---|
| 315 | self.filelist.files.remove(line) |
|---|
| 316 | |
|---|
| 317 | def run(self): |
|---|
| 318 | from distutils.filelist import FileList |
|---|
| 319 | self.keep_temp = 1 |
|---|
| 320 | #Rewrite: sdist.run(self) |
|---|
| 321 | self.manifest = "MANIFEST" |
|---|
| 322 | self.filelist = FileList() |
|---|
| 323 | self.check_metadata() |
|---|
| 324 | self.get_file_list() |
|---|
| 325 | ## Exclude mo files: |
|---|
| 326 | self.read_manifest_no_mo() |
|---|
| 327 | if self.manifest_only: |
|---|
| 328 | return |
|---|
| 329 | self.make_distribution() |
|---|
| 330 | |
|---|
| 331 | self.finish_banner() |
|---|
| 332 | |
|---|
| 333 | def finish_banner(self): |
|---|
| 334 | print |
|---|
| 335 | print "%s The packages for Umit %s are in ./dist %s" % \ |
|---|
| 336 | ("#" * 10, VERSION, "#" * 10) |
|---|
| 337 | print |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | ##################### Umit banner ######################## |
|---|
| 341 | print |
|---|
| 342 | print "%s Umit for Linux %s %s" % ("#" * 10, VERSION, "#" * 10) |
|---|
| 343 | print |
|---|
| 344 | ########################################################## |
|---|
| 345 | |
|---|
| 346 | |
|---|
| 347 | cmdclasses = { |
|---|
| 348 | "install": umit_install, |
|---|
| 349 | "build": umit_build, |
|---|
| 350 | "sdist": umit_sdist} |
|---|
| 351 | |
|---|
| 352 | if py2exe_cmdclass: |
|---|
| 353 | cmdclasses.update(py2exe_cmdclass) |
|---|
| 354 | |
|---|
| 355 | options = dict( |
|---|
| 356 | name = 'umit', |
|---|
| 357 | license = 'GNU GPL (version 2 or later)', |
|---|
| 358 | url = 'http://www.umitproject.org', |
|---|
| 359 | download_url = 'http://www.umitproject.org', |
|---|
| 360 | author = 'Adriano Monteiro & Cleber Rodrigues', |
|---|
| 361 | author_email = 'adriano@umitproject.org, cleber@globalred.com.br', |
|---|
| 362 | maintainer = 'Adriano Monteiro', |
|---|
| 363 | maintainer_email = 'adriano@umitproject.org', |
|---|
| 364 | description = ("Umit is a network scanning frontend, developed in " |
|---|
| 365 | "Python and GTK and was started with the sponsoring of " |
|---|
| 366 | "Google's Summer of Code."), |
|---|
| 367 | long_description = ("The project goal is to develop a network " |
|---|
| 368 | "scanning frontend that is really useful for advanced users and " |
|---|
| 369 | "easy to be used by newbies. With Umit, a network admin can " |
|---|
| 370 | "create scan profiles for faster and easier network scanning " |
|---|
| 371 | "or even compare scan results to easily see any changes. " |
|---|
| 372 | "A regular user will also be able to construct powerful scans " |
|---|
| 373 | "with Umit command creator wizards."), |
|---|
| 374 | version = VERSION, |
|---|
| 375 | scripts = [ |
|---|
| 376 | os.path.join(BIN_DIRNAME, 'umit'), |
|---|
| 377 | os.path.join(BIN_DIRNAME, 'umit_scheduler.py')], |
|---|
| 378 | packages = [ |
|---|
| 379 | 'umit', 'umit.core', 'umit.core.radialnet', 'umit.db', |
|---|
| 380 | 'umit.gui', 'umit.gui.radialnet', 'umit.interfaceeditor', |
|---|
| 381 | 'umit.interfaceeditor.selectborder', 'umit.inventory', |
|---|
| 382 | 'umit.plugin', 'higwidgets'], |
|---|
| 383 | data_files = data_files, |
|---|
| 384 | cmdclass = cmdclasses, |
|---|
| 385 | classifiers = [ |
|---|
| 386 | 'Development Status :: 4 - Beta', |
|---|
| 387 | 'Environment :: X11 Applications :: GTK', |
|---|
| 388 | 'Intended Audience :: End Users/Desktop', |
|---|
| 389 | 'Intended Audience :: System Administrators', |
|---|
| 390 | 'License :: OSI Approved :: GNU General Public License (GPL)', |
|---|
| 391 | 'Programming Language :: Python :: 2', |
|---|
| 392 | 'Programming Language :: Python :: 2.5' |
|---|
| 393 | 'Programming Language :: Python :: 2.6', |
|---|
| 394 | 'Topic :: System :: Networking', |
|---|
| 395 | ] |
|---|
| 396 | ) |
|---|
| 397 | |
|---|
| 398 | if py2exe_options: |
|---|
| 399 | options.update(py2exe_options) |
|---|
| 400 | |
|---|
| 401 | if py2app_options: |
|---|
| 402 | options.update(py2app_options) |
|---|
| 403 | |
|---|
| 404 | setup(**options) |
|---|