#!/bin/csh -f

set VERSION = "1.25"
set LIBVERSION = "3.16"

if ( -e /sbin/uname || -e /bin/uname ) then
	echo "  OS  : `uname -s`, version `uname -r`"
	switch ( "`uname -s`" )
	case IRIX:
		echo "  CPU : `hinv | grep CPU | cut -f3 -d' '` Processor (`uname -p`)"
		breaksw
	case SunOS:
		echo "  CPU : `uname -p`)"
		breaksw
	case Linux:
		breaksw
	case FreeBSD:
		breaksw
	endsw
else
	echo "Unknown system \!"
	exit
endif

switch ( "`id`" )
	case "uid=*(root)*":
		breaksw
	default:
		echo "You must be root \!"
		exit
endsw

#
#

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

set BASEDIR = /usr/local

if ( ! -e $BASEDIR ) then
	mkdir $BASEDIR
endif

if ( ! -e $BASEDIR ) then
	exit 0
endif

if ( ! -e $BASEDIR/bin ) then
	mkdir -p $BASEDIR/bin
	chmod 755 $BASEDIR/bin
endif

if ( ! -e $BASEDIR/lib ) then
	mkdir $BASEDIR/lib
	chmod 755 $BASEDIR/lib
endif

if ( ! -e $BASEDIR/man/cat1 ) then
	mkdir -p $BASEDIR/man/cat1
	chmod 755 $BASEDIR/man/cat1
endif

if ( ! -e $BASEDIR/doc/XnView ) then
	mkdir -p $BASEDIR/doc/XnView
	chmod 755 $BASEDIR/doc/XnView
endif

rm -f $BASEDIR/bin/nview $BASEDIR/bin/nconvert $BASEDIR/bin/xnview
rm -f $BASEDIR/man/cat1/nview.z $BASEDIR/man/cat1/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
else
	cp man/nview.1 man/xnview.1 $BASEDIR/man/cat1/
	chmod 644 $BASEDIR/man/cat1/nview.1 $BASEDIR/man/cat1/xnview.1
endif

##
## 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
endif
endif

##
## 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
endif
endif

echo 
echo Done!
