#!/bin/sh

VERSION="1.68"
LIBVERSION="4.16"

if [ -e /sbin/uname -o -e /bin/uname ]; then
	echo "  OS  : `uname -s`, version `uname -r`"
	case "`uname -s`" in
	IRIX)
		echo "  CPU : `hinv | grep CPU | cut -f3 -d' '` Processor (`uname -p`)"
		;;
	SunOS)
		echo "  CPU : `uname -p`)"
		;;
	Linux)
		;;
	FreeBSD)
		;;
	esac
else
	echo "Unknown system \!"
	exit
fi

case "`id`" in
	uid=*(root)*)
		;;
	*)
		echo "You must be root \!"
		exit
esac

#
#

echo This script will install nview/nconvert/xnview in the /usr/local/bin directory

BASEDIR="/usr/local"

if [ ! -e $BASEDIR ]; then
	mkdir $BASEDIR
fi

if [ ! -e $BASEDIR ]; then
	exit 0
fi

if [ ! -e $BASEDIR/bin ]; then
	mkdir -p $BASEDIR/bin
	chmod 755 $BASEDIR/bin
fi

if [ ! -e $BASEDIR/lib ]; then
	mkdir $BASEDIR/lib
	chmod 755 $BASEDIR/lib
fi

if [ ! -e $BASEDIR/man/man1 ]; then
	mkdir -p $BASEDIR/man/man1
	chmod 755 $BASEDIR/man/man1
fi

if [ ! -e $BASEDIR/doc/XnView ]; then
	mkdir -p $BASEDIR/doc/XnView
	chmod 755 $BASEDIR/doc/XnView
fi

rm -f $BASEDIR/bin/nview $BASEDIR/bin/nconvert $BASEDIR/bin/xnview
rm -f $BASEDIR/man/man1/nview.z $BASEDIR/man/man1/xnview.z

##
## Install BINARY
##
cp bin/nview bin/nconvert bin/xnview $BASEDIR/bin
chmod 755 $BASEDIR/bin/nview $BASEDIR/bin/nconvert $BASEDIR/bin/xnview

##
## Install APP-DEFAULTS
##
cp app-defaults/XnView.ad /usr/lib/X11/app-defaults/XnView
chmod 444 /usr/lib/X11/app-defaults/XnView

##
## Install MAN page
##

if [ -e man/nview.z ]; then
#	cp man/nview.z man/xnview.z $BASEDIR/man/cat1/
#	chmod 644 $BASEDIR/man/cat1/nview.z $BASEDIR/man/cat1/xnview.z
	cp man/nview.z $BASEDIR/man/man1/nview.1.gz
	cp man/xnview.z $BASEDIR/man/man1/xnview.1.gz
	chmod 644 $BASEDIR/man/man1/nview.1.gz $BASEDIR/man/man1/xnview.1.gz
else
	cp man/nview.1 man/xnview.1 $BASEDIR/man/man1/
	chmod 644 $BASEDIR/man/man1/nview.1 $BASEDIR/man/man1/xnview.1
fi

##
## Install LIBRARY
##
if [ "`uname -s`" = "HP-UX" ]; then
	cp lib/libformat.sl.${LIBVERSION} $BASEDIR/lib
	rm -f $BASEDIR/lib/libformat.sl
	chmod 755 $BASEDIR/lib/libformat.sl.${LIBVERSION}
	ln -s $BASEDIR/lib/libformat.sl.${LIBVERSION} $BASEDIR/lib/libformat.sl
else
if [ "`uname -s`" = "AIX" ]; then
	cp lib/libformat.a.${LIBVERSION} $BASEDIR/lib
	rm -f $BASEDIR/lib/libformat.a
	chmod 755 $BASEDIR/lib/libformat.a.${LIBVERSION}
	ln -s $BASEDIR/lib/libformat.a.${LIBVERSION} $BASEDIR/lib/libformat.a
else
	cp lib/libformat.so.${LIBVERSION} $BASEDIR/lib
	rm -f $BASEDIR/lib/libformat.so
	chmod 755 $BASEDIR/lib/libformat.so.${LIBVERSION}
	ln -s $BASEDIR/lib/libformat.so.${LIBVERSION} $BASEDIR/lib/libformat.so
fi
fi

##
## Install DOC
##
cp *.txt $BASEDIR/doc/XnView
chmod 644 $BASEDIR/doc/XnView/*.txt

echo You must add to the PATH environment variable /usr/local/bin
if [ "`uname -s`" = "HP-UX" ]; then
	echo "  and /usr/local/lib to the SHLIB_PATH"
else
if [ "`uname -s`" = "AIX" ]; then
	echo "  and /usr/local/lib to the LIBPATH"
else
	echo "  and /usr/local/lib to the LD_LIBRARY_PATH"
fi
fi

echo 
echo Done!
