#!/bin/bash

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

BINDIR=/usr/bin
IMGDIR=/usr/share/SkantiControl/Img
FONTSDIR=/usr/share/fonts/d
PIXMAPSDIR=/usr/share/pixmaps
MANDIR=/usr/share/man/man1
MANDIRIT=/usr/share/man/it/man1
FONTSDIR=/usr/share/fonts/SkantiControl
DOCDIR=/usr/share/doc/skanticontrol
LOCALEDIR=/usr/share/locale/it/LC_MESSAGES/

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 -z $GZIP ; then
	echo "'gzip' 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 $DOCDIR ; then
	mkdir -p $DOCDIR
fi

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

$INSTALL -m 644 src/icons/SkantiControl.gif $PIXMAPSDIR
$INSTALL -m 644 src/icons/SkantiControl.ico $PIXMAPSDIR
$INSTALL -m 644 src/img/off-red.bmp $IMGDIR
$INSTALL -m 644 src/img/on-red.bmp $IMGDIR
$INSTALL -m 644 src/img/off-green.bmp $IMGDIR
$INSTALL -m 644 src/img/on-green.bmp $IMGDIR
$INSTALL -m 644 src/img/off-yellow.bmp $IMGDIR
$INSTALL -m 644 src/img/on-yellow.bmp $IMGDIR
$INSTALL -m 644 src/img/arrow-up-on-yellow.bmp $IMGDIR
$INSTALL -m 644 src/img/arrow-down-on-yellow.bmp $IMGDIR
$INSTALL -m 644 src/img/arrow-up-off-yellow.bmp $IMGDIR
$INSTALL -m 644 src/img/arrow-down-off-yellow.bmp $IMGDIR
$INSTALL -m 644 src/img/arrow-up-on-green.bmp $IMGDIR
$INSTALL -m 644 src/img/arrow-down-on-green.bmp $IMGDIR
$INSTALL -m 644 src/img/arrow-up-off-green.bmp $IMGDIR
$INSTALL -m 644 src/img/arrow-down-off-green.bmp $IMGDIR
$INSTALL -m 644 src/img/arrow-up-on-red.bmp $IMGDIR
$INSTALL -m 644 src/img/arrow-down-on-red.bmp $IMGDIR
$INSTALL -m 644 src/img/arrow-up-off-red.bmp $IMGDIR
$INSTALL -m 644 src/img/arrow-down-off-red.bmp $IMGDIR
$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/man/en/SkantiControl.1 $MANDIR
$GZIP -n -9 -f $MANDIR/SkantiControl.1
$INSTALL -m 644 src/man/it/SkantiControl.1 $MANDIRIT
$GZIP -n -9 -f $MANDIRIT/SkantiControl.1
$INSTALL -m 644 src/doc/Manual-en.txt $DOCDIR
$INSTALL -m 644 src/doc/Manual-en.pdf $DOCDIR
$INSTALL -m 644 src/doc/Manual-en.html $DOCDIR
$INSTALL -m 644 src/doc/Manual-it.txt $DOCDIR
$INSTALL -m 644 src/doc/Manual-it.pdf $DOCDIR
$INSTALL -m 644 src/doc/Manual-it.html $DOCDIR
$INSTALL -m 644 src/GPLv3/gpl-3.0.txt $DOCDIR
$INSTALL -m 644 src/locale/it/SkantiControl.mo $LOCALEDIR
$INSTALL -m 644 src/doc/changelog $DOCDIR
$GZIP -n -9 -f $DOCDIR/changelog


echo Done!
