diff mbox

[1/1] UBUNTU: [Config] linux-image-extras needs full postinst

Message ID 1338228820-9965-2-git-send-email-apw@canonical.com
State New
Headers show

Commit Message

Andy Whitcroft May 28, 2012, 6:13 p.m. UTC
Currently after installing the linux-image-extras package we attempt to
rebuild the module lists (via depmod) which succeeds, and then rebuild the
initramfs which does not.  We call update-initramfs but this does not works
from a kernel postinst, we end up indicating that we would like to trigger
a delayed initramfs build but do not actually then go on to trigger it
(which is positive as it would likely build the wrong initramfs anyhow).

When we install the extras package we may well need to perform whatever
processing we perform when the original kernel is installed.  Copy the
depmod and hook calls from the main linux package.

Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 debian/control-scripts/postinst.extra |  154 +++++++++++++++++++++++++++++++--
 debian/control-scripts/postrm.extra   |  143 ++++++++++++++++++++++++++++--
 debian/rules.d/2-binary-arch.mk       |    5 +-
 3 files changed, 284 insertions(+), 18 deletions(-)
diff mbox

Patch

diff --git a/debian/control-scripts/postinst.extra b/debian/control-scripts/postinst.extra
index a370b4c..2800a95 100644
--- a/debian/control-scripts/postinst.extra
+++ b/debian/control-scripts/postinst.extra
@@ -1,8 +1,146 @@ 
-#!/bin/sh
-
-case "$1" in
-  configure)
-    depmod -a -F /boot/System.map-@@KVER@@ @@KVER@@
-    update-initramfs -u -k @@KVER@@
-    ;;
-esac
+#! /usr/bin/perl
+# OriginalAuthor : Manoj Srivastava ( srivasta@pilgrim.umass.edu )
+#
+# Customized for Ubuntu by: Ben Collins <bcollins@ubuntu.com>
+# Further customised for extras package by: Andy Whitcroft <apw@canonical.com>
+
+#use strict; #for debugging
+use Cwd 'abs_path';
+
+$|=1;
+
+# Predefined values:
+my $version           = "=V";
+my $postinst_hook     = '';          #Normally we do not
+my $kernel_arch       = "=B";
+my $image_dir         = "/boot";        # where the image is located
+
+my $temp_file_name = "/var/log/$loader" . "_log.$$";
+my $realimageloc    = "/$image_dir/";
+
+# Ignore all invocations except when called on to configure.
+exit 0 unless $ARGV[0] =~ /configure/;
+
+# Do some preliminary sanity checks here to ensure we actually have an
+# valid image dir
+chdir('/')           or die "could not chdir to /:$!\n";
+die "Internal Error: ($image_dir) is not a directory!\n"
+  unless -d $image_dir;
+
+# remove multiple leading slashes; make sure there is at least one.
+$realimageloc  =~ s|^/*|/|o;
+$realimageloc  =~ s|/+|/|o;
+die "Internal Error: ($realimageloc) is not a directory!\n"
+  unless -d $realimageloc;
+
+if (-r "$CONF_LOC" && -f "$CONF_LOC"  ) {
+  if (open(CONF, "$CONF_LOC")) {
+    while (<CONF>) {
+      chomp;
+      s/\#.*$//g;
+      next if /^\s*$/;
+
+      $postinst_hook   = "$1"  if /^\s*postinst_hook\s*=\s*(\S+)/ig;
+    }
+    close CONF;
+    $have_conffile = "Yes";
+  }
+}
+
+$ENV{KERNEL_ARCH}=$kernel_arch if $kernel_arch;
+
+######################################################################
+######################################################################
+######################################################################
+######################################################################
+
+# We may not have any modules installed
+if ( -d "$modules_base/$version" ) {
+  print STDERR "Running depmod.\n";
+  my $ret = system("depmod -a $version");
+  if ($ret) {
+    print STDERR "Failed to run depmod\n";
+    exit(1);
+  }
+}
+
+# set the env var stem
+$ENV{'STEM'} = "linux";
+sub exec_script {
+  my $type   = shift;
+  my $script = shift;
+  print STDERR "Running $type hook script $script.\n";
+  system ("$script $version $realimageloc$kimage-$version") &&
+    print STDERR "User $type hook script [$script] ";
+  if ($?) {
+    if ($? == -1) {
+      print STDERR "failed to execute: $!\n";
+    }
+    elsif ($? & 127) {
+      printf STDERR "died with signal %d, %s coredump\n",
+        ($? & 127),  ($? & 128) ? 'with' : 'without';
+    }
+    else {
+      printf STDERR "exited with value %d\n", $? >> 8;
+    }
+    exit $? >> 8;
+  }
+}
+sub run_hook {
+  my $type   = shift;
+  my $script = shift;
+  if ($script =~ m,^/,) {
+    # Full path provided for the hook script
+    if (-x "$script") {
+      &exec_script($type,$script);
+    }
+    else {
+      die "The provided $type hook script [$script] could not be run.\n";
+    }
+  }
+  else {
+    # Look for it in a safe path
+    for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
+      if (-x "$path/$script") {
+        &exec_script($type, "$path/$script");
+        return 0;
+      }
+    }
+    # No luck
+    print STDERR "Could not find $type hook script [$script].\n";
+    die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
+  }
+}
+
+my $options;
+for (@ARGV) {
+	s,','\\'',g;
+	$options .= " '$_'";
+}
+$ENV{'DEB_MAINT_PARAMS'}="$options";
+
+## Run user hook script here, if any
+if ($postinst_hook) {
+  &run_hook("postinst", $postinst_hook);
+}
+
+if (-d "/etc/kernel/postinst.d") {
+  print STDERR "Examining /etc/kernel/postinst.d.\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version " .
+          "--arg=$realimageloc$kimage-$version " .
+          "/etc/kernel/postinst.d") &&
+            die "Failed to process /etc/kernel/postinst.d";
+}
+
+if (-d "/etc/kernel/postinst.d/$version") {
+  print STDERR "Examining /etc/kernel/postinst.d/$version.\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version " .
+          "--arg=$realimageloc$kimage-$version " .
+          "/etc/kernel/postinst.d/$version") &&
+            die "Failed to process /etc/kernel/postinst.d/$version";
+}
+
+exit 0;
+
+__END__
+
diff --git a/debian/control-scripts/postrm.extra b/debian/control-scripts/postrm.extra
index 0adcc62..cc548fb 100644
--- a/debian/control-scripts/postrm.extra
+++ b/debian/control-scripts/postrm.extra
@@ -1,8 +1,135 @@ 
-#!/bin/sh
-
-case "$1" in
-  remove|purge)
-    depmod -a -F /boot/System.map-@@KVER@@ @@KVER@@
-    update-initramfs -u -k @@KVER@@
-    ;;
-esac
+#! /usr/bin/perl
+#                              -*- Mode: Cperl -*- 
+# image.postrm --- 
+# Author           : Manoj Srivastava ( srivasta@glaurung.green-gryphon.com ) 
+# Created On       : Sat May 15 11:05:13 1999
+# Created On Node  : glaurung.green-gryphon.com
+# Last Modified By : Manoj Srivastava
+# Last Modified On : Wed Sep 13 11:26:19 2006
+# Last Machine Used: glaurung.internal.golden-gryphon.com
+# Update Count     : 57
+# Status           : Unknown, Use with caution!
+# HISTORY          : 
+# Description      : 
+# 
+#     $Id: image.postrm,v 1.31 2003/10/07 16:24:20 srivasta Exp $
+#
+
+#use strict; #for debugging
+
+$|=1;
+
+# Predefined values:
+my $version           = "=V";
+my $postrm_hook       = '';       #Normally we do not
+my $kernel_arch       = "=B";
+my $image_dir         = "/boot";        # where the image is located
+
+my $temp_file_name = "/var/log/$loader" . "_log.$$";
+my $temp_file_name = "/var/log/$loader" . "_log.$$";
+
+# Do some preliminary sanity checks here to ensure we actually have an
+# valid image dir
+chdir('/')           or die "could not chdir to /:$!\n";
+die "Internal Error: ($image_dir) is not a directory!\n"
+  unless -d $image_dir;
+
+# remove multiple leading slashes; make sure there is at least one.
+$realimageloc  =~ s|^/*|/|o;
+$realimageloc  =~ s|/+|/|o;
+die "Internal Error: ($realimageloc) is not a directory!\n"
+  unless -d $realimageloc;
+
+if (-r "$CONF_LOC" && -f "$CONF_LOC"  ) {
+  if (open(CONF, "$CONF_LOC")) {
+    while (<CONF>) {
+      chomp;
+      s/\#.*$//g;
+      next if /^\s*$/;
+
+      $postrm_hook     = "$1"  if /^\s*postrm_hook\s*=\s*(\S+)/ig;
+    }
+    close CONF;
+    $have_conffile = "Yes";
+  }
+}
+
+$ENV{KERNEL_ARCH}=$kernel_arch if $kernel_arch;
+
+# set the env var stem
+$ENV{'STEM'} = "linux";
+sub exec_script {
+  my $type   = shift;
+  my $script = shift;
+  print STDERR "Running $type hook script $script.\n";
+  system ("$script $version $realimageloc$kimage-$version") &&
+    print STDERR "User $type hook script [$script] ";
+  if ($?) {
+    if ($? == -1) {
+      print STDERR "failed to execute: $!\n";
+    }
+    elsif ($? & 127) {
+      printf STDERR "died with signal %d, %s coredump\n",
+        ($? & 127),  ($? & 128) ? 'with' : 'without';
+    }
+    else {
+      printf STDERR "exited with value %d\n", $? >> 8;
+    }
+  }
+}
+sub run_hook {
+  my $type   = shift;
+  my $script = shift;
+  if ($script =~ m,^/,) {
+    # Full path provided for the hook script
+    if (-x "$script") {
+      &exec_script($type,$script);
+    }
+    else {
+      warn "The provided $type hook script [$script] could not be run.\n";
+    }
+  }
+  else {
+    # Look for it in a safe path
+    for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
+      if (-x "$path/$script") {
+        &exec_script($type, "$path/$script");
+        return 0;
+      }
+    }
+    # No luck
+    print STDERR "Could not find $type hook script [$script].\n";
+    warn "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
+  }
+}
+
+my $options;
+for (@ARGV) {
+	s,','\\'',g;
+	$options .= " '$_'";
+}
+$ENV{'DEB_MAINT_PARAMS'}="$options";
+
+## Run user hook script here, if any
+if ($postrm_hook) {
+  &run_hook("postrm", $postrm_hook);
+}
+if (-d "/etc/kernel/postrm.d") {
+  warn "Examining /etc/kernel/postrm.d .\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version " .
+          "--arg=$realimageloc$kimage-$version " .
+          "/etc/kernel/postrm.d") &&
+            die "Failed to process /etc/kernel/postrm.d";
+}
+if (-d "/etc/kernel/postrm.d/$version") {
+  warn "Examining /etc/kernel/postrm.d/$version .\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version " .
+          "--arg=$realimageloc$kimage-$version " .
+          "/etc/kernel/postrm.d/$version") &&
+            die "Failed to process /etc/kernel/postrm.d/$version";
+}
+
+exit 0;
+
+__END__
+
diff --git a/debian/rules.d/2-binary-arch.mk b/debian/rules.d/2-binary-arch.mk
index ad8c812..781152c 100644
--- a/debian/rules.d/2-binary-arch.mk
+++ b/debian/rules.d/2-binary-arch.mk
@@ -127,8 +127,9 @@  endif
 	if [ -f $(DEBIAN)/control.d/$(target_flavour).inclusion-list ] ; then	\
 		install -d $(pkgdir_ex)/DEBIAN;					\
 		for script in postinst postrm ; do				\
-			sed -e 's/@@KVER@@/$(release)-$(abinum)-$(target_flavour)/g' \
-				debian/control-scripts/$$script.extra > $(pkgdir_ex)/DEBIAN/$$script; \
+			sed -e 's/=V/$(abi_release)-$*/g' -e 's/=K/$(install_file)/g'		\
+			    -e 's/=L/$(loader)/g'         -e 's@=B@$(build_arch)@g'		\
+			    debian/control-scripts/$$script.extra > $(pkgdir_ex)/DEBIAN/$$script; \
 			chmod 755 $(pkgdir_ex)/DEBIAN/$$script;			\
 		done;								\
 	fi