File: include.postrm

package info (click to toggle)
kernel-package 6.05
  • links: PTS
  • area: main
  • in suites: slink
  • size: 620 kB
  • ctags: 190
  • sloc: perl: 1,228; makefile: 703; sh: 39
file content (125 lines) | stat: -rwxr-xr-x 2,624 bytes parent folder | download | duplicates (2)
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
#! /usr/bin/perl
#                              -*- Mode: Perl -*- 
# debian.postrm --- 
# Author           : Manoj Srivastava ( srivasta@pilgrim.umass.edu )
# Created On       : Sat Apr 27 05:44:16 1996
# Created On Node  : melkor.pilgrim.umass.edu
# Last Modified By : Manoj Srivastava
# Last Modified On : Wed Feb 18 15:43:38 1998
# Last Machine Used: tiamat.datasync.com
# Update Count     : 18
# Status           : Unknown, Use with caution!
# HISTORY          : 
# Description      : 
# 
# 
#
#    $Id: include.postrm,v 1.5 1998/02/18 22:25:05 srivasta Exp $
#


$|=1;

# Predefined values:
my $package="=P";
my $version="=V";

my $LastVersion = '';
my $AnotherVersion = '';

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

# most of our work is done in /usr/src.
chdir '/usr/src' or die "Could not chdir to /usr/src:$!";

# let us make sure that if the file .linux-versions exists, and that
# we can read and write to it.
if (-f '.linux-versions') {
  my $found = 0;
  my @Versions = ();

  $LastVersion = '';
  if (open(REGISTRY,"/usr/src/.linux-versions")) {
    while (<REGISTRY>) {
      chop;

      $found = 1, next if /^\s*$package\s*$/o;
      push @Versions, $_ ;

      s/\s+//;
      next if /^\s*$/;
      next if /^\#/o;

      $LastVersion = $_ ;

      # See if there is a package with the same version
      if (/\-$version$/o) {	# Aha!
	$AnotherVersion = $_;
      }
    }
    close (REGISTRY);
  }
  else {
    warn "Could not read /usr/src/.linux-versions: $!";
  }
  if ($found && open(REGISTRY,">/usr/src/.linux-versions")) {
    foreach (@Versions) {
      print REGISTRY "$_\n";
    }
    close(REGISTRY);
  }
  else {
    warn "Could not write /usr/src/.linux-versions: $!" if $found;
  }
}

# Test if we need to do anything at all. This test and exit make us
# idempotent. 

if (-l 'linux') {
  my $old_target = readlink('linux');
  die "could not read link /usr/src/linux:$!" unless defined $old_target;

  if ("$old_target" eq "$package") {
    unlink 'linux' or do {
      print STDERR <<"ERR";
  Could not remove /usr/src/linux ($!)
  Please remove manually.
ERR
  ;
      exit 1;
    } ;
    unlink "linux-$version" or do {
      print STDERR <<"ERR";
  Could not remove /usr/src/linux-$version ($!)
  Please remove manually.
ERR
  ;
      exit 1;
    } ;
  
    if ($AnotherVersion) {
      if (-d "$AnotherVersion") {
	symlink $AnotherVersion, "linux-$version" or 
	  die 
	    "Error linking /usr/src/$AnotherVersion to /usr/src/linux-$version: $!";
      }
    }
  }
  else {
    exit 0;
  }
}


exit 0
__END__