home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / .extra.d / usr / sbin / pkginst / pkgsavfiles < prev   
Encoding:
Text File  |  1998-08-19  |  6.0 KB  |  220 lines

  1. # Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  2. #                                                                         
  3. #        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  4. #                   SANTA CRUZ OPERATION INC.                             
  5. #                                                                         
  6. #   The copyright notice above does not evidence any actual or intended   
  7. #   publication of such source code.                                      
  8.  
  9. #ident    "@(#)pkgsavfiles.sh    15.1"
  10. #ident    "$Header: $"
  11.  
  12. # this routine is done if auto install mode was selected
  13. # and PKGINSTALL_TYPE for this pkg is not known
  14.  
  15. find_install_type ()
  16. {
  17.     [ "$UPDEBUG" = "YES" ] && set -x
  18.  
  19.     AUTOMERGE=Yes
  20.  
  21.     PKGINSTALL_TYPE=NEWINSTALL
  22.  
  23. #chkpkgrel, returns a code, indicating which version of this pkg is installed.
  24. #Return code 2 indicates overlay of the same or older version. For overlay,
  25. #existence of the file $UPGRADE_STORE/$PKGINST.ver indicates presence of older
  26. #version. This file contains the old version.
  27.  
  28. #    ${SCRIPTS}/chkpkgrel returns    0 if pkg is not installed
  29. #                    1 if pkg if unknown version
  30. #                    2 if OVERLAY
  31. #                    4 if UPGRADE  (from uw1.1.x)
  32. #                    6 if UPGRADE2 (from sbird2.0.1)
  33. #                    9 if newer pkg is installed
  34.     
  35.     [ "$UPDEBUG" = "YES" ] && goany "running $SCRIPTS/chkpkgrel from $0"
  36.     ${SCRIPTS}/chkpkgrel
  37.     PKGVERSION=$?
  38.     case $PKGVERSION in
  39.         2)    PKGINSTALL_TYPE=OVERLAY    ;;
  40.         4)    PKGINSTALL_TYPE=UPGRADE    ;;
  41.         6)    PKGINSTALL_TYPE=UPGRADE2    ;;
  42.         9)    exit 3    ;;         # pkgrm newer pkg before 
  43.                         # older pkg can be installed.
  44.         *)    AUTOMERGE=NULL ;;
  45.     esac
  46.  
  47.     # we are in this procedure in case of auto install, when request
  48.     # script is bypassed.
  49.     # rm $UPGFILE so that the env vars get written into $UPGFILE
  50.     # in write_vars_and_exit.
  51.  
  52.     rm -f $UPGFILE
  53.  
  54.     [ "$UPDEBUG" = "YES" ] && goany
  55. }
  56.  
  57. # arg 1 for this routine is either 0 or 1
  58. # this routine sets AUTOMERGE to NULL if arg1 is 1, saves vars and exits with $1
  59.  
  60. write_vars_and_exit () {
  61.  
  62.     [ "$UPDEBUG" = "YES" ] && set -x
  63.  
  64.     [ "$1" = 1 ] && AUTOMERGE=NULL
  65.  
  66.     # if $UPGFILE exists, the environment has AUTOMERGE and
  67.     # PKGINSTALL_TYPE defined already because the request 
  68.     # script must have been run
  69.  
  70.     [ -f "$UPGFILE"  ] && {     # contains exit code of chkpkgrel
  71.         # reset AUTOMERGE to NULL
  72.         [ $1 = 1 ] && echo "AUTOMERGE=\"$AUTOMERGE\"" >$UPGFILE
  73.  
  74.         [ "$UPDEBUG" = "YES" ] && goany "exiting $0"
  75.         exit $1
  76.     }
  77.  
  78.     echo "AUTOMERGE=\"$AUTOMERGE\"" >$UPGFILE
  79.     echo "PKGINSTALL_TYPE=\"$PKGINSTALL_TYPE\"" >>$UPGFILE
  80.     [ "$UPDEBUG" = "YES" ] && goany "exiting $0"
  81.     exit $1
  82. }
  83.  
  84. ### main()
  85.  
  86. #  This script is called with 1 arg, $PKGINST, from the preinstall script
  87.  
  88. #  For upgrade the volatile files list is:
  89. #    /etc/inst/up/patch/${PKGINST}.LIST
  90. #
  91. #  For overlay, this script gets the volatile files from the
  92. #      'contents' file for  $PKGINST
  93. #  It saves the 'v' files in /etc/inst/save.user
  94. #  It makes a list of the files saved in  in ${UPGRADE_STORE}/$1.sav
  95.  
  96. #  Exit codes are:
  97. #   0     when volatiles are saved in $UPGRADE_STORE
  98. #   1     no volatile files exist for $PKGINST so AUTOMERGE is set to NULL
  99.  
  100. SCRIPTS=/usr/sbin/pkginst
  101.  
  102. . $SCRIPTS/updebug
  103.  
  104. [ "$UPDEBUG" = "YES" ] && set -x
  105.  
  106.  
  107. [ "$1" ] || {
  108.     pfmt -s nostd -g uxupgrade:3 "Usage: %s <PKGINST>\n" $0 2>&1
  109.     echo "Usage: $0  <PKGINST>"  >>$UPERR
  110.     exit 2
  111. }
  112.     
  113. pkg=$1
  114.  
  115. S=" ";            # space
  116. T="    ";        # tab
  117. UPGLIST=/etc/inst/up/patch/${1}.LIST
  118. UPGRADE_STORE=/etc/inst/save.user
  119. [ -d $UPGRADE_STORE ] || mkdir -p $UPGRADE_STORE
  120. UPDIR=/etc/inst/up
  121. [ -d $UPDIR ] || mkdir -p $UPDIR
  122.  
  123. sav=$UPGRADE_STORE/$1.sav
  124. rm -f $sav
  125.  
  126. UPGFILE=$UPGRADE_STORE/${1}.env
  127.  
  128. # $UPGFILE is created if pkgchkrel has been run from the request script.
  129. # remember that request script is bypassed in AUTOMATIC install mode
  130.  
  131. [ "$UPDEBUG" = "YES" ] && goany
  132.  
  133. [ -f "$UPGFILE" ] || find_install_type
  134.  
  135. # PKGINSTALL_TYPE must  be set by now
  136.  
  137. [ "$PKGINSTALL_TYPE" ] || { 
  138.     pfmt -s nostd -g uxupgrade:4 "Error: %s:   PKGINSTALL_TYPE must be set by now\n" $0 2>&1
  139.     echo "Error: $0:   PKGINSTALL_TYPE must be set by now"  >>$UPERR
  140.     exit 2
  141. }
  142.  
  143. [ "$PKGINSTALL_TYPE" = NEWINSTALL ] && write_vars_and_exit 1
  144.  
  145. [ "$PKGINSTALL_TYPE" = UPGRADE2 -o "$PKGINSTALL_TYPE" = UPGRADE ] && {
  146.  
  147.     [ -f "$UPGLIST" ] || {
  148.         echo "Error: $0:   $UPGLIST missing"  >>$UPERR
  149.         write_vars_and_exit 1
  150.     }
  151.  
  152.     # eliminate comment lines from the list of volatile files
  153.     cat $UPGLIST | grep -v '^[     ]*#' | grep -v '^[     ]*$' >$sav
  154.  
  155.     [ -s $sav ] || {
  156.         echo "Error: $0:   $UPGLIST has 0 non-commentary lines"  >>$UPERR
  157.         write_vars_and_exit 1
  158.     }
  159. }
  160.  
  161. [ "$UPDEBUG" = "YES" ] && goany
  162.  
  163. [ "$PKGINSTALL_TYPE" = OVERLAY ] && {
  164.  
  165.     CONTENTS=/var/sadm/install/contents
  166.     olist=/tmp/list.$$
  167.  
  168.     # grep volatile files from 'contents'  and save temporarily in $sav
  169.  
  170.     # first grep for $pkg in the end of line
  171.  
  172.     PATTERN="${S}${T}+-~*\:!"
  173.     grep "^.*[${T}${S}][ve][${T}${S}].*[$PATTERN]${pkg}$" $CONTENTS  \
  174.                          >$sav   2>>$UPERR
  175.     # now grep for $pkg preceeded and followed by any of the chars:
  176.     # whitespace  * \ ~ : ! + -
  177.  
  178.     grep "^.*[${T}${S}][ve][${T}${S}].*[${PATTERN}]${pkg}[${PATTERN}]" \
  179.             $CONTENTS >>$sav   2>>$UPERR
  180.     
  181.     # get rid from the list, the files in /etc/conf that are 
  182.     # marked 'v' in $CONTENTS
  183.  
  184.     grep -v "^/etc/conf/" $sav | grep -v "^/tmp/" >$olist 2>>$UPERR
  185.     grep  "^/etc/conf/init.d/kernel" $sav >>$olist 2>>$UPERR
  186.     grep  "^/etc/conf/node.d/" $sav >>$olist 2>>$UPERR
  187.     grep  "^/etc/conf/mtune.d/" $sav >>$olist 2>>$UPERR
  188.     grep  "^/etc/conf/cf.d/stune" $sav >>$olist 2>>$UPERR
  189.  
  190.     #if empty list, exit 1 to set AUTOMERGE to NULL
  191.  
  192.     [ -s $olist ] || {
  193.  
  194.         # We don't want $sav to be lying around. Also clean up $olist
  195.  
  196.         rm -f $sav $olist
  197.         echo "Error: $0:   no volatile files for $PKGINST"  >>$UPERR
  198.         write_vars_and_exit 1
  199.     }
  200.     [ "$UPDEBUG" = "YES" ] && goany
  201.  
  202.     #  get the file name (1st field), make it relative path, save final
  203.     #  list of volatile files that will be preserved in $sav
  204.  
  205.     cat $olist | sed 's/[     ].*$//' | sed 's/^\///'  >$sav
  206.     rm -f $olist
  207. }
  208.  
  209. [ "$UPDEBUG" = "YES" ] && goany
  210.  
  211. # save files listed in $sav in $UPGRADE_STORE
  212. #
  213.  
  214. cd /
  215. cat $sav | cpio -pdmu $UPGRADE_STORE       >>$UPERR 2>&1
  216.  
  217. [ "$UPDEBUG" = "YES" ] && goany
  218.  
  219. write_vars_and_exit 0
  220.