#!/bin/bash

INSTALL=`which install`
STRIP=`which strip`
GZIP=`which gzip`

BINDIR=/usr/bin
PIXMAPSDIR=/usr/share/pixmaps
MANDIREN=/usr/share/man/man1
MANDIRIT=/usr/share/man/it/man1
FONTSDIR=/usr/share/fonts/ra1792control
LOCALEDIR=/usr/share/locale/it/LC_MESSAGES
DOCSDIR=/usr/share/doc/ra1792control
GPLV3DIR=$DOCSDIR/GPLv3

echo Installing...

if ! test "$UID" = "0" ; then
    echo "'Install' must be run as root"
    exit
fi

if test -z $INSTALL ; then
	echo "'install' program not found"
	exit
fi

if ! test -d $IMGDIR ; then
	mkdir -p $IMGDIR
fi

if ! test -d $FONTSDIR ; then
	mkdir -p $FONTSDIR
fi

if ! test -d $DOCSDIR ; then
	mkdir -p $DOCSDIR
fi

if ! test -d $GPLV3DIR ; then
	mkdir -p $GPLV3DIR
fi

$INSTALL -m 755 src/RA1792Control $BINDIR
if test -n $STRIP ; then
	$STRIP $BINDIR/RA1792Control
fi

$INSTALL -m 644 RA1792Control.gif $PIXMAPSDIR
$INSTALL -m 644 src/fonts/digital-dream-fat.ttf $FONTSDIR
$INSTALL -m 644 src/fonts/Arial.ttf $FONTSDIR
$INSTALL -m 644 src/fonts/Arial_Bold.ttf $FONTSDIR
$INSTALL -m 644 src/fonts/DejaVuSansMono.ttf $FONTSDIR
$INSTALL -m 644 src/locale/it/RA1792Control.mo $LOCALEDIR
$INSTALL -m 644 src/GPLv3/gpl-3.0.txt $GPLV3DIR
$INSTALL -m 644 src/GPLv3/gplv3-it-final.pdf $GPLV3DIR
$INSTALL -m 644 src/doc/Manual-en.txt $DOCSDIR
$INSTALL -m 644 src/doc/Manual-it.txt $DOCSDIR
$INSTALL -m 644 src/doc/changelog $DOCSDIR
if test -n $GZIP ; then
$GZIP -n -9 -f $DOCSDIR/changelog
fi
$INSTALL -m 644 src/man/en/RA1792Control.1 $MANDIREN
$INSTALL -m 644 src/man/it/RA1792Control.1 $MANDIRIT

echo "Done"
