Rev 1530 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#set -x# This script creates the backout package for a patch package## directory format options.## @(#) postinstall 1.10 99/04/23 SMI## Copyright (c) 1995 by Sun Microsystems, Inc.# All rights reserved## Description:# Set the TYPE parameter for the remote file## Parameters:# none## Globals set:# TYPEset_TYPE_parameter () {if [ ${PATCH_UNDO_ARCHIVE:?????} = "/dev" ]; then# handle device specific stuffTYPE="removable"elseTYPE="filesystem"fi}## Description:# Build the remote file that points to the backout data## Parameters:# $1: the un/compressed undo archive## Globals set:# UNDO, STATEbuild_remote_file () {remote_path=$PKGSAV/$SUNW_PATCHID/remoteset_TYPE_parameterSTATE="active"if [ $1 = "undo" ]; thenUNDO="undo"elseUNDO="undo.Z"ficat > $remote_path << EOF# Backout data stored remotelyTYPE=$TYPEFIND_AT=$ARCHIVE_DIR/$UNDOSTATE=$STATEEOF}PATH=/usr/sadm/bin:$PATHif [ "$PKG_INSTALL_ROOT" = "/" ]; thenPKG_INSTALL_ROOT=""fiif [ -n "$PATCH_BUILD_DIR" -a -d "$PATCH_BUILD_DIR" ]; thenBUILD_DIR="$PATCH_BUILD_DIR/$SUNW_PATCHID.$PKGINST"elseBUILD_DIR="$PKG_INSTALL_ROOT/var/tmp/$SUNW_PATCHID.$PKGINST"fiif [ ! -n "$PATCH_UNDO_ARCHIVE" ]; thenPATCH_UNDO_ARCHIVE="none"fiFILE_DIR=$BUILD_DIR/filesRELOC_DIR=$FILE_DIR/relocROOT_DIR=$FILE_DIR/rootBO_Deletes=$FILE_DIR/deletesTHIS_DIR=`dirname $0`PROTO_FILE=$BUILD_DIR/prototypeTEMP_REMOTE=$PKGSAV/$SUNW_PATCHID/tempif [ "$PATCH_PROGRESSIVE" = "true" ]; then# remove the scripts that are left behindinstall_scripts=`dirname $0`rm $install_scripts/checkinstall $install_scripts/patch_checkinstall $install_scripts/patch_postinstall# If this is being used in an old-style patch, insert# the old-style script commands here.#XXXOld_CommandsXXX#exit 0fi## At this point we either have a deletes file or we don't. If we do,# we create a prototype entry.#if [ -f $BO_Deletes ]; thenecho "i deletes=$BO_Deletes" >> $BUILD_DIR/prototypefi## Now delete everything in the deletes list after transferring# the file to the backout package and the entry to the prototype# file. Remember that the pkgmap will get the CLIENT_BASEDIR path# but we have to actually get at it using the BASEDIR path. Also# remember that removef will import our PKG_INSTALL_ROOT#Our_Deletes=$THIS_DIR/deletesif [ -f $Our_Deletes ]; thencd $BASEDIRcat $Our_Deletes | while read path; doReg_File=0if valpath -l $path; thenClient_Path="$CLIENT_BASEDIR/$path"Build_Path="$RELOC_DIR/$path"Proto_Path=$BASEDIR/$pathelse # It's an absolute pathClient_Path=$pathBuild_Path="$ROOT_DIR$path"Proto_Path=$PKG_INSTALL_ROOT$pathfi# If BASEDIR/CLIENTBASEDIR = "/", then the previous prepends# an extra / i.e. //. The sed command later can't find a# Proto_Path with // and therefore will not substitute the# correct build_Path resulting in the backout pkg not being# created.if [ "$CLIENT_BASEDIR" = "/" ]; thenClient_Path=`echo $Client_Path | sed 's|^\/\/|\/|'`Proto_Path=`echo $Proto_Path | sed 's|^\/\/|\/|'`fi# Note: If the file isn't really there, pkgproto# doesn't write anything.LINE=`pkgproto $Proto_Path=$path`ftype=`echo $LINE | nawk '{ print $1 }'`if [ "$ftype" = "f" ]; thenReg_File=1fiif [ $Reg_File = 1 ]; then# Add source file to the prototype entryif [ "$Proto_Path" = "$path" ]; thenLINE=`echo $LINE | sed -e "s|$Proto_Path|$Build_Path|2"`elseLINE=`echo $LINE | sed -e "s|$Proto_Path|$Build_Path|"`fiDirName=`dirname $Build_Path`# make room in the build treemkdir -p $DirNamecp -p $Proto_Path $Build_Pathfi# Insert it into the prototype fileecho $LINE 1>>$PROTO_FILE 2>/dev/null# Remove the file only if it's OK'd by removefrm `removef $PKGINST $Client_Path` 1>/dev/null 2>&1doneremovef -f $PKGINSTrm $Our_Deletesfi## Unless specifically denied, make the backout package.#if [ "$PATCH_NO_UNDO" != "true" ]; thencd $BUILD_DIR # We have to build from here.if [ "$PATCH_UNDO_ARCHIVE" != "none" ]; thenSTAGE_DIR="$PATCH_UNDO_ARCHIVE"ARCHIVE_DIR="$PATCH_UNDO_ARCHIVE/$SUNW_PATCHID/$PKGINST"mkdir -p $ARCHIVE_DIRmkdir -p $PKGSAV/$SUNW_PATCHIDelseif [ -d $PKGSAV/$SUNW_PATCHID ]; thenrm -r $PKGSAV/$SUNW_PATCHIDfiSTAGE_DIR=$PKGSAVARCHIVE_DIR=$PKGSAV/$SUNW_PATCHIDmkdir $ARCHIVE_DIRfipkgmk -o -d $STAGE_DIR 1>/dev/null 2>&1pkgtrans -s $STAGE_DIR $ARCHIVE_DIR/undo $PKG 1>/dev/null 2>&1compress $ARCHIVE_DIR/undoretcode=$?if [ "$PATCH_UNDO_ARCHIVE" != "none" ]; thenif [ $retcode != 0 ]; thenbuild_remote_file "undo"elsebuild_remote_file "undo.Z"fifirm -r $STAGE_DIR/$PKGcd ..rm -r $BUILD_DIR# remove the scripts that are left behindinstall_scripts=`dirname $0`rm $install_scripts/checkinstall $install_scripts/patch_checkinstall $install_scripts/patch_postinstallfi## Since this apparently worked, we'll mark as obsoleted the prior# versions of this patch - installpatch deals with explicit obsoletions.#cd ${PKG_INSTALL_ROOT:-/}cd var/sadm/pkgactive_base=`echo $SUNW_PATCHID | nawk '{ print substr($0, 1, match($0, "-")-1) } '`List=`ls -d $PKGINST/save/${active_base}* 2>/dev/null`if [ $? -ne 0 ]; thenList=""fifor savedir in $List; dopatch=`basename $savedir`if [ $patch = $SUNW_PATCHID ]; thenbreakfi# If we get here then the previous patch gets deletedif [ -f $savedir/undo ]; thenmv $savedir/undo $savedir/obsoleteecho $SUNW_PATCHID >> $savedir/obsoleted_byelif [ -f $savedir/undo.Z ]; thenmv $savedir/undo.Z $savedir/obsolete.Zecho $SUNW_PATCHID >> $savedir/obsoleted_byelif [ -f $savedir/remote ]; then`grep . $PKGSAV/$patch/remote | sed 's|STATE=.*|STATE=obsolete|' > $TEMP_REMOTE`rm -f $PKGSAV/$patch/remotemv $TEMP_REMOTE $PKGSAV/$patch/remoterm -f $TEMP_REMOTEecho $SUNW_PATCHID >> $savedir/obsoleted_byelif [ -f $savedir/obsolete -o -f $savedir/obsolete.Z ]; thenecho $SUNW_PATCHID >> $savedir/obsoleted_byfidone# If additional operations are required for this package, place# those package-specific commands here.#XXXSpecial_CommandsXXX#exit 0