home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / Other / Coherent / base / disk1.4.10.dd / etc / install < prev    next >
Encoding:
Text File  |  1994-04-04  |  6.4 KB  |  338 lines

  1. # /etc/install
  2. #
  3. # Revised Mon Mar  7 15:26:48 1994 CST
  4.  
  5. # Special handling for COHERENT operating system installation (-b or -u):
  6. #    /etc/mount.all before install, /etc/umount.all after.
  7. #    Diskettes go from 2 to ndisks, not 1 to ndisks (#1 was boot disk).
  8. #    Reboot system after installation complete.
  9.  
  10.  
  11. . /usr/lib/shell_lib.sh
  12.  
  13. # Set TESTMODE nonempty to do testing of this script.
  14.  
  15. TESTMODE=
  16.  
  17. if is_empty $TESTMODE; then
  18.     LOGFILE=/etc/install.log
  19.     DO_COMMAND=
  20. else
  21.     LOGFILE=/tmp/log
  22.     DO_COMMAND=/bin/echo
  23. fi
  24.  
  25. PARAMS=$*
  26. COMMAND_NAME=$0
  27.  
  28. # Validation function for read_input, want [rRsSaA].
  29.  
  30. require_rsa () {
  31.     case $1 in
  32.     [rRsSaA])
  33.         return 0
  34.         ;;
  35.     *)
  36.         echo "You must enter a letter:  r, s, or a."
  37.         return 1
  38.         ;;
  39.     esac
  40. }
  41.  
  42. ###############
  43. # report_error
  44. #
  45. # Output an error message to standard error, prefixed by the command name.
  46. ###############
  47.  
  48. report_error () {
  49.     basename $COMMAND_NAME "" "echo " ": $*" 1>&2
  50. }
  51.  
  52. ###############
  53. # usage
  54. #
  55. # Report a usage message to standard error.
  56. ###############
  57.  
  58. usage () {
  59.     cat << \END 1>&2
  60. usage:    /etc/install [-b] [-u] [-c] id device ndisks
  61.     -b    Initial installation of COHERENT operating system.
  62.     -u    Update of COHERENT operating system.
  63.     -c    Uncompress, rather than copy, contents of /compressed directory
  64.         on diskette (uses /etc/install.u)
  65.     id    Package identification, e.g. "Drv_420"
  66.     device    Device name for diskette drive, e.g. "/dev/fva0".
  67.     ndisks    Number of diskettes in the package.
  68. END
  69.     exit 1
  70. }
  71.  
  72. ###############
  73. # mount_disk
  74. ###############
  75.  
  76. mount_disk () {
  77.  
  78.     # Skip this diskette if it's already installed.
  79.  
  80.     if [ -f /$ID.$1 ]; then
  81.         read_input "Disk $1 of $ID appears already installed - skip it" \
  82.         yesno "y" require_yes_or_no
  83.         if is_yes $yesno; then
  84.             return 0
  85.         fi
  86.     fi
  87.  
  88.     # Main loop for the current diskette of the installation set.
  89.  
  90.     COPIED=
  91.     RETRY=
  92.     while is_empty $COPIED; do
  93.         is_empty $RETRY || {
  94.             read_input \
  95. "(r)etry disk $1 / (s)kip disk $1 / (a)bort installation" \
  96.               option "r" require_rsa
  97.             case $option in
  98.             [rR])
  99.                 ;;
  100.             [sS])
  101.                 return 0
  102.                 ;;
  103.             [aA])
  104.                 exit 1
  105.                 ;;
  106.             esac
  107.         }
  108.         RETRY=y
  109.  
  110.         # Ask for a diskette.
  111.         read_input "\nInsert disk $1 into the drive and hit <Enter>." \
  112.           junk
  113.  
  114.         # Try to mount the diskette.
  115.         if /etc/mount $DEVICE /mnt -r; then
  116.             :
  117.         else
  118.             report_error "Could not access file system on diskette."
  119.             continue
  120.         fi
  121.  
  122.         # Make sure diskette has the right ID.
  123.         if [ ! -f /mnt/$ID.$1 ];then
  124.             report_error "That is not disk $1 of set $ID."
  125.             /etc/umount $DEVICE
  126.             continue
  127.         fi
  128.  
  129.         echo "Reading disk $1..."
  130.  
  131.         # See if a "pre-file" exists, and if so, run it first.
  132.         PRE_FILE=/mnt/$ID.$1.pre
  133.         EX_PRE_FILE=/conf/$ID.$1.pre
  134.         PRE_ARCH_LIST=/mnt/$ID.$1.arch
  135.  
  136.         if [ -f $PRE_FILE ]
  137.         then
  138.             cp $PRE_FILE /conf || \
  139.               report_error "Could not copy $PRE_FILE to /conf"
  140.  
  141.             if [ -f $EX_PRE_FILE ]
  142.             then if [ "$UPDATE" ]
  143.                  then
  144.                 $EX_PRE_FILE -u $PRE_ARCH_LIST || \
  145.                    report_error "$EX_PRE_FILE failed!"
  146.                  else
  147.                 echo $EX_PRE_FILE $PRE_ARCH_LIST
  148.                 $EX_PRE_FILE $PRE_ARCH_LIST || \
  149.                    report_error "$EX_PRE_FILE failed!"
  150.                  fi
  151.             fi
  152.  
  153.         fi
  154.             
  155.              
  156.         # About to copy data from install diskette using /bin/cpdir.
  157.         # The cpdir step copies the diskette id to the root directory.
  158.  
  159.         CPDIR_PARMS="-ad -smnt "
  160.  
  161.         # If files are compressed on disk, don't copy compressed data.
  162.         if [ "$COMPRESSED" ]; then
  163.             CPDIR_PARMS="${CPDIR_PARMS} -scompressed"
  164.         fi
  165.  
  166.         # If updating COHERENT operating system, don't overwrite files
  167.         # named in /conf/upd_suppress.
  168.         if [ "$UPDATE" ]; then
  169.             SUPPRESSED=$(/bin/sed -e "s/^/-s/" < /conf/upd_suppress)
  170.             CPDIR_PARMS="${CPDIR_PARMS} $SUPPRESSED"
  171.         fi
  172.  
  173.  
  174.         # Also suppress any files specified on the dist. disk
  175.         # NOTE: $ID.supp *MUST* be on disk #1!!
  176.         SUP_FILE=/mnt/$ID.supp
  177.         SUPPRESSED=
  178.  
  179.         if [ -f $SUP_FILE ]
  180.         then
  181.             SUP_LIST=$(/bin/sed -e "s/^//" < ${SUP_FILE})
  182.             for each in $SUP_LIST
  183.             do
  184.                 SUP_EL=`ls /mnt/$each | /bin/sed -e "s/^\/mnt\//-s/"`
  185.                 SUPPRESSED="${SUPPRESSED} $SUP_EL"
  186.                 echo $SUP_EL
  187.             done
  188.             CPDIR_PARMS="${CPDIR_PARMS} $SUPPRESSED"
  189.             echo $CPDIR_PARMS
  190.         fi
  191.  
  192.         $DO_COMMAND /bin/cpdir $CPDIR_PARMS /mnt / || {
  193.             report_error "Copy of disk $1 failed"
  194.         }
  195.  
  196.         # Uncompress files that are compressed on source diskette.
  197.         if [ "$COMPRESSED" ]; then
  198.  
  199.             # If updating COHERENT operating system,
  200.             # pass this info to uncompressing script.
  201.             # This is again so as not to step on files
  202.             # named in /conf/upd_suppress.
  203.             if [ "$UPDATE" ]; then
  204.                 UFLAG="-u"
  205.             else
  206.                 UFLAG=
  207.             fi
  208.             $DO_COMMAND /etc/install.u $UFLAG || {
  209.                 report_error "Uncompress of disk $1 failed"
  210.             }
  211.         fi
  212.  
  213.         COPIED=Y
  214.     done
  215.  
  216.     /etc/umount $DEVICE
  217.  
  218.     /bin/echo "/etc/install: disk $1 installed" >>$LOGFILE
  219.     /bin/sync
  220. }
  221.  
  222. ###############
  223. # Main.
  224. ###############
  225.  
  226. # Parse command line.
  227.  
  228. COMPRESSED=
  229. BUILD=
  230. UPDATE=
  231. COH=
  232. while [ $# -gt 3 ]; do
  233.     ARG=$1
  234.     case $ARG in
  235.     -c)
  236.         COMPRESSED=y
  237.         ;;
  238.     -b)
  239.         BUILD=y
  240.         COMPRESSED=y
  241.         COH=y
  242.         ;;
  243.     -u)
  244.         UPDATE=y
  245.         COMPRESSED=y
  246.         COH=y
  247.         ;;
  248.  
  249.     -*)
  250.         report_error "bad argument: $ARG"
  251.         usage
  252.         ;;
  253.     esac
  254.     shift
  255. done
  256.  
  257. if [ $# -ne 3 ]; then
  258.     usage
  259. fi
  260.  
  261. ID=$1
  262. DEVICE=$2
  263. NDISKS=$3
  264.  
  265. if [ "$TESTMODE" ];then
  266.     echo ID=$ID DEVICE=$DEVICE NDISKS=$NDISKS
  267.     echo COMPRESSED=$COMPRESSED BUILD=$BUILD UPDATE=$UPDATE
  268. fi
  269.  
  270. # Echo command line, followed by date, to $LOGFILE.
  271.  
  272. echo $0 $* >> $LOGFILE
  273. /bin/date >> $LOGFILE
  274.  
  275. # If installing COHERENT (initial or update), mount everything.
  276. # Install disks.
  277. # Disk numbers are 2 to ndisks for build, 1 to ndisks otherwise.
  278.  
  279. if [ "$COH" ]; then
  280.     $DO_COMMAND /etc/mount.all
  281.     for DISK_NUM in $(from 2 to $NDISKS);do
  282.         mount_disk $DISK_NUM
  283.     done
  284. else
  285.     for DISK_NUM in $(from 1 to $NDISKS);do
  286.         mount_disk $DISK_NUM
  287.     done
  288. fi
  289.  
  290. # Delete diskette ids.
  291.  
  292. $DO_COMMAND /bin/rm -f /$ID.*
  293.  
  294. # Execute postfile if present.
  295. # Append "-u" for COHERENT update.
  296.  
  297. POSTFILE=/conf/$ID.post
  298.  
  299. if [ -f $POSTFILE ];then
  300.     if [ "$UPDATE" ];then
  301.         $POSTFILE -u
  302.     else
  303.         $POSTFILE
  304.     fi
  305. fi
  306.  
  307. # Echo success message with date to log file.
  308.  
  309. /bin/echo "/etc/install: success" >>$LOGFILE
  310. /bin/date >>$LOGFILE
  311. /bin/echo >>$LOGFILE
  312.  
  313. # If installing COHERENT (initial or update), unmount everything.
  314.  
  315. if [ "$COH" ]; then
  316.     $DO_COMMAND /etc/umount.all
  317. fi
  318.  
  319. # Completion message to operator.
  320.  
  321. echo "
  322. Installation complete.
  323. Don't forget to remove the last diskette from the disk drive.
  324. "
  325. /bin/sync
  326.  
  327. # Need to reboot if installing COHERENT, to get tertiary kernel.
  328.  
  329. if [ "$COH" ]; then
  330.     echo "
  331. You must reboot your system in order to allow the preceding
  332. configuration steps to take effect.
  333. "
  334.     /etc/reboot -p
  335. fi
  336.  
  337. exit 0
  338.