File: image.prerm

package info (click to toggle)
kernel-package 7.04.potato.3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 736 kB
  • ctags: 243
  • sloc: perl: 1,629; makefile: 1,002; sh: 217
file content (154 lines) | stat: -rwxr-xr-x 4,117 bytes parent folder | download
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
#! /usr/bin/perl
#                              -*- Mode: Perl -*- 
# image.prerm --- 
# Author           : root ( root@melkor.pilgrim.umass.edu ) 
# Created On       : Fri May 17 03:28:59 1996
# Created On Node  : melkor.pilgrim.umass.edu
# Last Modified By : Manoj Srivastava
# Last Modified On : Tue Oct 13 12:14:06 1998
# Last Machine Used: tiamat.datasync.com
# Update Count     : 58
# Status           : Unknown, Use with caution!
# HISTORY          : 
# Description      : 
# 
#
#    $Id: image.prerm,v 1.8 1999/10/08 10:33:42 srivasta Exp $
#
# 

$|=1;
# Predefined values:
my $version = "=V";		# 
my $loader  = "=L";		# lilo or silo

# Variables used
my $image='';
my $answer='';
my $running = '';
my $WouldInvalidate = 0;

if ($ARGV[0] && ($ARGV[0] =~ /remove/ || $ARGV[0] =~ /upgrade/)) {
  if (-l "/usr/doc/kernel-image-$version") {
    unlink "/usr/doc/kernel-image-$version";
  }
}

# Ignore all invocations uxcept when called on to remove
exit 0 unless ($ARGV[0] && $ARGV[0] =~ /remove/) ;

#check to see if we are trying to remove a running kernel
# if so we abort right now.
chop($running=`uname -r`);
if ($running eq $version) {
  print STDERR <<"EOFERR";

  You are running a kernel (version $running) and attempting to remove
  the same version. This is a potentially disastrous action. Not only
  will /boot/vmlinuz-$running be removed, making it impossible to boot
  it, (you will have to take action to change your boot loader to boot
  a new kernel), it will also remove all modules under the directory 
  /lib/modules/$running. Just having a copy of the kernel image is not
  enough, you will have to replace the modules too.

    I repeat, this is very dangerous. If at all in doubt, answer
    no. If you know exactly what you are doing, and are prepared to
    hose your system, then answer Yes.
EOFERR
  
  my $done = 0;
  while (!$done) {
    print "Remove the running kernel image (not recommended) [No]? ";
    $answer=<STDIN>;
    if ($answer !~ /^\s*[Yy]/o) {
      exit 1; #Operation not permitted
    }
    if ($answer =~ /yes/io) {
      $done = 1;
      print "Ok, proceeding with removing running kernel image.\n";
      last;
    }
    print "Please answer yes or no.\n\n";
    $done = 0;
  }
}

#Now, they have an alternate kernel which they are currently running
# The rest is just us being nice to lilo users.

chdir("/") or die "could not chdir to /:$!\n";

if (-f "/etc/$loader.conf") { #I know, could be a link, but ..
  open (LILO, "/etc/$loader.conf") || &success(); # this is not critical
  while (<LILO>) {
    chop;
    s/\#.*//;			  # nix the comments
    next unless /^\s*image\s*=\s(\S+)/o;
    $image = $1;
    if ($image && -e $image) {
      while (defined($image) && -l $image) {
	$image = readlink ($image);
      }
      if (defined($image) && -e $image) {
	$WouldInvalidate |= $image =~ /vmlinuz-$version/;
      }
      else {
	&success(); # invalid $loader.conf file
      }
    }
    else {
      &success(); # invalid $loader.conf file
    }
  }
  close (LILO);
  if ($WouldInvalidate) {
    print STDERR <<"EOF";

 You have a valid /etc/$loader.conf file that mentions
 vmlinuz-$version.  Removing kernel-image-$version would invalidate
 that file. (you will have to edit /etc/$loader.conf or re-target
 symbolic links mentioned there (typically, /vmlinuz and /vmlinuz.old)
 to not refer to vmlinuz-$version and will have to re-run $loader). 

 I repeat: you shall have to make changes to your boot loader setup
 and will have to re-run $loader.

EOF
  ;
    if (&ask("Are you sure you want to remove kernel-image-$version")) {
      print STDERR <<"EOG";

Remember to edit /etc/$loader.conf and re-run $loader, or Make other
arrangements to boot your machine.

EOG
;
      &success();
    }
    else {
      print STDERR "\nNot removing kernel-image-$version.\n";
      exit 1;
    }
  }
}

sub success () {
    -f "/lib/modules/$version/modules.dep"  && 
      unlink "/lib/modules/$version/modules.dep";
    exit 0;
}

sub ask {
    print @_,"? [Yes] ";
    $answer=<STDIN>;
    return ( $answer !~ /^[Nn].*/ );
}

&success();
exit 0;
__END__