| 1 | #!/usr/bin/env python |
|---|
| 2 | # Copyright (C) 2005 Insecure.Com LLC. |
|---|
| 3 | # |
|---|
| 4 | # Authors: Adriano Monteiro Marques <py.adriano@gmail.com> |
|---|
| 5 | # |
|---|
| 6 | # This program 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 | # This program 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 this program; if not, write to the Free Software |
|---|
| 18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | |
|---|
| 20 | import os |
|---|
| 21 | import re |
|---|
| 22 | |
|---|
| 23 | from distutils.core import setup |
|---|
| 24 | from distutils.command.install import install |
|---|
| 25 | from distutils.command.sdist import sdist |
|---|
| 26 | |
|---|
| 27 | from glob import glob |
|---|
| 28 | from stat import ST_MODE |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | VERSION = "0.9.4" |
|---|
| 32 | REVISION = "1451" |
|---|
| 33 | |
|---|
| 34 | # Directories for POSIX operating systems |
|---|
| 35 | # These are created after a "install" or "py2exe" command |
|---|
| 36 | # These directories are relative to the installation or dist directory |
|---|
| 37 | # Ex: python setup.py install --prefix=/tmp/umit |
|---|
| 38 | # Will create the directory /tmp/umit with the following directories |
|---|
| 39 | pixmaps_dir = os.path.join('share', 'pixmaps') |
|---|
| 40 | icons_dir = os.path.join('share', 'icons') |
|---|
| 41 | locale_dir = os.path.join('share', 'umit', 'locale') |
|---|
| 42 | config_dir = os.path.join('share', 'umit', 'config') |
|---|
| 43 | docs_dir = os.path.join('share', 'umit', 'docs') |
|---|
| 44 | misc_dir = os.path.join('share', 'umit', 'misc') |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | def mo_find(result, dirname, fnames): |
|---|
| 48 | files = [] |
|---|
| 49 | for f in fnames: |
|---|
| 50 | p = os.path.join(dirname, f) |
|---|
| 51 | if os.path.isfile(p) and f.endswith(".mo"): |
|---|
| 52 | files.append(p) |
|---|
| 53 | |
|---|
| 54 | if files: |
|---|
| 55 | result.append((dirname, files)) |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | ################################################################################ |
|---|
| 59 | # Installation variables |
|---|
| 60 | |
|---|
| 61 | svg = glob(os.path.join('share', 'pixmaps', '*.svg')) |
|---|
| 62 | data_files = [ (pixmaps_dir, svg + glob(os.path.join(pixmaps_dir, '*.png')) + |
|---|
| 63 | glob(os.path.join(pixmaps_dir, 'umit.o*'))), |
|---|
| 64 | |
|---|
| 65 | (config_dir, [os.path.join(config_dir, 'umit.conf')] + |
|---|
| 66 | [os.path.join(config_dir, 'scan_profile.usp')] + |
|---|
| 67 | [os.path.join(config_dir, 'umit_version')] + |
|---|
| 68 | [os.path.join(config_dir, 'umit.db')] + |
|---|
| 69 | glob(os.path.join(config_dir, '*.xml'))+ |
|---|
| 70 | glob(os.path.join(config_dir, '*.txt'))), |
|---|
| 71 | |
|---|
| 72 | (misc_dir, glob(os.path.join(misc_dir, '*.dmp'))), |
|---|
| 73 | |
|---|
| 74 | (icons_dir, glob(os.path.join('share', 'icons', '*.ico'))+ |
|---|
| 75 | glob(os.path.join('share', 'icons', '*.png'))), |
|---|
| 76 | |
|---|
| 77 | (docs_dir, glob(os.path.join(docs_dir, '*.html'))+ |
|---|
| 78 | glob(os.path.join(docs_dir, |
|---|
| 79 | 'comparing_results', '*.xml'))+ |
|---|
| 80 | glob(os.path.join(docs_dir, |
|---|
| 81 | 'profile_editor', '*.xml'))+ |
|---|
| 82 | glob(os.path.join(docs_dir, |
|---|
| 83 | 'scanning', '*.xml'))+ |
|---|
| 84 | glob(os.path.join(docs_dir, |
|---|
| 85 | 'searching', '*.xml'))+ |
|---|
| 86 | glob(os.path.join(docs_dir, |
|---|
| 87 | 'wizard', '*.xml'))+ |
|---|
| 88 | glob(os.path.join(docs_dir, |
|---|
| 89 | 'screenshots', '*.png')))] |
|---|
| 90 | |
|---|
| 91 | # Add i18n files to data_files list |
|---|
| 92 | os.path.walk(locale_dir, mo_find, data_files) |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | ################################################################################ |
|---|
| 97 | # Distutils subclasses |
|---|
| 98 | |
|---|
| 99 | class umit_install(install): |
|---|
| 100 | def run(self): |
|---|
| 101 | old_umask = os.umask("0022") |
|---|
| 102 | print ">>> Old system umask:", old_umask |
|---|
| 103 | |
|---|
| 104 | install.run(self) |
|---|
| 105 | |
|---|
| 106 | self.fix_paths() |
|---|
| 107 | self.create_uninstaller() |
|---|
| 108 | self.finish_banner() |
|---|
| 109 | |
|---|
| 110 | def create_uninstaller(self): |
|---|
| 111 | uninstaller_filename = os.path.join(self.install_scripts, "uninstall_umit") |
|---|
| 112 | uninstaller = """#!/usr/bin/env python |
|---|
| 113 | import os, sys |
|---|
| 114 | |
|---|
| 115 | print |
|---|
| 116 | print '%(line)s Uninstall Umit %(version)s-%(revision)s %(line)s' |
|---|
| 117 | print |
|---|
| 118 | |
|---|
| 119 | answer = raw_input('Are you sure that you want to completly uninstall Umit %(version)s? \ |
|---|
| 120 | (yes/no) ') |
|---|
| 121 | |
|---|
| 122 | if answer != 'yes' and answer != 'y': |
|---|
| 123 | sys.exit(0) |
|---|
| 124 | |
|---|
| 125 | print |
|---|
| 126 | print '%(line)s Uninstalling Umit %(version)s... %(line)s' |
|---|
| 127 | print |
|---|
| 128 | """ % {'version':VERSION, 'revision':REVISION, 'line':'-'*10} |
|---|
| 129 | |
|---|
| 130 | for output in self.get_outputs(): |
|---|
| 131 | uninstaller += "print 'Removing %s...'\n" % output |
|---|
| 132 | uninstaller += "os.remove('%s')\n" % output |
|---|
| 133 | |
|---|
| 134 | uninstaller += "print 'Removing uninstaller itself...'\n" |
|---|
| 135 | uninstaller += "os.remove('%s')\n" % uninstaller_filename |
|---|
| 136 | |
|---|
| 137 | uninstaller_file = open(uninstaller_filename, 'w') |
|---|
| 138 | uninstaller_file.write(uninstaller) |
|---|
| 139 | uninstaller_file.close() |
|---|
| 140 | |
|---|
| 141 | # Set exec bit for uninstaller |
|---|
| 142 | mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0555) & 07777 |
|---|
| 143 | os.chmod(uninstaller_filename, mode) |
|---|
| 144 | |
|---|
| 145 | def fix_paths(self): |
|---|
| 146 | su = os.path.join("share", "umit") |
|---|
| 147 | interesting_paths = {"CONFIG_DIR":os.path.join(su, "config"), |
|---|
| 148 | "DOCS_DIR":os.path.join(su, "docs"), |
|---|
| 149 | "LOCALE_DIR":os.path.join(su, "locale"), |
|---|
| 150 | "MISC_DIR":os.path.join(su, "misc"), |
|---|
| 151 | "PIXMAPS_DIR":os.path.join("share", "pixmaps"), |
|---|
| 152 | "ICONS_DIR":os.path.join("share", "icons"), |
|---|
| 153 | "UMIT_ICON":"umit_48.ico"} |
|---|
| 154 | |
|---|
| 155 | pcontent = "" |
|---|
| 156 | paths_file = os.path.join("umitCore", "Paths.py") |
|---|
| 157 | installed_files = self.get_outputs() |
|---|
| 158 | for f in installed_files: |
|---|
| 159 | #print ">>> PATHS FILE:", re.findall("(%s)" % \ |
|---|
| 160 | # re.escape(paths_file), f) |
|---|
| 161 | if re.findall("(%s)" % re.escape(paths_file), f): |
|---|
| 162 | #print ">>>>> FOUND PATHS FILE! <<<<<" |
|---|
| 163 | paths_file = f |
|---|
| 164 | pf = open(paths_file) |
|---|
| 165 | pcontent = pf.read() |
|---|
| 166 | pf.close() |
|---|
| 167 | break |
|---|
| 168 | |
|---|
| 169 | for path in interesting_paths: |
|---|
| 170 | for f in installed_files: |
|---|
| 171 | result = re.findall("(.*%s)" %\ |
|---|
| 172 | re.escape(interesting_paths[path]), |
|---|
| 173 | f) |
|---|
| 174 | #print ">>> PATH:", path, result |
|---|
| 175 | if len(result) == 1: |
|---|
| 176 | result = result[0] |
|---|
| 177 | #print ">>>>> FOUND! <<<<<" |
|---|
| 178 | pcontent = re.sub("%s\s+=\s+.+" % path, |
|---|
| 179 | "%s = \"%s\"" % (path, result), |
|---|
| 180 | pcontent) |
|---|
| 181 | break |
|---|
| 182 | |
|---|
| 183 | pf = open(paths_file, "w") |
|---|
| 184 | pf.write(pcontent) |
|---|
| 185 | pf.close() |
|---|
| 186 | |
|---|
| 187 | def finish_banner(self): |
|---|
| 188 | print |
|---|
| 189 | print "%s Thanks for using Umit %s-%s %s" % \ |
|---|
| 190 | ("#"*10, VERSION, REVISION, "#"*10) |
|---|
| 191 | print |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | class umit_sdist(sdist): |
|---|
| 195 | def run(self): |
|---|
| 196 | sdist.run(self) |
|---|
| 197 | self.finish_banner() |
|---|
| 198 | |
|---|
| 199 | def finish_banner(self): |
|---|
| 200 | print |
|---|
| 201 | print "%s The packages for Umit %s-%s are in ./dist %s" % \ |
|---|
| 202 | ("#" * 10, VERSION, REVISION, "#" * 10) |
|---|
| 203 | print |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | ##################### Umit banner ######################## |
|---|
| 207 | print |
|---|
| 208 | print "%s Umit for Linux %s-%s %s" % ("#" * 10, VERSION, REVISION, "#" * 10) |
|---|
| 209 | print |
|---|
| 210 | ########################################################## |
|---|
| 211 | |
|---|
| 212 | setup(name = 'umit', |
|---|
| 213 | license = 'GNU GPL (version 2 or later)', |
|---|
| 214 | url = 'http://umit.sourceforge.net', |
|---|
| 215 | download_url = 'http://sourceforge.net/project/showfiles.php?group_id=142490', |
|---|
| 216 | author = 'Adriano Monteiro & Cleber Rodrigues', |
|---|
| 217 | author_email = 'py.adriano@gmail.com, cleber@globalred.com.br', |
|---|
| 218 | maintainer = 'Adriano Monteiro', |
|---|
| 219 | maintainer_email = 'py.adriano@gmail.com', |
|---|
| 220 | description = """UMIT is a nmap frontend, developed in Python and GTK and was \ |
|---|
| 221 | started with the sponsoring of Google's Summer of Code.""", |
|---|
| 222 | long_description = """The project goal is to develop a nmap frontend that \ |
|---|
| 223 | is really useful for advanced users and easy to be used by newbies. With UMIT, a network admin \ |
|---|
| 224 | could create scan profiles for faster and easier network scanning or even compare \ |
|---|
| 225 | scan results to easily see any changes. A regular user will also be able to construct \ |
|---|
| 226 | powerful scans with UMIT command creator wizards.""", |
|---|
| 227 | version = VERSION, |
|---|
| 228 | scripts = ['umit'], |
|---|
| 229 | packages = ['', 'umitCore', 'umitGUI', 'higwidgets'], |
|---|
| 230 | data_files = data_files, |
|---|
| 231 | cmdclass = {"install":umit_install, |
|---|
| 232 | "sdist":umit_sdist}) |
|---|