~nicktux/utappia/optimus-kernel

« back to all changes in this revision

Viewing changes to debian/control-scripts/postinst

  • Committer: NickTh
  • Date: 2015-10-15 08:11:04 UTC
  • Revision ID: nick-athens30@ubuntu.com-20151015081104-cr4qwkh27u0mw0e2
Creating Initial Project

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/perl
 
2
# OriginalAuthor : Manoj Srivastava ( srivasta@pilgrim.umass.edu )
 
3
#
 
4
# Customized for Ubuntu by: Ben Collins <bcollins@ubuntu.com>
 
5
 
 
6
#use strict; #for debugging
 
7
use Cwd 'abs_path';
 
8
 
 
9
$|=1;
 
10
 
 
11
# Predefined values:
 
12
my $version           = "=V";
 
13
my $link_in_boot      = "";  # Should be empty, mostly
 
14
my $no_symlink        = "";   # Should be empty, mostly
 
15
my $reverse_symlink   = "";   # Should be empty, mostly
 
16
my $do_symlink        = "Yes";  # target machine defined
 
17
my $do_boot_enable    = "Yes";  # target machine defined
 
18
my $do_bootfloppy     = "Yes";  # target machine defined
 
19
my $do_bootloader     = "Yes";  # target machine defined
 
20
my $move_image        = '';     # target machine defined
 
21
my $kimage            = "=K";   # Should be empty, mostly
 
22
my $loader            = "=L"; # lilo, silo, quik, palo, vmelilo, nettrom, arcboot or delo
 
23
my $image_dir         = "/boot";        # where the image is located
 
24
my $clobber_modules   = '';          # target machine defined
 
25
my $relative_links    = "";          # target machine defined
 
26
my $initrd            = "YES";        # initrd kernel
 
27
my $do_initrd         = '';     # Normally we do not
 
28
my $use_hard_links    = ''; # hardlinks do not work across fs boundaries
 
29
my $postinst_hook     = '';          #Normally we do not
 
30
my $postrm_hook       = '';          #Normally we do not
 
31
my $preinst_hook      = '';          #Normally we do not
 
32
my $prerm_hook        = '';          #Normally we do not
 
33
my $minimal_swap      = '';          # Do not swap symlinks
 
34
my $ignore_depmod_err = '';          # normally we do not
 
35
my $kernel_arch       = "=B";
 
36
my $ramdisk           = "/usr/sbin/update-initramfs";  # List of tools to create initial ram fs.
 
37
my $notifier          = "/usr/share/update-notifier/notify-reboot-required";
 
38
my $package_name      = "linux-image-$version";
 
39
my $explicit_do_loader = 'Yes';
 
40
 
 
41
my $Loader          = "NoLOADER"; #
 
42
$Loader             = "LILO"     if $loader =~ /^lilo/io;
 
43
$Loader             = "SILO"     if $loader =~ /^silo/io;
 
44
$Loader             = "QUIK"     if $loader =~ /^quik/io;
 
45
$Loader             = "yaboot"   if $loader =~ /^yaboot/io;
 
46
$Loader             = "PALO"     if $loader =~ /^palo/io;
 
47
$Loader             = "NETTROM"  if $loader =~ /^nettrom/io;
 
48
$Loader             = "VMELILO"  if $loader =~ /^vmelilo/io;
 
49
$Loader             = "ZIPL"     if $loader =~ /^zipl/io;
 
50
$Loader             = "ELILO"    if $loader =~ /^elilo/io;
 
51
$Loader             = "ARCBOOT"  if $loader =~ /^arcboot/io;
 
52
$Loader             = "DELO"     if $loader =~ /^delo/io;
 
53
 
 
54
# This should not point to /tmp, because of security risks.
 
55
my $temp_file_name = "/var/log/$loader" . "_log.$$";
 
56
 
 
57
#known variables
 
58
my $image_dest      = "/";
 
59
my $realimageloc    = "/$image_dir/";
 
60
my $have_conffile   = "";
 
61
my $silent_modules  = '';
 
62
my $silent_loader   = '';
 
63
my $warn_reboot     = 'Yes';     # Warn that we are installing a version of
 
64
                                 # the kernel we are running
 
65
 
 
66
my $modules_base    = '/lib/modules';
 
67
my $CONF_LOC        = '/etc/kernel-img.conf';
 
68
 
 
69
# Ignore all invocations except when called on to configure.
 
70
exit 0 unless $ARGV[0] =~ /configure/;
 
71
 
 
72
my $DEBUG = 0;
 
73
 
 
74
# Do some preliminary sanity checks here to ensure we actually have an
 
75
# valid image dir
 
76
chdir('/')           or die "could not chdir to /:$!\n";
 
77
die "Internal Error: ($image_dir) is not a directory!\n"
 
78
  unless -d $image_dir;
 
79
 
 
80
# remove multiple leading slashes; make sure there is at least one.
 
81
$realimageloc  =~ s|^/*|/|o;
 
82
$realimageloc  =~ s|/+|/|o;
 
83
die "Internal Error: ($realimageloc) is not a directory!\n"
 
84
  unless -d $realimageloc;
 
85
 
 
86
if (-r "$CONF_LOC" && -f "$CONF_LOC"  ) {
 
87
  if (open(CONF, "$CONF_LOC")) {
 
88
    while (<CONF>) {
 
89
      chomp;
 
90
      s/\#.*$//g;
 
91
      next if /^\s*$/;
 
92
 
 
93
      $do_symlink      = "" if /^\s*do_symlinks\s*=\s*(no|false|0)\s*$/ig;
 
94
      $no_symlink      = "" if /^\s*no_symlinks\s*=\s*(no|false|0)\s*$/ig;
 
95
      $reverse_symlink = "" if /^\s*reverse_symlink\s*=\s*(no|false|0)\s*$/ig;
 
96
      $link_in_boot    = "" if /^\s*image_in_boot\s*=\s*(no|false|0)\s*$/ig;
 
97
      $link_in_boot    = "" if /^\s*link_in_boot\s*=\s*(no|false|0)\s*$/ig;
 
98
      $move_image      = "" if /^\s*move_image\s*=\s*(no|false|0)\s*$/ig;
 
99
      $clobber_modules = '' if /^\s*clobber_modules\s*=\s*(no|false|0)\s*$/ig;
 
100
      $do_boot_enable  = '' if /^\s*do_boot_enable\s*=\s*(no|false|0)\s*$/ig;
 
101
      $do_bootfloppy   = '' if /^\s*do_bootfloppy\s*=\s*(no|false|0)\s*$/ig;
 
102
      $relative_links  = '' if /^\s*relative_links \s*=\s*(no|false|0)\s*$/ig;
 
103
      $do_bootloader   = '' if /^\s*do_bootloader\s*=\s*(no|false|0)\s*$/ig;
 
104
      $explicit_do_loader = '' if /^\s*do_bootloader\s*=\s*(no|false|0)\s*$/ig;
 
105
      $do_initrd       = '' if /^\s*do_initrd\s*=\s*(no|false|0)\s*$/ig;
 
106
      $use_hard_links  = '' if /^\s*use_hard_links\s*=\s*(no|false|0)\s*$/ig;
 
107
      $silent_modules  = '' if /^\s*silent_modules\s*=\s*(no|false|0)\s*$/ig;
 
108
      $silent_loader   = '' if /^\s*silent_loader\s*=\s*(no|false|0)\s*$/ig;
 
109
      $warn_reboot     = '' if /^\s*warn_reboot\s*=\s*(no|false|0)\s*$/ig;
 
110
      $minimal_swap    = '' if /^\s*minimal_swap\s*=\s*(no|false|0)\s*$/ig;
 
111
      $ignore_depmod_err = '' if /^\s*ignore_depmod_err\s*=\s*(no|false|0)\s*$/ig;
 
112
 
 
113
      $do_symlink      = "Yes" if /^\s*do_symlinks\s*=\s*(yes|true|1)\s*$/ig;
 
114
      $no_symlink      = "Yes" if /^\s*no_symlinks\s*=\s*(yes|true|1)\s*$/ig;
 
115
      $reverse_symlink = "Yes" if /^\s*reverse_symlinks\s*=\s*(yes|true|1)\s*$/ig;
 
116
      $link_in_boot    = "Yes" if /^\s*image_in_boot\s*=\s*(yes|true|1)\s*$/ig;
 
117
      $link_in_boot    = "Yes" if /^\s*link_in_boot\s*=\s*(yes|true|1)\s*$/ig;
 
118
      $move_image      = "Yes" if /^\s*move_image\s*=\s*(yes|true|1)\s*$/ig;
 
119
      $clobber_modules = "Yes" if /^\s*clobber_modules\s*=\s*(yes|true|1)\s*$/ig;
 
120
      $do_boot_enable  = "Yes" if /^\s*do_boot_enable\s*=\s*(yes|true|1)\s*$/ig;
 
121
      $do_bootfloppy   = "Yes" if /^\s*do_bootfloppy\s*=\s*(yes|true|1)\s*$/ig;
 
122
      $do_bootloader   = "Yes" if /^\s*do_bootloader\s*=\s*(yes|true|1)\s*$/ig;
 
123
      $explicit_do_loader = "YES" if /^\s*do_bootloader\s*=\s*(yes|true|1)\s*$/ig;
 
124
      $relative_links  = "Yes" if /^\s*relative_links\s*=\s*(yes|true|1)\s*$/ig;
 
125
      $do_initrd       = "Yes" if /^\s*do_initrd\s*=\s*(yes|true|1)\s*$/ig;
 
126
      $use_hard_links  = "Yes" if /^\s*use_hard_links\s*=\s*(yes|true|1)\s*$/ig;
 
127
      $silent_modules  = 'Yes' if /^\s*silent_modules\s*=\s*(yes|true|1)\s*$/ig;
 
128
      $silent_loader   = 'Yes' if /^\s*silent_loader\s*=\s*(yes|true|1)\s*$/ig;
 
129
      $warn_reboot     = 'Yes' if /^\s*warn_reboot\s*=\s*(yes|true|1)\s*$/ig;
 
130
      $minimal_swap    = 'Yes' if /^\s*minimal_swap\s*=\s*(yes|true|1)\s*$/ig;
 
131
      $ignore_depmod_err = 'Yes' if /^\s*ignore_depmod_err\s*=\s*(yes|true|1)\s*$/ig;
 
132
 
 
133
      $image_dest      = "$1"  if /^\s*image_dest\s*=\s*(\S+)/ig;
 
134
      $postinst_hook   = "$1"  if /^\s*postinst_hook\s*=\s*(\S+)/ig;
 
135
      $postrm_hook     = "$1"  if /^\s*postrm_hook\s*=\s*(\S+)/ig;
 
136
      $preinst_hook    = "$1"  if /^\s*preinst_hook\s*=\s*(\S+)/ig;
 
137
      $prerm_hook      = "$1"  if /^\s*prerm_hook\s*=\s*(\S+)/ig;
 
138
      $ramdisk         = "$1"  if /^\s*ramdisk\s*=\s*(.+)$/ig;
 
139
    }
 
140
    close CONF;
 
141
    $have_conffile = "Yes";
 
142
  }
 
143
}
 
144
 
 
145
 
 
146
 
 
147
# For some versions of kernel-package, we had this warning in the
 
148
# postinst, but the rules did not really interpolate the value in.
 
149
# Here is a sanity check.
 
150
my $pattern = "=" . "I";
 
151
$initrd=~ s/^$pattern$//;
 
152
 
 
153
if ($link_in_boot) {
 
154
  $image_dest = "/$image_dir/"; # same as realimageloc
 
155
}
 
156
 
 
157
# Tack on at least one trainling /
 
158
$image_dest = "$image_dest/";
 
159
$image_dest =~ s|^/*|/|o;
 
160
$image_dest =~ s|/+$|/|o;
 
161
 
 
162
if (! -d "$image_dest") {
 
163
  die "Expected Image Destination dir ($image_dest) to be a valid directory!\n";
 
164
}
 
165
 
 
166
# sanity
 
167
if (!($do_bootfloppy || $do_bootloader)) {
 
168
  $do_boot_enable = '';
 
169
}
 
170
if ($do_symlink && $no_symlink) {
 
171
  warn "Both do_symlinks and no_symlinks options enabled; disabling no_symlinks\n";
 
172
  $no_symlink = 0;
 
173
}
 
174
 
 
175
# most of our work is done in $image_dest (nominally /)
 
176
chdir("$image_dest") or die "could not chdir to $image_dest:$!\n";
 
177
 
 
178
# Paranoid check to make sure that the correct value is put in there
 
179
if    (! $kimage)                 { $kimage = "vmlinuz"; } # Hmm. empty
 
180
elsif ($kimage =~ m/^b?uImage$/o) { $kimage = "vmlinuz"; } # these produce vmlinuz
 
181
elsif ($kimage =~ m/^b?zImage$/o) { $kimage = "vmlinuz"; } # these produce vmlinuz
 
182
elsif ($kimage =~ m/^[iI]mage$/o) { my $nop = $kimage;   }
 
183
elsif ($kimage =~ m/^vmlinux$/o)  { my $nop = $kimage;   }
 
184
else                              { $kimage = "vmlinuz"; } # Default
 
185
 
 
186
$ENV{KERNEL_ARCH}=$kernel_arch if $kernel_arch;
 
187
 
 
188
 
 
189
die "Internal Error: Could not find image (" . $realimageloc
 
190
  . "$kimage-$version)\n" unless -e $realimageloc
 
191
  . "$kimage-$version";
 
192
 
 
193
# search for the boot loader in the path
 
194
my $loader_exec;
 
195
($loader_exec = $loader)  =~ s|.*/||;
 
196
my ($loaderloc) = grep -x, map "$_/$loader_exec",
 
197
  map { length($_) ? $_ : "." }  split /:/, $ENV{PATH};
 
198
 
 
199
 
 
200
######################################################################
 
201
######################################################################
 
202
###########        Test whether a relative symlinkwould be OK #######
 
203
######################################################################
 
204
######################################################################
 
205
sub test_relative {
 
206
  my %params = @_;
 
207
  my $cwd;
 
208
 
 
209
  die "Internal Error: Missing Required paramater 'Old Dir' "
 
210
    unless $params{'Old Dir'};
 
211
  die "Internal Error: Missing Required paramater New Dir' "
 
212
    unless $params{'New Dir'};
 
213
 
 
214
 
 
215
  die "Internal Error: No such dir $params{'Old Dir'} "
 
216
    unless -d $params{'Old Dir'};
 
217
  die "Internal Error: No such dir $params{'New Dir'} "
 
218
    unless -d $params{'New Dir'};
 
219
 
 
220
  # If the caller specified a test file, and it does not exist try and find
 
221
  # another file to use in its stead.  As we are installing kernels we can
 
222
  # use any versioned file from this kernel which should be in the same place.
 
223
  if (defined $params{'Test File'} and
 
224
      ! -f $params{'Old Dir'} . '/' . $params{'Test File'}) {
 
225
 
 
226
      my @possible = glob($params{'Old Dir'} . "/*$version*");
 
227
      if ($#possible >= 0) {
 
228
        $params{'Test File'} = `basename "$possible[0]"`;
 
229
        chomp($params{'Test File'});
 
230
        warn "Test relative: selected $params{'Test File'}"
 
231
          if $DEBUG;
 
232
      }
 
233
  }
 
234
 
 
235
  warn "Test relative: testing $params{'Old Dir'} -> $params{'New Dir'}"
 
236
    if $DEBUG;
 
237
  chomp($cwd = `pwd`);
 
238
  chdir ($params{'New Dir'}) or die "Could not chdir to $params{'New Dir'}:$!";
 
239
  my $ok = 0;
 
240
  $params{'Old Dir'}  =~ s|^/*||o;
 
241
  if (-d $params{'Old Dir'} ) {
 
242
    if (defined $params{'Test File'}) {
 
243
      if (-e $params{'Old Dir'} . $params{'Test File'}) {
 
244
        $ok  = 1;
 
245
      }
 
246
    } else {
 
247
      $ok = 1;                  # well, backward compatibility
 
248
    }
 
249
  }
 
250
  chdir ($cwd) or die "Could not chdir to $params{'New Dir'}:$!";
 
251
  return $ok;
 
252
}
 
253
 
 
254
######################################################################
 
255
######################################################################
 
256
############
 
257
######################################################################
 
258
######################################################################
 
259
# sub CanonicalizePath {
 
260
#   my $path = join '/', @_;
 
261
#   my @work = split '/', $path;
 
262
#   my @out;
 
263
#   my $is_absolute;
 
264
 
 
265
#   if (@work && $work[0] eq "") {
 
266
#     $is_absolute = 1; shift @work;
 
267
#   }
 
268
 
 
269
#   while (@work) {
 
270
#     my $seg = shift @work;
 
271
#     if ($seg eq "." || $seg eq "") {
 
272
#     } 
 
273
#     elsif ($seg eq "..") {
 
274
#       if (@out && $out[-1] ne "..") {
 
275
#         pop @out;
 
276
#       } 
 
277
#       else {
 
278
#         # Leading "..", or "../..", etc.
 
279
#         push @out, $seg;
 
280
#       }
 
281
#     } 
 
282
#     else {
 
283
#       push @out, $seg;
 
284
#     }
 
285
#   }
 
286
 
 
287
#   unshift @out, "" if $is_absolute;
 
288
#   return join('/', @out);
 
289
# }
 
290
######################################################################
 
291
######################################################################
 
292
############
 
293
######################################################################
 
294
######################################################################
 
295
 
 
296
sub spath {
 
297
  my %params = @_;
 
298
 
 
299
  die "Missing Required paramater 'Old'" unless $params{'Old'};
 
300
  die "Missing Required paramater 'New'" unless  $params{'New'};
 
301
 
 
302
  my @olddir  = split '/', `readlink -q -m $params{'Old'}`;
 
303
  my @newdir  = split '/', `readlink -q -m $params{'New'}`;
 
304
  my @outdir  = @olddir;
 
305
 
 
306
  my $out = '';
 
307
  my $i;
 
308
  for ($i = 0; $i <= $#olddir && $i <= $#newdir; $i++) {
 
309
    $out++ if ($olddir[$i] ne $newdir[$i]);
 
310
    shift @outdir unless $out;
 
311
    unshift @outdir, ".." if $out;
 
312
  }
 
313
  if ($#newdir > $#olddir) {
 
314
    for ($i=0; $i < $#newdir; $i++) {
 
315
      unshift @outdir, "..";
 
316
    }
 
317
  }
 
318
  return join ('/', @outdir);
 
319
}
 
320
######################################################################
 
321
######################################################################
 
322
############
 
323
######################################################################
 
324
######################################################################
 
325
 
 
326
 
 
327
# This routine actually moves the kernel image
 
328
# From: $realimageloc/$kimage-$version (/boot/vmlinuz-2.6.12)
 
329
# To:   $image_dest/$kimage-$version   (/vmlinuz-2.6.12)
 
330
# Note that the image is moved to a versioned destination, but ordinary
 
331
# symlinks we create otherwise are not normally versioned
 
332
sub really_move_image {
 
333
  my $src_dir  = $_[0];
 
334
  my $target   = $_[1];
 
335
  my $dest_dir = $_[2];
 
336
 
 
337
  warn "Really move image: src_dir=$src_dir, target=$target,\n destdir=$dest_dir"
 
338
    if $DEBUG;
 
339
  if (-e "$target") {
 
340
    # we should be in dir $dest_dir == $image_dest /, normally
 
341
    rename("$target", "$target.$$") ||
 
342
      die "failed to move " . $dest_dir . "$target:$!";
 
343
    warn "mv $target $target.$$" if $DEBUG;
 
344
  }
 
345
  warn "mv -f $src_dir$target $target" if $DEBUG;
 
346
  my $ret = system("mv -f " . $src_dir . "$target " .
 
347
                   " $target");
 
348
  if ($ret) {
 
349
    die("Failed to move " . $src_dir . "$target to "
 
350
        . $dest_dir . "$target");
 
351
  }
 
352
  # Ok, now we may clobber the previous .old files
 
353
  if (-e "$target.$$") {
 
354
    rename("$target.$$", "$target.old") ||
 
355
      die "failed to move " . $dest_dir . "$target:$!";
 
356
    warn "mv $target.$$ $target " if $DEBUG;
 
357
  }
 
358
}
 
359
 
 
360
# Normally called after really_move_image; and only called if we asked for 
 
361
# reversed link this routine reverses the symbolic link that is notmally 
 
362
# created. Since the real kernel image has been moved over to 
 
363
# $image_dest/$kimage-$version. So, this routine links
 
364
# From:   $image_dest/$kimage-$version   (/vmlinuz-2.6.12)
 
365
# To:     $realimageloc/$kimage-$version (/boot/vmlinuz-2.6.12)
 
366
sub really_reverse_link {
 
367
  my $src_dir    = $_[0];
 
368
  my $link_name  = $_[1];
 
369
  my $dest_dir   = $_[2];
 
370
  warn "Really reverse link: src_dir=$src_dir, link name=$link_name\n" .
 
371
    "\tdestdir=$dest_dir" if $DEBUG;
 
372
 
 
373
  my $Old = $dest_dir;
 
374
  if (test_relative ('Old Dir' => $Old, 'New Dir' => $src_dir,
 
375
                     'Test File' => "$link_name")) {
 
376
    $Old   =~ s|^/*||o;
 
377
  }
 
378
  # Special case is they are in the same dir
 
379
  my $rel_path = spath('Old' => "$Old", 'New' => "$src_dir" );
 
380
  $Old ="" if $rel_path =~ m/^\s*$/o;
 
381
 
 
382
  if ($use_hard_links =~ m/YES/i) {
 
383
    link($Old . "$link_name", $src_dir . "$link_name") ||
 
384
      die("Failed to link " . $dest_dir . "$link_name to " . $src_dir . 
 
385
          "$link_name:$!");
 
386
    warn "ln " . $Old . "$link_name " . $src_dir . "$link_name"  if $DEBUG;
 
387
  }
 
388
  else {
 
389
    symlink($Old . "$link_name", $src_dir . "$link_name") ||
 
390
      die("Failed to symbolic-link " . $dest_dir . "$link_name to " . $src_dir
 
391
          . "$link_name:$!");
 
392
    warn "ln -s " . $Old . "$link_name " . $src_dir . "$link_name" if $DEBUG;
 
393
  }
 
394
}
 
395
 
 
396
# This routine is invoked if there is a symbolic link in place
 
397
# in $image_dest/$kimage -- so a symlink exists in the destination.
 
398
# What we are trying to determine is if we need to move the symbolic link over
 
399
# to the the .old location
 
400
sub move_p {
 
401
  my $kimage     = $_[0];       # Name of the symbolic link
 
402
  my $image_dest = $_[1];       # The directory the links goes into
 
403
  my $image_name = $_[2]; 
 
404
  my $src_dir    = $_[3]; 
 
405
  my $force_move = 0;
 
406
  warn "Move?: kimage=$kimage, image_dest=$image_dest, \n" .
 
407
    "\timage_name=$image_name, src_dir=$src_dir" if $DEBUG;
 
408
 
 
409
  if ($no_symlink || $reverse_symlink) {
 
410
    # we do not want links, yet we have a symbolic link here!
 
411
    warn "found a symbolic link in " . $image_dest . "$kimage \n" .
 
412
      "even though no_symlink is defined\n" if $no_symlink;
 
413
    warn "found a symbolic link in " . $image_dest . "$kimage \n" .
 
414
      "even though reverse_symlink is defined\n" if $reverse_symlink;
 
415
    # make sure we change this state of affairs
 
416
    $force_move = 1;
 
417
    return $force_move;
 
418
  }
 
419
 
 
420
  warn "DEBUG: OK. We found symlink, and we should have a symlink here.\n"
 
421
    if $DEBUG;
 
422
  my $vmlinuz_target = readlink "$kimage";
 
423
  my $real_target = '';
 
424
  my $target = `readlink -q -m "${realimageloc}${kimage}-${version}"`;
 
425
  $real_target = abs_path($vmlinuz_target) if defined($vmlinuz_target);
 
426
 
 
427
  if (!defined($vmlinuz_target) || ! -f "$real_target") {
 
428
    # what, a dangling symlink?
 
429
    warn "The link "  . $image_dest . "$kimage is a dangling link" .
 
430
      "to $real_target\n";
 
431
    $force_move = 1;
 
432
    return $force_move;
 
433
  }
 
434
 
 
435
 
 
436
  warn "DEBUG: The link $kimage points to ($vmlinuz_target)\n" if $DEBUG;
 
437
  warn "DEBUG: ($vmlinuz_target) is really ($real_target)\n" if $DEBUG;
 
438
  my $cwd;
 
439
  chomp ($cwd=`pwd`);
 
440
  if ($vmlinuz_target !~ m|^/|o) {
 
441
    $vmlinuz_target = $cwd . "/" . $vmlinuz_target;
 
442
    $vmlinuz_target =~ s|/+|/|o;
 
443
  }
 
444
  $vmlinuz_target = `readlink -q -m $vmlinuz_target`;
 
445
 
 
446
  if ("$vmlinuz_target" ne "$target") {
 
447
    warn "DEBUG: We need to handle this.\n" if $DEBUG;
 
448
    if ($minimal_swap) {
 
449
      warn "DEBUG: Minimal swap.\n" if $DEBUG;
 
450
      if (-l "$kimage.old") {
 
451
        warn "DEBUG: There is an old link at $kimage.old\n" if $DEBUG;
 
452
        my $old_target = readlink "$kimage.old";
 
453
        my $real_old_target = '';
 
454
        $real_old_target=abs_path($old_target) if defined ($old_target);
 
455
 
 
456
        if ($real_old_target  && -f "$real_old_target") {
 
457
          if ($old_target !~ m|^/|o) {
 
458
            $old_target = $cwd . "/" . $old_target;
 
459
            $old_target =~ s|/+|/|o;
 
460
          }
 
461
          $old_target = `readlink -q -m $old_target`;
 
462
          if ("$old_target"  ne "$target") {
 
463
            $force_move = 1;
 
464
            warn "DEBUG: Old link ($old_target) does not point to us ($target)\n"
 
465
              if $DEBUG;
 
466
          } 
 
467
          else {            # The .old points to the current
 
468
            warn "$kimage.old --> $target -- doing nothing";
 
469
            $force_move = 0;
 
470
          }
 
471
        } 
 
472
        else { 
 
473
          warn "DEBUG: Well, the old link does not exist -- so we move\n"
 
474
            if $DEBUG;
 
475
          $force_move = 1;
 
476
        }
 
477
      } 
 
478
      else {
 
479
        warn "DEBUG: No .old link -- OK to move\n"
 
480
          if $DEBUG;
 
481
        $force_move = 1;
 
482
      }
 
483
    } 
 
484
    else {
 
485
      warn "DEBUG: ok, minimal swap is no-- so we move.\n"
 
486
        if $DEBUG;
 
487
      $force_move = 1;
 
488
    }
 
489
  }
 
490
  else {                  # already have proper link
 
491
    warn "$kimage($vmlinuz_target) points to $target ($real_target) -- doing nothing";
 
492
    $force_move = 0;
 
493
  }
 
494
  return $force_move;
 
495
}
 
496
 
 
497
 
 
498
# This routine moves the symbolic link around (/vmlinuz -> /vmlinuz.old)
 
499
# It pays attention to whether we should the fact whether we should be using
 
500
# hard links or not.
 
501
sub really_move_link {
 
502
  my $kimage     = $_[0];       # Name of the symbolic link
 
503
  my $image_dest = $_[1];       # The directory the links goes into
 
504
  my $image_name = $_[2]; 
 
505
  my $src_dir    = $_[3]; 
 
506
  warn "really_move_link: kimage=$kimage, image_dest=$image_dest\n" .
 
507
    "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
 
508
 
 
509
  # don't clobber $kimage.old quite yet
 
510
  rename("$kimage", "$kimage.$$") ||
 
511
    die "failed to move " . $image_dest . "$kimage:$!";
 
512
  warn "mv $kimage $kimage.$$" if $DEBUG;
 
513
  my $Old = $src_dir;
 
514
  my $cwd;
 
515
 
 
516
  chomp($cwd=`pwd`);
 
517
  if (test_relative ('Old Dir' => $Old, 'New Dir' => $cwd,
 
518
                     'Test File' => "$image_name")) {
 
519
    $Old   =~ s|^/*||o;
 
520
  }
 
521
  # Special case is they are in the same dir
 
522
  my $rel_path = spath('Old' => "$Old", 'New' => "$cwd" );
 
523
  $Old ="" if $rel_path =~ m/^\s*$/o;
 
524
 
 
525
  if ($use_hard_links =~ m/YES/i) {
 
526
    warn "ln ${Old}${image_name} $kimage" if $DEBUG;
 
527
    if (! link("${Old}${image_name}", "$kimage")) {
 
528
      rename("$kimage.$$", "$kimage");
 
529
      die("Failed to link ${Old}${image_name} to " .
 
530
          "${image_dest}${kimage}:$!");
 
531
    }
 
532
  } 
 
533
  else {
 
534
    warn "ln -s ${Old}${image_name} $kimage" if $DEBUG;
 
535
    if (! symlink("${Old}${image_name}", "$kimage")) {
 
536
      rename("$kimage.$$", "$kimage");
 
537
      die("Failed to symbolic-link ${Old}${image_name} to " .
 
538
          "${image_dest}${kimage}:$!");
 
539
    }
 
540
  }
 
541
 
 
542
  # Ok, now we may clobber the previous .old file
 
543
  if (-l "$kimage.old" || ! -e "$kimage.old" ) {
 
544
    rename("$kimage.$$", "$kimage.old");
 
545
    warn "mv $kimage.$$ $kimage.old" if $DEBUG;
 
546
  }
 
547
  else {
 
548
    warn "$kimage.old is not a symlink, not clobbering\n";
 
549
    warn "rm $kimage.$$";
 
550
    unlink "$kimage.$$" if $DEBUG;
 
551
  }
 
552
}
 
553
 
 
554
# This routine handles a request to do symlinks, but there is no
 
555
# symlink file already there.  Either we are supposed to use copy, or we are
 
556
# installing on a pristine system, or the user does not want symbolic links at
 
557
# all.  We use a configuration file to tell the last two cases apart, creating
 
558
# a config file if needed.
 
559
sub handle_missing_link {
 
560
  my $kimage     = $_[0];       # Name of the symbolic link
 
561
  my $image_dest = $_[1];       # The directory the links goes into
 
562
  my $image_name = $_[2]; 
 
563
  my $src_dir    = $_[3]; 
 
564
  warn "handle_missing_link: kimage=$kimage, image_dest=$image_dest\n" .
 
565
    "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
 
566
 
 
567
  if ($no_symlink) {
 
568
    warn "cp -a --backup=t $realimageloc$image_name $kimage" if $DEBUG;
 
569
    my $ret = system("cp -a --backup=t " . $realimageloc .
 
570
                     "$image_name "   . " $kimage");
 
571
    if ($ret) {
 
572
      die("Failed to copy " . $realimageloc . "$image_name to "
 
573
          . $image_dest . "$kimage");
 
574
    }
 
575
  } 
 
576
  elsif ($reverse_symlink) {
 
577
    warn "mv -f $realimageloc$image_name $kimage" if $DEBUG;
 
578
    my $ret = system("mv -f " . $realimageloc . "$image_name "
 
579
                     . "$kimage");
 
580
    if ($ret) {
 
581
      die("Failed to move " . $realimageloc . "$image_name to "
 
582
          . $image_dest . "$kimage");
 
583
    }
 
584
  } 
 
585
  else {
 
586
    if (! $have_conffile) {
 
587
      my $ret;
 
588
      my $answer='';
 
589
      $do_symlink = "Yes";
 
590
 
 
591
      if (open(CONF, ">$CONF_LOC")) {
 
592
        print CONF "# Kernel Image management overrides\n";
 
593
        print CONF "# See kernel-img.conf(5) for details\n";
 
594
        if ($loader =~ /palo/i) {
 
595
          print CONF "link_in_boot = Yes\n";
 
596
          print CONF "do_symlinks = Yes\n";
 
597
          print CONF "relative_links = Yes\n";
 
598
          print CONF "do_bootloader = No\n";
 
599
        } else {
 
600
          print CONF "do_symlinks = $do_symlink\n";
 
601
        }
 
602
        close CONF;
 
603
      }
 
604
      $have_conffile = "Yes";
 
605
    }
 
606
  }
 
607
 
 
608
  if (! $no_symlink && $do_symlink =~ /Yes/i) {
 
609
    my $Old = $realimageloc;
 
610
    my $New = $image_dest;
 
611
    my $Name = "$image_name";
 
612
    my $Link_Dest = "$kimage";
 
613
 
 
614
    if ($reverse_symlink) {
 
615
      $Old = $image_dest;
 
616
      $New = $realimageloc;
 
617
      $Name = "$kimage";
 
618
      $Link_Dest = $realimageloc . "$image_name";
 
619
    }
 
620
    if (test_relative ('Old Dir' => $Old,
 
621
                       'New Dir' => $New,
 
622
                       'Test File' => $Name)) {
 
623
      $Old   =~ s|^/*||o;
 
624
    }
 
625
    # Special case is they are in the same dir
 
626
    my $rel_path = spath('Old' => "$Old", 'New' => "$New" );
 
627
    $Old ="" if $rel_path =~ m/^\s*$/o;
 
628
 
 
629
    symlink($Old . "$Name", "$Link_Dest") ||
 
630
      die("Failed to symbolic-link ${Old}$Name to $Link_Dest:$!");
 
631
    warn "ln -s ${Old}$Name $Link_Dest" if $DEBUG;
 
632
 
 
633
  }
 
634
}
 
635
 
 
636
# This routine handles the rest of the cases, where the user has requested 
 
637
# non-traditional handling, like using cp, or reverse symlinks, or hard links.
 
638
sub handle_non_symlinks {
 
639
  my $kimage     = $_[0];       # Name of the symbolic link
 
640
  my $image_dest = $_[1];       # The directory the links goes into
 
641
  my $image_name = $_[2]; 
 
642
  my $src_dir    = $_[3]; 
 
643
  warn "handle_non_link: kimage=$kimage, image_dest=$image_dest\n" .
 
644
    "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
 
645
 
 
646
  # Save the current image. We do this in all four cases
 
647
  rename("$kimage", "$kimage.$$") || 
 
648
    die "failed to move " . $image_dest . "$kimage:$!";
 
649
  warn "mv $kimage $kimage.$$" if $DEBUG;
 
650
 
 
651
  ##,#### 
 
652
  # case One
 
653
  #`####
 
654
  if ($no_symlink) {
 
655
    # Maybe /$image_dest is on a dos system?
 
656
    warn "cp -a --backup=t $realimageloc$image_name $kimage" if $DEBUG;
 
657
    my $ret = system("cp -a --backup=t " . $realimageloc
 
658
                     . "$image_name " . "$kimage");
 
659
    if ($ret) {
 
660
      if (-e "$kimage.$$") {
 
661
        rename("$kimage.$$", "$kimage");
 
662
        warn "mv $kimage.$$ $kimage" if $DEBUG;
 
663
      }
 
664
      die("Failed to copy " . $realimageloc . "$image_name to "
 
665
          . $image_dest . "$kimage");
 
666
    }
 
667
  }
 
668
  ##,#### 
 
669
  # case Two
 
670
  #`####
 
671
  elsif ($reverse_symlink) {  # Maybe /$image_dest is on a dos system?
 
672
    warn "mv -f  $realimageloc$image_name $kimage" if $DEBUG;
 
673
    my $ret = system("mv -f " . $realimageloc . "$image_name "
 
674
                     . $image_dest . "$kimage");
 
675
    if ($ret) {
 
676
      if (-e "$kimage.$$") {
 
677
        rename("$kimage.$$", "$kimage");
 
678
        warn "mv $kimage.$$ $kimage" if $DEBUG;
 
679
      }
 
680
      die("Failed to move " . $realimageloc . "$image_name to "
 
681
          . $image_dest . "$kimage");
 
682
    }
 
683
    my $Old = $image_dest;
 
684
    if (test_relative ('Old Dir' => $Old, 'New Dir' => $realimageloc,
 
685
                       'Test File' => "$kimage")) {
 
686
      $Old   =~ s|^/*||o;
 
687
    }
 
688
    # Special case is they are in the same dir
 
689
    my $rel_path = spath('Old' => "$Old", 'New' => "$realimageloc" );
 
690
    $Old ="" if $rel_path =~ m/^\s*$/o;
 
691
 
 
692
    if ($use_hard_links =~ m/YES/i) {
 
693
      warn "ln " . $Old . "$kimage " . $realimageloc . "$image_name" if $DEBUG;
 
694
      if (! link($Old . "$kimage", $realimageloc . "$image_name")) {
 
695
        warn "Could not link " . $image_dest .
 
696
          "$kimage to $image_name :$!";
 
697
      }
 
698
    }
 
699
    else {
 
700
      warn "ln -s " . $Old . "$kimage " . $realimageloc . "$image_name" if $DEBUG;
 
701
      if (! symlink($Old . "$kimage", $realimageloc . "$image_name")) {
 
702
        warn "Could not symlink " . $image_dest .
 
703
          "$kimage to $image_name :$!";
 
704
      }
 
705
    }
 
706
  }
 
707
  ##,####
 
708
  # case Three
 
709
  #`####
 
710
  elsif ($use_hard_links =~ m/YES/i ) {
 
711
    # Ok then. this ought to be a hard link, and hence fair game
 
712
    # don't clobber $kimage.old quite yet
 
713
    my $Old = $realimageloc;
 
714
    my $cwd;
 
715
    chomp($cwd=`pwd`);
 
716
    if (test_relative ('Old Dir' => $Old, 'New Dir' => $cwd,
 
717
                       'Test File' => "$image_name")) {
 
718
      $Old   =~ s|^/*||o;
 
719
    }
 
720
    # Special case is they are in the same dir
 
721
    my $rel_path = spath('Old' => "$Old", 'New' => "$cwd" );
 
722
    $Old ="" if $rel_path =~ m/^\s*$/o;
 
723
 
 
724
    warn "ln " . $Old . "$image_name " . "$kimage" if $DEBUG;
 
725
    if (! link($Old . "$image_name", "$kimage")) {
 
726
      warn "mv $kimage.$$ $kimage" if $DEBUG;
 
727
      rename("$kimage.$$", "$kimage");
 
728
      die("Failed to link " . $realimageloc . "$image_name to "
 
729
          . $image_dest . "$kimage");
 
730
    }
 
731
  }
 
732
  ##,####
 
733
  # case Four
 
734
  #`####
 
735
  else {
 
736
    # We just use cp
 
737
    warn "cp -a --backup=t $realimageloc$image_name $kimage" if $DEBUG;
 
738
    my $ret = system("cp -a --backup=t " . $realimageloc
 
739
                     . "$image_name " . "$kimage");
 
740
    if ($ret) {
 
741
      if (-e "$kimage.$$") {
 
742
        warn "mv $kimage.$$ $kimage" if $DEBUG;
 
743
        rename("$kimage.$$", "$kimage");
 
744
      }
 
745
      die("Failed to copy " . $realimageloc . "$image_name to "
 
746
          . $image_dest . "$kimage");
 
747
    }
 
748
  }
 
749
  # Ok, now we may clobber the previous .old file
 
750
  warn "mv $kimage.$$ $kimage.old if -e $kimage.$$" if $DEBUG;
 
751
  rename("$kimage.$$", "$kimage.old") if -e "$kimage.$$";
 
752
}
 
753
 
 
754
# This routine is responsible for setting up the symbolic links
 
755
# So, the actual kernel image lives in
 
756
# $realimageloc/$image_name (/boot/vmlinuz-2.6.12).
 
757
# This routine creates symbolic links in $image_dest/$kimage (/vmlinuz)
 
758
sub image_magic {
 
759
  my $kimage     = $_[0];       # Name of the symbolic link
 
760
  my $image_dest = $_[1];       # The directory the links goes into
 
761
  my $image_name = "$kimage-$version";
 
762
  my $src_dir    = $realimageloc;
 
763
  warn "image_magic: kimage=$kimage, image_dest=$image_dest\n" .
 
764
    "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
 
765
 
 
766
  # Well, in any case, if the destination (the symlink we are trying
 
767
  # to create) is a directory, we should do nothing, except throw a
 
768
  # diagnostic.
 
769
  if (-d "$kimage" ) {
 
770
    die ("Hmm. $kimage is a directory, which I did not expect.  I am\n" .
 
771
         "trying to create a symbolic link with that name linked to \n" .
 
772
         "$image_dest . Since a directory exists here, my assumptions \n" .
 
773
         "are way off, and I am aborting.\n" );
 
774
    exit (3);
 
775
  }
 
776
 
 
777
  if ($move_image) {   # Maybe $image_dest is in on dos, or something?
 
778
    #                   source dir,    link name,        dest dir
 
779
    really_move_image(  $realimageloc, $image_name, $image_dest);
 
780
    really_reverse_link($realimageloc, $image_name, $image_dest)
 
781
      if $reverse_symlink;
 
782
    return;
 
783
  }
 
784
 
 
785
  if (-l "$kimage") {           # There is a symbolic link
 
786
    warn "DEBUG: There is a symlink for $kimage\n" if $DEBUG;
 
787
    my $force_move = move_p($kimage, $image_dest, $image_name, $src_dir);
 
788
 
 
789
    if ($force_move) {
 
790
      really_move_link($kimage, $image_dest, $image_name, $src_dir);
 
791
    }
 
792
  }
 
793
  elsif (! -e "$kimage") {
 
794
    # Hmm. Pristine system? How can that be? Installing from scratch?
 
795
    # Or maybe the user does not want a symbolic link here.
 
796
    # Possibly they do not want a link here. (we should be in /
 
797
    # here[$image_dest, really]
 
798
    handle_missing_link($kimage, $image_dest, $image_name, $src_dir);
 
799
  }
 
800
  elsif (-e "$kimage" ) {
 
801
    # OK, $kimage exists -- but is not a link
 
802
    handle_non_symlinks($kimage, $image_dest, $image_name, $src_dir);
 
803
  }
 
804
}
 
805
 
 
806
######################################################################
 
807
######################################################################
 
808
######################################################################
 
809
######################################################################
 
810
 
 
811
# We may not have any modules installed
 
812
if ( -d "$modules_base/$version" ) {
 
813
  print STDERR "Running depmod.\n";
 
814
  my $ret = system("depmod -a $version");
 
815
  if ($ret) {
 
816
    print STDERR "Failed to run depmod\n";
 
817
    exit(1);
 
818
  }
 
819
}
 
820
 
 
821
 
 
822
 
 
823
sub find_initrd_tool {
 
824
  my $hostversion = shift;
 
825
  my $version = shift;
 
826
  print STDERR "Finding valid ramdisk creators.\n";
 
827
  my @ramdisks =
 
828
    grep {
 
829
      my $args = 
 
830
        "$_ " .
 
831
          "--supported-host-version=$hostversion " .
 
832
            "--supported-target-version=$version " .
 
833
              "1>/dev/null 2>&1"
 
834
                ;
 
835
      system($args) == 0;
 
836
    }
 
837
      split (/[:,\s]+/, $ramdisk);
 
838
}
 
839
 
 
840
# The initrd symlink should probably be in the same dir that the
 
841
# symlinks are in
 
842
if ($initrd) {
 
843
  my $success = 0;
 
844
 
 
845
  # Update-initramfs is called slightly different than mkinitrd and
 
846
  # mkinitramfs. XXX It should really be made compatible with this stuff
 
847
  # some how.
 
848
  my $upgrading = 1;
 
849
  if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/og) {
 
850
    $upgrading = 0;
 
851
  }
 
852
  my $ret = system("$ramdisk " . ($upgrading ? "-u" : "-c") . " -k " . $version . " >&2");
 
853
  $success = 1 unless $ret;
 
854
  die "Failed to create initrd image.\n" unless $success;
 
855
  if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/og) {
 
856
    image_magic("initrd.img", $image_dest);
 
857
  }
 
858
  else {
 
859
    if (! -e "initrd.img") {
 
860
      handle_missing_link("initrd.img", $image_dest, "initrd.img-$version",
 
861
                          $realimageloc);
 
862
    }
 
863
    else {
 
864
      print STDERR
 
865
        "Not updating initrd symbolic links since we are being updated/reinstalled \n";
 
866
      print STDERR
 
867
        "($ARGV[1] was configured last, according to dpkg)\n";
 
868
    }
 
869
  }
 
870
 
 
871
  if ($initrd && -l "initrd" ) {
 
872
    unlink "initrd";
 
873
  }
 
874
 
 
875
  if ($initrd && -l "$image_dir/initrd" && ! $link_in_boot) {
 
876
    unlink "$image_dir/initrd";
 
877
  }
 
878
}
 
879
else {                        # Not making an initrd emage
 
880
  if (-l "initrd.img") {
 
881
    # Ooh, last image was an initrd image? in any case, we should move it. 
 
882
    my $target = readlink "initrd.img";
 
883
    my $real_target = '';
 
884
    $real_target = abs_path($target) if defined ($target);
 
885
 
 
886
    if (!defined($target) || ! -f "$real_target") {
 
887
      # Eh. dangling link. can safely be removed.
 
888
      unlink("initrd.img");
 
889
    } else {
 
890
      if (-l "initrd.img.old" || ! -e "initrd.img.old" ) {
 
891
        rename("initrd.img", "initrd.img.old");
 
892
      } else {
 
893
        warn "initrd.img.old is not a symlink, not clobbering\n";
 
894
        unlink("initrd.img");
 
895
      }
 
896
    }
 
897
  }
 
898
}
 
899
 
 
900
# Warn of a reboot
 
901
if (-x $notifier) {
 
902
  system($notifier);
 
903
}
 
904
 
 
905
# Let programs know not to hibernate if the kernel that would be used for
 
906
# resume-from-hibernate is likely to differ from the currently running kernel.
 
907
system("mountpoint -q /var/run");
 
908
if ($? eq 0) {
 
909
        system("touch /var/run/do-not-hibernate");
 
910
}
 
911
 
 
912
# Only change the symlinks if we are not being upgraded
 
913
if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/og) {
 
914
  image_magic($kimage, $image_dest);
 
915
}
 
916
else {
 
917
  if (! -e "$kimage") {
 
918
    handle_missing_link($kimage, $image_dest, "$kimage-$version", 
 
919
                        $realimageloc);
 
920
  }
 
921
  else {
 
922
    print STDERR
 
923
      "Not updating image symbolic links since we are being updated/reinstalled \n";
 
924
    print STDERR
 
925
      "($ARGV[1] was configured last, according to dpkg)\n";
 
926
  }
 
927
}
 
928
 
 
929
# We used to have System.* files in /
 
930
if (-e "/System.map" || -e "/System.old") {
 
931
  unlink '/System.map' if -e '/System.map';
 
932
  unlink '/System.old' if -e '/System.old';
 
933
}
 
934
 
 
935
# creating some info about kernel and initrd
 
936
if ($DEBUG) {
 
937
  my $ksize=sprintf("%.0f",(stat($realimageloc .
 
938
                                 "$kimage-$version"))[7]/1024)."kB";
 
939
  my $initrdsize='';
 
940
  if ($initrd) {
 
941
    $initrdsize=sprintf("%.0f",(stat($realimageloc .
 
942
                                     "initrd.img-$version"))[7]/1024)."kB";
 
943
  }
 
944
 
 
945
  print STDERR <<"EOMSG";
 
946
A new kernel image has been installed at $realimageloc$kimage-$version
 
947
 (Size: $ksize)
 
948
 
 
949
Symbolic links, unless otherwise specified, can be found in $image_dest
 
950
 
 
951
EOMSG
 
952
  ;
 
953
 
 
954
  if ($initrd) {
 
955
    print STDERR <<"EOMSGA";
 
956
 
 
957
 Initial rootdisk image: ${realimageloc}initrd.img-$version (Size: $initrdsize)
 
958
EOMSGA
 
959
    ;
 
960
  }
 
961
}
 
962
 
 
963
# set the env var stem
 
964
$ENV{'STEM'} = "linux";
 
965
sub exec_script {
 
966
  my $type   = shift;
 
967
  my $script = shift;
 
968
  print STDERR "Running $type hook script $script.\n";
 
969
  system ("$script $version $realimageloc$kimage-$version") &&
 
970
    print STDERR "User $type hook script [$script] ";
 
971
  if ($?) {
 
972
    if ($? == -1) {
 
973
      print STDERR "failed to execute: $!\n";
 
974
    }
 
975
    elsif ($? & 127) {
 
976
      printf STDERR "died with signal %d, %s coredump\n",
 
977
        ($? & 127),  ($? & 128) ? 'with' : 'without';
 
978
    }
 
979
    else {
 
980
      printf STDERR "exited with value %d\n", $? >> 8;
 
981
    }
 
982
    exit $? >> 8;
 
983
  }
 
984
}
 
985
sub run_hook {
 
986
  my $type   = shift;
 
987
  my $script = shift;
 
988
  if ($script =~ m,^/,) {
 
989
    # Full path provided for the hook script
 
990
    if (-x "$script") {
 
991
      &exec_script($type,$script);
 
992
    }
 
993
    else {
 
994
      die "The provided $type hook script [$script] could not be run.\n";
 
995
    }
 
996
  }
 
997
  else {
 
998
    # Look for it in a safe path
 
999
    for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
 
1000
      if (-x "$path/$script") {
 
1001
        &exec_script($type, "$path/$script");
 
1002
        return 0;
 
1003
      }
 
1004
    }
 
1005
    # No luck
 
1006
    print STDERR "Could not find $type hook script [$script].\n";
 
1007
    die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
 
1008
  }
 
1009
}
 
1010
 
 
1011
my $options;
 
1012
for (@ARGV) {
 
1013
        s,','\\'',g;
 
1014
        $options .= " '$_'";
 
1015
}
 
1016
$ENV{'DEB_MAINT_PARAMS'}="$options";
 
1017
 
 
1018
## Run user hook script here, if any
 
1019
if ($postinst_hook) {
 
1020
  &run_hook("postinst", $postinst_hook);
 
1021
}
 
1022
 
 
1023
if (-d "/etc/kernel/postinst.d") {
 
1024
  print STDERR "Examining /etc/kernel/postinst.d.\n";
 
1025
  system ("run-parts --verbose --exit-on-error --arg=$version " .
 
1026
          "--arg=$realimageloc$kimage-$version " .
 
1027
          "/etc/kernel/postinst.d") &&
 
1028
            die "Failed to process /etc/kernel/postinst.d";
 
1029
}
 
1030
 
 
1031
if (-d "/etc/kernel/postinst.d/$version") {
 
1032
  print STDERR "Examining /etc/kernel/postinst.d/$version.\n";
 
1033
  system ("run-parts --verbose --exit-on-error --arg=$version " .
 
1034
          "--arg=$realimageloc$kimage-$version " .
 
1035
          "/etc/kernel/postinst.d/$version") &&
 
1036
            die "Failed to process /etc/kernel/postinst.d/$version";
 
1037
}
 
1038
 
 
1039
LOADER: {
 
1040
  last unless $do_boot_enable; # Exit if explicitly asked to
 
1041
 
 
1042
  last if $loader =~ /silo/i; # SILO does not have to be executed.
 
1043
  last if $loader =~ /yaboot/i; # yaboot does not have to be executed.
 
1044
  last if $loader =~ /milo/i; # MILO does not have to be executed.
 
1045
  last if $loader =~ /nettrom/i; # NETTROM does not have to be executed.
 
1046
  last if $loader =~ /arcboot/i; # ARCBOOT does not have to be executed.
 
1047
  last if $loader =~ /delo/i; # DELO does not have to be executed.
 
1048
  last if $loader =~ /quik/i; # maintainer asked quik invocation to be ignored
 
1049
 
 
1050
  last unless $loaderloc;
 
1051
  last unless -x $loaderloc;
 
1052
  last unless $do_bootloader;
 
1053
 
 
1054
  if (-T "/etc/$loader.conf") {
 
1055
    # Trust and use the existing lilo.conf.
 
1056
    print STDERR "You already have a $Loader configuration in /etc/$loader.conf\n";
 
1057
    my $ret = &run_lilo();
 
1058
    exit $ret if $ret;
 
1059
  }
 
1060
}
 
1061
 
 
1062
 
 
1063
sub run_lilo (){
 
1064
  my $ret;
 
1065
  # Try and figure out if the user really wants lilo to be run --
 
1066
  # since the default is to run the boot laoder, which is ! grub -- but
 
1067
  # the user may be using grub now, and not changed the default.
 
1068
 
 
1069
  # So, if the user has explicitly asked for the loader to be run, or
 
1070
  # if there is no postinst hook, or if there is no grub installed --
 
1071
  # we are OK. Or else, we ask.
 
1072
  if ($explicit_do_loader || (! ($postinst_hook && -x '/usr/sbin/grub')))  {
 
1073
    print STDERR "Running boot loader as requested\n";
 
1074
  } else {
 
1075
    print STDERR "Ok, not running $loader\n";
 
1076
  }
 
1077
  if ($loader =~ /^lilo/io or $loader =~ /vmelilo/io) {
 
1078
    print STDERR "Testing $loader.conf ... \n";
 
1079
    unlink $temp_file_name;     # security
 
1080
    $ret = system("$loaderloc -t >$temp_file_name 2>&1");
 
1081
    if ($ret) {
 
1082
      print STDERR "Boot loader test failed\n";
 
1083
      return $ret;
 
1084
    }
 
1085
    unlink "$temp_file_name";
 
1086
    print STDERR "Testing successful.\n";
 
1087
    print STDERR "Installing the ";
 
1088
    print STDERR "partition " if $loader =~ /^lilo/io;
 
1089
    print STDERR "boot sector... \n";
 
1090
  }
 
1091
 
 
1092
  print STDERR "Running $loaderloc  ... \n";
 
1093
  if ($loader =~ /^elilo/io) {
 
1094
    $ret = system("$loaderloc 2>&1 | tee $temp_file_name");
 
1095
  } else {
 
1096
    $ret = system("$loaderloc >$temp_file_name 2>&1");
 
1097
  }
 
1098
  if ($ret) {
 
1099
    print STDERR "Boot loader failed to run\n";
 
1100
    return $ret;
 
1101
  }
 
1102
  unlink $temp_file_name;
 
1103
  print STDERR "Installation successful.\n";
 
1104
  return 0;
 
1105
}
 
1106
 
 
1107
exit 0;
 
1108
 
 
1109
__END__
 
1110