#!/bin/bash

INSTALL=`which install`
STRIP=`which strip`

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

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

echo "Installing..."

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/RA3701Control $BINDIR
if test -n $STRIP ; then
	$STRIP $BINDIR/RA3701Control
fi

$INSTALL -m 644 RA3701Control.png $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/fonts/Dotrice-Regular.otf $FONTSDIR
$INSTALL -m 644 src/fonts/NotoMono-Regular.ttf $FONTSDIR
$INSTALL -m 644 src/locale/it/RA3701Control.mo $LOCALEDIR/RA3701Control.mo
$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
$INSTALL -m 644 src/man/en/RA3701Control.1 $MANDIREN
$INSTALL -m 644 src/man/it/RA3701Control.1 $MANDIRIT

echo "Done!"
