#!/bin/sh
# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.

# ident "$Header: setup-pts.sh 1.7 90/07/29 $"

PATH=/etc:/bin:/usr/bin:.; export PATH
WHOAMI=`id | sed 's/^.*(\(.*\)).*(.*).*$/\1/'`
COMPANY_NAME=/usr/lib/mailbug_co_name
ALIASES=/usr/lib/mailx/mailx.rc

if [ "$WHOAMI" != "root" ]
then
	echo "$0: Must be run as root"
	exit 1
fi
if [ ! -d /usr/bin ]; then
	echo "$0: /usr filesystem does not appear to be mounted"
	echo "$0: mount it and try again"
	exit 1
fi
#
#	Must be run as root while with at least the /usr file system mounted
#
# ----------------------------------------------------------------------
HOST=`uname`
if [ "$HOST" = "" -o "$HOST" = nodename ]; then
	echo "$0: System name not set"
	exit 1
fi

echo "Name of remote machine: \c"; read REMOTEHOST
if [ -z "$REMOTEHOST" ]; then
	echo "$0: remote machine name cannot be empty"
	exit 1
fi
echo "Name of Company or Organization: \c"; read COMPANY

echo "using: remote=$REMOTEHOST company=$COMPANY"
# ----------------------------------------------------------------------
#	Put company name in the right place so mailbug can find it.

cat > $COMPANY_NAME <<@
Company: $COMPANY
@

# ----------------------------------------------------------------------
#	Alias pts so the mailbug command will work.  aliases.dir and
#	aliases.pag have to be initialized for 'newaliases' to work the
#	first time.
#
if [ "`grep -c -s 'alias[ 	]*pts[	 ]' $ALIASES`" -gt 0 ]
then
	: "pts already in $ALIASES"
else
	echo "** Adding pts alias to $ALIASES"
	cat >> $ALIASES << EOF

# Alias for problem tracking system (mailbug)
alias pts ${REMOTEHOST}!pts
EOF
fi

if [ `uuname | grep -c $REMOTEHOST` -eq 0 ]
then
cat << EOF

WARNING:

  A UUCP connection to '${REMOTEHOST}' has not been set up yet --
  Use the menu system (ptx/ADMIN) to set up UUCP to ${REMOTEHOST}.

  Also, notify Sequent Service that they should add the line:

	`uname` Never

  to their /usr/lib/uucp/Systems file.

EOF
fi


#----------------------------------------------------------------------
#       Initialize the /usr/service/site-information and serial-number
#       files.
SERVICE=/usr/service
echo ">> Setting up mailbug information files ..."

# check if /usr/service exists. If not create it.
if [ ! -s $SERVICE ]
then
   mkdir $SERVICE
fi

# check if the mailbug directory exists. If not create it and allow public
# to write to it.

if [ ! -s $SERVICE/mailbug ]
then
    mkdir $SERVICE/mailbug
fi

chmod 777 $SERVICE/mailbug

# check if site-information file exists and is not blank. If not create it and
# prompt user for input.
if [ ! -s $SERVICE/site-information ]
then
    echo "Company Name: \c" ; read it
    echo "site_name: "$it > $SERVICE/site-information
    echo "Address: \c" ; read it
    echo "address: "$it >> $SERVICE/site-information
    echo "City: \c" ; read it
    echo "city: "$it >> $SERVICE/site-information
    echo "State/Province Code: \c" ; read it
    echo "state_province_code: "$it >> $SERVICE/site-information
    echo "Postal Code: \c" ; read it
    echo "postal_code: "$it >> $SERVICE/site-information
    echo "Country: \c" ; read it
    echo "country: "$it >> $SERVICE/site-information
    echo "Phone Number: \c" ; read it
    echo "phone_number: "$it >> $SERVICE/site-information
    echo "Valid site types are: OEM, VAR, Distributor, and end user."
    echo "Site Type: \c" ; read it
    echo "site_type: "$it >> $SERVICE/site-information
    echo "Valid system types are: S27, S81, S16, and S3"
    echo "System Type: \c" ; read it
    echo "system_type: "$it >> $SERVICE/site-information
    echo "Would you like to edit this information now? (y/n) \c" ; read it
        case "$it" in
            [yY]* ) ${EDITOR-vi} $SERVICE/site-information ;;
            *) ;;
        esac
fi

# check if serial-number file exists and is not blank. If not create it and
# prompt user for input.
if [ ! -s $SERVICE/serial-number ]
then
    echo "System Serial Number: \c" ; read it
    echo "serial_number: "$it > $SERVICE/serial-number
    echo "Would you like to edit this information now? (y/n) \c" ; read it
        case "$it" in
            [yY]* ) ${EDITOR-vi} $SERVICE/serial-number ;;
            *) ;;
        esac
fi

echo "** All done"
