root/trunk/install_scripts/unix/setup.py @ 2791

Revision 2791, 9.7 kB (checked in by xvg, 6 years ago)

Merge r5894:5918 and r6029 (omitting some that were previously merged) from
Nmap umit branch. Overhaul the way versioning is handled. Get rid of REVISION.

Remove all usage of REVISION. This was too hard to maintain for too little
benefit.

Remove some more occurrences of REVISION.

Put VERSION in its own file Version.py.

Remove most of the custom sdist command. The special logic that prohibited
hardlinking is not necessary now. One new problem is that "build" depends on
install_scripts/utils/version_update.py, which is not part of an sdist. I'll
work on that later.

In install_scripts/windows/copy_and_compile.bat, copy setup.py to the root of
the umit source before running it. This is necessary so VERSION can be
extracted from umitCore/Version.py.

Handle all Umit version updating in a specialized script. Now, instead of Nmap
updating one of Umit's version numbers and having Umit adjust all the others,
Nmap calls a script of Umit's that updates all its version numbers at once.
This also makes Umit's versioning scheme more independent of Nmap's.

Import VERSION from umitCore.Version, not umitCore.Paths.

  • Property svn:executable set to *
Line 
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
20import sys
21import os
22import os.path
23import re
24
25from distutils.core import setup
26from distutils.command.install import install
27from distutils.command.sdist import sdist
28from distutils import log, dir_util
29
30from glob import glob
31from stat import *
32
33from umitCore.Version import VERSION
34
35VERSION_FILE = os.path.join("share", "umit", "config", "umit_version")
36
37# Directories for POSIX operating systems
38# These are created after a "install" or "py2exe" command
39# These directories are relative to the installation or dist directory
40# Ex: python setup.py install --prefix=/tmp/umit
41# Will create the directory /tmp/umit with the following directories
42pixmaps_dir = os.path.join('share', 'pixmaps')
43icons_dir = os.path.join('share', 'icons')
44locale_dir = os.path.join('share', 'umit', 'locale')
45config_dir = os.path.join('share', 'umit', 'config')
46docs_dir = os.path.join('share', 'umit', 'docs')
47misc_dir = os.path.join('share', 'umit', 'misc')
48
49
50def mo_find(result, dirname, fnames):
51    files = []
52    for f in fnames:
53        p = os.path.join(dirname, f)
54        if os.path.isfile(p) and f.endswith(".mo"):
55            files.append(p)
56       
57    if files:
58        result.append((dirname, files))
59
60
61################################################################################
62# Installation variables
63
64svg = glob(os.path.join('share', 'pixmaps', '*.svg'))
65data_files = [ (pixmaps_dir, glob(os.path.join(pixmaps_dir, '*.svg')) +
66                             glob(os.path.join(pixmaps_dir, '*.png')) +
67                             glob(os.path.join(pixmaps_dir, 'umit.o*'))),
68
69               (config_dir, [os.path.join(config_dir, 'umit.conf')] +
70                            [os.path.join(config_dir, 'scan_profile.usp')] +
71                            [os.path.join(config_dir, 'umit_version')] +
72                            glob(os.path.join(config_dir, '*.xml'))+
73                            glob(os.path.join(config_dir, '*.txt'))),
74
75               (misc_dir, glob(os.path.join(misc_dir, '*.dmp'))), 
76
77               (icons_dir, glob(os.path.join('share', 'icons', '*.ico'))+
78                           glob(os.path.join('share', 'icons', '*.png'))),
79
80               (docs_dir, glob(os.path.join(docs_dir, '*.html'))+
81                          glob(os.path.join(docs_dir,
82                                            'comparing_results', '*.xml'))+
83                          glob(os.path.join(docs_dir,
84                                            'profile_editor', '*.xml'))+
85                          glob(os.path.join(docs_dir,
86                                            'scanning', '*.xml'))+
87                          glob(os.path.join(docs_dir,
88                                            'searching', '*.xml'))+
89                          glob(os.path.join(docs_dir,
90                                            'wizard', '*.xml'))+
91                          glob(os.path.join(docs_dir,
92                                            'screenshots', '*.png')))]
93
94# Add i18n files to data_files list
95os.path.walk(locale_dir, mo_find, data_files)
96
97
98
99################################################################################
100# Distutils subclasses
101
102class umit_install(install):
103    def run(self):
104        install.run(self)
105
106        self.set_perms()
107        self.set_modules_path()
108        self.fix_paths()
109        self.create_uninstaller()
110        self.finish_banner()
111
112    def create_uninstaller(self):
113        uninstaller_filename = os.path.join(self.install_scripts, "uninstall_umit")
114        uninstaller = """#!/usr/bin/env python
115import os, os.path, sys
116
117print
118print '%(line)s Uninstall Umit %(version)s %(line)s'
119print
120
121answer = raw_input('Are you sure that you want to completly uninstall Umit %(version)s? \
122(yes/no) ')
123
124if answer != 'yes' and answer != 'y':
125    sys.exit(0)
126
127print
128print '%(line)s Uninstalling Umit %(version)s... %(line)s'
129print
130""" % {'version':VERSION, 'line':'-'*10}
131
132        for output in self.get_outputs():
133            uninstaller += "print 'Removing %s...'\n" % output
134            uninstaller += "if os.path.exists('%s'): os.remove('%s')\n" % (output,
135                                                                         output)
136
137        uninstaller += "print 'Removing uninstaller itself...'\n"
138        uninstaller += "os.remove('%s')\n" % uninstaller_filename
139
140        uninstaller_file = open(uninstaller_filename, 'w')
141        uninstaller_file.write(uninstaller)
142        uninstaller_file.close()
143
144        # Set exec bit for uninstaller
145        mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0555) & 07777
146        os.chmod(uninstaller_filename, mode)
147
148    def set_modules_path(self):
149        umit = os.path.join(self.install_scripts, "umit")
150        modules = self.install_lib
151
152        re_sys = re.compile("^import sys$")
153
154        ufile = open(umit, "r")
155        ucontent = ufile.readlines()
156        ufile.close()
157
158        uline = None
159        for line in xrange(len(ucontent)):
160            if re_sys.match(ucontent[line]):
161                uline = line + 1
162                break
163
164        ucontent.insert(uline, "sys.path.append('%s')\n" % modules)
165
166        ufile = open(umit, "w")
167        ufile.writelines(ucontent)
168        ufile.close()
169
170    def set_perms(self):
171        re_bin = re.compile("(bin)")
172        for output in self.get_outputs():
173            if re_bin.findall(output):
174                continue
175
176            if os.path.isdir(output):
177                os.chmod(output, S_IRWXU | \
178                                 S_IRGRP | \
179                                 S_IXGRP | \
180                                 S_IROTH | \
181                                 S_IXOTH)
182            else:
183                os.chmod(output, S_IRWXU | \
184                                 S_IRGRP | \
185                                 S_IROTH)
186
187
188    def fix_paths(self):
189        su = os.path.join("share", "umit")
190        interesting_paths = {"CONFIG_DIR":os.path.join(su, "config"),
191                             "DOCS_DIR":os.path.join(su, "docs"),
192                             "LOCALE_DIR":os.path.join(su, "locale"),
193                             "MISC_DIR":os.path.join(su, "misc"),
194                             "PIXMAPS_DIR":os.path.join("share", "pixmaps"),
195                             "ICONS_DIR":os.path.join("share", "icons"),
196                             "UMIT_ICON":"umit_48.ico"}
197
198        pcontent = ""
199        paths_file = os.path.join("umitCore", "Paths.py")
200        installed_files = self.get_outputs()
201        for f in installed_files:
202            if re.findall("(%s)" % re.escape(paths_file), f):
203                paths_file = f
204                pf = open(paths_file)
205                pcontent = pf.read()
206                pf.close()
207                break
208
209        for path in interesting_paths:
210            for f in installed_files:
211                result = re.findall("(.*%s)" %\
212                                    re.escape(interesting_paths[path]),
213                                    f)
214                if len(result) == 1:
215                    result = result[0]
216                    pcontent = re.sub("%s\s+=\s+.+" % path,
217                                      "%s = \"%s\"" % (path, result),
218                                      pcontent)
219                    break
220
221        pf = open(paths_file, "w")
222        pf.write(pcontent)
223        pf.close()
224
225    def finish_banner(self):
226        print 
227        print "%s Thanks for using Umit %s %s" % \
228              ("#"*10, VERSION, "#"*10)
229        print
230
231
232class umit_sdist(sdist):
233    def run(self):
234        self.keep_temp = 1
235        sdist.run(self)
236        self.finish_banner()
237
238    def finish_banner(self):
239        print 
240        print "%s The packages for Umit %s are in ./dist %s" % \
241              ("#" * 10, VERSION, "#" * 10)
242        print
243
244##################### Umit banner ########################
245print
246print "%s Umit for Linux %s %s" % ("#" * 10, VERSION, "#" * 10)
247print
248##########################################################
249
250setup(name = 'umit',
251      license = 'GNU GPL (version 2 or later)',
252      url = 'http://umit.sourceforge.net',
253      download_url = 'http://sourceforge.net/project/showfiles.php?group_id=142490',
254      author = 'Adriano Monteiro & Cleber Rodrigues',
255      author_email = 'py.adriano@gmail.com, cleber@globalred.com.br',
256      maintainer = 'Adriano Monteiro',
257      maintainer_email = 'py.adriano@gmail.com',
258      description = """UMIT is a nmap frontend, developed in Python and GTK and was \
259started with the sponsoring of Google's Summer of Code.""",
260      long_description = """The project goal is to develop a nmap frontend that \
261is really useful for advanced users and easy to be used by newbies. With UMIT, a network admin \
262could create scan profiles for faster and easier network scanning or even compare \
263scan results to easily see any changes. A regular user will also be able to construct \
264powerful scans with UMIT command creator wizards.""",
265      version = VERSION,
266      scripts = ['umit'],
267      packages = ['', 'umitCore', 'umitGUI', 'higwidgets'],
268      data_files = data_files,
269      cmdclass = {"install":umit_install,
270                  "sdist":umit_sdist})
Note: See TracBrowser for help on using the browser.