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

  1. #!/bin/sh
  2. #
  3. #       @(#) postinstall.shinc 13.1 98/01/16 
  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. #    @(#) replace_with_newer.sh_h 12.2 97/10/27 
  23. #
  24. # Standard routine to update the /etc/encrypt_config script with the
  25. # one held in this package if, and only if, it can be determined that
  26. # the one held in this package is at a later SCCS revision level.
  27. #
  28. # The routine uses what(C,1) to decide which file is the newer.  Missing
  29. # numbers in the SCCS R.L.B.S versioning are assumed to be 0.  A file
  30. # with no SCCS ID at all in it is assumed to be at 0.0.0.0.
  31. #
  32. # Arguments are:
  33. #
  34. #    $1    - PKGINST
  35. #    $2    - action: 'test' or 'update'
  36. #    $3    - path to the original file
  37. #    $4    - path to the file to update it with
  38. #    $5    - mode of the 'new' file
  39. #    $6    - owner of the 'new' file
  40. #    $7    - group of the 'new' file
  41. #
  42. # Return values are:
  43. #
  44. #    0    - success; the file was upgraded if $2 is 'update', the
  45. #          file should be updated if $2 is 'test'
  46. #    1    - failure; the file is as new or newer than the replacement
  47. #          we have for it
  48. #
  49. # Also uses:
  50. #
  51. #    $ME    - name of the shell script calling the routine
  52. #    $SUCCESS- success value 0
  53. #    $FAIL    - error value 1
  54. #############################################################################
  55. replace_with_newer()
  56. {
  57.     pkginst="$1"
  58.     action="$2"
  59.     original_file="$3"
  60.     shipped_file="$4"
  61.     mode="$5"
  62.     owner="$6"
  63.     group="$7"
  64.  
  65.     # first, decide whether to update the file at all
  66.     update=0
  67.     if [ ! -f $shipped_file ]; then
  68.         echo "$ME: can't find $shipped_file" >&2
  69.         return $FAIL
  70.     fi
  71.     if [ ! -f $original_file ]; then
  72.         update=1
  73.     else
  74.         # find the SCCS IDs of both files
  75.         set -- `what $original_file | awk 'NR==2 { print $2 }' \
  76.                 | awk -F'.' '{ print $1" "$2" "$3" "$4 }'`
  77.         oR=$1; oL=$2; oB=$3; oS=$4
  78.         [ -z "$oR" ] && oR=0; [ -z "$oL" ] && oL=0
  79.         [ -z "$oB" ] && oB=0; [ -z "$oS" ] && oS=0
  80.         set -- `what $shipped_file | awk 'NR==2 { print $2 }' \
  81.                 | awk -F'.' '{ print $1" "$2" "$3" "$4 }'`
  82.         sR=$1; sL=$2; sB=$3; sS=$4
  83.         [ -z "$sR" ] && sR=0; [ -z "$sL" ] && sL=0
  84.         [ -z "$sB" ] && sB=0; [ -z "$sS" ] && sS=0
  85.  
  86.         # now compare the SCCS releases
  87.         [ $sR -gt $oR ] && update=1
  88.         [ $sR -eq $oR -a $sL -gt $oL ] && update=1
  89.         [ $sR -eq $oR -a $sL -eq $oL -a $sB -gt $oB ] && update=1
  90.         [ $sR -eq $oR -a $sL -eq $oL -a $sB -eq $oB -a $sS -gt $oS ] && update=1
  91.     fi
  92.  
  93.     if [ "$action" = "test" ]; then
  94.  
  95.         # return a value based on what we found out about the
  96.         # file's comparative SCCS versions
  97.         if [ $update -eq 1 ]; then
  98.             return $SUCCESS
  99.         else
  100.             return $FAIL
  101.         fi
  102.  
  103.     else
  104.  
  105.         # if updating then copy over the file and update our packaging
  106.         # to reflect the fact that we now (jointly?) own this item
  107.         if [ $update -eq 1 ]; then
  108.  
  109.             # copy the file, and update packaging; note that we
  110.             # make it volatile so that pkgchk won't complain if
  111.             # someone else installs a newer version later
  112.             cp $shipped_file $original_file
  113.             chmod $mode $original_file
  114.             chown $owner:$group $original_file
  115.             installf $pkginst $original_file v $mode $owner $group
  116.  
  117.             # return file updated status
  118.             return $SUCCESS
  119.         else
  120.  
  121.             # adopt joint ownership of the file that's there
  122.             # so that it isn't removed while we remain installed
  123.             chmod $mode $original_file
  124.             chown $owner:$group $original_file
  125.             installf $pkginst $original_file v $mode $owner $group
  126.  
  127.             # return no change status
  128.             return $FAIL
  129.         fi
  130.     fi
  131.  
  132.     # don't forget to run installf -f and removef -f before your
  133.     # installation script exits
  134.  
  135.     echo "$ME: internal error - replace_with_newer: no valid end condition" >&2
  136.     return $FAIL
  137. }
  138.  
  139.  
  140.  
  141.  
  142. #############################################################################
  143. #
  144. # restart_admin
  145. #
  146. # restart any admin server with the new server to administer
  147. #############################################################################
  148. restart_admin()
  149. {
  150.     # if a server looks like it's running, restart it
  151.     if [ -x /usr/sbin/nsadmin ]; then
  152.         /usr/sbin/nsadmin restart
  153.     fi
  154. }
  155.  
  156.  
  157. #############################################################################
  158. #
  159. # start_servers
  160. #
  161. # start and enable the preconfigured servers, as a default
  162. #############################################################################
  163. start_servers()
  164. {
  165.     if [ -x /usr/sbin/nsfast ]; then
  166.         /usr/sbin/nsfast enable
  167.     fi
  168. }
  169.  
  170.  
  171. #############################################################################
  172. #
  173. # COUNTER_set
  174. #         add a full list of system names (x, x.y, x.y.z...) to the
  175. #         count.cfg file in place of XXHOSTXX; also, remove XXNODEXX
  176. #         since it's covered by the last XXHOSTXX replacement
  177. #
  178. #############################################################################
  179. COUNTER_set()
  180. {
  181.   if [ -f /etc/inst/scripts/postreboot.sh ]
  182.   then
  183.     HOST=`grep TCP_DOMAIN_NAME /isl/ifile`
  184.     HOSTNAME=`uname -n`.`echo $HOST | sed -e "s/^.*=\"\(.*\)\"$/\1/p"`
  185.   else
  186.     HOSTPROG=/usr/ucb/hostname
  187.     if [ -x $HOSTPROG ] 
  188.     then
  189.       HOSTNAME=`$HOSTPROG`
  190.     else
  191.       HOSTNAME=localhost
  192.     fi
  193.   fi
  194.   [ "$HOSTNAME" ] || HOSTNAME=localhost
  195.   COUNTER_FILES="/usr/ns-home/cgi-bin/counters/conf/count.cfg"
  196.   for i in $COUNTER_FILES; do
  197.   [ -f $i ] && {
  198.     for n in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
  199.       echo "$HOSTNAME" | grep -q '\.' || break
  200.       sed -e "/^XXHOSTXX$/a\\
  201. $HOSTNAME" < $i > /tmp/_ccs$$
  202.       mv /tmp/_ccs$$ $i
  203.       rm -f /tmp/_ccs$$ /tmp/_ccs_ip$$
  204.       HOSTNAME=`echo $HOSTNAME | sed -e 's/\.[^\.]*$//'`
  205.     done
  206.     sed -e "s/^XXHOSTXX$/$HOSTNAME/g" \
  207.         -e "/^XXNODEXX$/d" < $i > /tmp/_ccs$$
  208.     mv /tmp/_ccs$$ $i
  209.     rm -f /tmp/_ccs$$ /tmp/_ccs_ip$$
  210.     chown nobody:sys $i
  211.     installf $PKGINST $i v 755 nobody sys
  212.   }
  213.   done
  214. }
  215.  
  216.  
  217. #############################################################################
  218. #
  219. # NODE_set
  220. #         fixup the NODE name in any configuration files
  221. #
  222. #############################################################################
  223. NODE_set()
  224. {
  225.   NODENAME=`/usr/bin/uname -n`
  226.   NODE_FILES=/usr/ns-home/cgi-bin/counters/conf/count.cfg
  227.   for i in $NODE_FILES
  228.   do
  229.   [ -f $i ] && {
  230.     sed -e "s/XXNODEXX/$NODENAME/g" < $i > /tmp/_ccs$$
  231.     mv /tmp/_ccs$$ $i
  232.     rm -f /tmp/_ccs$$ /tmp/_ccs_ip$$
  233.     chown nobody:sys $i
  234.     installf $PKGINST $i v 755 nobody sys
  235.   }
  236.   done
  237. }
  238.  
  239.  
  240. #############################################################################
  241. #
  242. # HOST_set
  243. #         fixup the NODE name in any configuration files
  244. #
  245. #############################################################################
  246. HOST_set()
  247. {
  248.   if [ -f /etc/inst/scripts/postreboot.sh ]
  249.   then
  250.     HOST=`grep TCP_DOMAIN_NAME /isl/ifile`
  251.     HOSTNAME=`uname -n`.`echo $HOST | sed -e "s/^.*=\"\(.*\)\"$/\1/p"`
  252.   else
  253.     HOSTPROG=/usr/ucb/hostname
  254.     if [ -x $HOSTPROG ] 
  255.     then
  256.       HOSTNAME=`$HOSTPROG`
  257.     else
  258.       HOSTNAME=localhost
  259.     fi
  260.   fi
  261.   [ "$HOSTNAME" ] || HOSTNAME=localhost
  262.   HOST_FILES="/usr/ns-home/httpd-80/config/magnus.conf \
  263.           /usr/ns-home/admserv/httpd-80/magnus.conf \
  264.               /usr/ns-home/cgi-bin/counters/conf/count.cfg"
  265.   for i in $HOST_FILES
  266.   do
  267.   [ -f $i ] && {
  268.     sed -e "s/XXHOSTXX/$HOSTNAME/g" < $i > /tmp/_ccs$$
  269.     mv /tmp/_ccs$$ $i
  270.     rm -f /tmp/_ccs$$ /tmp/_ccs_ip$$
  271.     chown nobody:sys $i
  272.     installf $PKGINST $i v 755 nobody sys
  273.   }
  274.   done
  275. }
  276.  
  277.  
  278. #############################################################################
  279. #
  280. # IP_set
  281. #         fixup the IP address in any configuration files
  282. #
  283. #############################################################################
  284. IP_set()
  285. {
  286.   if [ -f /etc/inst/scripts/postreboot.sh ]
  287.   then
  288.     IFIP=`grep TCP_IPADDR /isl/ifile`
  289.     IP=`echo $IFIP | sed -e "s/^.*=\"\(.*\)\"$/\1/p"`
  290.   else
  291.     if [ -c /dev/inet/ip ]
  292.     then
  293.      netstat -in | grep -v atl0 | grep -v lo0 | grep -v Network > /tmp/_ccs_ip$$
  294.      NUMIPS=`cat /tmp/_ccs_ip$$ | wc -l`
  295.      if [ $NUMIPS = 1 ]
  296.      then
  297.         IP=`cat /tmp/_ccs_ip$$ | awk '{print $4}'`
  298.      else
  299.         IPLIST=`cat /tmp/_ccs_ip$$ | awk '{print $4}'`
  300.         FIRST=1
  301.         for i in $IPLIST
  302.         do
  303.             [ "$FIRST" ] && {
  304.                 IP=$i
  305.                 FIRST=
  306.             }
  307.         done
  308.      fi
  309.     fi
  310.   fi
  311.   [ "$IP" ] || IP=127.0.0.1
  312.   IP_FILES="/usr/ns-home/cgi-bin/counters/conf/count.cfg"
  313.   for i in $IP_FILES
  314.   do
  315.   [ -f $i ] && {
  316.     sed -e "s/XXIPADDRXX/$IP/g" < $i > /tmp/_ccs$$
  317.     mv /tmp/_ccs$$ $i
  318.     rm -f /tmp/_ccs$$ /tmp/_ccs_ip$$
  319.     chown nobody:sys $i
  320.     installf $PKGINST $i v 755 nobody sys
  321.   }
  322.   done
  323. }
  324.  
  325.  
  326. #############################################################################
  327. #
  328. # disown_content
  329. #
  330. # deliberately disown the package files in /usr/ns-home/docs_nsfast and
  331. # cgi-bin_nsfast, then move these to docs and cgi-bin (having moved any
  332. # existing ones out of the way first; these are files the user may well
  333. # modify and/or delete, and we don't want the packaging complaining
  334. # about it, or removing some of the user's files if the package is removed
  335. #############################################################################
  336. disown_content()
  337. {
  338.     # remove the example content from the package database
  339.     find /usr/ns-home/docs_nsfast /usr/ns-home/cgi-bin_nsfast \
  340.         -type f -print | removef $PKGINST - >/dev/null
  341.     find /usr/ns-home/docs_nsfast /usr/ns-home/cgi-bin_nsfast \
  342.         -type d -print | removef $PKGINST - >/dev/null
  343.  
  344.     # if there's existing content, back it up
  345.     if [ -d /usr/ns-home/docs ]; then
  346.         mv /usr/ns-home/docs /usr/ns-home/docs.bak_$$
  347.     fi
  348.     if [ -d /usr/ns-home/cgi-bin ]; then
  349.         mv /usr/ns-home/cgi-bin /usr/ns-home/cgi-bin.bak_$$
  350.     fi
  351.  
  352.     # now move our example content across; save the packaging
  353.     # tools getting all bent out of shape
  354.     mv /usr/ns-home/docs_nsfast /usr/ns-home/docs
  355.     mv /usr/ns-home/cgi-bin_nsfast /usr/ns-home/cgi-bin
  356. }
  357.  
  358.  
  359. #############################################################################
  360. #
  361. # disown_new_content
  362. #
  363. # disown any new files placed in /usr/ns-home/docs and cgi-bin by general
  364. # package configuration
  365. #############################################################################
  366. disown_new_content()
  367. {
  368.     # remove the complete content from the package database
  369.     find /usr/ns-home/docs /usr/ns-home/cgi-bin \
  370.         -type f -print | removef $PKGINST - >/dev/null
  371.     find /usr/ns-home/docs /usr/ns-home/cgi-bin \
  372.         -type d -print | removef $PKGINST - >/dev/null
  373. }
  374.  
  375.  
  376. #############################################################################
  377. #
  378. # fasttrack_config
  379. #             run script to configure fastrack server
  380. #
  381. #############################################################################
  382. fasttrack_config()
  383. {
  384.     # create blank log files and add them to the package data
  385.     # so that removal deletes them
  386.     LOG_FILES="/usr/ns-home/httpd-80/logs/access \
  387.             /usr/ns-home/httpd-80/logs/errors"
  388.     for i in $LOG_FILES; do
  389.         >$i; chmod 0755 $i; chown nobody:nobody $i
  390.         installf $PKGINST $i v 755 nobody nobody
  391.     done
  392.  
  393.     # add an entry to the admin server's list of managed server types
  394.     # and make our package (joint-)owner of the file (volatile)
  395.     [ -f /usr/ns-home/admserv/servers.lst ] || \
  396.             >/usr/ns-home/admserv/servers.lst
  397.     grep -q "^httpd:" /usr/ns-home/admserv/servers.lst
  398.     if [ $? -ne 0 ]; then
  399.         echo "httpd:Netscape FastTrack Server" \
  400.                 >>/usr/ns-home/admserv/servers.lst
  401.     fi
  402.     chmod 644 /usr/ns-home/admserv/servers.lst
  403.     chown root:sys /usr/ns-home/admserv/servers.lst
  404.     installf $PKGINST /usr/ns-home/admserv/servers.lst v 644 root sys
  405.  
  406.     # run the RC setup script, if installed.
  407.     # This generates some HTML fragments for the port 80 server to use
  408.     [ -f /etc/rc2.d/S90sysinfo2html ] && sh /etc/rc2.d/S90sysinfo2html
  409. }
  410.  
  411.  
  412. #############################################################################
  413. #
  414. # main
  415. #
  416. #############################################################################
  417.  
  418. # before we do anything else, move our example content into it's
  419. # correct directories, otherwise much of the config file editing is
  420. # going to fail
  421. disown_content
  422.  
  423. # edit configuration files
  424. COUNTER_set
  425. NODE_set
  426. HOST_set
  427. IP_set
  428. fasttrack_config
  429.  
  430. # now disown anything that got created above in the example content
  431. # directories
  432. disown_new_content
  433.  
  434. # update file links for US/International versions
  435. if [ -f "$INSTALL_DIR/exportpaths.sh" ]; then
  436.  
  437.     # determine the right location for messages - try /etc/inst/locale
  438.     # first, and if no messages there then use ones in the installation
  439.     # set - try for local ones first, then fall back on C
  440.     LOCALE="${LC_ALL:-${LC_MESSAGES:-${LANG:-C}}}"
  441.     MENU_DIR="/etc/inst/locale/$LOCALE/menus/$PKGINST"
  442.     if [ ! -f $MENU_DIR/exportpaths.msgs ]; then
  443.         if [ ! -d $INSTALL_DIR/$LOCALE ]; then
  444.             LOCALE="C"
  445.         fi
  446.         MENU_DIR=$INSTALL_DIR/$LOCALE
  447.     fi
  448.  
  449.     sh $INSTALL_DIR/exportpaths.sh $PKGINST $INSTALL_DIR/links.fl \
  450.             $INSTALL_DIR/l_info $MENU_DIR
  451.     if [ $? -ne 0 ]; then
  452.         echo "$ME: exportpaths.sh script failed" >&2
  453.         exit $FAIL
  454.     fi
  455. else
  456.     echo "$ME: unable to find $INSTALL_DIR/exportpaths.sh" >&2
  457.     exit $FAIL
  458. fi
  459.  
  460. # install our encrypt_config if it is newer
  461. if [ -f $INSTALL_DIR/encrypt_config ]; then
  462.     replace_with_newer $PKGINST update /usr/sbin/encrypt_config \
  463.             $INSTALL_DIR/encrypt_config 700 root sys
  464.     ln -f /usr/sbin/encrypt_config /etc/encrypt_config
  465.     installf $PKGINST /etc/encrypt_config=/usr/sbin/encrypt_config
  466. fi
  467.  
  468. # no more files to add or remove
  469. removef -f $PKGINST
  470. installf -f $PKGINST
  471.  
  472. # finally, if not in ISL then stop and restart any running admin server,
  473. # and start our servers; if in ISL, then set up rc2.d for port 80 server
  474. # only
  475. if [ -f $ISL_FILE ]; then
  476.     if [ "$ENABLE_IN_POSTINSTALL" = "YES" ]; then
  477.         ln /etc/init.d/nsfast /etc/rc2.d/S91nsfast-80 2>/dev/null
  478.     fi
  479. else
  480.     restart_admin
  481.     if [ "$ENABLE_IN_POSTINSTALL" = "YES" ]; then
  482.         start_servers
  483.     fi
  484. fi
  485.  
  486. # done
  487. exit $SUCCESS
  488.