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