#!/bin/bash

#
# Startup script for APLX for Linux (GUI version)
#
# (This is a default placeholder file which is overwritten during a normal install
# once the installation directories are known)
#


# Default printing font path
APLX_PRINT_FONT_PATH=/usr/lib/X11/fonts/Type1


# First find out real 'startaplx' file location if we are being run through
# a symbolic link
THIS_FILE=$0
if [ -L "$THIS_FILE" ]; then
	THIS_FILE=$(readlink "$THIS_FILE")
	if [ $? -ne 0 ]; then
		echo "Error starting APLX for Linux"
		echo "Could not find APLX startup file"
		exit 1
	fi
fi

# Strip out utf-8 part of 'en_US.utf-8' and ensure right character set
LANG=$(echo $LANG | sed 's/\.utf-8\|\.UTF-8//'); export LANG
LC_CTYPE=iso_8859_1;export LC_CTYPE

# Assume APLX binary and libraries are in the same directory as this script
cd $(dirname "$THIS_FILE")
APLX_BIN_PATH=$(pwd)
APLX_LD_PATH=$APLX_BIN_PATH


# Add APLX directory to LD_LIBRARY_PATH
if [ -n "$LD_LIBRARY_PATH" ]; then
	# Already have an LD_LIBRARY_PATH. Prepend ours
	export LD_LIBRARY_PATH="$APLX_LD_PATH:$LD_LIBRARY_PATH"
else
	# Don't yet have an LD_LIBRARY_PATH. Create it now
	export LD_LIBRARY_PATH="$APLX_LD_PATH"
fi


# Put the APLX printing font in the X server font path
if [ -n "$APLX_PRINT_FONT_PATH" ]; then
	xset fp+ $APLX_PRINT_FONT_PATH
	xset fp rehash
fi


# Run APLX
$APLX_BIN_PATH/aplxlinux $*

