| 1530 |
dpurdie |
1 |
#set -x
|
|
|
2 |
# This script creates the backout package for a patch package
|
|
|
3 |
#
|
|
|
4 |
# directory format options.
|
|
|
5 |
#
|
|
|
6 |
# @(#) postinstall 1.10 99/04/23 SMI
|
|
|
7 |
#
|
|
|
8 |
# Copyright (c) 1995 by Sun Microsystems, Inc.
|
|
|
9 |
# All rights reserved
|
|
|
10 |
#
|
|
|
11 |
|
|
|
12 |
# Description:
|
|
|
13 |
# Set the TYPE parameter for the remote file
|
|
|
14 |
#
|
|
|
15 |
# Parameters:
|
|
|
16 |
# none
|
|
|
17 |
#
|
|
|
18 |
# Globals set:
|
|
|
19 |
# TYPE
|
|
|
20 |
|
|
|
21 |
set_TYPE_parameter () {
|
|
|
22 |
if [ ${PATCH_UNDO_ARCHIVE:?????} = "/dev" ]; then
|
|
|
23 |
# handle device specific stuff
|
|
|
24 |
TYPE="removable"
|
|
|
25 |
else
|
|
|
26 |
TYPE="filesystem"
|
|
|
27 |
fi
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
#
|
|
|
31 |
# Description:
|
|
|
32 |
# Build the remote file that points to the backout data
|
|
|
33 |
#
|
|
|
34 |
# Parameters:
|
|
|
35 |
# $1: the un/compressed undo archive
|
|
|
36 |
#
|
|
|
37 |
# Globals set:
|
|
|
38 |
# UNDO, STATE
|
|
|
39 |
|
|
|
40 |
build_remote_file () {
|
|
|
41 |
remote_path=$PKGSAV/$SUNW_PATCHID/remote
|
|
|
42 |
set_TYPE_parameter
|
|
|
43 |
STATE="active"
|
|
|
44 |
|
|
|
45 |
if [ $1 = "undo" ]; then
|
|
|
46 |
UNDO="undo"
|
|
|
47 |
else
|
|
|
48 |
UNDO="undo.Z"
|
|
|
49 |
fi
|
|
|
50 |
|
|
|
51 |
cat > $remote_path << EOF
|
|
|
52 |
# Backout data stored remotely
|
|
|
53 |
TYPE=$TYPE
|
|
|
54 |
FIND_AT=$ARCHIVE_DIR/$UNDO
|
|
|
55 |
STATE=$STATE
|
|
|
56 |
EOF
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
PATH=/usr/sadm/bin:$PATH
|
|
|
60 |
|
|
|
61 |
if [ "$PKG_INSTALL_ROOT" = "/" ]; then
|
|
|
62 |
PKG_INSTALL_ROOT=""
|
|
|
63 |
fi
|
|
|
64 |
|
|
|
65 |
if [ -n "$PATCH_BUILD_DIR" -a -d "$PATCH_BUILD_DIR" ]; then
|
|
|
66 |
BUILD_DIR="$PATCH_BUILD_DIR/$SUNW_PATCHID.$PKGINST"
|
|
|
67 |
else
|
|
|
68 |
BUILD_DIR="$PKG_INSTALL_ROOT/var/tmp/$SUNW_PATCHID.$PKGINST"
|
|
|
69 |
fi
|
|
|
70 |
|
|
|
71 |
if [ ! -n "$PATCH_UNDO_ARCHIVE" ]; then
|
|
|
72 |
PATCH_UNDO_ARCHIVE="none"
|
|
|
73 |
fi
|
|
|
74 |
|
|
|
75 |
FILE_DIR=$BUILD_DIR/files
|
|
|
76 |
RELOC_DIR=$FILE_DIR/reloc
|
|
|
77 |
ROOT_DIR=$FILE_DIR/root
|
|
|
78 |
BO_Deletes=$FILE_DIR/deletes
|
|
|
79 |
THIS_DIR=`dirname $0`
|
|
|
80 |
PROTO_FILE=$BUILD_DIR/prototype
|
|
|
81 |
TEMP_REMOTE=$PKGSAV/$SUNW_PATCHID/temp
|
|
|
82 |
|
|
|
83 |
if [ "$PATCH_PROGRESSIVE" = "true" ]; then
|
|
|
84 |
# remove the scripts that are left behind
|
|
|
85 |
install_scripts=`dirname $0`
|
|
|
86 |
rm $install_scripts/checkinstall $install_scripts/patch_checkinstall $install_scripts/patch_postinstall
|
|
|
87 |
|
|
|
88 |
# If this is being used in an old-style patch, insert
|
|
|
89 |
# the old-style script commands here.
|
|
|
90 |
|
|
|
91 |
#XXXOld_CommandsXXX#
|
|
|
92 |
|
|
|
93 |
exit 0
|
|
|
94 |
fi
|
|
|
95 |
|
|
|
96 |
#
|
|
|
97 |
# At this point we either have a deletes file or we don't. If we do,
|
|
|
98 |
# we create a prototype entry.
|
|
|
99 |
#
|
|
|
100 |
if [ -f $BO_Deletes ]; then
|
|
|
101 |
echo "i deletes=$BO_Deletes" >> $BUILD_DIR/prototype
|
|
|
102 |
fi
|
|
|
103 |
|
|
|
104 |
#
|
|
|
105 |
# Now delete everything in the deletes list after transferring
|
|
|
106 |
# the file to the backout package and the entry to the prototype
|
|
|
107 |
# file. Remember that the pkgmap will get the CLIENT_BASEDIR path
|
|
|
108 |
# but we have to actually get at it using the BASEDIR path. Also
|
|
|
109 |
# remember that removef will import our PKG_INSTALL_ROOT
|
|
|
110 |
#
|
|
|
111 |
Our_Deletes=$THIS_DIR/deletes
|
|
|
112 |
if [ -f $Our_Deletes ]; then
|
|
|
113 |
cd $BASEDIR
|
|
|
114 |
|
|
|
115 |
cat $Our_Deletes | while read path; do
|
|
|
116 |
Reg_File=0
|
|
|
117 |
|
|
|
118 |
if valpath -l $path; then
|
|
|
119 |
Client_Path="$CLIENT_BASEDIR/$path"
|
|
|
120 |
Build_Path="$RELOC_DIR/$path"
|
|
|
121 |
Proto_Path=$BASEDIR/$path
|
|
|
122 |
else # It's an absolute path
|
|
|
123 |
Client_Path=$path
|
|
|
124 |
Build_Path="$ROOT_DIR$path"
|
|
|
125 |
Proto_Path=$PKG_INSTALL_ROOT$path
|
|
|
126 |
fi
|
|
|
127 |
|
|
|
128 |
# If BASEDIR/CLIENTBASEDIR = "/", then the previous prepends
|
|
|
129 |
# an extra / i.e. //. The sed command later can't find a
|
|
|
130 |
# Proto_Path with // and therefore will not substitute the
|
|
|
131 |
# correct build_Path resulting in the backout pkg not being
|
|
|
132 |
# created.
|
|
|
133 |
|
|
|
134 |
if [ "$CLIENT_BASEDIR" = "/" ]; then
|
|
|
135 |
Client_Path=`echo $Client_Path | sed 's|^\/\/|\/|'`
|
|
|
136 |
Proto_Path=`echo $Proto_Path | sed 's|^\/\/|\/|'`
|
|
|
137 |
fi
|
|
|
138 |
|
|
|
139 |
# Note: If the file isn't really there, pkgproto
|
|
|
140 |
# doesn't write anything.
|
|
|
141 |
LINE=`pkgproto $Proto_Path=$path`
|
|
|
142 |
ftype=`echo $LINE | nawk '{ print $1 }'`
|
|
|
143 |
if [ "$ftype" = "f" ]; then
|
|
|
144 |
Reg_File=1
|
|
|
145 |
fi
|
|
|
146 |
|
|
|
147 |
if [ $Reg_File = 1 ]; then
|
|
|
148 |
# Add source file to the prototype entry
|
|
|
149 |
if [ "$Proto_Path" = "$path" ]; then
|
|
|
150 |
LINE=`echo $LINE | sed -e "s|$Proto_Path|$Build_Path|2"`
|
|
|
151 |
else
|
|
|
152 |
LINE=`echo $LINE | sed -e "s|$Proto_Path|$Build_Path|"`
|
|
|
153 |
fi
|
|
|
154 |
|
|
|
155 |
DirName=`dirname $Build_Path`
|
|
|
156 |
# make room in the build tree
|
|
|
157 |
mkdir -p $DirName
|
|
|
158 |
cp -p $Proto_Path $Build_Path
|
|
|
159 |
fi
|
|
|
160 |
|
|
|
161 |
# Insert it into the prototype file
|
|
|
162 |
echo $LINE 1>>$PROTO_FILE 2>/dev/null
|
|
|
163 |
|
|
|
164 |
# Remove the file only if it's OK'd by removef
|
|
|
165 |
rm `removef $PKGINST $Client_Path` 1>/dev/null 2>&1
|
|
|
166 |
done
|
|
|
167 |
removef -f $PKGINST
|
|
|
168 |
|
|
|
169 |
rm $Our_Deletes
|
|
|
170 |
fi
|
|
|
171 |
|
|
|
172 |
#
|
|
|
173 |
# Unless specifically denied, make the backout package.
|
|
|
174 |
#
|
|
|
175 |
if [ "$PATCH_NO_UNDO" != "true" ]; then
|
|
|
176 |
cd $BUILD_DIR # We have to build from here.
|
|
|
177 |
|
|
|
178 |
if [ "$PATCH_UNDO_ARCHIVE" != "none" ]; then
|
|
|
179 |
STAGE_DIR="$PATCH_UNDO_ARCHIVE"
|
|
|
180 |
ARCHIVE_DIR="$PATCH_UNDO_ARCHIVE/$SUNW_PATCHID/$PKGINST"
|
|
|
181 |
mkdir -p $ARCHIVE_DIR
|
|
|
182 |
mkdir -p $PKGSAV/$SUNW_PATCHID
|
|
|
183 |
else
|
|
|
184 |
if [ -d $PKGSAV/$SUNW_PATCHID ]; then
|
|
|
185 |
rm -r $PKGSAV/$SUNW_PATCHID
|
|
|
186 |
fi
|
|
|
187 |
STAGE_DIR=$PKGSAV
|
|
|
188 |
ARCHIVE_DIR=$PKGSAV/$SUNW_PATCHID
|
|
|
189 |
mkdir $ARCHIVE_DIR
|
|
|
190 |
fi
|
|
|
191 |
|
|
|
192 |
pkgmk -o -d $STAGE_DIR 1>/dev/null 2>&1
|
|
|
193 |
pkgtrans -s $STAGE_DIR $ARCHIVE_DIR/undo $PKG 1>/dev/null 2>&1
|
|
|
194 |
compress $ARCHIVE_DIR/undo
|
|
|
195 |
retcode=$?
|
|
|
196 |
if [ "$PATCH_UNDO_ARCHIVE" != "none" ]; then
|
|
|
197 |
if [ $retcode != 0 ]; then
|
|
|
198 |
build_remote_file "undo"
|
|
|
199 |
else
|
|
|
200 |
build_remote_file "undo.Z"
|
|
|
201 |
fi
|
|
|
202 |
fi
|
|
|
203 |
rm -r $STAGE_DIR/$PKG
|
|
|
204 |
|
|
|
205 |
cd ..
|
|
|
206 |
rm -r $BUILD_DIR
|
|
|
207 |
# remove the scripts that are left behind
|
|
|
208 |
install_scripts=`dirname $0`
|
|
|
209 |
rm $install_scripts/checkinstall $install_scripts/patch_checkinstall $install_scripts/patch_postinstall
|
|
|
210 |
fi
|
|
|
211 |
|
|
|
212 |
#
|
|
|
213 |
# Since this apparently worked, we'll mark as obsoleted the prior
|
|
|
214 |
# versions of this patch - installpatch deals with explicit obsoletions.
|
|
|
215 |
#
|
|
|
216 |
cd ${PKG_INSTALL_ROOT:-/}
|
|
|
217 |
cd var/sadm/pkg
|
|
|
218 |
|
|
|
219 |
active_base=`echo $SUNW_PATCHID | nawk '
|
|
|
220 |
{ print substr($0, 1, match($0, "-")-1) } '`
|
|
|
221 |
|
|
|
222 |
List=`ls -d $PKGINST/save/${active_base}* 2>/dev/null`
|
|
|
223 |
if [ $? -ne 0 ]; then
|
|
|
224 |
List=""
|
|
|
225 |
fi
|
|
|
226 |
|
|
|
227 |
for savedir in $List; do
|
|
|
228 |
patch=`basename $savedir`
|
|
|
229 |
if [ $patch = $SUNW_PATCHID ]; then
|
|
|
230 |
break
|
|
|
231 |
fi
|
|
|
232 |
|
|
|
233 |
# If we get here then the previous patch gets deleted
|
|
|
234 |
if [ -f $savedir/undo ]; then
|
|
|
235 |
mv $savedir/undo $savedir/obsolete
|
|
|
236 |
echo $SUNW_PATCHID >> $savedir/obsoleted_by
|
|
|
237 |
elif [ -f $savedir/undo.Z ]; then
|
|
|
238 |
mv $savedir/undo.Z $savedir/obsolete.Z
|
|
|
239 |
echo $SUNW_PATCHID >> $savedir/obsoleted_by
|
|
|
240 |
elif [ -f $savedir/remote ]; then
|
|
|
241 |
`grep . $PKGSAV/$patch/remote | sed 's|STATE=.*|STATE=obsolete|' > $TEMP_REMOTE`
|
|
|
242 |
rm -f $PKGSAV/$patch/remote
|
|
|
243 |
mv $TEMP_REMOTE $PKGSAV/$patch/remote
|
|
|
244 |
rm -f $TEMP_REMOTE
|
|
|
245 |
echo $SUNW_PATCHID >> $savedir/obsoleted_by
|
|
|
246 |
elif [ -f $savedir/obsolete -o -f $savedir/obsolete.Z ]; then
|
|
|
247 |
echo $SUNW_PATCHID >> $savedir/obsoleted_by
|
|
|
248 |
fi
|
|
|
249 |
done
|
|
|
250 |
|
|
|
251 |
# If additional operations are required for this package, place
|
|
|
252 |
# those package-specific commands here.
|
|
|
253 |
|
|
|
254 |
#XXXSpecial_CommandsXXX#
|
|
|
255 |
|
|
|
256 |
exit 0
|