home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #
- # @(#) postinstall.shinc 13.1 98/01/16
- #
- # 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
- #############################################################################
- #
- # @(#) 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
- }
-
-
-
-
- #############################################################################
- #
- # restart_admin
- #
- # restart any admin server with the new server to administer
- #
- #############################################################################
- restart_admin()
- {
- # if a server looks like it's running, restart it
- if [ -x /usr/sbin/nsadmin ]; then
- /usr/sbin/nsadmin restart
- fi
- }
-
-
- #############################################################################
- #
- # start_servers
- #
- # start and enable the preconfigured servers, as a default
- #
- #############################################################################
- start_servers()
- {
- if [ -x /usr/sbin/nsfast ]; then
- /usr/sbin/nsfast enable
- fi
- }
-
-
- #############################################################################
- #
- # COUNTER_set
- # add a full list of system names (x, x.y, x.y.z...) to the
- # count.cfg file in place of XXHOSTXX; also, remove XXNODEXX
- # since it's covered by the last XXHOSTXX replacement
- #
- #############################################################################
- COUNTER_set()
- {
- if [ -f /etc/inst/scripts/postreboot.sh ]
- then
- HOST=`grep TCP_DOMAIN_NAME /isl/ifile`
- HOSTNAME=`uname -n`.`echo $HOST | sed -e "s/^.*=\"\(.*\)\"$/\1/p"`
- else
- HOSTPROG=/usr/ucb/hostname
- if [ -x $HOSTPROG ]
- then
- HOSTNAME=`$HOSTPROG`
- else
- HOSTNAME=localhost
- fi
- fi
- [ "$HOSTNAME" ] || HOSTNAME=localhost
- COUNTER_FILES="/usr/ns-home/cgi-bin/counters/conf/count.cfg"
- for i in $COUNTER_FILES; do
- [ -f $i ] && {
- for n in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
- echo "$HOSTNAME" | grep -q '\.' || break
- sed -e "/^XXHOSTXX$/a\\
- $HOSTNAME" < $i > /tmp/_ccs$$
- mv /tmp/_ccs$$ $i
- rm -f /tmp/_ccs$$ /tmp/_ccs_ip$$
- HOSTNAME=`echo $HOSTNAME | sed -e 's/\.[^\.]*$//'`
- done
- sed -e "s/^XXHOSTXX$/$HOSTNAME/g" \
- -e "/^XXNODEXX$/d" < $i > /tmp/_ccs$$
- mv /tmp/_ccs$$ $i
- rm -f /tmp/_ccs$$ /tmp/_ccs_ip$$
- chown nobody:sys $i
- installf $PKGINST $i v 755 nobody sys
- }
- done
- }
-
-
- #############################################################################
- #
- # NODE_set
- # fixup the NODE name in any configuration files
- #
- #############################################################################
- NODE_set()
- {
- NODENAME=`/usr/bin/uname -n`
- NODE_FILES=/usr/ns-home/cgi-bin/counters/conf/count.cfg
- for i in $NODE_FILES
- do
- [ -f $i ] && {
- sed -e "s/XXNODEXX/$NODENAME/g" < $i > /tmp/_ccs$$
- mv /tmp/_ccs$$ $i
- rm -f /tmp/_ccs$$ /tmp/_ccs_ip$$
- chown nobody:sys $i
- installf $PKGINST $i v 755 nobody sys
- }
- done
- }
-
-
- #############################################################################
- #
- # HOST_set
- # fixup the NODE name in any configuration files
- #
- #############################################################################
- HOST_set()
- {
- if [ -f /etc/inst/scripts/postreboot.sh ]
- then
- HOST=`grep TCP_DOMAIN_NAME /isl/ifile`
- HOSTNAME=`uname -n`.`echo $HOST | sed -e "s/^.*=\"\(.*\)\"$/\1/p"`
- else
- HOSTPROG=/usr/ucb/hostname
- if [ -x $HOSTPROG ]
- then
- HOSTNAME=`$HOSTPROG`
- else
- HOSTNAME=localhost
- fi
- fi
- [ "$HOSTNAME" ] || HOSTNAME=localhost
- HOST_FILES="/usr/ns-home/httpd-80/config/magnus.conf \
- /usr/ns-home/admserv/httpd-80/magnus.conf \
- /usr/ns-home/cgi-bin/counters/conf/count.cfg"
- for i in $HOST_FILES
- do
- [ -f $i ] && {
- sed -e "s/XXHOSTXX/$HOSTNAME/g" < $i > /tmp/_ccs$$
- mv /tmp/_ccs$$ $i
- rm -f /tmp/_ccs$$ /tmp/_ccs_ip$$
- chown nobody:sys $i
- installf $PKGINST $i v 755 nobody sys
- }
- done
- }
-
-
- #############################################################################
- #
- # IP_set
- # fixup the IP address in any configuration files
- #
- #############################################################################
- IP_set()
- {
- if [ -f /etc/inst/scripts/postreboot.sh ]
- then
- IFIP=`grep TCP_IPADDR /isl/ifile`
- IP=`echo $IFIP | sed -e "s/^.*=\"\(.*\)\"$/\1/p"`
- else
- if [ -c /dev/inet/ip ]
- then
- netstat -in | grep -v atl0 | grep -v lo0 | grep -v Network > /tmp/_ccs_ip$$
- NUMIPS=`cat /tmp/_ccs_ip$$ | wc -l`
- if [ $NUMIPS = 1 ]
- then
- IP=`cat /tmp/_ccs_ip$$ | awk '{print $4}'`
- else
- IPLIST=`cat /tmp/_ccs_ip$$ | awk '{print $4}'`
- FIRST=1
- for i in $IPLIST
- do
- [ "$FIRST" ] && {
- IP=$i
- FIRST=
- }
- done
- fi
- fi
- fi
- [ "$IP" ] || IP=127.0.0.1
- IP_FILES="/usr/ns-home/cgi-bin/counters/conf/count.cfg"
- for i in $IP_FILES
- do
- [ -f $i ] && {
- sed -e "s/XXIPADDRXX/$IP/g" < $i > /tmp/_ccs$$
- mv /tmp/_ccs$$ $i
- rm -f /tmp/_ccs$$ /tmp/_ccs_ip$$
- chown nobody:sys $i
- installf $PKGINST $i v 755 nobody sys
- }
- done
- }
-
-
- #############################################################################
- #
- # disown_content
- #
- # deliberately disown the package files in /usr/ns-home/docs_nsfast and
- # cgi-bin_nsfast, then move these to docs and cgi-bin (having moved any
- # existing ones out of the way first; these are files the user may well
- # modify and/or delete, and we don't want the packaging complaining
- # about it, or removing some of the user's files if the package is removed
- #
- #############################################################################
- disown_content()
- {
- # remove the example content from the package database
- find /usr/ns-home/docs_nsfast /usr/ns-home/cgi-bin_nsfast \
- -type f -print | removef $PKGINST - >/dev/null
- find /usr/ns-home/docs_nsfast /usr/ns-home/cgi-bin_nsfast \
- -type d -print | removef $PKGINST - >/dev/null
-
- # if there's existing content, back it up
- if [ -d /usr/ns-home/docs ]; then
- mv /usr/ns-home/docs /usr/ns-home/docs.bak_$$
- fi
- if [ -d /usr/ns-home/cgi-bin ]; then
- mv /usr/ns-home/cgi-bin /usr/ns-home/cgi-bin.bak_$$
- fi
-
- # now move our example content across; save the packaging
- # tools getting all bent out of shape
- mv /usr/ns-home/docs_nsfast /usr/ns-home/docs
- mv /usr/ns-home/cgi-bin_nsfast /usr/ns-home/cgi-bin
- }
-
-
- #############################################################################
- #
- # disown_new_content
- #
- # disown any new files placed in /usr/ns-home/docs and cgi-bin by general
- # package configuration
- #
- #############################################################################
- disown_new_content()
- {
- # remove the complete content from the package database
- find /usr/ns-home/docs /usr/ns-home/cgi-bin \
- -type f -print | removef $PKGINST - >/dev/null
- find /usr/ns-home/docs /usr/ns-home/cgi-bin \
- -type d -print | removef $PKGINST - >/dev/null
- }
-
-
- #############################################################################
- #
- # fasttrack_config
- # run script to configure fastrack server
- #
- #############################################################################
- fasttrack_config()
- {
- # create blank log files and add them to the package data
- # so that removal deletes them
- LOG_FILES="/usr/ns-home/httpd-80/logs/access \
- /usr/ns-home/httpd-80/logs/errors"
- for i in $LOG_FILES; do
- >$i; chmod 0755 $i; chown nobody:nobody $i
- installf $PKGINST $i v 755 nobody nobody
- done
-
- # add an entry to the admin server's list of managed server types
- # and make our package (joint-)owner of the file (volatile)
- [ -f /usr/ns-home/admserv/servers.lst ] || \
- >/usr/ns-home/admserv/servers.lst
- grep -q "^httpd:" /usr/ns-home/admserv/servers.lst
- if [ $? -ne 0 ]; then
- echo "httpd:Netscape FastTrack Server" \
- >>/usr/ns-home/admserv/servers.lst
- fi
- chmod 644 /usr/ns-home/admserv/servers.lst
- chown root:sys /usr/ns-home/admserv/servers.lst
- installf $PKGINST /usr/ns-home/admserv/servers.lst v 644 root sys
-
- # run the RC setup script, if installed.
- # This generates some HTML fragments for the port 80 server to use
- [ -f /etc/rc2.d/S90sysinfo2html ] && sh /etc/rc2.d/S90sysinfo2html
- }
-
-
- #############################################################################
- #
- # main
- #
- #############################################################################
-
- # before we do anything else, move our example content into it's
- # correct directories, otherwise much of the config file editing is
- # going to fail
- disown_content
-
- # edit configuration files
- COUNTER_set
- NODE_set
- HOST_set
- IP_set
- fasttrack_config
-
- # now disown anything that got created above in the example content
- # directories
- disown_new_content
-
- # update file links for US/International 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
-
- # no more files to add or remove
- removef -f $PKGINST
- installf -f $PKGINST
-
- # finally, if not in ISL then stop and restart any running admin server,
- # and start our servers; if in ISL, then set up rc2.d for port 80 server
- # only
- if [ -f $ISL_FILE ]; then
- if [ "$ENABLE_IN_POSTINSTALL" = "YES" ]; then
- ln /etc/init.d/nsfast /etc/rc2.d/S91nsfast-80 2>/dev/null
- fi
- else
- restart_admin
- if [ "$ENABLE_IN_POSTINSTALL" = "YES" ]; then
- start_servers
- fi
- fi
-
- # done
- exit $SUCCESS
-