#!/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 ../SkantiControl $BINDIR
if test -n $STRIP ; then
	$STRIP $BINDIR/SkantiControl
fi

$INSTALL -m 644 ../icons/SkantiControl.gif $PIXMAPSDIR
$INSTALL -m 644 ../img/off-red.bmp $IMGDIR
$INSTALL -m 644 ../img/on-red.bmp $IMGDIR
$INSTALL -m 644 ../img/off-green.bmp $IMGDIR
$INSTALL -m 644 ../img/on-green.bmp $IMGDIR
$INSTALL -m 644 ../img/off-yellow.bmp $IMGDIR
$INSTALL -m 644 ../img/on-yellow.bmp $IMGDIR
$INSTALL -m 644 ../img/arrow-up-on-yellow.bmp $IMGDIR
$INSTALL -m 644 ../img/arrow-down-on-yellow.bmp $IMGDIR
$INSTALL -m 644 ../img/arrow-up-off-yellow.bmp $IMGDIR
$INSTALL -m 644 ../img/arrow-down-off-yellow.bmp $IMGDIR
$INSTALL -m 644 ../img/arrow-up-on-green.bmp $IMGDIR
$INSTALL -m 644 ../img/arrow-down-on-green.bmp $IMGDIR
$INSTALL -m 644 ../img/arrow-up-off-green.bmp $IMGDIR
$INSTALL -m 644 ../img/arrow-down-off-green.bmp $IMGDIR
$INSTALL -m 644 ../img/arrow-up-on-red.bmp $IMGDIR
$INSTALL -m 644 ../img/arrow-down-on-red.bmp $IMGDIR
$INSTALL -m 644 ../img/arrow-up-off-red.bmp $IMGDIR
$INSTALL -m 644 ../img/arrow-down-off-red.bmp $IMGDIR
$INSTALL -m 644 ../fonts/digital-dream-fat.ttf $FONTSDIR
$INSTALL -m 644 ../fonts/Arial.ttf $FONTSDIR
$INSTALL -m 644 ../fonts/Arial_Bold.ttf $FONTSDIR
$INSTALL -m 644 ../fonts/DejaVuSansMono.ttf $FONTSDIR
$INSTALL -m 644 ../man/en/SkantiControl.1 $MANDIR
$GZIP -n -9 -f $MANDIR/SkantiControl.1
$INSTALL -m 644 ../man/it/SkantiControl.1 $MANDIRIT
$GZIP -n -9 -f $MANDIRIT/SkantiControl.1
$INSTALL -m 644 ../doc/Manual-en.txt $DOCDIR
$INSTALL -m 644 ../doc/Manual-en.pdf $DOCDIR
$INSTALL -m 644 ../doc/Manual-en.html $DOCDIR
$INSTALL -m 644 ../doc/Manual-it.txt $DOCDIR
$INSTALL -m 644 ../doc/Manual-it.pdf $DOCDIR
$INSTALL -m 644 ../doc/Manual-it.html $DOCDIR
$INSTALL -m 644 ../GPLv3/gpl-3.0.txt $DOCDIR
$INSTALL -m 644 ../locale/it/SkantiControl.mo $LOCALEDIR
$INSTALL -m 644 ../doc/changelog $DOCDIR
$GZIP -n -9 -f $DOCDIR/changelog

echo Done!
