home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #
- # @(#) postinstall.shinc 12.5 97/11/17
- #
- # Copyright (c) 1997 The Santa Cruz Operation, Inc.. All Rights Reserved.
- # THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE SANTA CRUZ OPERATION INC.
- # The copyright notice above does not evidence any actual or intended
- # publication of such source code.
- #
- ME="`basename $0`"
- ISL_FILE="/etc/inst/scripts/postreboot.sh"
- SUCCESS=0; FAIL=1; INTR=3
- trap "exit $INTR" 2 3 15
- [ -f $ISL_FILE ] && exec 1>>/var/adm/log/$PKGINST.out
- [ -f $ISL_FILE ] && exec 2>>/var/adm/log/$PKGINST.err
-
- # location of the packaging information files during this phase of installation
- INSTALL_DIR="/var/sadm/pkg/$PKGINST/install/$PKGINST"
-
- # included standard routines
- #############################################################################
- #
- # @(#) rebuild_file.sh_h 11.5 97/10/15
- #
- # Standard routine to take a file that has been cut into pieces for
- # shipment as a package, and piece that file back together from its
- # component parts in a postinstall script.
- #
- # The routine looks for parts of the file as $1.Pnn, where nn are
- # digits, 01..99
- #
- # Arguments are:
- #
- # $1 - name of the file to rebuild (the target)
- # $2 - target file mode (e.g. 0711)
- # $3 - target file owner (e.g. root)
- # $4 - target file group (e.g. other)
- # $5 - optional argument; the checksum for the completed file
- #
- # Return values are:
- #
- # 0 - success
- # 1 - failure (for example, piece of the file missing)
- #
- # Also uses:
- #
- # $ME - name of the shell script calling the routine
- # $SUCCESS- success value 0
- # $FAIL - error value 1
- #
- #############################################################################
- rebuild_file()
- {
- target="$1"
- mode="$2"
- owner="$3"; group="$4"
- checksum="$5"
-
- # count the number of pieces to the file
- piececount=`ls $target.P[0-9][0-9] 2>/dev/null | wc -w | tr -d ' '`
- if [ $piececount -lt 1 ]; then
- echo "$ME: rebuild_file: $piececount is invalid (<1)" >&2
- return $FAIL
- else
- if [ $piececount -gt 99 ]; then
- echo "$ME: rebuild_file: $piececount is too many pieces" >&2
- return $FAIL
- fi
- fi
-
- # build the file by appending these pieces one after another
- >$target
- piece=0; while [ $piece -lt $piececount ]; do
- extn="`expr $piece + 1`"
- [ `expr length $extn` -lt 2 ] && extn="0$extn"
- if [ -f $target.P$extn ]; then
- cat $target.P$extn >>$target
- rmfile=`removef ${PKGINST} $target.P$extn`
- if [ -n "$rmfile" ]; then
- if [ -f "$rmfile" ]; then
- rm $target.P$extn >/dev/null 2>&1
- if [ $? -ne 0 ]; then
- echo "$ME: rebuild_file: error deleting $target.P$extn"
- fi
- fi
- else
- echo "$ME: rebuild_file: unsafe to remove $target.P$extn - not removed"
- fi
- else
- echo "$ME: rebuild_file: missing file piece $extn of $target" >&2
- return $FAIL
- fi
- piece=`expr $piece + 1`
- done
-
- # check the expected checksum, if supplied
- if [ -n "$checksum" ]; then
- sum="`cat $target | sum -r | sed -e 's/ .*//'`"
- if [ "$sum" != "$checksum" ]; then
- echo "$ME: rebuild_file: $target checksum mismatch ($sum!=$checksum" >&2
- return $FAIL
- fi
- fi
-
- # set up the file permissions and ownership
- chmod $mode $target
- chown ${owner}:${group} $target
- installf $PKGINST $target f $mode $owner $group
-
- # don't forget to run installf -f and removef -f before your
- # installation script exits
-
- # completed successfully
- return $SUCCESS
- }
-
-
- #############################################################################
- #
- # @(#) replace_with_newer.sh_h 12.2 97/10/27
- #
- # Standard routine to update the /etc/encrypt_config script with the
- # one held in this package if, and only if, it can be determined that
- # the one held in this package is at a later SCCS revision level.
- #
- # The routine uses what(C,1) to decide which file is the newer. Missing
- # numbers in the SCCS R.L.B.S versioning are assumed to be 0. A file
- # with no SCCS ID at all in it is assumed to be at 0.0.0.0.
- #
- # Arguments are:
- #
- # $1 - PKGINST
- # $2 - action: 'test' or 'update'
- # $3 - path to the original file
- # $4 - path to the file to update it with
- # $5 - mode of the 'new' file
- # $6 - owner of the 'new' file
- # $7 - group of the 'new' file
- #
- # Return values are:
- #
- # 0 - success; the file was upgraded if $2 is 'update', the
- # file should be updated if $2 is 'test'
- # 1 - failure; the file is as new or newer than the replacement
- # we have for it
- #
- # Also uses:
- #
- # $ME - name of the shell script calling the routine
- # $SUCCESS- success value 0
- # $FAIL - error value 1
- #
- #############################################################################
- replace_with_newer()
- {
- pkginst="$1"
- action="$2"
- original_file="$3"
- shipped_file="$4"
- mode="$5"
- owner="$6"
- group="$7"
-
- # first, decide whether to update the file at all
- update=0
- if [ ! -f $shipped_file ]; then
- echo "$ME: can't find $shipped_file" >&2
- return $FAIL
- fi
- if [ ! -f $original_file ]; then
- update=1
- else
- # find the SCCS IDs of both files
- set -- `what $original_file | awk 'NR==2 { print $2 }' \
- | awk -F'.' '{ print $1" "$2" "$3" "$4 }'`
- oR=$1; oL=$2; oB=$3; oS=$4
- [ -z "$oR" ] && oR=0; [ -z "$oL" ] && oL=0
- [ -z "$oB" ] && oB=0; [ -z "$oS" ] && oS=0
- set -- `what $shipped_file | awk 'NR==2 { print $2 }' \
- | awk -F'.' '{ print $1" "$2" "$3" "$4 }'`
- sR=$1; sL=$2; sB=$3; sS=$4
- [ -z "$sR" ] && sR=0; [ -z "$sL" ] && sL=0
- [ -z "$sB" ] && sB=0; [ -z "$sS" ] && sS=0
-
- # now compare the SCCS releases
- [ $sR -gt $oR ] && update=1
- [ $sR -eq $oR -a $sL -gt $oL ] && update=1
- [ $sR -eq $oR -a $sL -eq $oL -a $sB -gt $oB ] && update=1
- [ $sR -eq $oR -a $sL -eq $oL -a $sB -eq $oB -a $sS -gt $oS ] && update=1
- fi
-
- if [ "$action" = "test" ]; then
-
- # return a value based on what we found out about the
- # file's comparative SCCS versions
- if [ $update -eq 1 ]; then
- return $SUCCESS
- else
- return $FAIL
- fi
-
- else
-
- # if updating then copy over the file and update our packaging
- # to reflect the fact that we now (jointly?) own this item
- if [ $update -eq 1 ]; then
-
- # copy the file, and update packaging; note that we
- # make it volatile so that pkgchk won't complain if
- # someone else installs a newer version later
- cp $shipped_file $original_file
- chmod $mode $original_file
- chown $owner:$group $original_file
- installf $pkginst $original_file v $mode $owner $group
-
- # return file updated status
- return $SUCCESS
- else
-
- # adopt joint ownership of the file that's there
- # so that it isn't removed while we remain installed
- chmod $mode $original_file
- chown $owner:$group $original_file
- installf $pkginst $original_file v $mode $owner $group
-
- # return no change status
- return $FAIL
- fi
- fi
-
- # don't forget to run installf -f and removef -f before your
- # installation script exits
-
- echo "$ME: internal error - replace_with_newer: no valid end condition" >&2
- return $FAIL
- }
-
-
-
-
- ##############################################################################
- #
- # link_socketlib
- #
- # links libsocket.so.2 to target libsocket.so if .so.2 doesn't exist
- #
- #############################################################################
- link_socketlib()
- {
- [ -f /usr/lib/libsocket.so.2 ] || \
- ln -s /usr/lib/libsocket.so /usr/lib/libsocket.so.2 2>/dev/null
- }
-
-
- #############################################################################
- #
- # main
- #
- #############################################################################
-
- # fix up socket library things
- link_socketlib
-
- # piece the browser executable files back together
- for file in /usr/ns-home/lib/netscape/netscape-us \
- /usr/ns-home/lib/netscape/netscape-export; do
- rebuild_file "$file" 0711 root sys
- if [ $? -ne 0 ]; then
- echo "$ME: failed to rebuild file $file" >&2
- exit $FAIL
- fi
- done
-
- # update file links for US/International browser versions
- if [ -f "$INSTALL_DIR/exportpaths.sh" ]; then
-
- # determine the right location for messages - try /etc/inst/locale
- # first, and if no messages there then use ones in the installation
- # set - try for local ones first, then fall back on C
- LOCALE="${LC_ALL:-${LC_MESSAGES:-${LANG:-C}}}"
- MENU_DIR="/etc/inst/locale/$LOCALE/menus/$PKGINST"
- if [ ! -f $MENU_DIR/exportpaths.msgs ]; then
- if [ ! -d $INSTALL_DIR/$LOCALE ]; then
- LOCALE="C"
- fi
- MENU_DIR=$INSTALL_DIR/$LOCALE
- fi
-
- sh $INSTALL_DIR/exportpaths.sh $PKGINST $INSTALL_DIR/links.fl \
- $INSTALL_DIR/l_info $MENU_DIR
- if [ $? -ne 0 ]; then
- echo "$ME: exportpaths.sh script failed" >&2
- exit $FAIL
- fi
- else
- echo "$ME: unable to find $INSTALL_DIR/exportpaths.sh" >&2
- exit $FAIL
- fi
-
- # install our encrypt_config if it is newer
- if [ -f $INSTALL_DIR/encrypt_config ]; then
- replace_with_newer $PKGINST update /usr/sbin/encrypt_config \
- $INSTALL_DIR/encrypt_config 700 root sys
- ln -f /usr/sbin/encrypt_config /etc/encrypt_config
- installf $PKGINST /etc/encrypt_config=/usr/sbin/encrypt_config
- fi
-
- # done
- removef -f $PKGINST
- installf -f $PKGINST
- exit $SUCCESS
-