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 esnacc 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 # SPDX-License-Identifier: GPL-2.0-or-later
16 import getopt, os, string, sys, time
18 scriptinfo = """asn2deb version 2004-02-17
19 Copyright 2004, W. Borgert
20 Free software, released under the terms of the GPL."""
22 options = {'asn': None,
24 'email': "invalid@invalid.invalid",
30 def create_file(filename, content, mode = None):
31 """Create a file with given content."""
33 if options['preserve'] and os.path.isfile(filename):
35 f = open(filename, 'w')
39 os.chmod(filename, mode)
41 def create_files(version, deb, email, asn, name, iso, rfc):
42 """Create all files for the .deb build process."""
43 base = asn.lower()[:-5]
45 if not os.path.isdir("packaging/debian"):
46 os.mkdir("packaging/debian")
48 create_file("packaging/debian/rules", """#!/usr/bin/make -f
50 include /usr/share/cdbs/1/rules/debhelper.mk
51 include /usr/share/cdbs/1/class/autotools.mk
53 PREFIX=`pwd`/packaging/debian/wireshark-asn1-%s
55 binary-post-install/wireshark-asn1-%s::
56 rm -f $(PREFIX)/usr/lib/wireshark/plugins/%s/*.a
57 """ % (base, base, version), 0o755)
59 create_file("packaging/debian/control", """Source: wireshark-asn1-%s
63 Standards-Version: 3.6.1.0
64 Build-Depends: esnacc, autotools-dev, debhelper, cdbs
66 Package: wireshark-asn1-%s
68 Depends: wireshark (= %s)
69 Description: ASN.1/BER dissector for %s
70 This package provides a type table for decoding BER (Basic Encoding
71 Rules) data over TCP or UDP, described by an ASN.1 (Abstract Syntax
72 Notation 1) file '%s.asn1'.
73 """ % (base, name, email, base, deb, base, base))
75 create_file("packaging/debian/changelog",
76 """wireshark-asn1-%s (0.0.1-1) unstable; urgency=low
78 * Automatically created package.
81 """ % (base, name, email, rfc + "\n (" + iso + ")"))
83 create_file("packaging/debian/copyright",
84 """This package has been created automatically be asn2deb on
85 %s for Debian GNU/Linux.
87 Wireshark: https://www.wireshark.com/
91 GPL, as evidenced by existence of GPL license file \"COPYING\".
92 (the GNU GPL may be viewed on Debian systems in
93 /usr/share/common-licenses/GPL)
96 def get_wrs_version():
97 """Detect version of wireshark-dev package."""
99 "dpkg-query -W --showformat='${Version}' wireshark-dev").read()
100 debv = string.find(deb, "-")
101 if debv == -1: debv = len(deb)
102 version = deb[string.find(deb, ":")+1:debv]
106 """Detect current time and return ISO and RFC time string."""
107 currenttime = time.gmtime()
108 return time.strftime("%Y-%m-%d %H:%M:%S +0000", currenttime), \
109 time.strftime("%a, %d %b %Y %H:%M:%S +0000", currenttime)
113 process_opts(sys.argv)
114 iso, rfc = get_time()
115 version, deb = get_wrs_version()
116 create_files(version, deb,
117 options['email'], options['asn'], options['name'],
119 os.system("dpkg-buildpackage " + options['dbopts'])
121 def process_opts(argv):
122 """Process command line options."""
125 opts, args = getopt.getopt(argv[1:], "a:d:e:hn:pv",
133 except getopt.GetoptError:
137 if o in ("-a", "--asn"):
139 if o in ("-d", "--dbopts"):
140 options['dbopts'] = a
141 if o in ("-e", "--email"):
143 if o in ("-h", "--help"):
145 if o in ("-n", "--name"):
147 if o in ("-p", "--preserve"):
148 options['preserve'] = 1
149 if o in ("-v", "--version"):
150 options['version'] = 1
154 if options['version']:
157 if not options['asn']:
158 print("mandatory ASN.1 file parameter missing")
160 if not os.access(options['asn'], os.R_OK):
161 print("ASN.1 file not accessible")
165 """Print usage help."""
166 print("Usage: " + name + " <parameters>\n" + \
167 "Parameters are\n" + \
168 " --asn -a asn1file, ASN.1 file to use (mandatory)\n" + \
169 " --dbopts -d opts, options for dpkg-buildpackage\n" + \
170 " --email -e address, use e-mail address\n" + \
171 " --help -h, print help and exit\n" + \
172 " --name -n name, use user name\n" + \
173 " --preserve -p, do not overwrite files\n" + \
174 " --version -v, print version and exit\n" + \
176 name + " -e me@foo.net -a bar.asn1 -n \"My Name\" " + \
177 "-d \"-rfakeroot -uc -us\"")
178 if __name__ == '__main__':