#!/bin/sh

#**************************************************************************
#
#                 XX                X                XXX
#                                  XX                 XX   
#                XXX     XX XXX   XXXXX               XX
#                 XX     XXX XX    XX                 XX
#                 XX     XX  XX    XX      XXXXX      XX
#                 XX     XX  XX    XX XX  XX    X     XX
#                XXXX    XX  XX     XXX   XXXXXXX    XXXX
#                                         XX
#                                          XXXXX
#
# Copyright (c) 1998-2000 Intel Corporation.  All Rights Reserved
#
# This software is supplied under the terms of a license agreement or
# non-disclosure agreement with Intel Corporation and may not be copied
# or disclosed except in accordance with the terms of that agreement.
#
# FILE NAME:   prosetup.sh
#
# DESCRIPTION: Installation script that will Do the following:
#              1. Install necessary files from eznpunix.tar
#	       
#
# $Revision: 1.19 $
# $Author: build $
# $Date: 1999/01/14 19:25:45 $
#
#**************************************************************************


# Variable initialization
Version="V05.41a"

# Currently the Install path is constant.
InstallPath=/usr/intl

# GNU Tar Flag
GTar=0

## Display Copyright message
DisplayCopyright()
{
	clear
	# Copyright 
	cat << ENDMESSAGE


********************************************************************

                    UNIX* Installation script 
      Intel NetportExpress(tm) 10, 10/100 and PRO print servers





                      Version: $Version





 Copyright (c) 1998-2000 by Intel Corporation. All rights reserved.
      * Brand, Name or Trademark owned by another company

********************************************************************

Press Enter to continue.
ENDMESSAGE
read Key
}

## Get Unix OS manually
GetUnixOS()
{
	OSType=""
	until [ "$OSType" != "" ]
	do
		cat << ENDMESSAGE


	The print server supports the following operating systems
	and comes with binary files for these systems.


	1. SunOS* releases 4.1.3 or Solaris* release 1.1 (SPARC*)

	2. Solaris 2.5, 2.6 or SunOS 5.5, 5.6, 5.7 (SPARC)

	3. Solaris 2.5, 2.6 or SunOS 5.5, 5.6, 5.7 (x86)

	4. SCO* UNIX release 3.2, 4.2, 5.0 (x86)

	5. UnixWare* 1.1, 2.01, 7.0 (x86)

	6. HP-UX* 9.05, 10.01, 10.10, 11.00 (HP-9000/700 Series Workstations)

	7. IBM AIX* 3.2.5, 4.1.3 (RS/6000)

	8. Linux 2.X (x86)

    If your system is not listed, type Q to quit prosetup and see
    the NetportExpress Print Server Setup Guide to setup spooler

Enter your choice [1-8,q]:

ENDMESSAGE

		read OSType

		case "$OSType" in
		1) OSType="sun"
			OS="SunOS 4.1.x"
			;;
		2) OSType="solaris"
			OS="Solaris 2.5, 2.6 or SunOS 5.5, 5.6, 5.7 (SPARC)"
			;;
		3) OSType="solx86"
			OS="Solaris 2.5, 2.6 or SunOS 5.5, 5.6, 5.7 (x86)"
			;;
		4) OSType="sco"
			OS="SCO UNIX 3.2, 4.2, 5.0"
			;;
		5) OSType="unixware"
			OS="SCO/Novell UnixWare 1.1, 2.0, 7.0"
			;;
		6) OSType="hpux"
			OS="HP-UX 9.05, 10.01, 10.10, 11.00 (700 Series)"
			;;
		7) OSType="aix"
			OS="IBM AIX 3.2.5, 4.1"
			;;
		8) OSType="linux"
			OS="Linux 2.X (x86)"
			;;
		q | Q)
			exit 0
			;;
		*) OSType=""
			;;
		esac
	done  
}

## Detect Unix OS
DetectUnixOS()
{
	OSRev=`uname -r` 
	OSVer=`uname -v` 
	OSType=`uname -s` 
	OSMach=`uname -m` 

	OS="$OSType $OSVer.$OSRev ($OSMach)"

	case "$OSType" in
		SunOS)
			case "$OSRev" in
			5.*)
				if [ -z "`echo $OSMach | grep 86`" ]
				then
					OSType=solaris
                                        OS="Solaris 2.5, 2.6 or SunOS 5.5, 5.6, 5.7 (SPARC)"
				else
					OSType=solx86
                                        OS="Solaris 2.5, 2.6 or SunOS 5.5, 5.6, 5.7 (x86)"
				fi
				;;
			4.*)
				OSType=sun
                                OS="SunOS 4.1.x"
				;;
			*)
				OSType=""
				;;
			esac
			;;
		AIX)
			OSType=aix;
                        OS="IBM AIX 3.2.5, 4.1"
			;;
		HP-UX)
			OSType=hpux;
                        OS="HP-UX 9.05, 10.01, 10.10, 11.00 (700 Series)"
			;;
		sco* | Sco* | SCO*)
			OSType=sco;
                        OS="SCO UNIX 3.2, 4.2, 5.0"
			;;
		UNIX_SV | UNIXWARE | UnixWare)
			OSType=unixware;
                        OS="SCO/Novell UnixWare 1.1, 2.0, 7.0"
			;;
		Linux)
			OSType=linux;
			OS="Linux 2.X (x86)"
			;;
		*)
			OSType=""
			;;
	esac
}

## Check for GNU Tar by tar error output
CheckForGNUTar()
{
	GTar=`tar 2>&1 | grep "You must" | wc -w`
}

#### Main Routine starts here

DisplayCopyright

# Check the user has super user privileges.
if [ -z "`id | grep 'uid=0'`" ]
then
	echo
	echo "Error: You must be root or have super user privileges to run"
	echo "       this installation script"
	echo
	echo
	exit 1
fi

# Detect the unix operating system
DetectUnixOS

if [ -z "$OSType" ]
then
	echo "Unable to detect your operating system"
	echo "Press any key to select manually..."
	read Key
	GetUnixOS
else
	clear
	echo "ProSetup detected your operating system as $OS."
	echo "It installs binary files for this operating system"
	echo "under $InstallPath directory"
	echo 
	echo "Press 'm' to manually override the current operating system"
	echo "selection or press any other key to continue ..."
	echo 
	read Key
	if [ "$Key" = "m" -o "$Key" = "M" ]
	then
		GetUnixOS
	fi
fi

# Get the the tar filename
# TarFile="`ls eznpunix.tar* 2>/dev/null || ls EZNPUNIX.TAR* 2>/dev/null`"

if [ -f "eznpunix.tar" ]
then
	TarFile="eznpunix.tar"
elif [ -f "EZNPUNIX.TAR" ]
then
	TarFile="EZNPUNIX.TAR"
else
	echo "Script should be run from the same directory where eznpunix.tar exists"
	exit 1
fi

if [ -d "$InstallPath" ]
then
	while true
	do
		echo "$InstallPath already exists. Do you want to overwrite? (y/n):"
		read Key
		case "$Key" in
		n | N)
			exit 0
			;;
		y | Y)
			break
			;;
		esac
	done
fi

echo "Please wait ..."
echo

CheckForGNUTar

if [ $GTar =  0 ]
then
	tar -xf $TarFile $InstallPath/proinstall >/dev/null 2>&1 && \
	tar -xf $TarFile $InstallPath/netport.fw >/dev/null 2>&1 && \
	tar -xf $TarFile $InstallPath/$OSType >/dev/null 2>&1
else
	tar xfP  $TarFile $InstallPath/proinstall >/dev/null 2>&1 && \
	tar xfP  $TarFile $InstallPath/netport.fw >/dev/null 2>&1 && \
	tar xfP  $TarFile $InstallPath/$OSType >/dev/null 2>&1
fi

if [ $? != 0 ]
then
	echo "Installation failed"
	exit 1
fi

cp readme.txt $InstallPath >/dev/null 2>&1 || cp README.TXT $InstallPath >/dev/null 2>&1

echo "Installation completed. Please change the directory to $InstallPath"
echo "and run proinstall to configure Intel NetportExpress print servers"
echo "and local print spoolers"

exit 0

