#!/bin/sh
# Copyright (c) 1994 by Adobe Systems Incorporated.
#
# Shell script for integrating Photoshop 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
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/photoshop" ] ; then
        xconfirm -t "Unable to find desktop directory" -B OK
        exit 1
else
        if [ -x /usr/sbin/tag ]; then
                /usr/sbin/tag 0x00FF02C0 "$parentdir/bin/photoshop"
                #/usr/sbin/tag 0x00FF02C0 "$parentdir/bin/AdobePhotoshop3.0"
        else
                xconfirm -t "Unable tag photoshop executable" -B OK
        fi
fi

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

   (cd /usr/lib/filetype; make)

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

exit 0
