Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: debian.chrome/control-scripts/prerm

Issue 646032: Rename config to match naming convention. (Closed)
Patch Set: Send mail Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « debian.chrome/control-scripts/preinst ('k') | debian.chrome/control.d/flavour-control.stub » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #! /usr/bin/perl
2 # -*- Mode: Perl -*-
3 # image.prerm ---
4 # Author : root ( root@melkor.pilgrim.umass.edu )
5 # Created On : Fri May 17 03:28:59 1996
6 # Created On Node : melkor.pilgrim.umass.edu
7 # Last Modified By : Manoj Srivastava
8 # Last Modified On : Sat Aug 5 13:14:17 2006
9 # Last Machine Used: glaurung.internal.golden-gryphon.com
10 # Update Count : 85
11 # Status : Unknown, Use with caution!
12 # HISTORY :
13 # Description :
14 #
15 #
16 # $Id: image.prerm,v 1.22 2003/10/07 16:24:20 srivasta Exp $
17 #
18 #
19 #use strict;
20
21 $|=1;
22 # Predefined values:
23 my $version = "=V";
24 my $link_in_boot = ""; # Should be empty, mostly
25 my $no_symlink = ""; # Should be empty, mostly
26 my $reverse_symlink = ""; # Should be empty, mostly
27 my $do_symlinks = "Yes"; # target machine defined
28 my $do_boot_enable = "Yes"; # target machine defined
29 my $do_bootfloppy = "Yes"; # target machine defined
30 my $do_bootloader = "Yes"; # target machine defined
31 my $move_image = ''; # target machine defined
32 my $kimage = "=K"; # Should be empty, mostly
33 my $loader = "=L"; # lilo, silo, quik, palo, vmelilo, or nettrom
34 my $image_dir = "/boot"; # where the image is located
35 my $clobber_modules = ''; # target machine defined
36 my $initrd = "YES"; # initrd kernel
37 my $use_hard_links = ''; # hardlinks do not wirk across fs boundaries
38 my $postinst_hook = ''; #Normally we do not
39 my $postrm_hook = ''; #Normally we do not
40 my $preinst_hook = ''; #Normally we do not
41 my $prerm_hook = ''; #Normally we do not
42 my $minimal_swap = ''; # Do not swap symlinks
43 my $ignore_depmod_err = ''; # normally we do not
44 my $relink_build_link = 'YES'; # There is no harm in checking the link
45 my $force_build_link = ''; # There is no harm in checking the link
46 my $kernel_arch = "=B";
47 my $ramdisk = "/usr/sbin/update-initramfs";
48 my $package_name = "linux-image-$version";
49
50 my $Loader = "NoLOADER"; #
51 $Loader = "LILO" if $loader =~ /^lilo/io;
52 $Loader = "SILO" if $loader =~ /^silo/io;
53 $Loader = "QUIK" if $loader =~ /^quik/io;
54 $Loader = "yaboot" if $loader =~ /^yaboot/io;
55 $Loader = "PALO" if $loader =~ /^palo/io;
56 $Loader = "NETTROM" if $loader =~ /^nettrom/io;
57 $Loader = "VMELILO" if $loader =~ /^vmelilo/io;
58 $Loader = "ZIPL" if $loader =~ /^zipl/io;
59 $Loader = "ELILO" if $loader =~ /^elilo/io;
60
61
62 # This should not point to /tmp, because of security risks.
63 my $temp_file_name = "/var/log/$loader" . "_log.$$";
64
65 #known variables
66 my $image_dest = "/";
67 my $realimageloc = "/$image_dir/";
68 my $have_conffile = "";
69 my $CONF_LOC = '/etc/kernel-img.conf';
70 my $relative_links = '';
71 my $silent_loader = '';
72 my $warn_reboot = 'Yes'; # Warn that we are installing a version of
73 # the kernel we are running
74
75 # remove multiple leading slashes; make sure there is at least one.
76 $realimageloc =~ s|^/*|/|o;
77 $realimageloc =~ s|/+|/|o;
78
79 my $DEBUG = 0;
80
81 # Variables used
82 my $image='';
83 my $ret=0;
84 my $seen='';
85 my $answer='';
86 my $running = '';
87 my $WouldInvalidate = 0;
88
89 if ($ARGV[0] && ($ARGV[0] =~ /remove/ || $ARGV[0] =~ /upgrade/)) {
90 if (-l "/usr/doc/linux-image-$version") {
91 unlink "/usr/doc/linux-image-$version";
92 }
93 }
94
95 # Ignore all invocations uxcept when called on to remove
96 exit 0 unless ($ARGV[0] && $ARGV[0] =~ /remove/) ;
97
98 # Paranoid check to make sure that the correct value is put in there
99 if (! $kimage) { $kimage = "vmlinuz";} # Hmm. empty
100 elsif ($kimage =~ m/^b?zImage$/o) { $kimage = "vmlinuz";} # these produce vmlinu z
101 elsif ($kimage =~ m/^[iI]mage$/o) { my $nop = $kimage; }
102 elsif ($kimage =~ m/^vmlinux$/o) { my $nop = $kimage; }
103 else { $kimage = "vmlinuz";} # Default
104
105 if (-r "$CONF_LOC" && -f "$CONF_LOC" ) {
106 if (open(CONF, "$CONF_LOC")) {
107 while (<CONF>) {
108 chomp;
109 s/\#.*$//g;
110 next if /^\s*$/;
111
112 $do_symlink = "" if /^\s*do_symlinks\s*=\s*(no|false|0)\s*$/ig;
113 $no_symlink = "" if /^\s*no_symlinks\s*=\s*(no|false|0)\s*$/ig;
114 $reverse_symlink = "" if /^\s*reverse_symlinks\s*=\s*(no|false|0)\s*$/ig;
115 $link_in_boot = "" if /^\s*image_in_boot\s*=\s*(no|false|0)\s*$/ig;
116 $link_in_boot = "" if /^\s*link_in_boot\s*=\s*(no|false|0)\s*$/ig;
117 $move_image = "" if /^\s*move_image\s*=\s*(no|false|0)\s*$/ig;
118 $clobber_modules = '' if /^\s*clobber_modules\s*=\s*(no|false|0)\s*$/ig;
119 $do_boot_enable = '' if /^\s*do_boot_enable\s*=\s*(no|false|0)\s*$/ig;
120 $do_bootfloppy = '' if /^\s*do_bootfloppy\s*=\s*(no|false|0)\s*$/ig;
121 $relative_links = '' if /^\s*relative_links \s*=\s*(no|false|0)\s*$/ig;
122 $do_bootloader = '' if /^\s*do_bootloader\s*=\s*(no|false|0)\s*$/ig;
123 $do_initrd = '' if /^\s*do_initrd\s*=\s*(no|false|0)\s*$/ig;
124 $use_hard_links = '' if /^\s*use_hard_links\s*=\s*(no|false|0)\s*$/ig;
125 $silent_loader = '' if /^\s*silent_loader\s*=\s*(no|false|0)\s*$/ig;
126 $warn_reboot = '' if /^\s*warn_reboot\s*=\s*(no|false|0)\s*$/ig;
127 $minimal_swap = '' if /^\s*minimal_swap\s*=\s*(no|false|0)\s*$/ig;
128 $ignore_depmod_err = '' if /^\s*ignore_depmod_err\s*=\s*(no|false|0)\s*$/i g;
129 $relink_build_link = '' if /^\s*relink_build_link\s*=\s*(no|false|0)\s*$/i g;
130 $force_build_link = '' if /^\s*force_build_link\s*=\s*(no|false|0)\s*$/ig;
131
132
133 $do_symlink = "Yes" if /^\s*do_symlinks\s*=\s*(yes|true|1)\s*$/ig;
134 $no_symlink = "Yes" if /^\s*no_symlinks\s*=\s*(yes|true|1)\s*$/ig;
135 $reverse_symlink = "Yes" if /^\s*reverse_symlinks\s*=\s*(yes|true|1)\s*$/i g;
136 $link_in_boot = "Yes" if /^\s*image_in_boot\s*=\s*(yes|true|1)\s*$/ig;
137 $link_in_boot = "Yes" if /^\s*link_in_boot\s*=\s*(yes|true|1)\s*$/ig;
138 $move_image = "Yes" if /^\s*move_image\s*=\s*(yes|true|1)\s*$/ig;
139 $clobber_modules = "Yes" if /^\s*clobber_modules\s*=\s*(yes|true|1)\s*$/ig ;
140 $do_boot_enable = "Yes" if /^\s*do_boot_enable\s*=\s*(yes|true|1)\s*$/ig;
141 $do_bootfloppy = "Yes" if /^\s*do_bootfloppy\s*=\s*(yes|true|1)\s*$/ig;
142 $do_bootloader = "Yes" if /^\s*do_bootloader\s*=\s*(yes|true|1)\s*$/ig;
143 $relative_links = "Yes" if /^\s*relative_links\s*=\s*(yes|true|1)\s*$/ig;
144 $do_initrd = "Yes" if /^\s*do_initrd\s*=\s*(yes|true|1)\s*$/ig;
145 $use_hard_links = "Yes" if /^\s*use_hard_links\s*=\s*(yes|true|1)\s*$/ig;
146 $silent_loader = 'Yes' if /^\s*silent_loader\s*=\s*(yes|true|1)\s*$/ig;
147 $warn_reboot = 'Yes' if /^\s*warn_reboot\s*=\s*(yes|true|1)\s*$/ig;
148 $minimal_swap = 'Yes' if /^\s*minimal_swap\s*=\s*(yes|true|1)\s*$/ig;
149 $ignore_depmod_err = 'Yes' if /^\s*ignore_depmod_err\s*=\s*(yes|true|1)\s* $/ig;
150 $relink_build_link = 'Yes' if /^\s*relink_build_link\s*=\s*(yes|true|1)\s* $/ig;
151 $force_build_link = 'Yes' if /^\s*force_build_link\s*=\s*(yes|true|1)\s*$/ ig;
152
153 $image_dest = "$1" if /^\s*image_dest\s*=\s*(\S+)/ig;
154 $postinst_hook = "$1" if /^\s*postinst_hook\s*=\s*(\S+)/ig;
155 $postrm_hook = "$1" if /^\s*postrm_hook\s*=\s*(\S+)/ig;
156 $preinst_hook = "$1" if /^\s*preinst_hook\s*=\s*(\S+)/ig;
157 $prerm_hook = "$1" if /^\s*prerm_hook\s*=\s*(\S+)/ig;
158 $ramdisk = "$1" if /^\s*ramdisk\s*=\s*(.+)$/ig;
159 }
160 close CONF;
161 $have_conffile = "Yes";
162 }
163 }
164
165
166 $ENV{KERNEL_ARCH}=$kernel_arch if $kernel_arch;
167
168 #check to see if we are trying to remove a running kernel
169 # if so we abort right now.
170 chop($running=`uname -r`);
171 if ($running eq $version) {
172 print STDERR "WARN: Proceeding with removing running kernel image.\n";
173 }
174
175 #Now, they have an alternate kernel which they are currently running
176
177 # This is just us being nice to lilo users.
178
179 chdir("/") or die "could not chdir to /:$!\n";
180
181 if (-f "/etc/$loader.conf") { #I know, could be a link, but ..
182 open (LILO, "/etc/$loader.conf") || &success(); # this is not critical
183 while (<LILO>) {
184 chop;
185 s/\#.*//; # nix the comments
186 next unless /^\s*image\s*=\s(\S+)/o;
187 $image = $1;
188 if ($image && -e $image) {
189 while (defined($image) && -l $image) {
190 $image = readlink ($image);
191 }
192 if (defined($image) && -e $image) {
193 $WouldInvalidate |= $image =~ /$kimage-$version/;
194 }
195 else {
196 &success(); # invalid $loader.conf file
197 }
198 }
199 else {
200 &success(); # invalid $loader.conf file
201 }
202 }
203 close (LILO);
204 if ($WouldInvalidate) {
205 print STFERR "WARN: Proceeding with removing running kernel image.\n";
206 &success();
207 }
208 }
209
210
211 # set the env var stem
212 $ENV{'STEM'} = "linux";
213
214 sub exec_script {
215 my $type = shift;
216 my $script = shift;
217 print STDERR "Running $type hook script $script.\n";
218 system ("$script $version $realimageloc$kimage-$version") &&
219 print STDERR "User $type hook script [$script] ";
220 if ($?) {
221 if ($? == -1) {
222 print STDERR "failed to execute: $!\n";
223 }
224 elsif ($? & 127) {
225 printf STDERR "died with signal %d, %s coredump\n",
226 ($? & 127), ($? & 128) ? 'with' : 'without';
227 }
228 else {
229 printf STDERR "exited with value %d\n", $? >> 8;
230 }
231 exit $? >> 8;
232 }
233 }
234 sub run_hook {
235 my $type = shift;
236 my $script = shift;
237 if ($script =~ m,^/,) {
238 # Full path provided for the hook script
239 if (-x "$script") {
240 &exec_script($type,$script);
241 }
242 else {
243 die "The provided $type hook script [$script] could not be run.\n";
244 }
245 }
246 else {
247 # Look for it in a safe path
248 for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
249 if (-x "$path/$script") {
250 &exec_script($type, "$path/$script");
251 return 0;
252 }
253 }
254 # No luck
255 print STDERR "Could not find $type hook script [$script].\n";
256 die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
257 }
258 }
259
260
261 ## Run user hook script here, if any
262 if (-x "$prerm_hook") {
263 &run_hook("prerm", $prerm_hook);
264 }
265 if (-d "/etc/kernel/prerm.d") {
266 print STDERR "Examining /etc/kernel/prerm.d.\n";
267 system ("run-parts --verbose --exit-on-error --arg=$version " .
268 "--arg=$realimageloc$kimage-$version /etc/kernel/prerm.d") &&
269 die "Failed to process /etc/kernel/prerm.d";
270 }
271 if (-d "/etc/kernel/prerm.d/$version") {
272 print STDERR "Examining /etc/kernel/prerm.d/$version.\n";
273 system ("run-parts --verbose --exit-on-error --arg=$version" .
274 " --arg=$realimageloc$kimage-$version " .
275 "/etc/kernel/prerm.d/$version") &&
276 die "Failed to process /etc/kernel/prerm.d/$version";
277 }
278
279 sub success () {
280 my @files_to_remove = qw{
281 modules.dep modules.isapnpmap modules.pcimap
282 modules.usbmap modules.parportmap
283 modules.generic_string modules.ieee1394map
284 modules.ieee1394map modules.pnpbiosmap
285 modules.alias modules.ccwmap modules.inputmap
286 modules.symbols modules.ofmap modules.seriomap
287 modules.alias.bin modules.dep.bin modules.symbols.bin
288 };
289
290 foreach my $extra_file (@files_to_remove) {
291 if (-f "/lib/modules/$version/$extra_file") {
292 unlink "/lib/modules/$version/$extra_file";
293 }
294 }
295 exit 0;
296 }
297
298
299
300 &success();
301 exit 0;
302 __END__
303
304
305
306
307
OLDNEW
« no previous file with comments | « debian.chrome/control-scripts/preinst ('k') | debian.chrome/control.d/flavour-control.stub » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698