3
# Twisted, the Framework of Your Internet
4
# Copyright (C) 2001 Matthew W. Lefkowitz
6
# This library is free software; you can redistribute it and/or
7
# modify it under the terms of version 2.1 of the GNU Lesser General Public
8
# License as published by the Free Software Foundation.
10
# This library is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
# Lesser General Public License for more details.
15
# You should have received a copy of the GNU Lesser General Public
16
# License along with this library; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
import sys, os, string, pwd, shutil
23
# This makes sure that users don't have to set up their environment
24
# specially in order to run these programs from bin/.
27
if string.find(os.path.abspath(sys.argv[0]),'Twisted') != -1:
28
sys.path.append(os.path.dirname(
29
os.path.dirname(os.path.abspath(sys.argv[0]))))
33
from twisted.python import usage
35
class MyOptions(usage.Options):
36
optFlags = [["unsigned", "u"]]
37
optStrings = [["tapfile", "t", "twistd.tap"],
38
["maintainer", "m", ""],
39
["protocol", "p", ""],
40
["description", "e", ""],
41
["long_description", "l", ""],
42
["version", "v", "1.0"],
43
["debfile", "d", None]]
47
except usage.error, ue:
48
sys.exit("%s: %s" % (sys.argv[0], ue))
50
def save_to_file(file, text):
51
open(file, 'w').write(text)
53
tap_file = config.tapfile
54
protocol = config.protocol or os.path.splitext(tap_file)[0]
55
deb_file = config.debfile or 'twisted-'+protocol
56
version = config.version
57
maintainer = config.maintainer
58
description = config.description or ('A TCP server for %(protocol)s' % vars())
59
long_description = config.long_description or 'Automatically created by tap2deb'
60
date = string.strip(os.popen('822-date').read())
61
directory = deb_file + '-' + version
63
if os.path.exists(os.path.join('.build', directory)):
64
os.system('rm -rf %s' % os.path.join('.build', directory))
65
os.makedirs(os.path.join('.build', directory, 'debian'))
67
shutil.copy(tap_file, os.path.join('.build', directory))
69
save_to_file(os.path.join('.build', directory, 'debian', 'README.Debian'),
71
This package is auto-generated by tap2deb
74
save_to_file(os.path.join('.build', directory, 'debian', 'conffiles'),
76
/etc/init.d/%(deb_file)s
77
/etc/default/%(deb_file)s
81
save_to_file(os.path.join('.build', directory, 'debian', 'default'),
83
pidfile=/var/run/%(deb_file)s.pid \
84
rundir=/var/lib/%(deb_file)s/ \
85
file=/etc/%(tap_file)s \
86
logfile=/var/log/%(deb_file)s.log
89
save_to_file(os.path.join('.build', directory, 'debian', 'init.d'),
93
PATH=/sbin:/bin:/usr/sbin:/usr/bin
95
pidfile=/var/run/%(deb_file)s.pid \
96
rundir=/var/lib/%(deb_file)s/ \
97
file=/etc/%(tap_file)s \
98
logfile=/var/log/%(deb_file)s.log
100
[ -r /etc/default/%(deb_file)s ] && . /etc/default/%(deb_file)s
102
test -x /usr/bin/twistd || exit 0
103
test -r $file || exit 0
108
echo -n "Starting %(deb_file)s: twistd"
109
start-stop-daemon --start --quiet --exec /usr/bin/twistd -- \
119
echo -n "Stopping %(deb_file)s: twistd"
120
start-stop-daemon --stop --quiet \
135
echo "Usage: /etc/init.d/%(deb_file)s {start|stop|restart|force-reload}" >&2
143
os.chmod(os.path.join('.build', directory, 'debian', 'init.d'), 0755)
145
save_to_file(os.path.join('.build', directory, 'debian', 'postinst'),
148
if [ "$1" = "configure" ]; then
149
if [ -d /usr/doc -a ! -e /usr/doc/%(deb_file)s -a -d /usr/share/doc/%(deb_file)s ]; then
150
ln -sf ../share/doc/%(deb_file)s /usr/doc/%(deb_file)s
154
update-rc.d %(deb_file)s defaults >/dev/null
155
sh /etc/init.d/%(deb_file)s start
158
save_to_file(os.path.join('.build', directory, 'debian', 'prerm'),
161
if [ \( "$1" = "upgrade" -o "$1" = "remove" \) -a -L /usr/doc/%(deb_file)s ]; then
162
rm -f /usr/doc/%(deb_file)s
164
sh /etc/init.d/%(deb_file)s stop
167
save_to_file(os.path.join('.build', directory, 'debian', 'postrm'),
170
if [ "$1" = purge ]; then
171
update-rc.d %(deb_file)s remove >/dev/null
175
save_to_file(os.path.join('.build', directory, 'debian', 'changelog'),
177
%(deb_file)s (%(version)s) unstable; urgency=low
181
-- %(maintainer)s %(date)s
184
mode: debian-changelog
188
save_to_file(os.path.join('.build', directory, 'debian', 'control'),
193
Maintainer: %(maintainer)s
194
Build-Depends: debhelper
195
Standards-Version: 3.5.6
197
Package: %(deb_file)s
200
Description: %(description)s
204
save_to_file(os.path.join('.build', directory, 'debian', 'copyright'),
206
This package was auto-debianized by %(maintainer)s on
209
It was auto-generated by tap2deb
212
Moshe Zadka <moshez@twistedmatrix.com> -- tap2deb author
216
tap2deb is released under the GNU Lesser Generl Public License,
217
and this package contains bits of code from tap2deb, and hence is
218
a derived work of tap2deb, and is under the GNU Lesser General
222
save_to_file(os.path.join('.build', directory, 'debian', 'dirs'),
227
usr/share/doc/%(deb_file)s
230
save_to_file(os.path.join('.build', directory, 'debian', 'rules'),
244
rm -f build-stamp install-stamp
247
install: install-stamp
248
install-stamp: build-stamp
254
# Add here commands to install the package into debian/tmp.
255
cp %(tap_file)s debian/tmp/etc/
256
cp debian/init.d debian/tmp/etc/init.d/%(deb_file)s
257
cp debian/default debian/tmp/etc/default/%(deb_file)s
258
cp debian/copyright debian/tmp/usr/share/doc/%(deb_file)s/
259
cp debian/README.Debian debian/tmp/usr/share/doc/%(deb_file)s/
262
binary-arch: build install
264
binary-indep: build install
278
@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false
280
binary: binary-indep binary-arch
281
.PHONY: build clean binary-indep binary-arch binary install
284
os.chmod(os.path.join('.build', directory, 'debian', 'rules'), 0755)
286
os.chdir('.build/%(directory)s' % vars())
287
os.system('dpkg-buildpackage -rfakeroot'+ ['', ' -uc -us'][config.unsigned])