#!/bin/sh
#
# @(#)sunpc_upgrade 2.1 92/12/14 SMI; from UCB X.X XX/XX/XX
#
#       Copyright (c) 1991, Sun Microsystems, Inc.  All Rights Reserved
#       Sun considers its source code as an unpublished, proprietary
#       trade secret, and it is available only under strict license
#       provisions.  This copyright notice is placed here only to protect
#       Sun in the event the source is deemed a published work.  Dissassembly,
#       decompilation, or other means of reducing the object code to human
#       readable form is prohibited by the license agreement under which
#       this code is provided to the user or company in possession of this
#       copy.
#
#       RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
#       Government is subject to restrictions as set forth in subparagraph
#       (c)(1)(ii) of the Rights in Technical Data and Computer Software
#       clause at DFARS 52.227-7013 and in similar clauses in the FAR and
#       NASA FAR Supplement.
#
# set -x
#
# sunpc_upgrade - SunPC upgrade script.
#
# Usage:
#
#	sunpc_upgrade oldsetup newsetup 
#

SETUPPCS="$HOME/pc/setup.pcs"
SOFTPC="$HOME/.SoftPC"
DOSRC="$HOME/pc/.sunpcrc"
INPUTFILE=$SETUPPCS
INFILE=$INPUTFILE
OUTPUTFILE=$DOSRC
FILETYPE="-d"

abort() {
    exit 1
}

trap abort 1 2 3 15

# return "yes" or "no" into shell variable named $1.  $2 is the user prompt.
# $3 is the default answer to use
get_yesno_def () {
    yesno=""
    while [ ! "$yesno" ]
    do
		echo ""
		echo -n "$2 [yes|no]($3)? "
		read yesno
		case "$yesno" in
		[yY]*)	yesno=yes ;;
		[nN]*)	yesno=no ;;
		"")	yesno="$3" ;;
		*)	echo "" ; echo 'Please enter "yes" or "no".' ; yesno="" ;;
		esac
    done
    eval $1="$yesno"
}

########### BEGIN SETUP CODE #################


# Find out where this script lives to determine the distribution location.
#

FROM_PATH=`echo "$0" | /bin/grep "/"`

if [ -n "$FROM_PATH" ]
then
        #in this case $0 is a directory component.
        FIRSTARG=`echo ${FROM_PATH} | /bin/awk -F/ '{ print $1 }'`

        if [ -z "$FIRSTARG" ]; then
                SOURCE3=`echo ${0} | /bin/awk -F/ '{ for (i = 1; i < NF; i++)  { printf "%s", $i; printf "/" } }'`
        else
                SOURCE3=`echo ${0} | /bin/awk -F/ '{ if ($1 == "") printf "/"; for (i = 1; i < NF; i++)  { printf "%s", $i; printf "/" } }'`
        fi
else
        #in this case $0 is not a directory component.
        SOURCE3="./"
fi

CURRDIR=`pwd`
cd $SOURCE3
cd ..
SUNPCHOME=`pwd`
export SUNPCHOME
cd $CURRDIR
CNVSETUP="$SUNPCHOME/bin/cnvsetup"



echo ""
echo "The purpose of this script is to convert any additional setup" 
echo "files that you created for DOS Windows 1.0 (1.01) or SoftPC 2.0"
echo "to be used with SunPC 3.0. This script only converts one"
echo "file at a time."

answer="no"
while [ "$answer" = no ]
do
	echo ""
	echo  "Enter the software [DosWindows|SoftPC] used "
	echo -n "to create your setup file (DosWindows): "
	read FILETYPE
	case "$FILETYPE" in
		[Ss]*) FILETYPE="-s" ; INFILE=$SOFTPC ;;
		[Dd]*) FILETYPE="-d" ; INFILE=$SETUPPCS ;;
		"")    FILETYPE="-d" ; INFILE=$SETUPPCS ;;
	esac
	INPUTFILE=$INFILE
	echo ""
	echo   "Enter the Full Path of the setup File you"
	echo -n  "want to convert ($INFILE): "
	read INPUTFILE
	if [ "$INPUTFILE" = "" ]
	then
		INPUTFILE=$INFILE
	fi
	echo ""
	echo -n "Enter Full Path of the converted File ($OUTPUTFILE): "
	read OUTPUTFILE
	if [ "$OUTPUTFILE" = "" ]
	then
		OUTPUTFILE=$DOSRC
	fi
	echo ""
	echo "The " $INPUTFILE " file will be converted to" $OUTPUTFILE
	echo ""
	echo -n "Do you want to continue [yes/no/exit] (yes): "
	read accept
	case "$accept" in
		[Yy]*) answer="yes";;
		[Nn]*) answer="no";;
		[Ee]*) abort ;;
		"")    answer="yes";;
	esac
	if [ ! -f "$INPUTFILE" ]
	then
		echo ""
		echo $INPUTFILE " does not exist, please try again...."
		answer="no"
	fi
done

echo ""
echo "Converting file....."
"$CNVSETUP" "$FILETYPE" -i "$INPUTFILE" -o "$OUTPUTFILE"

#
#
exit 0
