Subversion Repositories DevTools

Rev

Rev 1530 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1530 dpurdie 1
#set -x
2
# This class action script copies the files being replaced
3
# into a package being constructed in $BUILD_DIR. This class
4
# action script is only appropriate for regular files that
5
# are installed by simply copying them into place.
6
#
7
# For special package objects such as edittable files, the patch
8
# producer must supply appropriate class action scripts.
9
#
10
# directory format options.
11
#
12
#       @(#)i.script 1.13 99/11/17 SMI
13
#
14
# Copyright (c) 1995 by Sun Microsystems, Inc.
15
# All rights reserved
16
#
17
 
18
 
19
# -------------------------------------------------------------------------------------
20
_processLibFile ()
21
#
22
#    A project speccific function to process a library item detected in 
23
#    the delivere prototype file.
24
#
25
#    Input: src, dst
26
#
27
# -------------------------------------------------------------------------------------
28
{
29
    SRC=$1
30
 
31
    m_base=`basename $SRC`
32
    m_libNameNoVersion=`perl -e '$item=$ARGV[0]; $item =~ s/\.so.*$/\.so/; printf("$item")' -- $m_base`
33
    m_libNameNoVersionOrBuildType=`perl -e '$item=$ARGV[0]; $item =~ s/D\.so.*$|P\.so.*$/\.so/; printf("$item")' -- $m_base`
34
 
35
    # now we need to detemrine what we were previously linked to
36
    # in the app dir.
37
    #
38
    if [ -f  "$m_libNameNoVersionOrBuildType" ]
39
    then
40
        m_tmp=`ls -l $m_libNameNoVersionOrBuildType | tr -s " "`
41
        m_previousLibNameSrc=`echo $m_tmp | cut -f11 -d" "`
42
    else
43
        m_previousLibNameSrc=none
44
    fi
45
 
46
    # lets now record what we have done so we can back out
47
    #
48
    if [ ! -f "$M_BACKOUT_SCRIPT" ]
49
    then
50
        echo "#!/bin/sh" > $M_BACKOUT_SCRIPT
51
        echo "set -x"    >> $M_BACKOUT_SCRIPT
52
    fi
53
 
54
    if [ ! -f "$M_POSTPATCH_SCRIPT" ]
55
    then
56
        echo "#!/bin/sh" >  $M_POSTPATCH_SCRIPT
57
        echo "set -x"    >> $M_POSTPATCH_SCRIPT
58
    fi
59
 
60
 
61
    echo "# -------------------------------------------------------------------------------------------------" >> $M_BACKOUT_SCRIPT
62
    echo "# lets backout lib file, from=[$m_base] to=[$m_previousLibNameSrc]" >> $M_BACKOUT_SCRIPT
63
 
64
    echo "# -------------------------------------------------------------------------------------------------" >> $M_POSTPATCH_SCRIPT
65
    echo "# lets postpatch lib file, to=[$m_base] from=[$m_previousLibNameSrc]" >> $M_POSTPATCH_SCRIPT
66
 
67
 
68
    if [ "x$m_previousLibNameSrc" = "xnone" ]
69
    then
70
 
71
        echo "no history for item [$m_base]."
72
 
73
        # deal with items in the app dir
74
        #
75
        echo "installf -c none $PKGINST $M_APPLIB_DIR/$m_libNameNoVersion=$m_base s" >> $M_POSTPATCH_SCRIPT
76
        echo "installf -c none $PKGINST $M_APPLIB_DIR/$m_libNameNoVersionOrBuildType=$m_base s" >> $M_POSTPATCH_SCRIPT
77
 
78
        echo "removef $PKGINST $M_APPLIB_DIR/$m_libNameNoVersion"            >> $M_BACKOUT_SCRIPT
79
        echo "rm -f            $M_APPLIB_DIR/$m_libNameNoVersion"            >> $M_BACKOUT_SCRIPT
80
 
81
        echo "removef $PKGINST $M_APPLIB_DIR/$m_libNameNoVersionOrBuildType" >> $M_BACKOUT_SCRIPT
82
        echo "rm -f            $M_APPLIB_DIR/$m_libNameNoVersionOrBuildType" >> $M_BACKOUT_SCRIPT
83
 
84
        # create common items by default ...
85
        #
86
        echo "installf -c none $PKGINST $M_BASELIB_DIR/$m_base=$M_APPLIB_DIR/$m_base s" \
87
             >> $M_POSTPATCH_SCRIPT
88
 
89
        echo "installf -c none $PKGINST $M_BASELIB_DIR/$m_libNameNoVersion=$M_APPLIB_DIR/$m_base s" \
90
             >> $M_POSTPATCH_SCRIPT
91
 
92
 
93
# Not required. To be removed.
94
#        echo "installf -c none $PKGINST $M_BASELIB_DIR/$m_libNameNoVersionOrBuildType=$M_APPLIB_DIR/$m_base s" \
95
#             >> $M_POSTPATCH_SCRIPT
96
 
97
 
98
        echo "removef $PKGINST $M_BASELIB_DIR/$m_libNameNoVersion"            >> $M_BACKOUT_SCRIPT
99
        echo "rm -f            $M_BASELIB_DIR/$m_libNameNoVersion"            >> $M_BACKOUT_SCRIPT
100
 
101
        echo "removef $PKGINST $M_BASELIB_DIR/$m_libNameNoVersionOrBuildType" >> $M_BACKOUT_SCRIPT
102
        echo "rm -f            $M_BASELIB_DIR/$m_libNameNoVersionOrBuildType" >> $M_BACKOUT_SCRIPT
103
 
104
 
105
# Not required. To be removed.
106
#        echo "removef $PKGINST $M_BASELIB_DIR/$m_base"                        >> $M_BACKOUT_SCRIPT
107
#        echo "rm -f            $M_BASELIB_DIR/$m_base"                        >> $M_BACKOUT_SCRIPT
108
 
109
 
110
    else
111
 
112
        # we have history.
113
 
114
        # deal with items in the app dir
115
        #
116
        _removeItem $M_APPLIB_DIR/$m_libNameNoVersion
117
 
118
        _linkItem   $m_base \
119
                    $m_libNameNoVersion \
120
                    $m_previousLibNameSrc \
121
                    $M_APPLIB_DIR
122
 
123
        _removeItem $M_APPLIB_DIR/$m_libNameNoVersionOrBuildType
124
 
125
        _linkItem   $m_base \
126
                    $m_libNameNoVersionOrBuildType \
127
                    $m_previousLibNameSrc \
128
                    $M_APPLIB_DIR
129
 
130
        # deal with common items if they exist ...
131
        #
132
        if [ -f "$M_BASELIB_DIR/$m_libNameNoVersion" ]
133
        then
134
             _removeItem $M_BASELIB_DIR/$m_libNameNoVersion
135
 
136
             _linkItem   $M_APPLIB_DIR/$m_base \
137
                         $m_libNameNoVersion \
138
                         $M_APPLIB_DIR/$m_previousLibNameSrc \
139
                         $M_BASELIB_DIR
140
        fi
141
 
142
        if [ -f "$M_BASELIB_DIR/$m_libNameNoVersionOrBuildType" ]
143
        then
144
             _removeItem $M_BASELIB_DIR/$m_libNameNoVersionOrBuildType
145
 
146
             _linkItem   $M_APPLIB_DIR/$m_base \
147
                         $m_libNameNoVersionOrBuildType \
148
                         $M_APPLIB_DIR/$m_previousLibNameSrc \
149
                         $M_BASELIB_DIR
150
        fi
151
 
152
 
153
# Not required, as we do not have any of these links in the baseDir/lib
154
# To be removed.
155
#
156
#        if [ -f "$M_BASELIB_DIR/$m_previousLibNameSrc" ]
157
#        then
158
#
159
#            echo "removef $PKGINST $M_BASELIB_DIR/$m_previousLibNameSrc" >> $M_POSTPATCH_SCRIPT
160
#            echo "rm -f            $M_BASELIB_DIR/$m_previousLibNameSrc" >> $M_POSTPATCH_SCRIPT
161
#
162
#            echo "installf -c none $PKGINST $M_BASELIB_DIR/$m_base=$M_APPLIB_DIR/$m_base s" \
163
#                 >> $M_POSTPATCH_SCRIPT
164
#
165
#            echo "removef $PKGINST $M_BASELIB_DIR/$m_base"                        >> $M_BACKOUT_SCRIPT
166
#            echo "rm -f            $M_BASELIB_DIR/$m_base"                        >> $M_BACKOUT_SCRIPT
167
#
168
#            echo "installf -c none $PKGINST $M_BASELIB_DIR/$m_previousLibNameSrc=$M_APPLIB_DIR/$m_previousLibNameSrc s" \
169
#                 >> $M_BACKOUT_SCRIPT
170
#
171
#        fi
172
 
173
    fi
174
}
175
 
176
_removeItem ()
177
{
178
    echo "rm -f $1"
179
    rm -f $1
180
    echo "rm -f $1" >> $M_BACKOUT_SCRIPT
181
}
182
 
183
_linkItem ()
184
{
185
    m_pwd=`pwd`
186
 
187
    cd $4
188
    echo "ln -s $1 $2"
189
    ln -s $1 $2 
190
 
191
    if [ "x$3" != "xnone" ]
192
    then
193
        echo "cd $4" >> $M_BACKOUT_SCRIPT
194
        echo "ln -s $3 $2" >> $M_BACKOUT_SCRIPT
195
    fi
196
 
197
    cd $m_pwd
198
}
199
 
200
 
201
PATH=/usr/sadm/bin:$PATH
202
 
203
ECHO="/usr/bin/echo"
204
SED="/usr/bin/sed"
205
PKGPROTO="/usr/bin/pkgproto"
206
EXPR="/usr/bin/expr"	# used by dirname
207
MKDIR="/usr/bin/mkdir"
208
CP="/usr/bin/cp"
209
RM="/usr/bin/rm"
210
MV="/usr/bin/mv"
211
 
212
recovery="no"
213
Pn=$$
214
procIdCtr=0
215
 
216
CMDS_USED="$ECHO $SED $PKGPROTO $EXPR $MKDIR $CP $RM $MV"
217
LIBS_USED=""
218
 
219
if [ "$PKG_INSTALL_ROOT" = "/" ]; then
220
	PKG_INSTALL_ROOT=""
221
fi
222
 
223
# Check to see if this is a patch installation retry.
224
if [ "$INTERRUPTION" = "yes" ]; then
225
	if [ -d "$PKG_INSTALL_ROOT/var/tmp/$SUNW_PATCHID.$PKGINST" ] || [ -d "$PATCH_BUILD_DIR/$SUNW_PATCHID.$PKGINST" ]; then
226
		recovery="yes"
227
	fi
228
fi
229
 
230
if [ -n "$PATCH_BUILD_DIR" -a -d "$PATCH_BUILD_DIR" ]; then
231
	BUILD_DIR="$PATCH_BUILD_DIR/$SUNW_PATCHID.$PKGINST"
232
else
233
	BUILD_DIR="$PKG_INSTALL_ROOT/var/tmp/$SUNW_PATCHID.$PKGINST"
234
fi
235
 
236
FILE_DIR=$BUILD_DIR/files
237
RELOC_DIR=$FILE_DIR/reloc
238
ROOT_DIR=$FILE_DIR/root
239
BO_Deletes=$FILE_DIR/deletes
240
PROGNAME=`basename $0`
241
 
242
 
243
# 31-July-2002 VC: added these variable, required to generate the postbackout script.
244
#
245
M_PATCHDB=/var/sadm/patch
246
M_PKGINST_LC=`echo $PKGINST | tr -s '[A-Z]' '[a-z]'`
247
M_APPLIB_DIR="$BASEDIR/$M_PKGINST_LC/lib"
248
M_BASELIB_DIR="$BASEDIR/lib"
249
M_BACKOUT_SCRIPT="$M_PATCHDB/$SUNW_PATCHID/postbackout"
250
M_POSTPATCH_SCRIPT="$M_PATCHDB/$SUNW_PATCHID/postpatch"
251
 
252
if [ "$PATCH_PROGRESSIVE" = "true" ]; then
253
	PATCH_NO_UNDO="true"
254
fi
255
 
256
# Since this is generic, figure out the class.
257
Class=`echo $PROGNAME | nawk ' { print substr($0, 3)  }'`
258
 
259
# Since this is an update, $BASEDIR is guaranteed to be correct
260
BD=${BASEDIR:-/}
261
 
262
cd $BD
263
 
264
#
265
# First, figure out the dynamic libraries that can trip us up.
266
#
267
if [ -z "$PKG_INSTALL_ROOT" ]; then
268
	if [ -x /usr/bin/ldd ]; then
269
		LIB_LIST=`/usr/bin/ldd $CMDS_USED | sort -u | nawk '
270
			$1 ~ /\// { continue; }
271
			{ printf "%s ", $3 } '`
272
	else
273
		LIB_LIST="/usr/lib/libc.so.1 /usr/lib/libdl.so.1 /usr/lib/libw.so.1 /usr/lib/libintl.so.1 /usr/lib/libgen.so.1 /usr/lib/libadm.so.1 /usr/lib/libelf.so.1"
274
	fi
275
fi
276
 
277
#
278
# Now read the list of files in this class to be replaced. If the file
279
# is already in place, then this is a change and we need to copy it
280
# over to the build directory if undo is allowed. If it's a new entry
281
# (No $dst), then it goes in the deletes file for the backout package.
282
#
283
 
284
LD_LIB_DIR=$PKG_INSTALL_ROOT/var/tmp/LDLIB.$$
285
 
286
procIdCtr=0
287
while read src dst; do
288
	if [ -z "$PKG_INSTALL_ROOT" ]; then
289
		Chk_Path=$dst
290
		for library in $LIB_LIST; do
291
			if [ "$Chk_Path" = "$library" ]; then
292
				if [ ! -d "$LD_LIB_DIR" ]; then
293
					$MKDIR $LD_LIB_DIR
294
				fi
295
				$CP $dst $LD_LIB_DIR
296
				LD_LIBRARY_PATH=$LD_LIB_DIR
297
				export LD_LIBRARY_PATH
298
			fi
299
		done
300
	fi
301
 
302
	if [ "$PATCH_PROGRESSIVE" = "true" ]; then
303
		# If this is being used in an old-style patch, insert
304
		# the old-style script commands here.
305
 
306
		#XXXOld_CommandsXXX#
307
		echo >/dev/null	# dummy
308
	fi
309
 
310
	if [ "${PATCH_NO_UNDO}" != "true" ]; then
311
		#
312
		# Here we construct the path to the appropriate source
313
		# tree for the build. First we try to strip BASEDIR. If
314
		# there's no BASEDIR in the path, we presume that it is
315
		# absolute and construct the target as an absolute path
316
		# by stripping PKG_INSTALL_ROOT. FS_Path is the path to
317
		# the file on the file system (for deletion purposes).
318
		# Build_Path is the path to the object in the build
319
		# environment.
320
		#
321
		# The following rootPath variable accounts for a BASEDIR
322
		# that is used as a regular variable within the path and
323
		# not as a variable that a path needs to be relocated to.
324
 
325
		rootPath=`$ECHO $src | $SED s@"$INST_DATADIR/$PKGINST"@@ | \
326
			nawk -F/ '{print $2}'`
327
		if [ "$rootPath" = "root" ]; then
328
			FS_Path=$dst
329
		elif [ "$BD" = "/" ]; then
330
			FS_Path=`$ECHO $dst | $SED s@"$BD"@@`
331
		else
332
			FS_Path=`$ECHO $dst | $SED "s|$BD/||"`
333
		fi
334
 
335
		# If it's an absolute path the attempt to strip the
336
		# BASEDIR will have failed.
337
		if [ "$dst" = "$FS_Path" ]; then
338
			if [ -z "$PKG_INSTALL_ROOT" ]; then
339
				FS_Path=$dst
340
				Build_Path="$ROOT_DIR$dst"
341
			else
342
				Build_Path="$ROOT_DIR"`echo $dst | \
343
				    $SED "s|$PKG_INSTALL_ROOT||"`
344
				FS_Path=`echo $dst | \
345
				    $SED "s|$PKG_INSTALL_ROOT||"`
346
			fi
347
		else
348
			Build_Path="$RELOC_DIR/$FS_Path"
349
		fi
350
 
351
		if [ -f "$dst" ]; then	# If this is replacing something
352
			cd $FILE_DIR
353
			#
354
			# Construct the prototype file entry. We replace
355
			# the pointer to the filesystem object with the
356
			# build directory object.
357
			#
358
			$PKGPROTO -c $Class $dst=$FS_Path | \
359
			    $SED -e "s|=$dst|=$Build_Path|" >> \
360
			    $BUILD_DIR/prototype
361
 
362
			# Now copy over the file
363
			if [ "$recovery" = "no" ]; then
364
				DirName=`dirname $Build_Path`
365
				$MKDIR -p $DirName
366
				$CP -p $dst $Build_Path
367
			else
368
				# If this file is already in the build area skip it
369
				if [ -f "$Build_Path" ]; then
370
					cd $BD
371
					continue
372
				else
373
					DirName=`dirname $Build_Path`
374
					if [ ! -d "$DirName" ]; then
375
						$MKDIR -p $DirName
376
					fi
377
					$CP -p $dst $Build_Path
378
				fi
379
			fi
380
 
381
			cd $BD
382
		else	# It's brand new
383
			$ECHO $FS_Path >> $BO_Deletes
384
		fi
385
	fi
386
 
387
	# If special processing is required for each src/dst pair,
388
	# add that here.
389
	#
390
	#XXXSpecial_CommandsXXX#
391
	#
392
 
393
        # we need to determine if the item is a lib file
394
        `perl -e '$ARGV[0] =~ m/\.so/ or exit(1);' -- $src`
395
        isLib=$?
396
        if [ "$isLib" -eq "0" ]
397
        then
398
            OLD_DIR=`pwd`
399
            cd $M_APPLIB_DIR
400
            _processLibFile $src
401
            cd $OLD_DIR
402
        fi
403
 
404
 
405
	$CP -p $src $dst.$$$procIdCtr
406
	if [ $? -ne 0 ]; then
407
		$RM $dst.$$$procIdCtr 1>/dev/null 2>&1
408
	else
409
		$MV -f $dst.$$$procIdCtr $dst
410
		for library in $LIB_LIST; do
411
			if [ "$library" = "$dst" ]; then
412
				unset $LD_LIBRARY_PATH
413
			fi
414
		done
415
	fi
416
	procIdCtr=`expr $procIdCtr + 1`
417
done
418
 
419
# If additional operations are required for this package, place
420
# those package-specific commands here.
421
 
422
#XXXSpecial_CommandsXXX#
423
echo "removef -f $PKGINST"  >> $M_POSTPATCH_SCRIPT
424
echo "installf -f $PKGINST" >> $M_POSTPATCH_SCRIPT
425
echo "exit 0;"              >> $M_POSTPATCH_SCRIPT
426
chmod 755 $M_POSTPATCH_SCRIPT
427
 
428
echo "removef -f $PKGINST"  >> $M_BACKOUT_SCRIPT
429
echo "installf -f $PKGINST" >> $M_BACKOUT_SCRIPT
430
echo "exit 0;"              >> $M_BACKOUT_SCRIPT
431
chmod 755 $M_BACKOUT_SCRIPT
432
 
433
#
434
# Release the dynamic libraries
435
#
436
if [ -d "$LD_LIB_DIR" ]; then
437
	$RM -fr $LD_LIB_DIR
438
fi
439
 
440
exit 0
441