#!/bin/sh
# Copyright (c) 1994 by Adobe Systems Incorporated.
# Script called immediately after a package is installed.
# $1=Install directory for package. $2=License data file (unused)
########################################################

# Modify launch script with the information about install directory

# Worry about auto-mounter
SCRIPT=$0
ORIGDIR="$1"
TESTDIR=`expr $ORIGDIR : '/[^/]*\(.*\)'`
HEAD=`expr $ORIGDIR : '\(/[^/]*\)'/`

if [ "$HEAD" = "/tmp_mnt" ] ; then
    # automounter for sure, check for existance later
    IDIR="$TESTDIR"
else
    # if $TESTDIR exists, probably automounted
    if [ -d "$TESTDIR" ] ; then
        IDIR="$TESTDIR"
    else
        # Probably no automounting
        IDIR="$ORIGDIR"
    fi
fi

if [ ! -d "$IDIR" ] ; then
    echo "$IDIR does not exist, cannot continue."
    exit 1
fi

APP_BINDIR="$IDIR/bin"
APP_XRESDIR="$IDIR/app-defaults"

# The following commands MUST be defined properly
SED=sed
AWK=awk
RM="rm -f"
MV=mv
CD=cd
# The following commands CAN be replaced by "echo" for debugging
CP=cp
LN="ln -s"
MKDIR=mkdir
CHMOD=chmod

CURDATE="`date -u`"

valid_orig()
{
    FNAME="$1"
    ROM="$2"
    DASD="$3"
    FORIG="$FNAME".orig
    if [ ! -f $FORIG ] ; then
	$MV $FNAME $FORIG
	$CHMOD $ROM $FORIG
    fi
    if [ -f $FNAME -a -f $FORIG ] ; then
	$CHMOD $DASD $FNAME
	$RM $FNAME
    fi
}

valid_orig "$APP_BINDIR/showps" 555 755
$SED 's%INSTALL_DIR=FilledInByPostinstall$%INSTALL_DIR="'$IDIR'"%' \
< $APP_BINDIR/showps.orig \
| $SED 's%LAST_INSTALL_DATE=.*$%LAST_INSTALL_DATE="'"$CURDATE"'"%' \
| $AWK '/FilledInByPostinstall/ { next; } { print; }'  \
> $APP_BINDIR/showps
$CHMOD 755 $APP_BINDIR/showps

valid_orig "$APP_BINDIR/filterps" 555 755
$SED 's%filtbin=FilledInByPostinstall$%filtbin="'$APP_BINDIR'"%' \
< $APP_BINDIR/filterps.orig \
| $SED 's%LAST_INSTALL_DATE=.*$%LAST_INSTALL_DATE="'"$CURDATE"'"%' \
| $AWK '/FilledInByPostinstall/ { next; } { print; }'  \
> $APP_BINDIR/filterps
$CHMOD 755 $APP_BINDIR/filterps

valid_orig "$APP_XRESDIR/Showps" 444 644
$CP $APP_XRESDIR/Showps.orig $APP_XRESDIR/Showps
$CHMOD 644 $APP_XRESDIR/Showps
echo "*copyrightFile:		$APP_XRESDIR/ShowPSCopyright.ps" >> $APP_XRESDIR/Showps

if $IDIR/desktop/deskinstall ; then status=0; else status=1; fi
if [ $status != 0 ]; then
	echo ""
	echo "$SCRIPT: Icon installation failed."
	echo ""
	exit 1
fi

exit 0
