1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
#! /usr/bin/perl
# -*- Mode: Perl -*-
# image.preinst ---
# Author : Manoj Srivastava ( srivasta@tiamat.datasync.com )
# Created On : Sun Jun 14 03:38:02 1998
# Created On Node : tiamat.datasync.com
# Last Modified By : Manoj Srivastava
# Last Modified On : Fri Mar 1 16:16:34 2002
# Last Machine Used: glaurung.green-gryphon.com
# Update Count : 48
# Status : Unknown, Use with caution!
# HISTORY :
# Description :
#
#
#
#use strict; #for debugging
$|=1;
# Predefined values:
my $version = "=V";
my $image_in_boot = "=B"; # Should be empty, mostly
my $no_symlink = "=S"; # Should be empty, mostly
my $reverse_symlink = "=R"; # Should be empty, mostly
my $do_symlink = "Yes"; # target machine defined
my $do_boot_enable = "Yes"; # target machine defined
my $do_bootfloppy = "Yes"; # target machine defined
my $do_bootloader = "Yes"; # target machine defined
my $move_image = ''; # target machine defined
my $do_initrd = ''; # target machine defined
my $warn_initrd = 'YES'; # target machine defined
my $kimage = "=K"; # Should be empty, mostly
my $loader = "=L"; # lilo, silo, quik, palo, vmelilo, or nettrom
my $image_dir = "=D"; # where the image is located
my $clobber_modules = ''; # target machine defined
my $initrd = "=I"; # initrd kernel
my $use_hard_links = ''; # hardlinks do not wirk across fs boundaries
my $postinst_hook = ''; #Normally we do not
my $postrm_hook = ''; #Normally we do not
my $preinst_hook = ''; #Normally we do not
my $prerm_hook = ''; #Normally we do not
my $minimal_swap = ''; # Do not swap symlinks
my $Loader = "NoLOADER"; #
$Loader = "LILO" if $loader =~ /^lilo/io;
$Loader = "SILO" if $loader =~ /^silo/io;
$Loader = "QUIK" if $loader =~ /^quik/io;
$Loader = "yaboot" if $loader =~ /^yaboot/io;
$Loader = "PALO" if $loader =~ /^palo/io;
$Loader = "NETTROM" if $loader =~ /^nettrom/io;
$Loader = "VMELILO" if $loader =~ /^vmelilo/io;
$Loader = "ZIPL" if $loader =~ /^zipl/io;
$Loader = "ELILO" if $loader =~ /^elilo/io;
#known variables
my @boilerplate = ();
my @silotemplate = ();
my @quiktemplate = ();
my @palotemplate = ();
my @vmelilotemplate = ();
my $bootdevice = '';
my $rootdevice = '';
my $rootdisk = '';
my $rootpartition = '';
my $image_dest = "/";
my $realimageloc = "/$image_dir/";
my $have_conffile = "";
my $CONF_LOC = '/etc/kernel-img.conf';
my $relative_links = '';
my $silent_modules = '';
my $silent_loader = '';
die "Pre inst Internal error. Aborting." unless $version;
exit 0 if $ARGV[0] =~ /abort-upgrade/;
exit 1 unless $ARGV[0] =~ /(install|upgrade)/;
# remove multiple leading slashes; make sure there is at least one.
$realimageloc =~ s|^/*|/|o;
$realimageloc =~ s|/+|/|o;
if (-r "$CONF_LOC" && -f "$CONF_LOC" ) {
if (open(CONF, "$CONF_LOC")) {
while (<CONF>) {
chomp;
s/\#.*$//g;
next if /^\s*$/;
$do_symlink = "" if /do_symlinks\s*=\s*(no|false|0)\s*$/ig;
$no_symlink = "" if /no_symlinks\s*=\s*(no|false|0)\s*$/ig;
$reverse_symlink = "" if /reverse_symlinks\s*=\s*(no|false|0)\s*$/ig;
$image_in_boot = "" if /image_in_boot\s*=\s*(no|false|0)\s*$/ig;
$move_image = "" if /move_image\s*=\s*(no|false|0)\s*$/ig;
$clobber_modules = '' if /clobber_modules\s*=\s*(no|false|0)\s*$/ig;
$do_boot_enable = '' if /do_boot_enable\s*=\s*(no|false|0)\s*$/ig;
$do_bootfloppy = '' if /do_bootfloppy\s*=\s*(no|false|0)\s*$/ig;
$do_bootloader = '' if /do_bootloader\s*=\s*(no|false|0)\s*$/ig;
$do_initrd = '' if /do_initrd\s*=\s*(no|false|0)\s*$/ig;
$warn_initrd = '' if /warn_initrd\s*=\s*(no|false|0)\s*$/ig;
$relative_links = '' if /relative_links \s*=\s*(no|false|0)\s*$/ig;
$use_hard_links = '' if /use_hard_links\s*=\s*(no|false|0)\s*$/ig;
$silent_modules = '' if /silent_modules\s*=\s*(no|false|0)\s*$/ig;
$silent_loader = '' if /silent_loader\s*=\s*(no|false|0)\s*$/ig;
$minimal_swap = '' if /minimal_swap\s*=\s*(no|false|0)\s*$/ig;
$do_symlink = "Yes" if /do_symlinks\s*=\s*(yes|true|1)\s*$/ig;
$no_symlink = "Yes" if /no_symlinks\s*=\s*(yes|true|1)\s*$/ig;
$reverse_symlink = "Yes" if /reverse_symlinks\s*=\s*(yes|true|1)\s*$/ig;
$image_in_boot = "Yes" if /image_in_boot\s*=\s*(yes|true|1)\s*$/ig;
$move_image = "Yes" if /move_image\s*=\s*(yes|true|1)\s*$/ig;
$clobber_modules = "Yes" if /clobber_modules\s*=\s*(yes|true|1)\s*$/ig;
$do_boot_enable = "Yes" if /do_boot_enable\s*=\s*(yes|true|1)\s*$/ig;
$do_bootfloppy = "Yes" if /do_bootfloppy\s*=\s*(yes|true|1)\s*$/ig;
$do_bootloader = "Yes" if /do_bootloader\s*=\s*(yes|true|1)\s*$/ig;
$relative_links = "Yes" if /relative_links\s*=\s*(yes|true|1)\s*$/ig;
$do_initrd = "Yes" if /do_initrd\s*=\s*(yes|true|1)\s*$/ig;
$warn_initrd = "Yes" if /warn_initrd\s*=\s*(yes|true|1)\s*$/ig;
$use_hard_links = "Yes" if /use_hard_links\s*=\s*(yes|true|1)\s*$/ig;
$silent_modules = 'Yes' if /silent_modules\s*=\s*(yes|true|1)\s*$/ig;
$silent_loader = 'Yes' if /silent_loader\s*=\s*(yes|true|1)\s*$/ig;
$minimal_swap = 'Yes' if /minimal_swap\s*=\s*(yes|true|1)\s*$/ig;
$image_dest = "$1" if /image_dest\s*=\s*(\S+)/ig;
$postinst_hook = "$1" if /postinst_hook\s*=\s*(\S+)/ig;
$postrm_hook = "$1" if /postrm_hook\s*=\s*(\S+)/ig;
$preinst_hook = "$1" if /preinst_hook\s*=\s*(\S+)/ig;
$prerm_hook = "$1" if /prerm_hook\s*=\s*(\S+)/ig;
}
close CONF;
$have_conffile = "Yes";
$have_conffile = "Yes"; # stop perl complaining
}
}
if ($do_initrd) { $warn_initrd = ''; }
if (!$warn_initrd) { $do_initrd = "YES";}
# About to upgrade this package from version $2 TO THIS VERSION.
# "prerm upgrade" has already been called for the old version of
# this package.
# For some versions of kernel-package, we had tis warning in the
# postinst, but the rules did not really interpolate the value in.
# Here is a sanity check.
my $pattern = "=" . "I";
$initrd=~ s/^$pattern$//;
if ($initrd && !$do_initrd) {
print STDERR <<EOF;
You are attempting to install an initrd kernel image (version $version)
This will not work unless you have configured your boot loader to use
initrd. (An initrd image is a kernel image that expects to use an INITial
Ram Disk to mount a minimal root file system into RAM and use that for
booting).
EOF
if ($loader =~ m/^lilo/i) {
print STDERR "As a reminder, in order to configure lilo, you need to\n";
print STDERR "add an 'initrd=/initrd.img' to the image=/vmlinuz\n";
print STDERR "stanza of your /etc/lilo.conf\n";
}
print STDERR <<EOF;
I repeat, You need to configure your boot loader. If you have already done
so, and you wish to get rid of this message, please put
`do_initrd = Yes'
in /etc/kernel-img.conf. Note that this is optional, but if you do not,
you'll contitnue to see this message whenever you install a kernel
image using initrd.
EOF
if (-f "/etc/lilo.conf"){
my $ramdisk_found = 0;
open (CONF, "/etc/lilo.conf") or warn "Can't open /etc/lilo.conf: $!";
while (<CONF>) {
chomp;
if (m/^(\s*ramdisk\s*=\s*0)/g) {
print STDERR
"In addition, the line\n\t\"$1\"\nshould be removed or commented.";
last;
}
}
close CONF;
}
print STDERR "Do you want to stop now? [Y/n]";
my $answer = <STDIN>;
print STDERR "Ok, Aborting\n" unless $answer =~ /^n/i;
exit 1 unless $answer =~ /^n/i;
}
if (-d "/lib/modules/$version") {
if ($clobber_modules) {
my $ret = system("mv /lib/modules/$version /lib/modules/${version}_$$");
if ($ret) {
print STDERR <<EOF;
You are attempting to install a kernel image (version $version)
However, the directory /lib/modules/$version still exists.
As you have instructed, an attempt was made to move the directory out
of the way. Unfortunately, There was a problem moving
/lib/modules/$version to /lib/modules/${version}_$$.
I suggest you move /lib/modules/$version out of the way manually,
and then try re-installing this image.
I am aborting.
EOF
;
exit 1;
}
}
elsif ($silent_modules !~ m/YES/i) {
print STDERR <<EOF;
You are attempting to install a kernel image (version $version)
However, the directory /lib/modules/$version still exists. If this
directory belongs to a previous kernel-image-$version package, and if
you have deselected some modules, or installed standalone modules
packages, this could be bad. However, if this directory exists because
you are also installing some stand alone modules right now, and they
got unpacked before I did, then this is pretty benign. Unfortunately,
I can't tell the difference.
If /lib/modules/$version belongs to a old install of
kenel-image-$version, this is your last chance to abort the
installation of this kernel image (nothing has been changed yet).
If this directory is because of stand alone modules being installed
right now, or if it does belong to an older kernel-image-$version
package but you know what you are doing, and if you feel that this
image should be installed despite this anomaly, Please answer n to the
question.
Otherwise, I suggest you move /lib/modules/$version out of the way,
perhaps to /lib/modules/$version.old or something, and then try
re-installing this image.
EOF
;
print STDERR "Do you want to stop now? [Y/n]";
my $answer = <STDIN>;
print STDERR "Ok, Aborting\n" unless $answer =~ /^n/i;
exit 1 unless $answer =~ /^n/i;
}
else {
print STDERR <<EOF;
The directory /lib/modules/$version still exists. Continuing as directed.
EOF
;
}
}
## Run user hook script here, if any
if (-x "$preinst_hook") {
system ("$preinst_hook", $version, $realimageloc . "$kimage-$version") &&
die "User hook script $preinst_hook failed";
}
exit 0
|