File: linux-image-3.16.0-4-powerpc64.prerm

package info (click to toggle)
linux 3.16.7-ckt9-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 740,624 kB
  • ctags: 2,385,278
  • sloc: ansic: 12,217,941; asm: 277,354; perl: 53,978; xml: 47,771; makefile: 30,485; sh: 8,063; python: 6,597; cpp: 5,127; yacc: 4,254; lex: 2,215; awk: 741; pascal: 231; lisp: 218; sed: 30
file content (158 lines) | stat: -rw-r--r-- 4,038 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#! /usr/bin/perl
# 
use strict;
use warnings;
use Debconf::Client::ConfModule qw(:all);
version('2.0');
my $capb=capb("backup");

$|=1;
# Predefined values:
my $version         = "3.16.0-4-powerpc64";
my $kimage          = "vmlinux";
my $prerm_hook      = '';       #Normally we do not
my $package_name    = "linux-image-$version";

#known variables
my $realimageloc    = "/boot/";
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*$/;

      $prerm_hook      = "$1"  if /prerm_hook\s*=\s*(\S+)/i;
    }
    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) {
    print STDERR "Aborting removal of running kernel image.\n";
    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
$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 (-x "$prerm_hook") {
  &run_hook("prerm", $prerm_hook);
}
if (-d "/etc/kernel/prerm.d") {
  system ("run-parts --report --exit-on-error --arg=$version " . 
          "--arg=$realimageloc$kimage-$version /etc/kernel/prerm.d") &&
            die "Failed to process /etc/kernel/prerm.d";
}
if (-d "/etc/kernel/prerm.d/$version") {
  system ("run-parts --report --exit-on-error --arg=$version" .
          " --arg=$realimageloc$kimage-$version " .
          "/etc/kernel/prerm.d/$version") &&
            die "Failed to process /etc/kernel/prerm.d/$version";
}

exit 0;
__END__