3 # asn2deb - quick hack by W. Borgert <debacle@debian.org> to create
4 # Debian GNU/Linux packages from ASN.1 files for Wireshark.
5 # Copyright 2004, W. Borgert
7 # ASN.1 module for Wireshark, use of snacc type table:
8 # Copyright 2003, Matthijs Melchior <matthijs.melchior@xs4all.nl>
10 # Wireshark - Network traffic analyzer
11 # By Gerald Combs <gerald@wireshark.com>
12 # Copyright 1998 Gerald Combs
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 import getopt
, os
, string
, sys
, time
30 scriptinfo
= """asn2deb version 2004-02-17
31 Copyright 2004, W. Borgert
32 Free software, released under the terms of the GPL."""
34 options
= {'asn': None,
36 'email': "invalid@invalid.invalid",
43 """Generate Makefile.in and configure script."""
44 os
.system("aclocal-1.7")
46 os
.system("automake-1.7 --add-missing --copy --foreign")
48 def create_file(filename
, content
, mode
= None):
49 """Create a file with given content."""
51 if options
['preserve'] and os
.path
.isfile(filename
):
53 f
= open(filename
, 'w')
57 os
.chmod(filename
, mode
)
59 def create_files(version
, deb
, email
, asn
, name
, iso
, rfc
):
60 """Create all files for the .deb build process."""
61 base
= asn
.lower()[:-5]
62 create_file("Makefile.am", """#
65 asn1ttdir = $(datadir)/wireshark/asn1
68 %s.tt: """ % ((base
,) * 3) + asn
+ """
69 snacc -u /usr/include/snacc/asn1/asn-useful.asn1 -T $@ $<
72 create_file("configure.ac", """AC_INIT(%s, 1.0)
76 SNACC=\"`type -p snacc`\"
78 dnl WIRESHARK_VERSION=\"%s\"
79 dnl plugindir=\"$prefix/share/wireshark/asn.1\"
80 dnl AC_SUBST(plugindir)
82 """ % (base
, version
))
84 if not os
.path
.isdir("debian"):
87 create_file("debian/rules", """#!/usr/bin/make -f
89 include /usr/share/cdbs/1/rules/debhelper.mk
90 include /usr/share/cdbs/1/class/autotools.mk
92 PREFIX=`pwd`/debian/wireshark-asn1-%s
94 binary-post-install/wireshark-asn1-%s::
95 rm -f $(PREFIX)/usr/lib/wireshark/plugins/%s/*.a
96 """ % (base
, base
, version
), 0755)
98 create_file("debian/control", """Source: wireshark-asn1-%s
102 Standards-Version: 3.6.1.0
103 Build-Depends: snacc, autotools-dev, debhelper, cdbs
105 Package: wireshark-asn1-%s
107 Depends: wireshark (= %s)
108 Description: ASN.1/BER dissector for %s
109 This package provides a type table for decoding BER (Basic Encoding
110 Rules) data over TCP or UDP, described by an ASN.1 (Abstract Syntax
111 Notation 1) file '%s.asn1'.
112 """ % (base
, name
, email
, base
, deb
, base
, base
))
114 create_file("debian/changelog",
115 """wireshark-asn1-%s (0.0.1-1) unstable; urgency=low
117 * Automatically created package.
120 """ % (base
, name
, email
, rfc
+ "\n (" + iso
+ ")"))
122 create_file("debian/copyright",
123 """This package has been created automatically be asn2deb on
124 %s for Debian GNU/Linux.
126 Wireshark: http://www.wireshark.com/
130 GPL, as evidenced by existence of GPL license file \"COPYING\".
131 (the GNU GPL may be viewed on Debian systems in
132 /usr/share/common-licenses/GPL)
135 def get_wrs_version():
136 """Detect version of wireshark-dev package."""
138 "dpkg-query -W --showformat='${Version}' wireshark-dev").read()
139 debv
= string
.find(deb
, "-")
140 if debv
== -1: debv
= len(deb
)
141 version
= deb
[string
.find(deb
, ":")+1:debv
]
145 """Detect current time and return ISO and RFC time string."""
146 currenttime
= time
.gmtime()
147 return time
.strftime("%Y-%m-%d %H:%M:%S +0000", currenttime
), \
148 time
.strftime("%a, %d %b %Y %H:%M:%S +0000", currenttime
)
152 process_opts(sys
.argv
)
153 iso
, rfc
= get_time()
154 version
, deb
= get_wrs_version()
155 create_files(version
, deb
,
156 options
['email'], options
['asn'], options
['name'],
159 os
.system("dpkg-buildpackage " + options
['dbopts'])
161 def process_opts(argv
):
162 """Process command line options."""
165 opts
, args
= getopt
.getopt(argv
[1:], "a:d:e:hn:pv",
173 except getopt
.GetoptError
:
177 if o
in ("-a", "--asn"):
179 if o
in ("-d", "--dbopts"):
180 options
['dbopts'] = a
181 if o
in ("-e", "--email"):
183 if o
in ("-h", "--help"):
185 if o
in ("-n", "--name"):
187 if o
in ("-p", "--preserve"):
188 options
['preserve'] = 1
189 if o
in ("-v", "--version"):
190 options
['version'] = 1
194 if options
['version']:
197 if not options
['asn']:
198 print "mandatory ASN.1 file parameter missing"
200 if not os
.access(options
['asn'], os
.R_OK
):
201 print "ASN.1 file not accessible"
205 """Print usage help."""
206 print "Usage: " + name
+ " <parameters>\n" + \
207 "Parameters are\n" + \
208 " --asn -a asn1file, ASN.1 file to use (mandatory)\n" + \
209 " --dbopts -d opts, options for dpkg-buildpackage\n" + \
210 " --email -e address, use e-mail address\n" + \
211 " --help -h, print help and exit\n" + \
212 " --name -n name, use user name\n" + \
213 " --preserve -p, do not overwrite files\n" + \
214 " --version -v, print version and exit\n" + \
216 name
+ " -e me@foo.net -a bar.asn1 -n \"My Name\" " + \
217 "-d \"-rfakeroot -uc -us\""
218 if __name__
== '__main__':