summaryrefslogtreecommitdiffstats
path: root/tools/idl2deb
blob: 18f1b05647b94f89d44bf53d735c41c20417ffe1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python3

# idl2deb - quick hack by W. Martin Borgert <debacle@debian.org> to create
# Debian GNU/Linux packages from idl2wrs modules for Wireshark.
# Copyright 2003, 2008, W. Martin Borgert

# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.com>
# Copyright 1998 Gerald Combs

# SPDX-License-Identifier: GPL-2.0-or-later

import optparse
import os
import string
import sys
import time

scriptinfo = """idl2deb version 2008-03-10
Copyright 2003, 2008, W. Martin Borgert
Free software, released under the terms of the GPL."""

def create_file(preserve, filename, content, mode = None):
    """Create a file with given content."""
    if preserve and os.path.isfile(filename):
        return
    f = open(filename, 'w')
    f.write(content)
    f.close()
    if mode:
        os.chmod(filename, mode)

def create_files(version, deb, email, idl, name, preserve, iso, rfc):
    """Create all files for the .deb build process."""
    base = os.path.basename(idl.lower().split(".idl")[0])

    if not os.path.isdir("packaging/debian"):
        os.mkdir("packaging/debian")

    create_file(preserve, "packaging/debian/rules", """#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk

PREFIX=`pwd`/packaging/debian/wireshark-giop-%s

binary-post-install/wireshark-giop-%s::
	rm -f $(PREFIX)/usr/lib/wireshark/plugins/%s/*.a
""" % (base, base, version), 0o755)

    create_file(preserve, "packaging/debian/control", """Source: wireshark-giop-%s
Section: net
Priority: optional
Maintainer: %s <%s>
Standards-Version: 3.6.1.0
Build-Depends: wireshark-dev, autotools-dev, debhelper, cdbs

Package: wireshark-giop-%s
Architecture: any
Depends: wireshark (= %s), ${shlibs:Depends}
Description: GIOP dissector for CORBA interface %s
 This package provides a dissector for GIOP (General Inter-ORB
 Protocol) for the Wireshark protocol analyser.  It decodes the CORBA
 (Common Object Request Broker Architecture) interfaces described
 in the IDL (Interface Definition Language) file '%s.idl'.
""" % (base, name, email, base, deb, base, base))

    create_file(preserve, "packaging/debian/changelog",
            """wireshark-giop-%s (0.0.1-1) unstable; urgency=low

  * Automatically created package.

 -- %s <%s>  %s
""" % (base, name, email, rfc))

    create_file(preserve, "packaging/debian/copyright",
            """This package has been created automatically by idl2deb on
%s for Debian GNU/Linux.

Wireshark: https://www.wireshark.org/

Copyright:

GPL, as evidenced by existence of GPL license file \"COPYING\".
(the GNU GPL may be viewed on Debian systems in
/usr/share/common-licenses/GPL)
""" % (iso))

def get_wrs_version():
    """Detect version of wireshark-dev package."""
    deb = os.popen(
        "dpkg-query -W --showformat='${Version}' wireshark-dev").read()
    debv = string.find(deb, "-")
    if debv == -1: debv = len(deb)
    version = deb[string.find(deb, ":")+1:debv]
    return version, deb

def get_time():
    """Detect current time and return ISO and RFC time string."""
    currenttime = time.gmtime()
    return time.strftime("%Y-%m-%d %H:%M:%S +0000", currenttime), \
           time.strftime("%a, %d %b %Y %H:%M:%S +0000", currenttime)

def main():
    opts = process_opts(sys.argv)
    iso, rfc = get_time()
    version, deb = get_wrs_version()
    create_files(version, deb,
                 opts.email, opts.idl, opts.name, opts.preserve,
                 iso, rfc)
    os.system("dpkg-buildpackage " + opts.dbopts)

def process_opts(argv):
    """Process command line options."""
    parser = optparse.OptionParser(
        version=scriptinfo,
        description="""Example:
%prog -e me@foo.net -i bar.idl -n \"My Name\" -d \"-rfakeroot -uc -us\"""")
    parser.add_option("-d", "--dbopts",
                      default="", metavar="opts",
                      help="options for dpkg-buildpackage")
    parser.add_option("-e", "--email", metavar="address",
                      default="invalid@invalid.invalid",
                      help="use e-mail address")
    parser.add_option("-i", "--idl", metavar="idlfile",
                      help="IDL file to use (mandatory)")
    parser.add_option("-n", "--name", default="No Name",
                      help="use user name", metavar="name")
    parser.add_option("-p", "--preserve", action="store_true",
                      help="do not overwrite files")
    opts, args = parser.parse_args()
    if not opts.idl:
        print("mandatory IDL file parameter missing")
        sys.exit(1)
    if not os.access(opts.idl, os.R_OK):
        print("IDL file not accessible")
        sys.exit(1)
    return opts

if __name__ == '__main__':
    main()