#!/bin/sh
# Copyright (c) 1994-1995 by Adobe Systems Incorporated.
#
# Shell script for integrating ShowPS with Indigo Magic desktop.
#
###################################################################

# Make sure Berkeley stuff is on user's path so hostname can be found.
PATH=$PATH:/usr/ucb:/usr/bsd:/usr/bin/X11:/usr/sbin
WHOAMI=`/usr/bin/id | sed 's/^[^(]*.\([^)]*\).*/\1/'`
MKDIR="/usr/bin/mkdir -p"
RM="/usr/bin/rm -f"
CP="/usr/bin/cp"

# Abort installation if user not superuser
if [ "$WHOAMI" != root ] ; then
   echo ""
   echo "You must be logged in as root to install"
   echo 'Type "su root" and enter the password to become root.'
   exit 1
fi

# Try to determine the parent directory to this launch script.
thisscriptname=$0

# Follow any symbolic links in thisscriptname.
while : ; do
	lsresult=`ls -l $thisscriptname`
	symlink=`expr "$lsresult" : '.*>'.*`

	if [ "$symlink" -gt 0 ] ; then
		oldscriptname="$thisscriptname"
		thisscriptname=`echo $lsresult|sed -e 's/^.*-> *\(.*\) *$/\1/g'`
		abspath_new=`expr "$thisscriptname" : '^/'`
		if [ $abspath_new != 1 ] ; then
			abspath_old=`expr "$oldscriptname" : '^/'`
			if [ $abspath_old != 1 ] ; then
				olddir=`pwd`
			else
				olddir=`expr "$oldscriptname" : '\(.*\)/'`
			fi
			thisscriptname="$olddir/$thisscriptname"
		fi
	else
		break
	fi
done

# Determine directory containing this shell script.
scriptdir=`expr $thisscriptname : '\(.*\)/'` 
if [ "$scriptdir" = "" -o "$scriptdir" = "." ] ; then
	scriptdir=`pwd`
fi

# Determine root directory for installation ($scriptdir/..).
parentdir=`expr $scriptdir : '\(.*\)/'` 
if [ "$parentdir" = "" ] ; then
	tempdir=`pwd`
	parentdir=`expr $tempdir : '\(.*\)/'`
fi

if [ ! -x "$parentdir/bin/showps" ] ; then
	xconfirm -t "Unable to find desktop directory" -B OK
	exit 1
fi

# Integrate into Indigo Magic Desktop
osname=`uname -s`
if [ "$osname" = "IRIX" ] ; then
   echo ""
   echo "Installing icon files and file type rules."
   if [ ! -d /usr/lib/filetype/local/iconlib ] ; then
       ${MKDIR}  /usr/lib/filetype/local/iconlib
   fi
   ${RM} /usr/lib/filetype/local/showps.ftr
   ${RM} /usr/lib/filetype/local/showps*.fti
   ${CP} $scriptdir/showps.ftr /usr/lib/filetype/local
   ${CP} $scriptdir/showps*.fti /usr/lib/filetype/local/iconlib

   (cd /usr/lib/filetype; make)

   echo ""
   echo "Integrating ShowPS in the Applications catalog."
   iconbookedit -add "Category:File Name:$parentdir/bin/showps" -syspage Applications
fi

exit 0
