]>
Commit | Line | Data |
---|---|---|
0d34a427 LO |
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 | ||
2c21160b | 145 | $initrd = '' if (! -x "$ramdisk"); |
0d34a427 LO |
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 Five!?! | |
734 | #`#### | |
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; | |
739 | my $cwd; | |
740 | chomp($cwd=`pwd`); | |
741 | if (test_relative ('Old Dir' => $Old, 'New Dir' => $cwd, | |
742 | 'Test File' => "$image_name")) { | |
743 | $Old =~ s|^/*||o; | |
744 | } | |
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; | |
748 | ||
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"); | |
755 | } | |
756 | } | |
757 | ##,#### | |
758 | # case Four | |
759 | #`#### | |
760 | else { | |
761 | # We just use cp | |
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"); | |
765 | if ($ret) { | |
766 | if (-e "$kimage.$$") { | |
767 | warn "mv $kimage.$$ $kimage" if $DEBUG; | |
768 | rename("$kimage.$$", "$kimage"); | |
769 | } | |
770 | die("Failed to copy " . $realimageloc . "$image_name to " | |
771 | . $image_dest . "$kimage"); | |
772 | } | |
773 | } | |
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.$$"; | |
777 | } | |
778 | ||
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) | |
783 | sub image_magic { | |
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; | |
790 | ||
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 | |
793 | # diagnostic. | |
794 | if (-d "$kimage" ) { | |
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" ); | |
799 | exit (3); | |
800 | } | |
801 | ||
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) | |
806 | if $reverse_symlink; | |
807 | return; | |
808 | } | |
809 | ||
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); | |
813 | ||
814 | if ($force_move) { | |
815 | really_move_link($kimage, $image_dest, $image_name, $src_dir); | |
816 | } | |
817 | } | |
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); | |
824 | } | |
825 | elsif (-e "$kimage" ) { | |
826 | # OK, $kimage exists -- but is not a link | |
827 | handle_non_symlinks($kimage, $image_dest, $image_name, $src_dir); | |
828 | } | |
829 | } | |
830 | ||
831 | ###################################################################### | |
832 | ###################################################################### | |
833 | ###################################################################### | |
834 | ###################################################################### | |
835 | ||
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"); | |
840 | if ($ret) { | |
841 | print STDERR "Failed to run depmod\n"; | |
842 | exit(1); | |
843 | } | |
844 | } | |
845 | ||
846 | ||
847 | ||
848 | sub find_initrd_tool { | |
849 | my $hostversion = shift; | |
850 | my $version = shift; | |
851 | print STDERR "Finding valid ramdisk creators.\n"; | |
852 | my @ramdisks = | |
853 | grep { | |
854 | my $args = | |
855 | "$_ " . | |
856 | "--supported-host-version=$hostversion " . | |
857 | "--supported-target-version=$version " . | |
858 | "1>/dev/null 2>&1" | |
859 | ; | |
860 | system($args) == 0; | |
861 | } | |
862 | split (/[:,\s]+/, $ramdisk); | |
863 | } | |
864 | ||
865 | # The initrd symlink should probably be in the same dir that the | |
866 | # symlinks are in | |
867 | if ($initrd) { | |
868 | my $success = 0; | |
869 | ||
870 | # Update-initramfs is called slightly different than mkinitrd and | |
871 | # mkinitramfs. XXX It should really be made compatible with this stuff | |
872 | # some how. | |
873 | my $upgrading = 1; | |
874 | if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/og) { | |
875 | $upgrading = 0; | |
876 | } | |
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); | |
882 | } | |
883 | else { | |
884 | lstat("initrd.img"); | |
885 | if (! -e _) { | |
886 | handle_missing_link("initrd.img", $image_dest, "initrd.img-$version", | |
887 | $realimageloc); | |
888 | } | |
889 | else { | |
890 | print STDERR | |
891 | "Not updating initrd symbolic links since we are being updated/reinstalled \n"; | |
892 | print STDERR | |
893 | "($ARGV[1] was configured last, according to dpkg)\n"; | |
894 | } | |
895 | } | |
896 | ||
897 | if ($initrd && -l "initrd" ) { | |
898 | unlink "initrd"; | |
899 | } | |
900 | ||
901 | if ($initrd && -l "$image_dir/initrd" && ! $link_in_boot) { | |
902 | unlink "$image_dir/initrd"; | |
903 | } | |
904 | } | |
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); | |
911 | ||
912 | if (!defined($target) || ! -f "$real_target") { | |
913 | # Eh. dangling link. can safely be removed. | |
914 | unlink("initrd.img"); | |
915 | } else { | |
916 | if (-l "initrd.img.old" || ! -e "initrd.img.old" ) { | |
917 | rename("initrd.img", "initrd.img.old"); | |
918 | } else { | |
919 | warn "initrd.img.old is not a symlink, not clobbering\n"; | |
920 | unlink("initrd.img"); | |
921 | } | |
922 | } | |
923 | } | |
924 | } | |
925 | ||
926 | # Warn of a reboot | |
927 | if (-x $notifier) { | |
928 | system($notifier); | |
929 | } | |
930 | ||
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"); | |
934 | if ($? eq 0) { | |
935 | system("touch /var/run/do-not-hibernate"); | |
936 | } | |
937 | ||
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); | |
941 | } | |
942 | else { | |
943 | lstat("$kimage"); | |
944 | if (! -e _) { | |
945 | handle_missing_link($kimage, $image_dest, "$kimage-$version", | |
946 | $realimageloc); | |
947 | } | |
948 | else { | |
949 | print STDERR | |
950 | "Not updating image symbolic links since we are being updated/reinstalled \n"; | |
951 | print STDERR | |
952 | "($ARGV[1] was configured last, according to dpkg)\n"; | |
953 | } | |
954 | } | |
955 | ||
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'; | |
960 | } | |
961 | ||
962 | # creating some info about kernel and initrd | |
963 | if ($DEBUG) { | |
964 | my $ksize=sprintf("%.0f",(stat($realimageloc . | |
965 | "$kimage-$version"))[7]/1024)."kB"; | |
966 | my $initrdsize=''; | |
967 | if ($initrd) { | |
968 | $initrdsize=sprintf("%.0f",(stat($realimageloc . | |
969 | "initrd.img-$version"))[7]/1024)."kB"; | |
970 | } | |
971 | ||
972 | print STDERR <<"EOMSG"; | |
973 | A new kernel image has been installed at $realimageloc$kimage-$version | |
974 | (Size: $ksize) | |
975 | ||
976 | Symbolic links, unless otherwise specified, can be found in $image_dest | |
977 | ||
978 | EOMSG | |
979 | ; | |
980 | ||
981 | if ($initrd) { | |
982 | print STDERR <<"EOMSGA"; | |
983 | ||
984 | Initial rootdisk image: ${realimageloc}initrd.img-$version (Size: $initrdsize) | |
985 | EOMSGA | |
986 | ; | |
987 | } | |
988 | } | |
989 | ||
990 | # set the env var stem | |
991 | $ENV{'STEM'} = "linux"; | |
992 | sub exec_script { | |
993 | my $type = shift; | |
994 | my $script = shift; | |
995 | print STDERR "Running $type hook script $script.\n"; | |
996 | system ("$script $version $realimageloc$kimage-$version") && | |
997 | print STDERR "User $type hook script [$script] "; | |
998 | if ($?) { | |
999 | if ($? == -1) { | |
1000 | print STDERR "failed to execute: $!\n"; | |
1001 | } | |
1002 | elsif ($? & 127) { | |
1003 | printf STDERR "died with signal %d, %s coredump\n", | |
1004 | ($? & 127), ($? & 128) ? 'with' : 'without'; | |
1005 | } | |
1006 | else { | |
1007 | printf STDERR "exited with value %d\n", $? >> 8; | |
1008 | } | |
1009 | exit $? >> 8; | |
1010 | } | |
1011 | } | |
1012 | sub run_hook { | |
1013 | my $type = shift; | |
1014 | my $script = shift; | |
1015 | if ($script =~ m,^/,) { | |
1016 | # Full path provided for the hook script | |
1017 | if (-x "$script") { | |
1018 | &exec_script($type,$script); | |
1019 | } | |
1020 | else { | |
1021 | die "The provided $type hook script [$script] could not be run.\n"; | |
1022 | } | |
1023 | } | |
1024 | else { | |
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"); | |
1029 | return 0; | |
1030 | } | |
1031 | } | |
1032 | # No luck | |
1033 | print STDERR "Could not find $type hook script [$script].\n"; | |
1034 | die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n"; | |
1035 | } | |
1036 | } | |
1037 | ||
1038 | my $options; | |
1039 | for (@ARGV) { | |
1040 | s,','\\'',g; | |
1041 | $options .= " '$_'"; | |
1042 | } | |
1043 | $ENV{'DEB_MAINT_PARAMS'}="$options"; | |
1044 | ||
1045 | ## Run user hook script here, if any | |
1046 | if ($postinst_hook) { | |
1047 | &run_hook("postinst", $postinst_hook); | |
1048 | } | |
1049 | ||
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"; | |
1056 | } | |
1057 | ||
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"; | |
1064 | } | |
1065 | ||
1066 | LOADER: { | |
1067 | last unless $do_boot_enable; # Exit if explicitly asked to | |
1068 | ||
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 | |
1076 | ||
1077 | last unless $loaderloc; | |
1078 | last unless -x $loaderloc; | |
1079 | last unless $do_bootloader; | |
1080 | ||
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(); | |
1085 | exit $ret if $ret; | |
1086 | } | |
1087 | } | |
1088 | ||
1089 | ||
1090 | sub run_lilo (){ | |
1091 | my $ret; | |
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. | |
1095 | ||
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"; | |
1101 | } else { | |
1102 | print STDERR "Ok, not running $loader\n"; | |
1103 | } | |
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"); | |
1108 | if ($ret) { | |
1109 | print STDERR "Boot loader test failed\n"; | |
1110 | return $ret; | |
1111 | } | |
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"; | |
1117 | } | |
1118 | ||
1119 | print STDERR "Running $loaderloc ... \n"; | |
1120 | if ($loader =~ /^elilo/io) { | |
1121 | $ret = system("$loaderloc 2>&1 | tee $temp_file_name"); | |
1122 | } else { | |
1123 | $ret = system("$loaderloc >$temp_file_name 2>&1"); | |
1124 | } | |
1125 | if ($ret) { | |
1126 | print STDERR "Boot loader failed to run\n"; | |
1127 | return $ret; | |
1128 | } | |
1129 | unlink $temp_file_name; | |
1130 | print STDERR "Installation successful.\n"; | |
1131 | return 0; | |
1132 | } | |
1133 | ||
1134 | exit 0; | |
1135 | ||
1136 | __END__ | |
1137 |