name change
[obnox/wireshark/wip.git] / debian / patches / 02_asn2deb.dpatch
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 02_asn2deb.dpatch by  <fpeters@debian.org>
3 ##
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: asn2deb - create Debian packages from ASN.1 files
6
7 @DPATCH@
8 diff -urNad --exclude=CVS --exclude=.svn ./asn2deb /tmp/dpep-work.5BSR7A/ethereal-0.10.11/asn2deb
9 --- ./asn2deb   1970-01-01 01:00:00.000000000 +0100
10 +++ /tmp/dpep-work.5BSR7A/ethereal-0.10.11/asn2deb      2005-07-17 19:37:02.000000000 +0200
11 @@ -0,0 +1,219 @@
12 +#!/usr/bin/env python
13 +
14 +# asn2deb - quick hack by W. Borgert <debacle@debian.org> to create
15 +# Debian GNU/Linux packages from ASN.1 files for Ethereal.
16 +# Copyright 2004, W. Borgert
17 +
18 +# ASN.1 module for Ethereal, use of snacc type table:
19 +# Copyright 2003, Matthijs Melchior <matthijs.melchior@xs4all.nl>
20 +#
21 +# Wireshark - Network traffic analyzer
22 +# By Gerald Combs <gerald@wireshark.org>
23 +# Copyright 1998 Gerald Combs
24 +
25 +# This program is free software; you can redistribute it and/or
26 +# modify it under the terms of the GNU General Public License
27 +# as published by the Free Software Foundation; either version 2
28 +# of the License, or (at your option) any later version.
29 +# 
30 +# This program is distributed in the hope that it will be useful,
31 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
32 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33 +# GNU General Public License for more details.
34 +# 
35 +# You should have received a copy of the GNU General Public License
36 +# along with this program; if not, write to the Free Software
37 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
38 +
39 +import getopt, os, string, sys, time
40 +
41 +scriptinfo = """asn2deb version 2004-02-17
42 +Copyright 2004, W. Borgert
43 +Free software, released under the terms of the GPL."""
44 +
45 +options = {'asn':      None,
46 +           'dbopts':   "",
47 +           'email':    "invalid@invalid.invalid",
48 +           'help':     0,
49 +           'name':     "No Name",
50 +           'preserve': 0,
51 +           'version':  0}
52 +
53 +def bootstrap():
54 +    """Generate Makefile.in and configure script."""
55 +    os.system("aclocal-1.7")
56 +    os.system("autoconf")
57 +    os.system("automake-1.7 --add-missing --copy --foreign")
58 +
59 +def create_file(filename, content, mode = None):
60 +    """Create a file with given content."""
61 +    global options
62 +    if options['preserve'] and os.path.isfile(filename):
63 +        return
64 +    f = open(filename, 'w')
65 +    f.write(content)
66 +    f.close()
67 +    if mode:
68 +        os.chmod(filename, mode)
69 +
70 +def create_files(version, deb, email, asn, name, iso, rfc):
71 +    """Create all files for the .deb build process."""
72 +    base = asn.lower()[:-5]
73 +    create_file("Makefile.am", """#
74 +
75 +BUILT_SOURCES = %s.tt
76 +asn1ttdir = $(datadir)/ethereal/asn1
77 +asn1tt_DATA = %s.tt
78 +
79 +%s.tt: """  % ((base,) * 3) + asn + """
80 +       snacc -u /usr/include/snacc/asn1/asn-useful.asn1 -T $@ $<
81 +""")
82 +
83 +    create_file("configure.ac", """AC_INIT(%s, 1.0)
84 +AM_INIT_AUTOMAKE
85 +AM_MAINTAINER_MODE
86 +AC_PROG_INSTALL
87 +SNACC=\"`type -p snacc`\"
88 +AC_SUBST(SNACC)
89 +dnl ETHEREAL_VERSION=\"%s\"
90 +dnl plugindir=\"$prefix/share/ethereal/asn.1\"
91 +dnl AC_SUBST(plugindir)
92 +AC_OUTPUT([Makefile])
93 +""" % (base, version))
94 +
95 +    if not os.path.isdir("debian"):
96 +        os.mkdir("debian")
97 +
98 +    create_file("debian/rules", """#!/usr/bin/make -f
99 +
100 +include /usr/share/cdbs/1/rules/debhelper.mk
101 +include /usr/share/cdbs/1/class/autotools.mk
102 +
103 +PREFIX=`pwd`/debian/ethereal-asn1-%s
104 +
105 +binary-post-install/ethereal-asn1-%s::
106 +       rm -f $(PREFIX)/usr/lib/ethereal/plugins/%s/*.a
107 +""" % (base, base, version), 0755)
108 +
109 +    create_file("debian/control", """Source: ethereal-asn1-%s
110 +Section: net
111 +Priority: optional
112 +Maintainer: %s <%s>
113 +Standards-Version: 3.6.1.0
114 +Build-Depends: snacc, autotools-dev, debhelper, cdbs
115 +
116 +Package: ethereal-asn1-%s
117 +Architecture: all
118 +Depends: ethereal (= %s)
119 +Description: ASN.1/BER dissector for %s
120 + This package provides a type table for decoding BER (Basic Encoding
121 + Rules) data over TCP or UDP, described by an ASN.1 (Abstract Syntax
122 + Notation 1) file '%s.asn1'.
123 +""" % (base, name, email, base, deb, base, base))
124 +
125 +    create_file("debian/changelog",
126 +            """ethereal-asn1-%s (0.0.1-1) unstable; urgency=low
127 +
128 +  * Automatically created package.
129 +
130 + -- %s <%s>  %s
131 +""" % (base, name, email, rfc + "\n    (" + iso + ")"))
132 +
133 +    create_file("debian/copyright",
134 +            """This package has been created automatically be asn2deb on
135 +%s for Debian GNU/Linux.
136 +
137 +Ethereal: http://www.ethereal.com/
138 +
139 +Copyright:
140 +
141 +GPL, as evidenced by existence of GPL license file \"COPYING\".
142 +(the GNU GPL may be viewed on Debian systems in
143 +/usr/share/common-licenses/GPL)
144 +""" % (iso))
145 +
146 +def get_eth_version():
147 +    """Detect version of ethereal-dev package."""
148 +    deb = os.popen(
149 +        "dpkg-query -W --showformat='${Version}' ethereal-dev").read()
150 +    debv = string.find(deb, "-")
151 +    if debv == -1: debv = len(deb)
152 +    version = deb[string.find(deb, ":")+1:debv]
153 +    return version, deb
154 +
155 +def get_time():
156 +    """Detect current time and return ISO and RFC time string."""
157 +    currenttime = time.gmtime()
158 +    return time.strftime("%Y-%m-%d %H:%M:%S +0000", currenttime), \
159 +           time.strftime("%a, %d %b %Y %H:%M:%S +0000", currenttime)
160 +
161 +def main():
162 +    global options
163 +    process_opts(sys.argv)
164 +    iso, rfc = get_time()
165 +    version, deb = get_eth_version()
166 +    create_files(version, deb,
167 +                 options['email'], options['asn'], options['name'],
168 +                 iso, rfc)
169 +    bootstrap()
170 +    os.system("dpkg-buildpackage " + options['dbopts'])
171 +
172 +def process_opts(argv):
173 +    """Process command line options."""
174 +    global options
175 +    try:
176 +        opts, args = getopt.getopt(argv[1:], "a:d:e:hn:pv",
177 +                                   ["asn=",
178 +                                    "dbopts=",
179 +                                    "email=",
180 +                                    "help",
181 +                                    "name=",
182 +                                    "preserve",
183 +                                    "version"])
184 +    except getopt.GetoptError:
185 +        usage(argv[0])
186 +        sys.exit(1)
187 +    for o, a in opts:
188 +        if o in ("-a", "--asn"):
189 +            options['asn'] = a
190 +        if o in ("-d", "--dbopts"):
191 +            options['dbopts'] = a
192 +        if o in ("-e", "--email"):
193 +            options['email'] = a
194 +        if o in ("-h", "--help"):
195 +            options['help'] = 1
196 +        if o in ("-n", "--name"):
197 +            options['name'] = a
198 +        if o in ("-p", "--preserve"):
199 +            options['preserve'] = 1
200 +        if o in ("-v", "--version"):
201 +            options['version'] = 1
202 +    if options['help']:
203 +        usage(argv[0])
204 +        sys.exit(0)
205 +    if options['version']:
206 +        print scriptinfo
207 +        sys.exit(0)
208 +    if not options['asn']:
209 +        print "mandatory ASN.1 file parameter missing"
210 +        sys.exit(1)
211 +    if not os.access(options['asn'], os.R_OK):
212 +        print "ASN.1 file not accessible"
213 +        sys.exit(1)
214 +
215 +def usage(name):
216 +    """Print usage help."""
217 +    print "Usage: " + name + " <parameters>\n" + \
218 +          "Parameters are\n" + \
219 +          "  --asn      -a asn1file, ASN.1 file to use (mandatory)\n" + \
220 +          "  --dbopts   -d opts,     options for dpkg-buildpackage\n" + \
221 +          "  --email    -e address,  use e-mail address\n" + \
222 +          "  --help     -h,          print help and exit\n" + \
223 +          "  --name     -n name,     use user name\n" + \
224 +          "  --preserve -p,          do not overwrite files\n" + \
225 +          "  --version  -v,          print version and exit\n" + \
226 +          "Example:\n" + \
227 +          name + " -e me@foo.net -a bar.asn1 -n \"My Name\" " + \
228 +          "-d \"-rfakeroot -uc -us\""
229 +if __name__ == '__main__':
230 +    main()
231 diff -urNad --exclude=CVS --exclude=.svn ./asn2deb.dbk /tmp/dpep-work.5BSR7A/ethereal-0.10.11/asn2deb.dbk
232 --- ./asn2deb.dbk       1970-01-01 01:00:00.000000000 +0100
233 +++ /tmp/dpep-work.5BSR7A/ethereal-0.10.11/asn2deb.dbk  2005-07-17 19:37:02.000000000 +0200
234 @@ -0,0 +1,158 @@
235 +<?xml version='1.0' encoding='ISO-8859-1'?>
236 +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
237 +"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
238 +  <!ENTITY command     "<command>asn2deb</command>">
239 +  <!ENTITY email       "<email>debacle@debian.org</email>">
240 +  <!ENTITY author      "W. Borgert">
241 +  <!ENTITY debian      "<productname>Debian GNU/Linux</productname>">
242 +]>
243 +
244 +<refentry>
245 +  <refentryinfo>
246 +    <address>
247 +      &email;
248 +    </address>
249 +    <author>
250 +      <firstname>W.</firstname>
251 +      <surname>Borgert</surname>
252 +    </author>
253 +    <copyright>
254 +      <year>2003</year>
255 +      <year>2005</year>
256 +      <holder>&author;</holder>
257 +    </copyright>
258 +    <date>2004-02-18</date>
259 +    <keywordset>
260 +      <keyword>ASN.1</keyword>
261 +      <keyword>BER</keyword>
262 +      <keyword>Ethereal</keyword>
263 +    </keywordset>
264 +    <revhistory>
265 +      <revision>
266 +       <revnumber>1</revnumber>
267 +       <date>2004-02-18</date>
268 +       <authorinitials>debacle</authorinitials>
269 +       <revremark>First version.</revremark>
270 +      </revision>
271 +    </revhistory>
272 +  </refentryinfo>
273 +  <refmeta>
274 +    <refentrytitle>asn2deb</refentrytitle>
275 +
276 +    <manvolnum>1</manvolnum>
277 +  </refmeta>
278 +  <refnamediv>
279 +    <refname>asn2deb</refname>
280 +
281 +    <refpurpose>create a Debian package for BER monitoring from ASN.1</refpurpose>
282 +  </refnamediv>
283 +  <refsynopsisdiv>
284 +    <cmdsynopsis>
285 +      &command;
286 +      <arg>-a <replaceable>ASN.1 file</replaceable></arg>
287 +      <arg>--asn=<replaceable>ASN.1 file</replaceable></arg>
288 +      <arg><option>-d <replaceable>opts</replaceable></option></arg>
289 +      <arg><option>--dbopts=<replaceable>opts</replaceable></option></arg>
290 +      <arg><option>-e <replaceable>address</replaceable></option></arg>
291 +      <arg><option>--email=<replaceable>address</replaceable></option></arg>
292 +      <arg><option>-h</option></arg>
293 +      <arg><option>--help</option></arg>
294 +      <arg><option>-n <replaceable>name</replaceable></option></arg>
295 +      <arg><option>--name=<replaceable>name</replaceable></option></arg>
296 +      <arg><option>-p</option></arg>
297 +      <arg><option>--preserve</option></arg>
298 +      <arg><option>-v</option></arg>
299 +      <arg><option>--version</option></arg>
300 +    </cmdsynopsis>
301 +  </refsynopsisdiv>
302 +  <refsect1>
303 +    <title>Description</title>
304 +
305 +    <para>This manual page documents briefly the
306 +      <command>asn2deb</command> command.</para>
307 +
308 +    <para>&command; takes an ASN.1 file as input and creates a Debian
309 +    package from it.  The package contains a loadable type table file
310 +    for the ethereal network analyser.  The type table is generated by
311 +    the ASN.1 compiler <command>snacc</command>.</para>
312 +  </refsect1>
313 +  <refsect1>
314 +    <title>Options</title>
315 +
316 +    <variablelist>
317 +      <varlistentry>
318 +        <term><option>-a <replaceable>ASN.1 file</replaceable></option>
319 +          <option>--asn=<replaceable>ASN.1 file</replaceable></option></term>
320 +        <listitem>
321 +          <para>ASN.1 file to use (mandatory).</para>
322 +        </listitem>
323 +      </varlistentry>
324 +      <varlistentry>
325 +        <term><option>-d <replaceable>opts</replaceable></option>
326 +          <option>--dbopts=<replaceable>opts</replaceable></option></term>
327 +        <listitem>
328 +          <para>options for dpkg-buildpackage.</para>
329 +        </listitem>
330 +      </varlistentry>
331 +      <varlistentry>
332 +        <term><option>-e <replaceable>address</replaceable></option>
333 +          <option>--email=<replaceable>address</replaceable></option></term>
334 +        <listitem>
335 +          <para>use e-mail address.</para>
336 +        </listitem>
337 +      </varlistentry>
338 +      <varlistentry>
339 +        <term><option>-h</option>
340 +          <option>--help</option>
341 +        </term>
342 +        <listitem>
343 +          <para>print help and exit.</para>
344 +        </listitem>
345 +      </varlistentry>
346 +      <varlistentry>
347 +        <term><option>-n <replaceable>name</replaceable></option>
348 +          <option>--name=<replaceable>name</replaceable></option></term>
349 +        <listitem>
350 +          <para>use user name.</para>
351 +        </listitem>
352 +      </varlistentry>
353 +      <varlistentry>
354 +        <term><option>-p</option>
355 +          <option>--preserve</option></term>
356 +        <listitem>
357 +          <para>do not overwrite files.</para>
358 +        </listitem>
359 +      </varlistentry>
360 +      <varlistentry>
361 +        <term><option>-v</option>
362 +          <option>--version</option></term>
363 +        <listitem>
364 +          <para>print version and exit.</para>
365 +        </listitem>
366 +      </varlistentry>
367 +    </variablelist>
368 +
369 +    <para>Example:</para>
370 +
371 +    <programlisting>/usr/bin/asn2deb -e me@foo.net -a bar.asn1 \
372 +-n &quot;My Name&quot; -d &quot;-rfakeroot -uc -us&quot;</programlisting>
373 +
374 +  </refsect1>
375 +  <refsect1>
376 +    <title>See Also</title>
377 +
378 +    <para>A lot of tools are used, which you have to
379 +    <command>apt-get install</command>: ethereal-dev, python,
380 +    cdbs, autotools-dev, debhelper, dpkg-dev, snacc.</para>
381 +  </refsect1>
382 +
383 +  <refsect1>
384 +    <title>Copying</title>
385 +
386 +    <para>This manual page was written by &author; &email; for
387 +      &debian; (but may be used by others).  Permission is granted to
388 +      copy, distribute and/or modify this document under the terms of
389 +      the GNU General Public License, Version 2 or any later
390 +      version published by the Free Software Foundation.</para>
391 +  </refsect1>
392 +</refentry>