summaryrefslogtreecommitdiffstats
path: root/hooks/copy-host-apt-sources-and-preferences/customize00.pl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 14:14:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 14:14:39 +0000
commitee17e45964b786b48b455959dfe68715971893fb (patch)
tree118f40aa65dc838499053413b05adfd00f839c62 /hooks/copy-host-apt-sources-and-preferences/customize00.pl
parentInitial commit. (diff)
downloadmmdebstrap-ee17e45964b786b48b455959dfe68715971893fb.tar.xz
mmdebstrap-ee17e45964b786b48b455959dfe68715971893fb.zip
Adding upstream version 1.4.3.upstream/1.4.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'hooks/copy-host-apt-sources-and-preferences/customize00.pl')
-rwxr-xr-xhooks/copy-host-apt-sources-and-preferences/customize00.pl44
1 files changed, 44 insertions, 0 deletions
diff --git a/hooks/copy-host-apt-sources-and-preferences/customize00.pl b/hooks/copy-host-apt-sources-and-preferences/customize00.pl
new file mode 100755
index 0000000..53f6059
--- /dev/null
+++ b/hooks/copy-host-apt-sources-and-preferences/customize00.pl
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+#
+# This script makes sure that all packages that are installed both locally as
+# well as inside the chroot have the same version.
+#
+# It is implemented in Perl because there are no associative arrays in POSIX
+# shell.
+
+use strict;
+use warnings;
+
+sub get_pkgs {
+ my $root = shift;
+ my %pkgs = ();
+ open(my $fh, '-|', 'dpkg-query', "--root=$root", '--showformat',
+ '${binary:Package}=${Version}\n', '--show')
+ // die "cannot exec dpkg-query";
+ while (my $line = <$fh>) {
+ my ($pkg, $ver) = split(/=/, $line, 2);
+ $pkgs{$pkg} = $ver;
+ }
+ close $fh;
+ if ($? != 0) { die "failed to run dpkg-query" }
+ return %pkgs;
+}
+
+my %pkgs_local = get_pkgs('/');
+my %pkgs_chroot = get_pkgs($ARGV[0]);
+
+my @diff = ();
+foreach my $pkg (keys %pkgs_chroot) {
+ next unless exists $pkgs_local{$pkg};
+ if ($pkgs_local{$pkg} ne $pkgs_chroot{$pkg}) {
+ push @diff, $pkg;
+ }
+}
+
+if (scalar @diff > 0) {
+ print STDERR "E: packages from the host and the chroot differ:\n";
+ foreach my $pkg (@diff) {
+ print STDERR "E: $pkg $pkgs_local{$pkg} $pkgs_chroot{$pkg}\n";
+ }
+ exit 1;
+}