#!/bin/sh
# @(#)install_SCSI	2.1 10/7/93
# Copyright (c) 1993 Alias Research. All rights reserved.
# This is unpublished proprietary source code of Alias Research
# The copyright notice above does not evidence any
# actual or intended publication of such source code.

MUST_BE_ROOT=1

yorn()
{
    while :
    do
        if [ "$1" != "" ]
        then
            echo "(y/n)\c"
        else
            echo
            echo "Is this okay? (y/n)\c"
        fi
        read yorn_value
        case $yorn_value in
            y|Y) return 0 ;;
            n|N) return 1 ;;
            *) echo "Please answer using either y or n." ;;
        esac
    done
}

BOLD=`/usr/bin/tput bold`
UNBOLD=`/usr/bin/tput rmso`

#
# Ensure that this script is being run as root (uid == 0)
#
uid=`/usr/bin/id | cut -c5- | cut '-d(' -f 1`

if [ "$uid" != "0" -a "$MUST_BE_ROOT" = "1" ]
then
    echo "You must be logged in as \"root\" in order to install"
    echo "Alias 2D Products."
    exit 0
fi

###############################################################


echo
echo "The following SCSI devices are installed:"
echo

echo "-----------------------------------------------------------"
/bin/hinv | /bin/grep SCSI | /bin/grep unit |
    sed 's/unit \(.\)/unit '${BOLD}'\1'${UNBOLD}'/g'
echo "-----------------------------------------------------------"

echo
echo
echo "${BOLD}1)${UNBOLD} Install link for 9-Track tape (SCSI)"
echo "${BOLD}2)${UNBOLD} Install link for 9-Track tape (Xylogics)"
echo "${BOLD}3)${UNBOLD} Install link for 8mm tape (SCSI)"
echo "${BOLD}0)${UNBOLD} Do not install links at this time"

echo
while :
do
    echo "Select: \c"

    read choice
    case $choice in
        1)  TAPE=9track
            CONT=SCSI
            SRC1=/dev/mt/tps
            SRC2=nrnsv.6250
            break
            ;;
        2)  TAPE=9track
            CONT=Xylogics
            SRC1=/dev/mt/xmt
            SRC2=nrnsv.6250
            break
            ;;
        3)  TAPE=8mm
            CONT=SCSI
            SRC1=/dev/mt/tps
            SRC2=nrnsv
            break
            ;;
        0) exit 0
            ;;
    esac
done

while :
do
    echo "Enter the ${CONT} Controller id for the $TAPE device (0 or 1): \c"
    read cont_id
    if [ $cont_id -lt 0 -o $cont_id -gt 1 ]
    then
        echo "    ** The valid range of Controllers is 0-1,"
        echo "       if you are unsure, use 0."
    else
        break
    fi
done

if [ "$CONT" = "SCSI" ]
then
while :
do
    echo "Enter the SCSI id for the $TAPE device: \c"
    read id
    if [ $id -lt 2 -o $id -gt 7 ]
    then
        echo "    ** The valid range of SCSI id's is 2-7."
    else
        break
    fi
done
else
    echo "Enter the Xylogics address for the $TAPE device: \c"
    read id
fi

echo "Installing: "

FROM=${SRC1}${cont_id}d${id}${SRC2}
TO=/dev/${TAPE}

echo
echo "\t$FROM"
echo as
echo "\t$TO"
echo

if yorn
then
    ln $FROM $TO
    chmod 666 $TO
    echo "Done."
else
    echo "No actions taken."
fi
echo

exit 0
