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

Revision 1452, 8.7 kB (checked in by boltrix, 6 years ago)

Resolved the conflict generated by the update version script

  • 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 os
21import re
22
23from distutils.core import setup
24from distutils.command.install import install
25from distutils.command.sdist import sdist
26
27from glob import glob
28from stat import ST_MODE
29
30
31VERSION = "0.9.4"
32REVISION = "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
39pixmaps_dir = os.path.join('share', 'pixmaps')
40icons_dir = os.path.join('share', 'icons')
41locale_dir = os.path.join('share', 'umit', 'locale')
42config_dir = os.path.join('share', 'umit', 'config')
43docs_dir = os.path.join('share', 'umit', 'docs')
44misc_dir = os.path.join('share', 'umit', 'misc')
45
46
47def 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
61svg = glob(os.path.join('share', 'pixmaps', '*.svg'))
62data_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
92os.path.walk(locale_dir, mo_find, data_files)
93
94
95
96################################################################################
97# Distutils subclasses
98
99class 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
113import os, sys
114
115print
116print '%(line)s Uninstall Umit %(version)s-%(revision)s %(line)s'
117print
118
119answer = raw_input('Are you sure that you want to completly uninstall Umit %(version)s? \
120(yes/no) ')
121
122if answer != 'yes' and answer != 'y':
123    sys.exit(0)
124
125print
126print '%(line)s Uninstalling Umit %(version)s... %(line)s'
127print
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
194class 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 ########################
207print
208print "%s Umit for Linux %s-%s %s" % ("#" * 10, VERSION, REVISION, "#" * 10)
209print
210##########################################################
211
212setup(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 \
221started with the sponsoring of Google's Summer of Code.""",
222      long_description = """The project goal is to develop a nmap frontend that \
223is really useful for advanced users and easy to be used by newbies. With UMIT, a network admin \
224could create scan profiles for faster and easier network scanning or even compare \
225scan results to easily see any changes. A regular user will also be able to construct \
226powerful 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})
Note: See TracBrowser for help on using the browser.