#!/bin/sh

VERSION="1.70"
LIBVERSION="4.47"

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 DOC
##
cp *.txt $BASEDIR/doc/XnView
chmod 644 $BASEDIR/doc/XnView/*.txt

echo 
echo Done!
