#!/bin/bash

# postflight script for the MacTeX ghostscript installer

PKG_PATH=$1

# is our system pre 10.5.0?
if [[ `/usr/bin/uname -r | /usr/bin/cut -f 1 -d .` -lt 9 ]]; 
then
	rm /usr/local/bin/gs-noX11
	mv /usr/local/bin/gs-noX11-tiger /usr/local/bin/gs-noX11
	rm /usr/local/bin/gs-X11
	mv /usr/local/bin/gs-X11-tiger /usr/local/bin/gs-X11
	else
		rm /usr/local/bin/gs-noX11-tiger
		rm /usr/local/bin/gs-X11-tiger
fi


# link proper gs

if [[  -e /usr/X11R6/bin/X ]]; then
	echo "X11 exists; using appropriate gs"
	ln -fs /usr/local/bin/gs-X11 /usr/local/bin/gs
else
	echo "no X11; using appropriate gs"
	ln -fs /usr/local/bin/gs-noX11 /usr/local/bin/gs
fi

# add path setup code to /etc/profile and /etc/csh.login; on Leopard /usr/local/bin is already in the path
# unless the old files which do not call path_helper have been preserved

if [[ ( -e /etc/profile ) && ( $( grep -c '^[^#]*eval `/usr/libexec/path_helper -s`' /etc/profile ) = 0 ) ]]; then
	"${PKG_PATH}"/Contents/Resources/setloginpath /usr/local/bin
fi

if [[ ( -e /etc/csh.login ) && ( $( grep -c '^[^#]*eval `/usr/libexec/path_helper -c`' /etc/csh.login ) = 0 ) ]]; then
	"${PKG_PATH}"/Contents/Resources/setloginpath /usr/local/bin
fi

