#! /bin/sh
#
# {*******************************************************}
# {                                                       }
# {       NativeDB for SQL Anyhere                        }
# {       Linux Installation bash-script                  }
# {                                                       }
# {       Copyright (c) 1995-2005 Liodden Data            }
# {                                                       }
# {*******************************************************}

APPTITLE="NativeDB"
PRODUCT_NAME="NativeDB v1.95 for SQL Anywhere"
TARFILE_NAME=ndb195lst.tar

DEFAULT_INSTALLATION_DIR=$HOME/nativedb

get_dest_dir () 
{
   DEST_DIR=
    while [ "_$DEST_DIR" = "_" ]
    do
	echo
	echo "Please enter the installation directory ($DEFAULT_INSTALLATION_DIR):"
	read DEST_DIR

	if [ "_$DEST_DIR" = "_" ]
	then
	    DEST_DIR=$DEFAULT_INSTALLATION_DIR
	fi

	if [  -f "$DEST_DIR" ]
	then
	    echo "$DEST_DIR exists but is not a directory."
	    DEST_DIR=
	elif [ -d "$DEST_DIR" ]
	then
	    echo
	    echo "NOTE: $DEST_DIR exists -- files will be overwritten"
	    echo
	else
	    if mkdir -p "$DEST_DIR" 2>/dev/null
	    then
		true;
	    else
		echo "Cannot create directory $DEST_DIR"
		DEST_DIR=
	    fi
	fi
    done
}

do_welcome () 
{
    clear
    cat <<-WELCOME

    $PRODUCT_NAME
    ================================================================

    Welcome to $APPTITLE Setup program.
    This program will install $APPTITLE on your computer.

    WARNING: This software is protected by copyright law and
    international treaties.

    Unauthorized reproduction or distribution of this program, or any
    portion of it, may result in severe civil and criminal penalties,
    and will be prosecuted to the maximum extent possible under law.

    Press ENTER to continue

    =================================================================
    Copyright(c) 1995-2005 Liodden Data AS - All rights reserved


WELCOME

    read INP
}

do_choose_dir() 
{
    clear
    cat <<-CHOOSE_DIR

    $PRODUCT_NAME
    ================================================================

    Setup will install $APPTITLE in the following folder.

    Press ENTER to accept the default location.

    To install into a different folder, type the complete path
    of your prefered location.

    Destination folder:
    $DEFAULT_INSTALLATION_DIR

    =================================================================
    Copyright(c) 1995-2005 Liodden Data AS - All rights reserved


CHOOSE_DIR

    get_dest_dir
}

do_start_install() 
{
    clear
    cat <<-START_INSTALL

    $PRODUCT_NAME
    ================================================================

    You are now ready to install $APPTITLE.

    Press ENTER to begin the installation.

    Destination folder:
    $DEST_DIR

    =================================================================
    Copyright(c) 1995-2005 Liodden Data AS - All rights reserved


START_INSTALL

    read INP
}

do_install()
{
    echo
    echo "Installing $PRODUCT_NAME to $DEST_DIR"
    echo
    gtar -xv --file=$TARFILE_NAME --directory=$DEST_DIR --overwrite
}

do_finish_install ()
{
    clear
    cat <<-FINISH_INSTALL

    $PRODUCT_NAME
    ================================================================

    $PRODUCT_NAME has been successfully installed.

    Please view the "readme.txt" in $DEST_DIR
    for further instructions.

    Press ENTER to exit this installation.

    =================================================================
    Copyright(c) 1995-2005 Liodden Data AS - All rights reserved


FINISH_INSTALL

    read INP
}


do_welcome
do_choose_dir
do_start_install
do_install
do_finish_install








