]> git.donarmstrong.com Git - debian/debian-policy.git/blob - debian/postinst.in
Fixed an upgrade bug when /usr/doc happens to be a symlink, and does not point to...
[debian/debian-policy.git] / debian / postinst.in
1 #!/bin/sh
2 #                               -*- Mode: Sh -*- 
3 # postinst --- 
4 # Author           : Manoj Srivastava ( srivasta@tiamat.datasync.com ) 
5 # Created On       : Thu Oct 29 15:23:36 1998
6 # Created On Node  : tiamat.datasync.com
7 # Last Modified By : Manoj Srivastava
8 # Last Modified On : Mon Feb 28 22:32:47 2000
9 # Last Machine Used: glaurung.green-gryphon.com
10 # Update Count     : 5
11 # Status           : Unknown, Use with caution!
12 # HISTORY          : 
13 # Description      : 
14
15
16
17
18 # Abort if any command returns an error value
19 set -e
20
21 # This is filled in by debian/rules
22 PACKAGE=#PACKAGE#
23
24 # This script is called as the last step of the installation of the
25 # package.  All the package's files are in place, dpkg has already done
26 # its automatic conffile handling, and all the packages we depend of
27 # are already fully installed and configured.
28
29 package_name=debian-policy
30
31 if [ -z "package_name" ]; then
32     print >&2 "Internal Error. Please report a bug."
33     exit 1;
34 fi
35
36 #perl -e 'print readlink("/usr/doc/'$package_name'"), "\n"; '
37 case "$1" in
38   configure)
39     # Configure this package.  If the package must prompt the user for
40     # information, do it here.
41
42     if [ -d /usr/doc ]; then
43         # Well, we still need to handle this. At this point, /usr/doc
44         # can be a symlink
45         
46         if [  -d /usr/share/doc/$package_name ]; then
47             # So the new doc dir exists, goody
48             
49             # well, either one of these is a symlink, they can be
50             # pointing off _anywhere_
51             cd /usr/doc/;
52             target_dir=$(/bin/pwd);
53             cd /usr/share/doc 
54             starget_dir=$(/bin/pwd);
55             cd /
56
57             # Well, make sure that we do not get tripped up by the symlink
58             if [ -L /usr/doc/$package_name ]; then
59                 rm -f /usr/doc/$package_name
60             fi
61
62             if [ "$target_dir" != "$starget_dir" ]; then
63                 # Ok. The directories are in different locations
64                 if [ -d /usr/doc/$package_name ]; then
65                     echo "Yikes! The old directory, /usr/doc/$package_name,"
66                     echo "has not ben removed! This is an error; attempting"
67                     echo "repairs."
68                     find /usr/doc/$package_name/ -type f -name .dhelp \
69                         -exec rm {} \;
70                     find /usr/doc/$package_name/ -type d -depth \
71                          -exec rmdir --ignore-fail-on-non-empty {} \;
72
73                     if [ -d /usr/doc/$package_name ]; then
74                         cat <<EOF 
75 Failed repairs. There are old files in /usr/doc/$package_name/ created
76 by you or another script. I can copy them over to the new location
77 /usr/share/doc/$package_name, if you wish, preserving your versions of
78 the files.  No files shall be over written, instead, backup versions
79 shall be created in /usr/share/doc/$package_name as needed.
80
81 Shall I copy the files over [Yn]?
82 EOF
83                         read answer;
84                         case "$answer" in
85                             [Nn]*)
86                                 echo "Not copying over, aborting";
87                                 exit 1;
88                                 ;;      
89                             *)
90                                 cp -a --backup=t /usr/doc/$package_name  \
91                                     /usr/share/doc/$package_name/.. ;
92                                 rm -rf /usr/doc/$package_name;
93                         esac
94                     fi
95                 fi
96
97                 if [ -e /usr/doc/$package_name ]; then
98                     echo "/usr/doc/$package_name still exists"
99                     if [ -L /usr/doc/$package_name ]; then
100                         echo "it is a symbolic link, overwriting"
101                         ln -sf ../share/doc/$package_name /usr/doc/$package_name
102                     else
103                         echo "This is an error. Aborting"
104                         exit 1
105                     fi
106                 fi
107                 # File unexists. Free to go ahead and create link
108                 ln -sf ../share/doc/$package_name /usr/doc/$package_name
109
110             fi
111         fi
112     fi
113
114
115     if [ -x /usr/sbin/install-docs ]; then
116         /usr/sbin/install-docs -i /usr/share/doc-base/$PACKAGE
117     fi
118
119     # There are three sub-cases:
120     if test "${2+set}" != set; then
121       # We're being installed by an ancient dpkg which doesn't remember
122       # which version was most recently configured, or even whether
123       # there is a most recently configured version.
124       :
125
126     elif test -z "$2" -o "$2" = "<unknown>"; then
127       # The package has not ever been configured on this system, or was
128       # purged since it was last configured.
129       :
130
131     else
132       # Version $2 is the most recently configured version of this
133       # package.
134       :
135
136     fi
137
138     # FSSTND compatible symlinks
139     if [ -d /usr/doc -a ! -e /usr/doc/$PACKAGE \
140         -a -d /usr/share/doc/$PACKAGE ]; then
141             ln -sf ../share/doc/$PACKAGE /usr/doc/$PACKAGE
142     fi
143     ;;
144   abort-upgrade)
145     # Back out of an attempt to upgrade this package FROM THIS VERSION
146     # to version $2.  Undo the effects of "prerm upgrade $2".
147     :
148
149     ;;
150   abort-remove)
151     if test "$2" != in-favour; then
152       echo "$0: undocumented call to \`postinst $*'" 1>&2
153       exit 0
154     fi
155     # Back out of an attempt to remove this package, which was due to
156     # a conflict with package $3 (version $4).  Undo the effects of
157     # "prerm remove in-favour $3 $4".
158     :
159
160     ;;
161   abort-deconfigure)
162     if test "$2" != in-favour -o "$5" != removing; then
163       echo "$0: undocumented call to \`postinst $*'" 1>&2
164       exit 0
165     fi
166     # Back out of an attempt to deconfigure this package, which was
167     # due to package $6 (version $7) which we depend on being removed
168     # to make way for package $3 (version $4).  Undo the effects of
169     # "prerm deconfigure in-favour $3 $4 removing $6 $7".
170     :
171
172     ;;
173   *) echo "$0: didn't understand being called with \`$1'" 1>&2
174      exit 0;;
175 esac
176
177 exit 0