]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - debian/control-scripts/postinst
2 # OriginalAuthor : Manoj Srivastava ( srivasta@pilgrim.umass.edu )
4 # Customized for Ubuntu by: Ben Collins <bcollins@ubuntu.com>
6 #use strict; #for debugging
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';
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;
54 # This should not point to /tmp, because of security risks.
55 my $temp_file_name = "/var/log/$loader" . "_log.$$";
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
66 my $modules_base = '/lib/modules';
67 my $CONF_LOC = '/etc/kernel-img.conf';
69 # Ignore all invocations except when called on to configure.
70 exit 0 unless $ARGV[0] =~ /configure/;
74 # Do some preliminary sanity checks here to ensure we actually have an
76 chdir('/') or die "could not chdir to /:$!\n";
77 die "Internal Error: ($image_dir) is not a directory!\n"
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;
86 if (-r
"$CONF_LOC" && -f
"$CONF_LOC" ) {
87 if (open(CONF
, "$CONF_LOC")) {
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;
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;
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;
141 $have_conffile = "Yes";
145 $initrd = '' if (! -x
"$ramdisk");
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$//;
154 $image_dest = "/$image_dir/"; # same as realimageloc
157 # Tack on at least one trainling /
158 $image_dest = "$image_dest/";
159 $image_dest =~ s
|^/*|/|o
;
160 $image_dest =~ s
|/+$|/|o
;
162 if (! -d
"$image_dest") {
163 die "Expected Image Destination dir ($image_dest) to be a valid directory!\n";
167 if (!($do_bootfloppy || $do_bootloader)) {
168 $do_boot_enable = '';
170 if ($do_symlink && $no_symlink) {
171 warn "Both do_symlinks and no_symlinks options enabled; disabling no_symlinks\n";
175 # most of our work is done in $image_dest (nominally /)
176 chdir("$image_dest") or die "could not chdir to $image_dest:$!\n";
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
186 $ENV{KERNEL_ARCH
}=$kernel_arch if $kernel_arch;
189 die "Internal Error: Could not find image (" . $realimageloc
190 . "$kimage-$version)\n" unless -e
$realimageloc
191 . "$kimage-$version";
193 # search for the boot loader in the path
195 ($loader_exec = $loader) =~ s
|.*/||;
196 my ($loaderloc) = grep -x
, map "$_/$loader_exec",
197 map { length($_) ?
$_ : "." } split /:/, $ENV{PATH
};
200 ######################################################################
201 ######################################################################
202 ########### Test whether a relative symlinkwould be OK #######
203 ######################################################################
204 ######################################################################
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'};
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'};
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'}) {
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'}"
235 warn "Test relative: testing $params{'Old Dir'} -> $params{'New Dir'}"
238 chdir ($params{'New Dir'}) or die "Could not chdir to $params{'New Dir'}:$!";
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'}) {
247 $ok = 1; # well, backward compatibility
250 chdir ($cwd) or die "Could not chdir to $params{'New Dir'}:$!";
254 ######################################################################
255 ######################################################################
257 ######################################################################
258 ######################################################################
259 # sub CanonicalizePath {
260 # my $path = join '/', @_;
261 # my @work = split '/', $path;
265 # if (@work && $work[0] eq "") {
266 # $is_absolute = 1; shift @work;
270 # my $seg = shift @work;
271 # if ($seg eq "." || $seg eq "") {
273 # elsif ($seg eq "..") {
274 # if (@out && $out[-1] ne "..") {
278 # # Leading "..", or "../..", etc.
287 # unshift @out, "" if $is_absolute;
288 # return join('/', @out);
290 ######################################################################
291 ######################################################################
293 ######################################################################
294 ######################################################################
299 die "Missing Required paramater 'Old'" unless $params{'Old'};
300 die "Missing Required paramater 'New'" unless $params{'New'};
302 my @olddir = split '/', `readlink -q -m $params{'Old'}`;
303 my @newdir = split '/', `readlink -q -m $params{'New'}`;
304 my @outdir = @olddir;
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;
313 if ($#newdir > $#olddir) {
314 for ($i=0; $i < $#newdir; $i++) {
315 unshift @outdir, "..";
318 return join ('/', @outdir);
320 ######################################################################
321 ######################################################################
323 ######################################################################
324 ######################################################################
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
{
335 my $dest_dir = $_[2];
337 warn "Really move image: src_dir=$src_dir, target=$target,\n destdir=$dest_dir"
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;
345 warn "mv -f $src_dir$target $target" if $DEBUG;
346 my $ret = system("mv -f " . $src_dir . "$target " .
349 die("Failed to move " . $src_dir . "$target to "
350 . $dest_dir . "$target");
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;
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
{
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;
374 if (test_relative
('Old Dir' => $Old, 'New Dir' => $src_dir,
375 'Test File' => "$link_name")) {
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;
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 .
386 warn "ln " . $Old . "$link_name " . $src_dir . "$link_name" if $DEBUG;
389 symlink($Old . "$link_name", $src_dir . "$link_name") ||
390 die("Failed to symbolic-link " . $dest_dir . "$link_name to " . $src_dir
392 warn "ln -s " . $Old . "$link_name " . $src_dir . "$link_name" if $DEBUG;
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
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];
406 warn "Move?: kimage=$kimage, image_dest=$image_dest, \n" .
407 "\timage_name=$image_name, src_dir=$src_dir" if $DEBUG;
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
420 warn "DEBUG: OK. We found symlink, and we should have a symlink here.\n"
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);
427 if (!defined($vmlinuz_target) || ! -f
"$real_target") {
428 # what, a dangling symlink?
429 warn "The link " . $image_dest . "$kimage is a dangling link" .
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;
440 if ($vmlinuz_target !~ m
|^/|o
) {
441 $vmlinuz_target = $cwd . "/" . $vmlinuz_target;
442 $vmlinuz_target =~ s
|/+|/|o
;
444 $vmlinuz_target = `readlink -q -m $vmlinuz_target`;
446 if ("$vmlinuz_target" ne "$target") {
447 warn "DEBUG: We need to handle this.\n" if $DEBUG;
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);
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;
461 $old_target = `readlink -q
-m
$old_target`;
462 if ("$old_target" ne "$target") {
464 warn "DEBUG: Old link ($old_target) does not point to us ($target)\n"
467 else { # The .old points to the current
468 warn "$kimage.old --> $target -- doing nothing";
473 warn "DEBUG: Well, the old link does not exist -- so we move\n"
479 warn "DEBUG: No .old link -- OK to move\n"
485 warn "DEBUG: ok, minimal swap is no-- so we move.\n"
490 else { # already have proper link
491 warn "$kimage($vmlinuz_target) points to $target ($real_target) -- doing nothing";
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
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];
506 warn "really_move_link: kimage=$kimage, image_dest=$image_dest\n" .
507 "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
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;
517 if (test_relative
('Old Dir' => $Old, 'New Dir' => $cwd,
518 'Test File' => "$image_name")) {
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;
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}:$!");
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}:$!");
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;
548 warn "$kimage.old is not a symlink, not clobbering\n";
549 warn "rm $kimage.$$";
550 unlink "$kimage.$$" if $DEBUG;
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];
564 warn "handle_missing_link: kimage=$kimage, image_dest=$image_dest\n" .
565 "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
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");
572 die("Failed to copy " . $realimageloc . "$image_name to "
573 . $image_dest . "$kimage");
576 elsif ($reverse_symlink) {
577 warn "mv -f $realimageloc$image_name $kimage" if $DEBUG;
578 my $ret = system("mv -f " . $realimageloc . "$image_name "
581 die("Failed to move " . $realimageloc . "$image_name to "
582 . $image_dest . "$kimage");
586 if (! $have_conffile) {
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";
600 print CONF
"do_symlinks = $do_symlink\n";
604 $have_conffile = "Yes";
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";
614 if ($reverse_symlink) {
616 $New = $realimageloc;
618 $Link_Dest = $realimageloc . "$image_name";
620 if (test_relative
('Old Dir' => $Old,
622 'Test File' => $Name)) {
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;
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;
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];
643 warn "handle_non_link: kimage=$kimage, image_dest=$image_dest\n" .
644 "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
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;
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");
660 if (-e
"$kimage.$$") {
661 rename("$kimage.$$", "$kimage");
662 warn "mv $kimage.$$ $kimage" if $DEBUG;
664 die("Failed to copy " . $realimageloc . "$image_name to "
665 . $image_dest . "$kimage");
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");
676 if (-e
"$kimage.$$") {
677 rename("$kimage.$$", "$kimage");
678 warn "mv $kimage.$$ $kimage" if $DEBUG;
680 die("Failed to move " . $realimageloc . "$image_name to "
681 . $image_dest . "$kimage");
683 my $Old = $image_dest;
684 if (test_relative
('Old Dir' => $Old, 'New Dir' => $realimageloc,
685 'Test File' => "$kimage")) {
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;
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 :$!";
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 :$!";
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;
716 if (test_relative
('Old Dir' => $Old, 'New Dir' => $cwd,
717 'Test File' => "$image_name")) {
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;
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");
735 elsif ($do_symlink) {
736 # Ok then. this ought to be a symlink, and hence fair game
737 # don't clobber $kimage.old quite yet
738 my $Old = $realimageloc;
741 if (test_relative
('Old Dir' => $Old, 'New Dir' => $cwd,
742 'Test File' => "$image_name")) {
745 # Special case is they are in the same dir
746 my $rel_path = spath
('Old' => "$Old", 'New' => "$cwd" );
747 $Old ="" if $rel_path =~ m/^\s*$/o;
749 warn "symlink " . $Old . "$image_name " . "$kimage" if $DEBUG;
750 if (! symlink($Old . "$image_name", "$kimage")) {
751 warn "mv $kimage.$$ $kimage" if $DEBUG;
752 rename("$kimage.$$", "$kimage");
753 die("Failed to link " . $realimageloc . "$image_name to "
754 . $image_dest . "$kimage");
762 warn "cp -a --backup=t $realimageloc$image_name $kimage" if $DEBUG;
763 my $ret = system("cp -a --backup=t " . $realimageloc
764 . "$image_name " . "$kimage");
766 if (-e
"$kimage.$$") {
767 warn "mv $kimage.$$ $kimage" if $DEBUG;
768 rename("$kimage.$$", "$kimage");
770 die("Failed to copy " . $realimageloc . "$image_name to "
771 . $image_dest . "$kimage");
774 # Ok, now we may clobber the previous .old file
775 warn "mv $kimage.$$ $kimage.old if -e $kimage.$$" if $DEBUG;
776 rename("$kimage.$$", "$kimage.old") if -e
"$kimage.$$";
779 # This routine is responsible for setting up the symbolic links
780 # So, the actual kernel image lives in
781 # $realimageloc/$image_name (/boot/vmlinuz-2.6.12).
782 # This routine creates symbolic links in $image_dest/$kimage (/vmlinuz)
784 my $kimage = $_[0]; # Name of the symbolic link
785 my $image_dest = $_[1]; # The directory the links goes into
786 my $image_name = "$kimage-$version";
787 my $src_dir = $realimageloc;
788 warn "image_magic: kimage=$kimage, image_dest=$image_dest\n" .
789 "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
791 # Well, in any case, if the destination (the symlink we are trying
792 # to create) is a directory, we should do nothing, except throw a
795 die ("Hmm. $kimage is a directory, which I did not expect. I am\n" .
796 "trying to create a symbolic link with that name linked to \n" .
797 "$image_dest . Since a directory exists here, my assumptions \n" .
798 "are way off, and I am aborting.\n" );
802 if ($move_image) { # Maybe $image_dest is in on dos, or something?
803 # source dir, link name, dest dir
804 really_move_image
( $realimageloc, $image_name, $image_dest);
805 really_reverse_link
($realimageloc, $image_name, $image_dest)
810 if (-l
"$kimage") { # There is a symbolic link
811 warn "DEBUG: There is a symlink for $kimage\n" if $DEBUG;
812 my $force_move = move_p
($kimage, $image_dest, $image_name, $src_dir);
815 really_move_link
($kimage, $image_dest, $image_name, $src_dir);
818 elsif (! -e
"$kimage") {
819 # Hmm. Pristine system? How can that be? Installing from scratch?
820 # Or maybe the user does not want a symbolic link here.
821 # Possibly they do not want a link here. (we should be in /
822 # here[$image_dest, really]
823 handle_missing_link
($kimage, $image_dest, $image_name, $src_dir);
825 elsif (-e
"$kimage" ) {
826 # OK, $kimage exists -- but is not a link
827 handle_non_symlinks
($kimage, $image_dest, $image_name, $src_dir);
831 ######################################################################
832 ######################################################################
833 ######################################################################
834 ######################################################################
836 # We may not have any modules installed
837 if ( -d
"$modules_base/$version" ) {
838 print STDERR
"Running depmod.\n";
839 my $ret = system("depmod -a $version");
841 print STDERR
"Failed to run depmod\n";
848 sub find_initrd_tool
{
849 my $hostversion = shift;
851 print STDERR
"Finding valid ramdisk creators.\n";
856 "--supported-host-version=$hostversion " .
857 "--supported-target-version=$version " .
862 split (/[:,\s]+/, $ramdisk);
865 # The initrd symlink should probably be in the same dir that the
870 # Update-initramfs is called slightly different than mkinitrd and
871 # mkinitramfs. XXX It should really be made compatible with this stuff
874 if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/og) {
877 my $ret = system("$ramdisk " . ($upgrading ?
"-u" : "-c") . " -k " . $version . " >&2");
878 $success = 1 unless $ret;
879 die "Failed to create initrd image.\n" unless $success;
880 if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/og) {
881 image_magic
("initrd.img", $image_dest);
886 handle_missing_link
("initrd.img", $image_dest, "initrd.img-$version",
891 "Not updating initrd symbolic links since we are being updated/reinstalled \n";
893 "($ARGV[1] was configured last, according to dpkg)\n";
897 if ($initrd && -l
"initrd" ) {
901 if ($initrd && -l
"$image_dir/initrd" && ! $link_in_boot) {
902 unlink "$image_dir/initrd";
905 else { # Not making an initrd emage
906 if (-l
"initrd.img") {
907 # Ooh, last image was an initrd image? in any case, we should move it.
908 my $target = readlink "initrd.img";
909 my $real_target = '';
910 $real_target = abs_path
($target) if defined ($target);
912 if (!defined($target) || ! -f
"$real_target") {
913 # Eh. dangling link. can safely be removed.
914 unlink("initrd.img");
916 if (-l
"initrd.img.old" || ! -e
"initrd.img.old" ) {
917 rename("initrd.img", "initrd.img.old");
919 warn "initrd.img.old is not a symlink, not clobbering\n";
920 unlink("initrd.img");
931 # Let programs know not to hibernate if the kernel that would be used for
932 # resume-from-hibernate is likely to differ from the currently running kernel.
933 system("mountpoint -q /var/run");
935 system("touch /var/run/do-not-hibernate");
938 # Only change the symlinks if we are not being upgraded
939 if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/og) {
940 image_magic
($kimage, $image_dest);
945 handle_missing_link
($kimage, $image_dest, "$kimage-$version",
950 "Not updating image symbolic links since we are being updated/reinstalled \n";
952 "($ARGV[1] was configured last, according to dpkg)\n";
956 # We used to have System.* files in /
957 if (-e
"/System.map" || -e
"/System.old") {
958 unlink '/System.map' if -e
'/System.map';
959 unlink '/System.old' if -e
'/System.old';
962 # creating some info about kernel and initrd
964 my $ksize=sprintf("%.0f",(stat($realimageloc .
965 "$kimage-$version"))[7]/1024)."kB";
968 $initrdsize=sprintf("%.0f",(stat($realimageloc .
969 "initrd.img-$version"))[7]/1024)."kB";
972 print STDERR
<<"EOMSG";
973 A new kernel image has been installed at $realimageloc$kimage-$version
976 Symbolic links, unless otherwise specified, can be found in $image_dest
982 print STDERR
<<"EOMSGA";
984 Initial rootdisk image: ${realimageloc}initrd.img-$version (Size: $initrdsize)
990 # set the env var stem
991 $ENV{'STEM'} = "linux";
995 print STDERR
"Running $type hook script $script.\n";
996 system ("$script $version $realimageloc$kimage-$version") &&
997 print STDERR
"User $type hook script [$script] ";
1000 print STDERR
"failed to execute: $!\n";
1003 printf STDERR
"died with signal %d, %s coredump\n",
1004 ($? & 127), ($? & 128) ?
'with' : 'without';
1007 printf STDERR
"exited with value %d\n", $? >> 8;
1015 if ($script =~ m
,^/,) {
1016 # Full path provided for the hook script
1018 &exec_script
($type,$script);
1021 die "The provided $type hook script [$script] could not be run.\n";
1025 # Look for it in a safe path
1026 for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
1027 if (-x
"$path/$script") {
1028 &exec_script
($type, "$path/$script");
1033 print STDERR
"Could not find $type hook script [$script].\n";
1034 die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
1041 $options .= " '$_'";
1043 $ENV{'DEB_MAINT_PARAMS'}="$options";
1045 ## Run user hook script here, if any
1046 if ($postinst_hook) {
1047 &run_hook
("postinst", $postinst_hook);
1050 if (-d
"/etc/kernel/postinst.d") {
1051 print STDERR
"Examining /etc/kernel/postinst.d.\n";
1052 system ("run-parts --verbose --exit-on-error --arg=$version " .
1053 "--arg=$realimageloc$kimage-$version " .
1054 "/etc/kernel/postinst.d") &&
1055 die "Failed to process /etc/kernel/postinst.d";
1058 if (-d
"/etc/kernel/postinst.d/$version") {
1059 print STDERR
"Examining /etc/kernel/postinst.d/$version.\n";
1060 system ("run-parts --verbose --exit-on-error --arg=$version " .
1061 "--arg=$realimageloc$kimage-$version " .
1062 "/etc/kernel/postinst.d/$version") &&
1063 die "Failed to process /etc/kernel/postinst.d/$version";
1067 last unless $do_boot_enable; # Exit if explicitly asked to
1069 last if $loader =~ /silo/i; # SILO does not have to be executed.
1070 last if $loader =~ /yaboot/i; # yaboot does not have to be executed.
1071 last if $loader =~ /milo/i; # MILO does not have to be executed.
1072 last if $loader =~ /nettrom/i; # NETTROM does not have to be executed.
1073 last if $loader =~ /arcboot/i; # ARCBOOT does not have to be executed.
1074 last if $loader =~ /delo/i; # DELO does not have to be executed.
1075 last if $loader =~ /quik/i; # maintainer asked quik invocation to be ignored
1077 last unless $loaderloc;
1078 last unless -x
$loaderloc;
1079 last unless $do_bootloader;
1081 if (-T
"/etc/$loader.conf") {
1082 # Trust and use the existing lilo.conf.
1083 print STDERR
"You already have a $Loader configuration in /etc/$loader.conf\n";
1084 my $ret = &run_lilo
();
1092 # Try and figure out if the user really wants lilo to be run --
1093 # since the default is to run the boot laoder, which is ! grub -- but
1094 # the user may be using grub now, and not changed the default.
1096 # So, if the user has explicitly asked for the loader to be run, or
1097 # if there is no postinst hook, or if there is no grub installed --
1098 # we are OK. Or else, we ask.
1099 if ($explicit_do_loader || (! ($postinst_hook && -x
'/usr/sbin/grub'))) {
1100 print STDERR
"Running boot loader as requested\n";
1102 print STDERR
"Ok, not running $loader\n";
1104 if ($loader =~ /^lilo/io or $loader =~ /vmelilo/io) {
1105 print STDERR
"Testing $loader.conf ... \n";
1106 unlink $temp_file_name; # security
1107 $ret = system("$loaderloc -t >$temp_file_name 2>&1");
1109 print STDERR
"Boot loader test failed\n";
1112 unlink "$temp_file_name";
1113 print STDERR
"Testing successful.\n";
1114 print STDERR
"Installing the ";
1115 print STDERR
"partition " if $loader =~ /^lilo/io;
1116 print STDERR
"boot sector... \n";
1119 print STDERR
"Running $loaderloc ... \n";
1120 if ($loader =~ /^elilo/io) {
1121 $ret = system("$loaderloc 2>&1 | tee $temp_file_name");
1123 $ret = system("$loaderloc >$temp_file_name 2>&1");
1126 print STDERR
"Boot loader failed to run\n";
1129 unlink $temp_file_name;
1130 print STDERR
"Installation successful.\n";