--- /dev/null
+This is a quick hack because I'm fed up of not having all the entries I
+want in my /etc/services file. Now I can drop my local mods in
+/etc/services.d and run update-services when they change. Easy.
+
+-- [mdw]
--- /dev/null
+services (1.0.0) unstable; urgency=low
+
+ * Shiny and new!
+
+ -- Mark Wooding <mdw@nsict.org> Fri, 29 Apr 2005 20:26:47 +0100
+
--- /dev/null
+Source: services
+Section: net
+Priority: extra
+Build-Depends: python (>= 2.3), debhelper (>= 4.2.32)
+Maintainer: Mark Wooding <mdw@nsict.org>
+Standards-Version: 3.1.1
+
+Package: services
+Architecture: all
+Depends: ${python:Depends}
+Description: Amalgamate services tables into one big /etc/services file.
--- /dev/null
+This package is copyright (c) 2003 Mark Wooding.
+
+This package is free software; you can redistribute it and/or modify it under
+the terms of the GNU Library General Public License as published by the
+Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+This package is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for
+more details.
+
+You should have a copy of the GNU Library General Public License in
+/usr/share/common-licenses/LGPL-2; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
--- /dev/null
+#! /bin/sh -e
+
+dpkg-divert --add \
+ --package services \
+ --rename \
+ --divert /etc/services.d/netbase \
+ /etc/services
+
+/usr/sbin/update-services
+
+#DEBHELPER#
--- /dev/null
+#! /bin/sh -e
+
+rm -f /etc/services
+dpkg-divert --remove \
+ --package services \
+ --divert /etc/services.d/netbase \
+ /etc/services
--- /dev/null
+#! /usr/bin/make -f
+
+export DH_COMPAT = 4
+
+build:
+ touch build
+
+clean:
+ dh_clean
+ rm -f build
+
+install: build
+ dh_clean
+ mkdir -p debian/services/etc/services.d
+ mkdir -p debian/services/usr/bin
+ mkdir -p debian/services/usr/share/man/man1
+ mkdir -p debian/services/usr/share/man/man8
+ mkdir -p debian/services/usr/sbin
+ mkdir -p debian/services/usr/share/doc/services
+ install -m755 merge-services debian/services/usr/bin
+ install -m755 update-services debian/services/usr/sbin
+ install -m644 merge-services.1 debian/services/usr/share/man/man1
+ install -m644 update-services.8 debian/services/usr/share/man/man8
+ install -m644 README /usr/share/doc/services
+
+binary-indep:
+ dh_testdir -i
+ dh_testroot -i
+ dh_compress -i
+ dh_installdocs -i
+ dh_python -i
+ dh_fixperms -i
+ dh_gencontrol -i
+ dh_installdeb -i
+ dh_md5sums -i
+ dh_builddeb -i
+binary-arch:
+
+binary: binary-indep binary-arch
+
+source:
+ rm -rf =deb=
+ pkg=`sed '1s!^\([^ ]*\) .*$$!\1!;2q' debian/changelog`; \
+ ver=`sed '1s!^.* (\([0-9.]*\)) .*$$!\1!;2q' debian/changelog`; \
+ mkdir -p =deb=/$$pkg-$$ver/debian
+ cp update-services update-services.8 merge-services \
+ merge-services.1 =deb=/*/
+ cp debian/README debian/changelog debian/control debian/copyright \
+ debian/postinst debian/prerm debian/rules =deb=/*/debian
+ d=`pwd`; cd ..; dpkg-source -i -b $$d/=deb=/*
+ rm -rf =deb=
+
+.PHONY: binary binary-arch binary-indep install clean
--- /dev/null
+#! /usr/bin/python
+
+import sre as re
+import os
+from sys import argv, stderr
+
+class struct (object):
+ def __init__(me, **kw):
+ me.__dict__.update(kw)
+ def __repr__(me):
+ r = '%s(' % me.__class__.__name__
+ sep = ''
+ for k in me.__dict__:
+ r += sep + '%s=%r' % (k, me.__dict__[k])
+ sep = ', '
+ r += ')'
+ return r
+
+class service (struct):
+ def __str__(me):
+ return '%(name)s:%(port)d/%(proto)s' % me.__dict__
+ def key(me):
+ return me.port, me.proto, me.name
+ def parse(string):
+ m = re.match(r'''^ (\S+) \s+ (\d+)/(\S+) \s*
+ ([^#\s] [^#]* [^#\s] | [^#\s])? \s*
+ (?: \# \s* (\S .* \S | \S |) )? \s* $''',
+ string, re.VERBOSE)
+ if not m:
+ raise 'Bad service line %r' % string
+ me = service(name = m.group(1),
+ port = int(m.group(2)),
+ proto = m.group(3),
+ aliases = m.group(4) and m.group(4).split() or [],
+ comment = m.group(5))
+ return me
+ parse = staticmethod(parse)
+
+class servicetab (object):
+ def __init__(me):
+ me.tab = {}
+ def _insert(me, serv):
+ tab = me.tab
+ changep = False
+ if serv.key() not in tab:
+ tab[serv.key()] = serv
+ changep = True
+ else:
+ s = tab[serv.key()]
+ d = {}
+ for a in s.aliases:
+ d[a] = 1
+ #warnp = True
+ dd = {}
+ for a in serv.aliases:
+ dd[a] = 1
+ if a not in d:
+ #if warnp:
+ # print >>stderr, 'Merging aliases for %s' % s
+ # warnp = False
+ s.aliases += [a]
+ changep = True
+ #for a in s.aliases:
+ # if a not in dd:
+ # if warnp:
+ # print >>stderr, 'Merging aliases for %s' % s
+ # warnp = False
+ return changep
+ def scan(me, file):
+ changep = False
+ for l in open(file):
+ if re.match(r'^\s*(\#.*)?$', l):
+ continue
+ serv = service.parse(l)
+ if me._insert(serv):
+ changep = True
+ if not changep:
+ print >>stderr, 'File `%s\' redundant' % file
+ return changep
+ def write(me):
+ kk = me.tab.values()
+ kk.sort(lambda x, y: cmp(x.key(), y.key()))
+ print '## services file [generated]'
+ print
+ for s in kk:
+ print '%-20s %9s %s' % (s.name,
+ '%d/%s' % (s.port, s.proto),
+ ' '.join(s.aliases))
+
+if 'running_under_emacs_p' not in globals():
+ t = servicetab()
+ for f in argv[1:]:
+ t.scan(f)
+ t.write()
--- /dev/null
+.TH merge-services 1 "29 April 2005"
+.SH NAME
+merge-services \- merge entries from several /etc/services files
+.SH SYNOPSIS
+.B merge-services
+.I file
+\&...
+.SH DESCRIPTION
+The
+.B merge-services
+command reads the services files given on the command line and writes a
+merged file to its standard output.
+.PP
+A services entry consists of five parts: a
+.IR name ,
+a
+.IR "port number" ,
+a
+.IR protocol ,
+a list of
+.IR aliases ,
+and a
+.IR comment .
+The merging process discards all comments. Two entries match if their
+names, ports and protocols are all equal: in this case, the output
+contains a single entry listing the union of both sets of aliases. In
+all other cases, entries are left alone.
+.SH BUGS
+It's very stupid.
+.SH AUTHOR
+Mark Wooding, <mdw@nsict.org>
--- /dev/null
+#! /bin/sh
+
+set -e
+merge-services /etc/services.d/*[!#~] "$@" >/etc/services.new
+mv /etc/services.new /etc/services
--- /dev/null
+.TH update-services 8 "29 April 2005"
+.SH NAME
+update-services \- update the /etc/services file
+.SH SYNOPSIS
+.B update-services
+.IR [ file
+\&...]
+.SH DESCRIPTION
+The
+.B update-services
+merges the contents of the files in
+.B /etc/services.d
+and any given on the command line, and writes the result to
+.BR /etc/services .
+.PP
+To save Emacs users from going mental, it ignores files whose names end
+in
+.RB ` # '
+or
+.RB ` ~ '.
+.SH SEE ALSO
+.BR merge-services (1).
+.SH AUTHOR
+Mark Wooding, <mdw@nsict.org>