2006-12-06 10:31:20 +00:00
|
|
|
#! /usr/bin/perl
|
|
|
|
#
|
2010-08-30 00:33:54 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2006-12-06 10:31:20 +00:00
|
|
|
use Debconf::Client::ConfModule qw(:all);
|
|
|
|
version('2.0');
|
|
|
|
my $capb=capb("backup");
|
|
|
|
|
|
|
|
$|=1;
|
|
|
|
# Predefined values:
|
2013-08-17 11:35:06 +00:00
|
|
|
my $version = "@abiname@@localversion@";
|
|
|
|
my $kimage = "@image-stem@";
|
2006-12-06 10:31:20 +00:00
|
|
|
my $prerm_hook = ''; #Normally we do not
|
2010-06-18 03:35:05 +00:00
|
|
|
my $package_name = "linux-image-$version";
|
2006-12-06 10:31:20 +00:00
|
|
|
|
|
|
|
#known variables
|
2010-06-18 03:46:24 +00:00
|
|
|
my $realimageloc = "/boot/";
|
2006-12-06 10:31:20 +00:00
|
|
|
my $CONF_LOC = '/etc/kernel-img.conf';
|
|
|
|
|
|
|
|
# Variables used
|
|
|
|
my $image='';
|
|
|
|
my $ret=0;
|
|
|
|
my $seen='';
|
|
|
|
my $answer='';
|
|
|
|
my $running = '';
|
|
|
|
my $WouldInvalidate = 0;
|
|
|
|
|
|
|
|
# Ignore all invocations uxcept when called on to remove
|
|
|
|
exit 0 unless ($ARGV[0] && $ARGV[0] =~ /remove/) ;
|
|
|
|
|
|
|
|
if (-r "$CONF_LOC" && -f "$CONF_LOC" ) {
|
|
|
|
if (open(CONF, "$CONF_LOC")) {
|
|
|
|
while (<CONF>) {
|
|
|
|
chomp;
|
|
|
|
s/\#.*$//g;
|
|
|
|
next if /^\s*$/;
|
|
|
|
|
2010-02-16 03:45:59 +00:00
|
|
|
$prerm_hook = "$1" if /prerm_hook\s*=\s*(\S+)/i;
|
2006-12-06 10:31:20 +00:00
|
|
|
}
|
|
|
|
close CONF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#check to see if we are trying to remove a running kernel
|
|
|
|
# if so we abort right now.
|
|
|
|
chop($running=`uname -r`);
|
|
|
|
if ($running eq $version) {
|
|
|
|
my $question = "${package_name}/prerm/removing-running-kernel-$version";
|
|
|
|
|
|
|
|
($ret,$seen) = fset ("$question", 'seen', 'false');
|
|
|
|
die "Error setting debconf flags in $question: $seen" if $ret;
|
|
|
|
|
|
|
|
$ret = subst("$question", 'running', "$running");
|
|
|
|
die "Error setting debconf substitutions in $question: $seen" if $ret;
|
|
|
|
|
|
|
|
($ret,$seen) = input('critical', "$question");
|
|
|
|
if ($ret && $ret != 30 ) {
|
|
|
|
die "Error setting debconf question $question: $seen";
|
|
|
|
}
|
|
|
|
|
|
|
|
($ret,$seen) = go ();
|
|
|
|
if ($ret && $ret != 30 ) {
|
|
|
|
die "Error asking debconf question $question: $seen";
|
|
|
|
}
|
|
|
|
|
|
|
|
($ret,$answer) = get("$question");
|
|
|
|
die "Error retreiving answer for $question: $answer" if $ret;
|
|
|
|
|
|
|
|
if ($answer =~ /^(y|t)/i) {
|
2011-12-28 00:29:32 +00:00
|
|
|
print STDERR "Aborting removal of running kernel image.\n";
|
2006-12-06 10:31:20 +00:00
|
|
|
exit 1; #Operation not permitted
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print STDERR "Ok, proceeding with removing running kernel image.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#Now, they have an alternate kernel which they are currently running
|
|
|
|
|
|
|
|
chdir("/") or die "could not chdir to /:$!\n";
|
|
|
|
|
|
|
|
|
|
|
|
# set the env var stem
|
2010-06-18 03:35:05 +00:00
|
|
|
$ENV{'STEM'} = "linux";
|
2006-12-06 10:31:20 +00:00
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-26 17:24:06 +00:00
|
|
|
my $options;
|
|
|
|
for (@ARGV) {
|
|
|
|
s,','\\'',g;
|
|
|
|
$options .= " '$_'";
|
|
|
|
}
|
|
|
|
$ENV{'DEB_MAINT_PARAMS'}="$options";
|
|
|
|
|
2006-12-06 10:31:20 +00:00
|
|
|
## Run user hook script here, if any
|
|
|
|
if (-x "$prerm_hook") {
|
|
|
|
&run_hook("prerm", $prerm_hook);
|
|
|
|
}
|
|
|
|
if (-d "/etc/kernel/prerm.d") {
|
2014-01-05 18:33:11 +00:00
|
|
|
system ("run-parts --report --exit-on-error --arg=$version " .
|
2006-12-06 10:31:20 +00:00
|
|
|
"--arg=$realimageloc$kimage-$version /etc/kernel/prerm.d") &&
|
|
|
|
die "Failed to process /etc/kernel/prerm.d";
|
|
|
|
}
|
|
|
|
if (-d "/etc/kernel/prerm.d/$version") {
|
2014-01-05 18:33:11 +00:00
|
|
|
system ("run-parts --report --exit-on-error --arg=$version" .
|
2006-12-06 10:31:20 +00:00
|
|
|
" --arg=$realimageloc$kimage-$version " .
|
|
|
|
"/etc/kernel/prerm.d/$version") &&
|
|
|
|
die "Failed to process /etc/kernel/prerm.d/$version";
|
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
__END__
|