On Sun, May 23, 2010 at 05:29:13PM -0400, Joey Hess wrote: > dpkg-maintscript-helper is in dpkg now, so moving or removing > conffiles just involves pasting the same call to it into 3 > maintainer scripts. > > Since to be safe it needs to know the version of the package > in which the conffile move/removal took place, and since > using it means a versioned predependency on dpkg, it's difficult > to make debhelper fully automate using it. > > Still, the need to paste the same code into all the maintainer > scripts (or most of them, and it should be ok if dpkg-maintscript-helper > is called by all 4), is something that it seems debhelper could > help with. Maybe have a way to insert debian/maintscript-common > into all of them, for example.
I was wondering about this today. I'd like to get to the point where we can say for a large number of packages that they only contain debhelper autoscript code; this would make it much quicker to audit those packages for safety. Along with adding some more operations to dpkg-maintscript-helper, this seems like a good way to approach that. It would be better if we weren't looking at shell code pasted in from another file, though, since that just creates another file we need to audit. I think perhaps debian/maintscript should be parsed rather than just inserted, and this would allow us to generate appropriate Pre-Depends as well. As a strawman, how about something like this? This implementation does mean that you can't move conffiles whose names contain spaces; I'm not sure if that matters. I just did it in dh_installdeb rather than introducing another script, since there wasn't much code involved. diff --git a/autoscripts/maintscript-helper b/autoscripts/maintscript-helper new file mode 100644 index 0000000..c7e06c4 --- /dev/null +++ b/autoscripts/maintscript-helper @@ -0,0 +1 @@ +dpkg-maintscript-helper #PARAMS# -- "$@" diff --git a/dh_installdeb b/dh_installdeb index 35c9016..49f9f4a 100755 --- a/dh_installdeb +++ b/dh_installdeb @@ -50,12 +50,27 @@ In v3 compatibility mode and higher, all files in the etc/ directory in a package will automatically be flagged as conffiles by this program, so there is no need to list them manually here. +=item I<package>.maintscript + +Lines in this file correspond to L<dpkg-maintscript-helper(1)> commands and +parameters. Any shell metacharacters will be escaped, so arbitrary shell +code cannot be inserted here. For example, a line such as C<mv_conffile +/etc/oldconffile /etc/newconffile> will insert maintainer script snippets +into all maintainer scripts sufficient to move that conffile. + =back =cut init(); +# dpkg-maintscript-helper commands with their associated dpkg pre-dependency +# versions. +my %maintscript_predeps = ( + "rm_conffile" => "1.15.7.2", + "mv_conffile" => "1.15.7.2", +); + foreach my $package (@{$dh{DOPACKAGES}}) { my $tmp=tmpdir($package); @@ -76,6 +91,22 @@ foreach my $package (@{$dh{DOPACKAGES}}) { next; } + my $maintscriptfile=pkgfile($package, "maintscript"); + if ($maintscriptfile) { + foreach my $line (filedoublearray($maintscriptfile)) { + my $cmd=$line->[0]; + error("unknown dpkg-maintscript-helper command: $cmd") + unless exists $maintscript_predeps{$cmd}; + addsubstvar($package, "misc:Pre-Depends", "dpkg", + ">= $maintscript_predeps{$cmd}"); + my $params=escape_shell(@$line); + foreach my $script (qw{postinst preinst prerm postrm}) { + autoscript($package, $script, "maintscript-helper", + "s!#PARAMS#!$params!g"); + } + } + } + # Install debian scripts. foreach my $script (qw{postinst preinst prerm postrm}) { debhelper_script_subst($package, $script); diff --git a/t/maintscript b/t/maintscript new file mode 100755 index 0000000..bf15d44 --- /dev/null +++ b/t/maintscript @@ -0,0 +1,19 @@ +#!/usr/bin/perl +use Test; +plan(tests => 8); + +system("mkdir -p t/tmp/debian"); +system("cp debian/control t/tmp/debian"); +open(OUT, ">", "t/tmp/debian/maintscript") || die "$!"; +print OUT <<EOF; +rm_conffile /etc/1 +mv_conffile /etc/2 /etc/3 1.0-1 +EOF +close OUT; +system("cd t/tmp && DH_COMPAT=7 fakeroot ../../dh_installdeb"); +for my $script (qw{postinst preinst prerm postrm}) { + my @output=`cat t/tmp/debian/debhelper.$script.debhelper`; + ok(grep { m{^dpkg-maintscript-helper rm_conffile /etc/1 -- "\$\@"$} } @output); + ok(grep { m{^dpkg-maintscript-helper mv_conffile /etc/2 /etc/3 1\.0-1 -- "\$\@"$} } @output); +} +system("rm -rf t/tmp"); -- Colin Watson [cjwat...@debian.org] -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org