home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / browser / net_linx / ns-install < prev    next >
Text File  |  1997-11-07  |  9KB  |  369 lines

  1. #!/bin/sh
  2. #################################################################################
  3. #                                        #
  4. #    NETSCAPE Platform-Independent Software Installation            #
  5. #    Copyright (c) 1997 by Netscape Communications Corporation        #
  6. #                                        #
  7. #    File name:    ns-install                        #
  8. #                                        #
  9. #    Version:    0.9                            #
  10. #                                        #
  11. #    Description:    This script installs Netscape software on a        #
  12. #            workstation and creates or updates the Version        #
  13. #            Registry to allow for the future use of Automatic    #
  14. #            Software Download (ASD).                #
  15. #                                        #
  16. #    Usage:        To execute the script, type:                #
  17. #                                        #
  18. #                ./ns-install [ -v ]                #
  19. #                                        #
  20. #            Where -v turns on the verbose flag for the        #
  21. #            interesting tar commands.                #
  22. #                                        #
  23. #    Exit codes:    0    Successful completion                #
  24. #            1    Package file is missing                #
  25. #            2    Can't create the target directory        #
  26. #            3    Unable to register the product            #
  27. #                                        #
  28. #    Author(s):    Brian Ostrom (briano@netscape.com)            #
  29. #                                        #
  30. #    Notes:        * Will use MOZILLA_HOME as the default if it is set.    #
  31. #                                        #
  32. #################################################################################
  33. #
  34. PACKAGE="netscape-v404.nif"
  35. PRODUCT="Communicator"
  36. RELEASE="4.04"
  37. BLDVERS="4.04.0.97310"
  38.  
  39. TESTFILE="testfile.ns.$$"
  40. REG_INFILE="nsreg.$$"
  41. VREGISTRY="registry"
  42. VR_PRODSTR="${PRODUCT}"
  43.  
  44. #
  45. # Do not set tar option verbose, unless -v flag is specified.
  46. #
  47. case $1 in
  48.     -v)
  49.         v="v"
  50.         ;;
  51.  
  52.     *)
  53.         v=""
  54.         ;;
  55. esac
  56.  
  57. echo ""
  58. echo "=================================================================="
  59. echo ""
  60. echo "       NETSCAPE Platform-Independent Software Installation"
  61. echo "                 For ${PRODUCT} release ${RELEASE}"
  62. echo "       Copyright (c) 1997 by Netscape Communications Corp."
  63. echo ""
  64. echo "=================================================================="
  65. echo ""
  66. echo ""
  67.  
  68. #
  69. # Make sure the package we expect is where we expect it.
  70. #
  71. if test ! -f ${PACKAGE}
  72. then
  73.     echo "ERROR: ${PACKAGE}: no such file"
  74.     exit 1
  75. fi
  76.  
  77. #
  78. # If MOZILLA_HOME is set, assume that is the place to install.
  79. #
  80. if test ! -z "${MOZILLA_HOME}"
  81. then
  82.     INSTALL_DIR="${MOZILLA_HOME}"
  83. else
  84.     if test -d /opt
  85.     then
  86.         INSTALL_DIR="/opt/netscape"
  87.     else
  88.         INSTALL_DIR="/usr/local/netscape"
  89.     fi
  90. fi
  91.  
  92. #
  93. # See if we have to use the lame SYS-V echo command flags.
  94. #
  95. if test "`/bin/echo 'blah\c'`" = "blah\c"
  96. then
  97.     EFLAG="-n"
  98.     ENDER=""
  99. else
  100.     EFLAG=""
  101.     ENDER="\c"
  102. fi
  103. ECHO="/bin/echo ${EFLAG}"
  104.  
  105. #
  106. # Even though the user has already used gzip to extract the file (or
  107. # we wouldn't be here), make sure we can find it.
  108. #
  109. GZIP="gzip"
  110. flag=1
  111. while test ${flag} -eq 1
  112. do
  113.     ${GZIP} -h >/dev/null 2>&1
  114.     if test $? -ne 0
  115.     then
  116.         echo ""
  117.         echo "Unable to locate 'gzip' in your path.  Please provide the fully-qualified"
  118.         echo "directory in which it can be found."
  119.         echo ""
  120.         ${ECHO} "Directory containing the 'gzip' binary: ${ENDER}"
  121.         read GZIP_DIR
  122.         GZIP="${GZIP_DIR}/gzip"
  123.     else
  124.         flag=0
  125.     fi
  126. done
  127.  
  128. echo ""
  129. echo "Please specify the directory path under which the software will be"
  130. echo "installed.  The default directory is ${INSTALL_DIR}."
  131. echo ""
  132. flag=1
  133. while test ${flag} -eq 1
  134. do
  135.     ${ECHO} "Location for ${PRODUCT} software [${INSTALL_DIR}]: ${ENDER}"
  136.     read TARGET
  137.     if test -z "${TARGET}"
  138.     then
  139.         TARGET="${INSTALL_DIR}"
  140.     fi
  141.     if test ! -z "`echo ${TARGET} | grep '~'`"
  142.     then
  143.         TARGET=`echo ${TARGET} | sed "s:~:${HOME}:"`
  144.     fi
  145.  
  146.     flag=0
  147.     if test ! -d ${TARGET}
  148.     then
  149.         echo ""
  150.         ${ECHO} "${TARGET}: No such directory.  Do you wish to create it? (y/n)[y] ${ENDER}"
  151.         read check
  152.         if test "${check}" = "n" -o "${check}" = "N"
  153.         then
  154.             flag=1
  155.         else
  156.             #
  157.             # The -p flag may cause an error on some HP-UX systems.
  158.             # Removing the -p will work for 'basename TARGET' as long
  159.             # as 'dirname TARGET' exists.
  160.             #
  161.             mkdir -p ${TARGET}
  162.             if test $? -ne 0
  163.             then
  164.                 echo "ERROR: Problem creating ${TARGET}"
  165.                 exit 2
  166.             fi
  167.         fi
  168.     else
  169.         echo ""
  170.         echo "Existing '${TARGET}' directory found."
  171.         echo ""
  172.         echo "The existing contents may be modified or replaced if you install in"
  173.         echo "this directory.  If you choose not to install in '${TARGET}',"
  174.         echo "you will be prompted for a different directory."
  175.         echo ""
  176.         ${ECHO} "Do you wish to continue with the installation in '${TARGET}'? (y/n)[y] ${ENDER}"
  177.         read check
  178.         if test "${check}" = "n" -o "${check}" = "N"
  179.         then
  180.             flag=1
  181.         fi
  182.     fi
  183.  
  184.     if test ${flag} -eq 0
  185.     then
  186.         (echo "Write test." 2>/dev/null > ${TARGET}/${TESTFILE}) 2>/dev/null
  187.         if test $? -ne 0
  188.         then
  189.             echo ""
  190.             echo "You do not have write permission in ${TARGET}."
  191.             echo "Change the permissions, or select another directory, and try again."
  192.             echo ""
  193.             flag=1
  194.         else
  195.             /bin/rm -f ${TARGET}/${TESTFILE}
  196.         fi
  197.     fi
  198. done
  199.  
  200. #
  201. # Begin the installation.
  202. #
  203. echo ""
  204. echo ""
  205. echo "Installing ${PRODUCT} files..."
  206.  
  207. #
  208. # Make a list of the files in this package, so we can check for
  209. # existing files with the same names and save them.
  210. #
  211. FILELIST="`${GZIP} -dc ${PACKAGE} | tar -tvf - | awk '{print $NF}'`"
  212.  
  213. #
  214. # Keep a log of this installation for reference.
  215. #
  216. LOGFILE="ns-install.log-$$"
  217. date > ${LOGFILE}
  218. echo "Files installed:" >> ${LOGFILE}
  219. echo "================" >> ${LOGFILE}
  220.  
  221. #
  222. # Check for existing files and move them out of the way.
  223. #
  224. for i in ${FILELIST}
  225. do
  226.     echo "${i}" >> ${LOGFILE}
  227.     if test ! -d ${TARGET}/${i}
  228.     then
  229.         (cd ${TARGET}; \
  230.          /bin/rm -f ${i}.old; \
  231.          if test -f ${i}; then \
  232.             echo " ==> moving existing '${TARGET}/${i}' to '${TARGET}/${i}.old'"; \
  233.             mv ${i} ${i}.old; \
  234.          fi)
  235.     fi
  236. done
  237.  
  238. #
  239. # Actually install the package in TARGET.
  240. #
  241. ${GZIP} -dc ${PACKAGE} | (cd ${TARGET}; tar -x${v}f -)
  242.  
  243. /bin/rm -f ${REG_INFILE}
  244. echo "${VR_PRODSTR},${BLDVERS},${TARGET}" > ${REG_INFILE}
  245.  
  246. #
  247. # Install the Java class ARchive (JAR) files.
  248. #
  249. if test "${PRODUCT}" = "Communicator" -o "${PRODUCT}" = "Navigator"
  250. then
  251.     echo ""
  252.     echo "Installing ${PRODUCT} Java files..."
  253.     if test ! -d ${TARGET}/java/classes
  254.     then
  255.         (cd ${TARGET}; mkdir -p java/classes)
  256.     fi
  257.     for i in *.jar
  258.     do
  259.         if test -f ${TARGET}/java/classes/${i}
  260.         then
  261.             echo " ==> moving existing '${TARGET}/java/classes/${i}' to '${TARGET}/java/classes/${i}.old'"
  262.             /bin/rm -f ${TARGET}/java/classes/${i}.old
  263.             mv ${TARGET}/java/classes/${i} ${TARGET}/java/classes/${i}.old
  264.         fi
  265.         tar -cf - ${i} | (cd ${TARGET}/java/classes; tar -xf -)
  266.         echo "${i}" >> ${LOGFILE}
  267.         /bin/rm -f ${TARGET}/${i} ./${i}
  268.         echo "${i},${BLDVERS},${TARGET}/java/classes" >> ${REG_INFILE}
  269.     done
  270.     #
  271.     # Is this a virgin install?  If so, create the .netscape dir
  272.     # and put the default bookmark file in it.
  273.     #
  274.     if test ! -d ${HOME}/.netscape
  275.     then
  276.         # New install, or upgrade from 0.x or 1.x.
  277.         mkdir ${HOME}/.netscape
  278.         cp ${TARGET}/bookmark.htm ${HOME}/.netscape/bookmarks.html
  279.         echo "${HOME}/.netscape/bookmarks.html" >> ${LOGFILE}
  280.     fi
  281. fi
  282.  
  283. echo ""
  284. echo "Installing additional component files..."
  285. for pkg in *.nif
  286. do
  287.     if test "${pkg}" = "${PACKAGE}"
  288.     then
  289.         continue
  290.     fi
  291.     #
  292.     # Don't need to save the old files for these components,
  293.     # since the new ones are backwards-compatible.
  294.     #
  295.     case ${pkg} in
  296.         nethelp*)
  297.             /bin/rm -rf ${TARGET}/nethelp
  298.             echo "nethelp/" >> ${LOGFILE}
  299.             ;;
  300.         spellchk*)
  301.             /bin/rm -rf ${TARGET}/spell
  302.             echo "spell/" >> ${LOGFILE}
  303.             ;;
  304.     esac
  305.     ${GZIP} -dc ${pkg} | (cd ${TARGET}; tar -x${v}f -)
  306.     echo "${pkg},${BLDVERS},${TARGET}" >> ${REG_INFILE}
  307.     /bin/rm -f ${pkg}
  308. done
  309.  
  310. #
  311. # Install the vreg binary in the TARGET directory.
  312. #
  313. if test -f ${TARGET}/vreg
  314. then
  315.     /bin/rm -f ${TARGET}/vreg.old
  316.     mv ${TARGET}/vreg ${TARGET}/vreg.old
  317.     # Handle the case where TARGET == . (meaning we just moved the file we just installed).
  318.     if test ! -f ./vreg
  319.     then
  320.         mv ${TARGET}/vreg.old ${TARGET}/vreg
  321.     else
  322.         mv ./vreg ${TARGET}/vreg
  323.     fi
  324. else
  325.     mv ./vreg ${TARGET}/vreg
  326. fi
  327.  
  328. #
  329. # Register the product so Automatic Software Download can work.
  330. # Just keeps track of the product name and version number for
  331. # comparison purposes later when newer versions become available.
  332. # Not necessary to run the product, but ASD will not be possible
  333. # without it....
  334. #
  335. echo ""
  336. echo "Registering ${PRODUCT} ${RELEASE}..."
  337. ${TARGET}/vreg ${TARGET}/${VREGISTRY} ${REG_INFILE} >/dev/null 2>&1
  338. if test $? -ne 0
  339. then
  340.     echo "ERROR: Installation completed, but unable to update/create the product"
  341.     echo "       version registry."
  342.     echo ""
  343.     echo "       If you are installing ${PRODUCT} from a platform other than"
  344.     echo "       that for which this package is intended, 'vreg' will not be"
  345.     echo "       able to run.  If this is the case, you may run 'vreg' manually"
  346.     echo "       (to enable ASD) on the appropriate platform using the following"
  347.     echo "       commands:"
  348.     echo ""
  349.     awk '{printf("\techo \"%s\" >>/tmp/infile\n", $0)}' ${REG_INFILE}
  350.     echo "    ${TARGET}/vreg ${TARGET}/${VREGISTRY} /tmp/infile"
  351.     echo ""
  352.     /bin/rm -f ns-install ${PACKAGE} ${REG_INFILE} core
  353.     exit 3
  354. fi
  355.  
  356. echo ""
  357. echo ""
  358. echo "The Netscape ${PRODUCT} software installation is complete."
  359. echo ""
  360. echo ""
  361.  
  362. #
  363. # Get rid of the trash.
  364. #
  365. /bin/rm -f ns-install ${PACKAGE} ${REG_INFILE}
  366.  
  367. echo ""
  368. exit 0
  369.