home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #
- # @(#) postinstall.shinc 12.9 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
- #############################################################################
- #
- # @(#) 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
- }
-
-
-
-
- #############################################################################
- #
- # start_servers
- #
- # start and enable the admin server, as a default
- #
- #############################################################################
- start_servers()
- {
- if [ -x /usr/sbin/nsadmin ]; then
- /usr/sbin/nsadmin enable
- fi
- }
-
-
- #############################################################################
- #
- # 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/admserv/ns-admin.conf"
- 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$$ 2>/dev/null
- chown root:sys $i
- installf $PKGINST $i v 755 root 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/admserv/ns-admin.conf"
- 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$$ 2>/dev/null
- chown root:sys $i
- installf $PKGINST $i v 755 root sys
- }
- done
- }
-
-
- #############################################################################
- #
- # admin_config()
- #
- # run script to configure admin server
- #
- #############################################################################
- admin_config()
- {
- # update the admin password with the root password
- grep "^root:" /etc/shadow | awk -F":" '{print $1 FS $2}' > /tmp/ftc_$$
- sed -e "s/root:/admin:/" /tmp/ftc_$$ > /tmp/ftc_$$.sed
- cp /usr/ns-home/admserv/admpw /usr/ns-home/admserv/admpw.org
- > /usr/ns-home/admserv/admpw
- if [ -f /tmp/ftc_$$.sed ]; then
- cat /tmp/ftc_$$.sed >> /usr/ns-home/admserv/admpw
- else
- echo "$ME: unable to update administrative password" >&2
- > /usr/ns-home/admserv/admpw
- cat /usr/ns-home/admserv/admpw.org > /usr/ns-home/admserv/admpw
- rm /tmp/ftc_$$*
- exit $FAIL
- fi
- rm /tmp/ftc_$$*
- rm /usr/ns-home/admserv/admpw.org
- installf $PKGINST /usr/ns-home/admserv/admpw v 755 root other
-
- # create blank log files and add them to the package data
- # so that removal deletes them
- LOG_FILES="/usr/ns-home/admserv/access \
- /usr/ns-home/admserv/errors \
- /usr/ns-home/admserv/cron.error"
- for i in $LOG_FILES; do
- >$i; chmod 0755 $i; chown root:sys $i
- installf $PKGINST $i v 755 root sys
- 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 "^admserv:" /usr/ns-home/admserv/servers.lst
- if [ $? -ne 0 ]; then
- echo "admserv:Netscape Administration 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
- }
-
-
- #############################################################################
- #
- # main
- #
- #############################################################################
-
- # edit configuration files
- HOST_set
- IP_set
- admin_config
-
- # register Netscape Admin Server with scoadmin
- /usr/bin/scoadmin -f -c /usr/lib/scoadmin/desktop/adminsvr.obj
-
- # 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, consider enabling and starting the admin server
- if [ -f $ISL_FILE ]; then
- if [ "$ENABLE_IN_POSTINSTALL" = "YES" ]; then
- ln /etc/init.d/nsadmin /etc/rc2.d/S91nsadmin 2>/dev/null
- fi
- else
- if [ "$ENABLE_IN_POSTINSTALL" = "YES" ]; then
- start_servers
- fi
- fi
-
- # done
- exit $SUCCESS
-