#!/bin/sh

##############################################################################
# Copyright (C) 2000 by Xerox Corp.  All rights reserved.
##############################################################################

# First determine if the OS package is installed
if [ -x /usr/bin/xprint ]; then
  # Determine current centerware install location 
  INSTALLDIR=`grep cd /usr/bin/xprint | sed -e "s/cd //"`
else
  # Emit the error message and exit
  echo "ERROR:  The OS package must be installed before the printer package."
  exit
fi

CURDIR=`dirname $0`

# determine the version of software installed
VERSION=`/usr/bin/xprint -v 2>&1 | sed -e "s/xprint //"`

# Check if driver is reporting correctly and installed
if [ `expr ${VERSION:+1}` ]
then
  MAJ=`echo "$VERSION" | sed -e "s/\./ /g" | cut -f1 -d" "`
  MID=`echo "$VERSION" | sed -e "s/\./ /g" | cut -f2 -d" "`
  LOW=`echo "$VERSION" | sed -e "s/\./ /g" | cut -f3 -d" "`
else
  # Set predef vals if driver not installed
  MAJ=1
  MID=1
  LOW=1
fi

MMAJ=3
MMID=0
MLOW=0

# Determine current operating system
this_os=`uname`

CheckAvailableDiskSpace()
{
    if [ `expr "${SpaceNeeded} -gt ${SpaceAvailable}"` ]
    then
	echo $FULLDISKMSG
	exit 0
    fi
}

Install ()
{
  CheckAvailableDiskSpace

  case $this_os in
    IRIX)
	cp -r $CURDIR/db/* $INSTALLDIR/db/
	cp -r $CURDIR/icon/* $INSTALLDIR/icon/
	;;

    AIX)
	cp -R $CURDIR/db/* $INSTALLDIR/db/
	cp -R $CURDIR/icon/* $INSTALLDIR/icon/

	slibclean
	OSLevel=`oslevel`
        case $OSLevel in
            4.3.3*)
                cp -R $CURDIR/lib/AIXrs6000/lib* $INSTALLDIR/lib/
                ;;

            5*)
                cp -R $CURDIR/lib/AIXpowerpc/lib* $INSTALLDIR/lib/
                ;;
        esac
	;;

    Linux)
	platform=`uname -p`
	case $platform in
	    ppc)
		cp -R $CURDIR/db/* $INSTALLDIR/db/
		cp -R $CURDIR/icon/* $INSTALLDIR/icon/
		cp -R $CURDIR/lib/Linuxppc/lib* $INSTALLDIR/lib/
		;;

	    i386 | i686 | x86_64 | athlon | *)
		cp -R $CURDIR/db/* $INSTALLDIR/db/
		cp -R $CURDIR/icon/* $INSTALLDIR/icon/
		cp -R $CURDIR/lib/Linuxi686/lib* $INSTALLDIR/lib/
		;;
	esac
	;;

    SunOS)
	platform=`uname -p`
	case $platform in
	    sparc)
		cp -R $CURDIR/db/* $INSTALLDIR/db/
		cp -R $CURDIR/icon/* $INSTALLDIR/icon/
		cp -R $CURDIR/lib/SunOSsparc/lib* $INSTALLDIR/lib/
		;;

	    i386 | i686 | x86_64 | athlon | *)
		cp -R $CURDIR/db/* $INSTALLDIR/db/
		cp -R $CURDIR/icon/* $INSTALLDIR/icon/
		cp -R $CURDIR/lib/SunOSi386/lib* $INSTALLDIR/lib/
		;;
	esac
	;;

    HP-UX)
	cp -R $CURDIR/db/* $INSTALLDIR/db/
	cp -R $CURDIR/icon/* $INSTALLDIR/icon/
	cp -R $CURDIR/lib/HPUXhppa1/lib* $INSTALLDIR/lib/
	;;
  esac

  cp $CURDIR/ppd/* $INSTALLDIR/ppd/
  cp $CURDIR/help/* $INSTALLDIR/help/
  cp $CURDIR/PSP.VERSION $INSTALLDIR/
  cp $CURDIR/trans.conf $INSTALLDIR/
  echo $MSGDONE
  exit
}

PrintMessage ()
{
  echo $MSG1
  echo $MSG2
  echo $MSG3
  echo $MSG4
}

# Get the space requirements
SpaceNeeded=`du -sk $CURDIR | sed -e "s/[A-Za-z\t \.\/].*//"`
case $this_os in
    AIX)
	TargetPartitionSpace=`df -k $INSTALLDIR | sed -e "1d"`
	SpaceAvailable="`echo $TargetPartitionSpace | cut -f3 -d' '`"
	;;

    Linux)
	platform=`uname -p`
	case $platform in
	    ppc)
		TargetPartitionSpace=`df -k $INSTALLDIR | sed -e "1d"`
		SpaceAvailable="`echo $TargetPartitionSpace | cut -f4 -d' '`"
		;;

	    i386 | i686 | x86_64 | athlon | *)
		TargetPartitionSpace=`df -k $INSTALLDIR | sed -e "1d"`
		Lines=`echo $TargetPartitionSpace | wc -l`
		while [ $Lines -gt 1 ];
		do
		  TargetPartitionSpace=`echo $TargetPartitionSpace | sed -e "1d"`
		  Lines=`echo $TargetPartitionSpace | wc -l`
		done
		SpaceAvailable="`echo $TargetPartitionSpace | cut -f4 -d' '`"
		;;
	esac
	;;

    SunOS)
	TargetPartitionSpace=`df -k $INSTALLDIR | sed -e "1d"`
	SpaceAvailable="`echo $TargetPartitionSpace | cut -f4 -d' '`"
	;;

    HP-UX)
	TargetPartitionSpace=`df -b $INSTALLDIR`
	SpaceAvailable="`echo $TargetPartitionSpace | cut -f5 -d' '`"
	;;
esac

case "$LANG" in
    ?*) CURLANG=`echo "$LANG" | sed 's/\..*//'` ;;
    *)  # LANG not set!
        # `export LANG=en_US`
	CURLANG="en_US"
        ;;
esac

  CURLANG=`echo "$LANG" | sed 's/\..*//'`
  case $CURLANG in
    en_US | en | english | en_AU | en_BW | en_CA | en_DK | en_GB | en_IE | en_NZ | en_SE | en_ZA | en_ZW)
	MSG1="The version of CentreWare Unix ($VERSION) currently installed on this system is not"
	MSG2="recent enough to support all of the printers contained in this support  "
	MSG3="pak. Please download the most recent version of CentreWare Unix from:   "
	MSG4="http://www.xerox.com  ftp://ftp.xerox.com                               "
	FULLDISKMSG="There isn't enough space in $INSTALLDIR to perform the installation activities. Restart the installation procedure using an install area that has enough space."
	MSGDONE="Installation of printer support package complete."
	;;

    es_ES | es | espaol | es_AR | es_BO | es_CL | es_CO | es_CR | es_EC | es_GT | es_MX | es_NI | es_PA | es_PE | es_PY | es_SV | es_UY | es_VE)
	MSG1="La versin de CentreWare Unix ($VERSION) instal actualmente en este sistema no es "
	MSG2="reciente suficiente al apoyo todas las impresoras contenidas en esta    "
	MSG3="mochila de apoyo.  Cargue por favor la versin ms reciente de          "
	MSG4="CentreWare Unix de:  http://www.xerox.com  ftp://ftp.xerox.com          "
	FULLDISKMSG="No hay espacio suficiente en $INSTALLDIR para realizar las actividades de instalacin. Reinicie el procedimiento de instalacin utilizando un rea de instalacin que tenga espacio suficiente."
	MSGDONE="La instalacin de paquete de apoyo de impresora completa."
	;;

    it_IT | it | italian)
	MSG1="La versione di CentreWare Unix ($VERSION) ha installato attualmente su questo sistema "
	MSG2="non  abbastanza recente al sostegno tutte le stampanti contenute in questo"
	MSG3="pacco di sostegno.  Per favore il download la versione pi recente di      "
	MSG4="CentreWare Unix da:  http://www.xerox.com  ftp://ftp.xerox.com             "
	MSGDONE="L'installazione di imballaggio di sostegno di stampante completa."
	FULLDISKMSG="Non c' abbastanza spazio in $INSTALLDIR per eseguire le attivit d'installazione. Ricominciare la procedura d'installazione utilizzando un'area di installazione che abbia spazio sufficiente."
	;;

    ge_GE | ge | german | de | de_AT | de_CH | De_DE | de_DE)
	MSG1="Die Ausfhrung ist von CentreWare Unix ($VERSION), das momentan auf diesem System  "
	MSG2="installiert wird, richt neu genug zu Sttze alle Drucker, dir in diesem "
	MSG3="Sttze Pack enthalten werdern.  Laden Sie bitte dir neuestre Ausfhrung "
	MSG4=" von CentreWare Unix von:  http://www.xerox.com  ftp://ftp.xerox.com    "
	MSGDONE="Installation von Drucker Sttze Paket vollendet."
	FULLDISKMSG="$INSTALLDIR enthlt nicht gengend Kapazitt zur Durchfhrung der Installationsvorgnge. Das Installationsverfahren in einem Arbeitsbereich mit der erforderlichen Kapazitt erneut beginnen."
	;;

    fr_FR | fr | franais | french | fr_BE | fr_CA | fr_CH)
	MSG1="La version de CentreWare Unix ($VERSION) a install actuellement sur ce systme     "
	MSG2="n'est pas assez rcent  toutes les imprimantes de soutien contenues     "
	MSG3="dans ce tas de soutien.  S'il vous plat charger la version la plus      "
	MSG4="rcente de CentreWare Unix de:  http://www.xerox.com  ftp://ftp.xerox.com"
	MSGDONE="L'installation de packet de soutien d'imprimante complte."
	FULLDISKMSG="Il n'y a pas suffisamment d'espace dans $INSTALLDIR pour effectuer l'installation. Relancez la procdure d'installation en utilisant une zone d'installation qui a suffisamment d'espace."
	;;

    pr_BR | pt | portuguese | pt_BR | pt_PT)
	MSG1="A verso de Unix de CentreWare ($VERSION) atualmente instalou neste sistema no   "
	MSG2="suficientemente recente a todas as as impressoras de apoio contido neste"
	MSG3="pacote de apoio.  Por download de favor a verso bem recente de Unix de "
	MSG4="CentreWare de:  http://www.xerox.com  ftp://ftp.xerox.com               "
	MSGDONE="A instalao de embruhlo de apoio de impressora completa."
	FULLDISKMSG="No h espao suficiente em $INSTALLDIR para executar as atividades de instalao. Reinicie o procedimento de instalao usando uma rea com espao suficiente."
	;;

      cs_CZ | fi_FI | finnish | sv_FI | hu_HU | hungarian | nl_NL | nl_BE | nb_NO | nn_NO | no_NO | norwegian | nynorsk | se_NO | pl_PL | ru_RU | russian | ru_UA | sv_FI | sv_SE | tr_TR | da_DK | danish | dansk)
	MSG1="The version of CentreWare Unix ($VERSION) currently installed on this system is not"
	MSG2="recent enough to support all of the printers contained in this support  "
	MSG3="pak. Please download the most recent version of CentreWare Unix from:   "
	MSG4="http://www.xerox.com  ftp://ftp.xerox.com                               "
	FULLDISKMSG="There isn't enough space in $INSTALLDIR to perform the installation activities. Restart the installation procedure using an install area that has enough space."
	MSGDONE="Installation of printer support package complete."
	;;

    *)
	echo "Environment variable LANG is undefined - Switching to English"
	MSG1="The version of CentreWare Unix ($VERSION) currently installed on this system is not"
	MSG2="recent enough to support all of the printers contained in this support  "
	MSG3="pak. Please download the most recent version of CentreWare Unix from:   "
	MSG4="http://www.xerox.com  ftp://ftp.xerox.com                               "
	FULLDISKMSG="There isn't enough space in $INSTALLDIR to perform the installation activities. Restart the installation procedure using an install area that has enough space."
	MSGDONE="Installation of printer support package complete."
	;;
    esac

case $VERSION in
1* | 2*)
    PrintMessage
    exit
    ;;
*)
    Install
    ;;
3 | 4*)
    Install
    ;;
esac
