home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / nsnavAu / install / postinstall < prev    next >
Text File  |  1998-08-19  |  9KB  |  312 lines

  1. #!/bin/sh
  2. #
  3. #       @(#) postinstall.shinc 12.5 97/11/17 
  4. #
  5. # Copyright (c) 1997 The Santa Cruz Operation, Inc.. All Rights Reserved.
  6. # THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE SANTA CRUZ OPERATION INC.
  7. # The copyright notice above does not evidence any actual or intended
  8. # publication of such source code.
  9. ME="`basename $0`"
  10. ISL_FILE="/etc/inst/scripts/postreboot.sh"
  11. SUCCESS=0; FAIL=1; INTR=3
  12. trap "exit $INTR" 2 3 15
  13. [ -f $ISL_FILE ] && exec 1>>/var/adm/log/$PKGINST.out
  14. [ -f $ISL_FILE ] && exec 2>>/var/adm/log/$PKGINST.err
  15.  
  16. # location of the packaging information files during this phase of installation
  17. INSTALL_DIR="/var/sadm/pkg/$PKGINST/install/$PKGINST"
  18.  
  19. # included standard routines
  20. #############################################################################
  21. #
  22. #    @(#) rebuild_file.sh_h 11.5 97/10/15 
  23. #
  24. # Standard routine to take a file that has been cut into pieces for
  25. # shipment as a package, and piece that file back together from its
  26. # component parts in a postinstall script.
  27. #
  28. # The routine looks for parts of the file as $1.Pnn, where nn are
  29. # digits, 01..99
  30. #
  31. # Arguments are:
  32. #
  33. #    $1    - name of the file to rebuild (the target)
  34. #    $2    - target file mode (e.g. 0711)
  35. #    $3    - target file owner (e.g. root)
  36. #    $4    - target file group (e.g. other)
  37. #    $5    - optional argument; the checksum for the completed file
  38. #
  39. # Return values are:
  40. #
  41. #    0    - success
  42. #    1    - failure (for example, piece of the file missing)
  43. #
  44. # Also uses:
  45. #
  46. #    $ME    - name of the shell script calling the routine
  47. #    $SUCCESS- success value 0
  48. #    $FAIL    - error value 1
  49. #############################################################################
  50. rebuild_file()
  51. {
  52.     target="$1"
  53.     mode="$2"
  54.     owner="$3"; group="$4"
  55.     checksum="$5"
  56.  
  57.     # count the number of pieces to the file
  58.     piececount=`ls $target.P[0-9][0-9] 2>/dev/null | wc -w | tr -d ' '`
  59.     if [ $piececount -lt 1 ]; then
  60.         echo "$ME: rebuild_file: $piececount is invalid (<1)" >&2
  61.         return $FAIL
  62.     else
  63.         if [ $piececount -gt 99 ]; then
  64.             echo "$ME: rebuild_file: $piececount is too many pieces" >&2
  65.             return $FAIL
  66.         fi
  67.     fi
  68.  
  69.     # build the file by appending these pieces one after another
  70.     >$target
  71.     piece=0; while [ $piece -lt $piececount ]; do
  72.         extn="`expr $piece + 1`"
  73.         [ `expr length $extn` -lt 2 ] && extn="0$extn"
  74.         if [ -f $target.P$extn ]; then
  75.             cat $target.P$extn >>$target
  76.             rmfile=`removef ${PKGINST} $target.P$extn`
  77.             if [ -n "$rmfile" ]; then
  78.                 if [ -f "$rmfile" ]; then
  79.                     rm $target.P$extn >/dev/null 2>&1
  80.                     if [ $? -ne 0 ]; then
  81.                         echo "$ME: rebuild_file: error deleting $target.P$extn"
  82.                     fi
  83.                 fi
  84.             else
  85.                 echo "$ME: rebuild_file: unsafe to remove $target.P$extn - not removed"
  86.             fi
  87.         else
  88.                 echo "$ME: rebuild_file: missing file piece $extn of $target" >&2
  89.             return $FAIL
  90.         fi
  91.         piece=`expr $piece + 1`
  92.     done
  93.  
  94.     # check the expected checksum, if supplied
  95.     if [ -n "$checksum" ]; then
  96.         sum="`cat $target | sum -r | sed -e 's/ .*//'`"
  97.         if [ "$sum" != "$checksum" ]; then
  98.                 echo "$ME: rebuild_file: $target checksum mismatch ($sum!=$checksum" >&2
  99.             return $FAIL
  100.         fi
  101.     fi
  102.  
  103.     # set up the file permissions and ownership
  104.     chmod $mode $target
  105.     chown ${owner}:${group} $target
  106.     installf $PKGINST $target f $mode $owner $group
  107.  
  108.     # don't forget to run installf -f and removef -f before your
  109.     # installation script exits
  110.  
  111.     # completed successfully
  112.     return $SUCCESS
  113. }
  114.  
  115.  
  116. #############################################################################
  117. #
  118. #    @(#) replace_with_newer.sh_h 12.2 97/10/27 
  119. #
  120. # Standard routine to update the /etc/encrypt_config script with the
  121. # one held in this package if, and only if, it can be determined that
  122. # the one held in this package is at a later SCCS revision level.
  123. #
  124. # The routine uses what(C,1) to decide which file is the newer.  Missing
  125. # numbers in the SCCS R.L.B.S versioning are assumed to be 0.  A file
  126. # with no SCCS ID at all in it is assumed to be at 0.0.0.0.
  127. #
  128. # Arguments are:
  129. #
  130. #    $1    - PKGINST
  131. #    $2    - action: 'test' or 'update'
  132. #    $3    - path to the original file
  133. #    $4    - path to the file to update it with
  134. #    $5    - mode of the 'new' file
  135. #    $6    - owner of the 'new' file
  136. #    $7    - group of the 'new' file
  137. #
  138. # Return values are:
  139. #
  140. #    0    - success; the file was upgraded if $2 is 'update', the
  141. #          file should be updated if $2 is 'test'
  142. #    1    - failure; the file is as new or newer than the replacement
  143. #          we have for it
  144. #
  145. # Also uses:
  146. #
  147. #    $ME    - name of the shell script calling the routine
  148. #    $SUCCESS- success value 0
  149. #    $FAIL    - error value 1
  150. #############################################################################
  151. replace_with_newer()
  152. {
  153.     pkginst="$1"
  154.     action="$2"
  155.     original_file="$3"
  156.     shipped_file="$4"
  157.     mode="$5"
  158.     owner="$6"
  159.     group="$7"
  160.  
  161.     # first, decide whether to update the file at all
  162.     update=0
  163.     if [ ! -f $shipped_file ]; then
  164.         echo "$ME: can't find $shipped_file" >&2
  165.         return $FAIL
  166.     fi
  167.     if [ ! -f $original_file ]; then
  168.         update=1
  169.     else
  170.         # find the SCCS IDs of both files
  171.         set -- `what $original_file | awk 'NR==2 { print $2 }' \
  172.                 | awk -F'.' '{ print $1" "$2" "$3" "$4 }'`
  173.         oR=$1; oL=$2; oB=$3; oS=$4
  174.         [ -z "$oR" ] && oR=0; [ -z "$oL" ] && oL=0
  175.         [ -z "$oB" ] && oB=0; [ -z "$oS" ] && oS=0
  176.         set -- `what $shipped_file | awk 'NR==2 { print $2 }' \
  177.                 | awk -F'.' '{ print $1" "$2" "$3" "$4 }'`
  178.         sR=$1; sL=$2; sB=$3; sS=$4
  179.         [ -z "$sR" ] && sR=0; [ -z "$sL" ] && sL=0
  180.         [ -z "$sB" ] && sB=0; [ -z "$sS" ] && sS=0
  181.  
  182.         # now compare the SCCS releases
  183.         [ $sR -gt $oR ] && update=1
  184.         [ $sR -eq $oR -a $sL -gt $oL ] && update=1
  185.         [ $sR -eq $oR -a $sL -eq $oL -a $sB -gt $oB ] && update=1
  186.         [ $sR -eq $oR -a $sL -eq $oL -a $sB -eq $oB -a $sS -gt $oS ] && update=1
  187.     fi
  188.  
  189.     if [ "$action" = "test" ]; then
  190.  
  191.         # return a value based on what we found out about the
  192.         # file's comparative SCCS versions
  193.         if [ $update -eq 1 ]; then
  194.             return $SUCCESS
  195.         else
  196.             return $FAIL
  197.         fi
  198.  
  199.     else
  200.  
  201.         # if updating then copy over the file and update our packaging
  202.         # to reflect the fact that we now (jointly?) own this item
  203.         if [ $update -eq 1 ]; then
  204.  
  205.             # copy the file, and update packaging; note that we
  206.             # make it volatile so that pkgchk won't complain if
  207.             # someone else installs a newer version later
  208.             cp $shipped_file $original_file
  209.             chmod $mode $original_file
  210.             chown $owner:$group $original_file
  211.             installf $pkginst $original_file v $mode $owner $group
  212.  
  213.             # return file updated status
  214.             return $SUCCESS
  215.         else
  216.  
  217.             # adopt joint ownership of the file that's there
  218.             # so that it isn't removed while we remain installed
  219.             chmod $mode $original_file
  220.             chown $owner:$group $original_file
  221.             installf $pkginst $original_file v $mode $owner $group
  222.  
  223.             # return no change status
  224.             return $FAIL
  225.         fi
  226.     fi
  227.  
  228.     # don't forget to run installf -f and removef -f before your
  229.     # installation script exits
  230.  
  231.     echo "$ME: internal error - replace_with_newer: no valid end condition" >&2
  232.     return $FAIL
  233. }
  234.  
  235.  
  236.  
  237.  
  238. ##############################################################################
  239. #
  240. # link_socketlib
  241. #
  242. # links libsocket.so.2 to target libsocket.so if .so.2 doesn't exist
  243. #
  244. #############################################################################
  245. link_socketlib()
  246. {
  247.     [ -f  /usr/lib/libsocket.so.2 ] || \
  248.         ln -s /usr/lib/libsocket.so /usr/lib/libsocket.so.2 2>/dev/null
  249. }
  250.  
  251.  
  252. #############################################################################
  253. #
  254. # main
  255. #
  256. #############################################################################
  257.  
  258. # fix up socket library things
  259. link_socketlib
  260.  
  261. # piece the browser executable files back together
  262. for file in /usr/ns-home/lib/netscape/netscape-us \
  263.         /usr/ns-home/lib/netscape/netscape-export; do
  264.     rebuild_file "$file" 0711 root sys
  265.     if [ $? -ne 0 ]; then
  266.         echo "$ME: failed to rebuild file $file" >&2
  267.         exit $FAIL
  268.     fi
  269. done
  270.  
  271. # update file links for US/International browser versions
  272. if [ -f "$INSTALL_DIR/exportpaths.sh" ]; then
  273.  
  274.     # determine the right location for messages - try /etc/inst/locale
  275.     # first, and if no messages there then use ones in the installation
  276.     # set - try for local ones first, then fall back on C
  277.     LOCALE="${LC_ALL:-${LC_MESSAGES:-${LANG:-C}}}"
  278.     MENU_DIR="/etc/inst/locale/$LOCALE/menus/$PKGINST"
  279.     if [ ! -f $MENU_DIR/exportpaths.msgs ]; then
  280.         if [ ! -d $INSTALL_DIR/$LOCALE ]; then
  281.             LOCALE="C"
  282.         fi
  283.         MENU_DIR=$INSTALL_DIR/$LOCALE
  284.     fi
  285.  
  286.     sh $INSTALL_DIR/exportpaths.sh $PKGINST $INSTALL_DIR/links.fl \
  287.             $INSTALL_DIR/l_info $MENU_DIR
  288.     if [ $? -ne 0 ]; then
  289.         echo "$ME: exportpaths.sh script failed" >&2
  290.         exit $FAIL
  291.     fi
  292. else
  293.     echo "$ME: unable to find $INSTALL_DIR/exportpaths.sh" >&2
  294.     exit $FAIL
  295. fi
  296.  
  297. # install our encrypt_config if it is newer
  298. if [ -f $INSTALL_DIR/encrypt_config ]; then
  299.     replace_with_newer $PKGINST update /usr/sbin/encrypt_config \
  300.             $INSTALL_DIR/encrypt_config 700 root sys
  301.     ln -f /usr/sbin/encrypt_config /etc/encrypt_config
  302.     installf $PKGINST /etc/encrypt_config=/usr/sbin/encrypt_config
  303. fi
  304.  
  305. # done
  306. removef -f $PKGINST
  307. installf -f $PKGINST
  308. exit $SUCCESS
  309.