How can I create a .deb file that adds a repository to sources.list.d?

I want to start sharing .deb files that automatically add new repos to an Ubuntu installation (like the ones present in puppetlabs.com).

How can I do that?


You could add a postinst script to your package:

Broadly speaking the preinst [script] is called before (a particular version of) a package is unpacked, and the postinst afterwards... The postinst should still attempt any actions for which its dependencies are required, since they will normally be available, but consider the correct error handling approach if those actions fail.

http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html

An example

The Opera browser is adding itself to the /etc/apt/sources.list.d/opera.list with the postinst script: http://pastebin.com/u6SR6krY