#!/bin/csh -f
#
#      $Id: install_soft,v 1.20 2002-02-04 14:49:21 haley Exp $
#
#########################################################################
#                                                                       #
#              Copyright (C)  1992                                      #
#        University Corporation for Atmospheric Research                #
#              All Rights Reserved                                      #
#                                                                       #
#########################################################################
#
#   File:       install_soft
#
#   Author:     John Clyne
#           National Center for Atmospheric Research
#           PO 3000, Boulder, Colorado
#
#   Date:       Tue Sep 29 08:31:24 MDT 1992
#
#   Description:    Configure the installation and install software
#
#   Usage:      install_soft
#
#   Environment:    LOCALDIR        path to install system
#           SYSTEM (exported)   The system type
#           RSH (exported)      rsh command
#           MT (exported)       mt command
#           AWK (exported)      awk command
#           SED (exported)      sed command
#           DF (exported)       df command
#           INSTALL_SOURCE (exported)   installation source
#           INSTALL_TYPE (exported)     installation type
#           INSTALL_FILE_DEV (exported) installation file device
#           INSTALL_CD_DEV (exported)   installation cd device
#           INSTALL_TAPE_DEV (exported) installation tape device
#
#   Files:      $LOCALDIR/env.cf        generic config
#           $LOCALDIR/config/env.$system    system specific config
#
#
#   Options:
#
#

onintr cleanup

source $LOCALDIR/env.cf
if (-e "$LOCALDIR/config/env.$SYSTEM") then
        source $LOCALDIR/config/env.$SYSTEM
endif

#
# Get site ID number
#
getsiteid:
clear

cat <<EOF

    If you paid a fee for this software, then please enter the 3 or
    4-digit order number that can be found in the top right corner of
    the cover of the NCAR Graphics Installer's Guide. This number is
    the one that the NCAR Graphics consulting office will ask for when
    the site representative or site installer calls for help.

    If you don't have the Installer's Guide, or you downloaded this
    software for free from the web, then just hit return twice.

EOF

echo -n "    NCAR Graphics order number: " > /dev/tty
set answer1 =  $<

echo -n "    Please enter it again to verify: " > /dev/tty
set answer2 =  $<

if ("$answer1" != "$answer2") then
  echo "" > /dev/tty
  echo "    Sorry, the two entries didn't match." > /dev/tty
  echo "    Please enter the number again." > /dev/tty
  echo "" > /dev/tty
  $LOCALDIR/pause
  goto getsiteid
else
  if ($answer1 == "") then
    setenv NCARG_SITE_ID ""
  else
    setenv NCARG_SITE_ID $answer1
  endif 
endif

#
#   don't know install paths yet
#
set bin_path = 
set inc_path = 
set lib_path = 
set man_path = 


while (1) 
    switch ("$INSTALL_SOURCE")

    case    "tape":
        set device = $INSTALL_TAPE_DEV
        breaksw

    case    "cdrom":
        set device = $INSTALL_CD_DEV
        breaksw

    case    "tar-file":
        set device = $INSTALL_FILE_DEV
        breaksw

    default:
        echo "$0 : Unknown install source <$INSTALL_SOURCE>" > /dev/tty
        exit 1
    endsw

    clear
cat <<EOF


                 NCAR Graphics Unix Version $VERSION
                     Copyright (C) 1987-2002
          University Corporation for Atmospheric Research
     The use of this Software is governed by a License Agreement.




    1.  Select distribution medium      [ install from $INSTALL_SOURCE ]
    2.  Select source device            [ device: $device ]
    3.  Select installation type        [ $INSTALL_TYPE ]
    4.  Show installation configuration
    5.  Perform installation
    6.  Help

    0.  Return to previous menu

EOF

    echo -n "    Select: " > /dev/tty
    set answer =  $<
    switch ($answer)
    case "1":
        set source = `$LOCALDIR/select_src`
        if ($status == 0) then
            setenv INSTALL_SOURCE $source
        endif
        breaksw

    case "2":
        switch ($INSTALL_SOURCE)

        case    "tape":
            set device = `$LOCALDIR/select_dev -t $INSTALL_TAPE_DEV`
            if ($status == 0) then
                setenv INSTALL_TAPE_DEV $device
            else
                $LOCALDIR/pause
            endif
            breaksw

        case    "cdrom":
            set device = `$LOCALDIR/select_dev -c $INSTALL_CD_DEV`
            if ($status == 0) then
                setenv INSTALL_CD_DEV $device
            else
                $LOCALDIR/pause
            endif
            breaksw

        case    "tar-file":
            set device = `$LOCALDIR/select_dev -f $INSTALL_FILE_DEV`
            if ($status == 0) then
                setenv INSTALL_FILE_DEV $device
            else
                $LOCALDIR/pause
            endif
            breaksw
        breaksw

        default:
            echo "$0 : Unknown install source <$INSTALL_SOURCE>" > /dev/tty
            exit 1
        endsw

        breaksw

    case "3":
        set config_line = `$LOCALDIR/select_config`
        if ($status == 0) then
            if ("$config_line" != "") then
                setenv INSTALL_TYPE $config_line[1]
                set bin_path = $config_line[2]
                set inc_path = $config_line[3]
                set lib_path = $config_line[4]
                set man_path = $config_line[5]
            endif
        else 
            $LOCALDIR/pause
        endif
        breaksw

    case "4":
        clear > /dev/tty
        echo "" > /dev/tty
        echo "" > /dev/tty
        echo "" > /dev/tty
        echo "  Current Installation Configuration" > /dev/tty
        echo "" > /dev/tty
        echo "" > /dev/tty
        echo "  Installing software for a(n) $SYSTEM_TO_INSTALL system" > /dev/tty
        echo "" > /dev/tty
        echo "  Order Number:          $NCARG_SITE_ID" > /dev/tty
        echo "  Installation source:   $INSTALL_SOURCE" > /dev/tty
        echo "  Source device:         $device" > /dev/tty
        echo "  Installation type:     $INSTALL_TYPE" > /dev/tty
        echo "" > /dev/tty

        if ("$bin_path" != "/dev/null") then
            echo "      Install executables to:     $bin_path" > /dev/tty
        endif
        if ("$inc_path" != "/dev/null") then
            echo "      Install C include files to: $inc_path" > /dev/tty
        endif
        if ("$lib_path" != "/dev/null") then
            echo "      Install libraries to:       $lib_path" > /dev/tty
        endif
        if ("$man_path" != "/dev/null") then
            echo "      Install man pages to:       $man_path" > /dev/tty
        endif
        
        $LOCALDIR/pause
        breaksw


    case "5":
        if ("$INSTALL_TYPE" == "?") then 
            clear > /dev/tty
            cat <<EOF  > /dev/tty



    Installation type not selected. Please select an installation type.
EOF
            $LOCALDIR/pause
            breaksw
        endif

        $LOCALDIR/perf_install $bin_path $inc_path $lib_path $man_path
        if ($status != 0) then
            $LOCALDIR/pause
        endif
        breaksw


    case "6":
        clear > /dev/tty
        cat <<EOF | $PAGER > /dev/tty


    This is the NCAR Graphics installation menu. Use this menu
    to customize your installation configuration and to install
    your software. 

    Configuring Your Installation

    Before you can install NCAR Graphics you need to inform the 
    installation system of the type and location of your distribution
    media. Menu items "1" and "2" perform this service. You also need
    to decide which components of NCAR Graphics you are installing 
    and where in your file system these components will be 
    installed (menu item "3"). If you only want to install NCAR 
    Graphics man pages, for example, the installation system allows 
    you to do so.

    You may examine your current installation configuration at any time
    by selecting menu item "4".

    Starting the Installation

    When you are satisfied with the configuration of your installation
    you may begin the installation process by selecting menu item "5".
EOF
        $LOCALDIR/pause
        breaksw

    case "0":
        exit 0
        breaksw

    case ""
        breaksw

    default
        echo "Invalid option <$answer>" > /dev/tty
        $LOCALDIR/pause
    endsw
end


cleanup:
exit 1
