#!/bin/sh
#
# Rebooter installation script
#
# Copyright (c) Tuomo Valkonen 1997-1998.
#

PIXMAPS=/usr/local/share/rebooter/pixmaps
LOCALE_DIR=/usr/share/locale
KDE_REBOOTER_DATA=share/apps/krebooter
KDE_PIXMAPS=$KDE_REBOOTER_DATA/pixmaps
KDE_APPLNK_DIR=share/applnk/System
KDE_DOCS=share/doc/HTML/en/krebooter
KDE_LOCALE_DIR=share/locale

question()
{
	read answer
	if [ "$answer" ] ; then
		return 1
	else
		answer=$1
		return 0
	fi
}

if [ `id -u` != 0 ]; then
	echo "You must be root to install rebooter." ; exit 1
fi

echo
echo Welcome to rebooter 0.2 !
echo
echo This script will install rebooter on your system.
echo Before you may continue, you must have read the README.
echo

#
# Has the user read the README?
#################################
echo -n "Have you read the README? [y/N] "
question "N"
case $answer in
y|Y|yes|YES|Yes)
	;;
*)
	less -r README
	echo
	echo Press any key to continue the installation process or ^C to abort...
	read
esac

echo Installing rebooter in /usr/bin/X11 ...
install -m 4755 rebooter /usr/bin/X11

echo Copying pixmaps in $PIXMAPS ...
mkdirhier $PIXMAPS
install -m 644 pixmaps/* $PIXMAPS

install_kde=0
if [ "$KDEDIR" != "" ] ; then
	echo "To install the kde version of rebooter, you must compile it."
	echo -n "Install the kde version of rebooter? [y/N]"
	question "N"
	case $answer in
	y|Y|yes|YES|Yes)
		install_kde=1
	esac
fi

if [ $install_kde = 1 ]; then

	echo Installing krebooter in $KDEDIR/bin ...
	install -m 4755 krebooter "$KDEDIR/bin"

	echo Installing krebooter.kdelnk in $KDEDIR/$KDE_APPLNK_DIR
	install -m 644 krebooter.kdelnk "$KDEDIR/$KDE_APPLNK_DIR"

	echo Symlinking $KDEDIR/$KDE_PIXMAPS to $PIXMAPS ...
	mkdirhier "$KDEDIR/$KDE_REBOOTER_DATA"
	rm -f "$KDEDIR/$KDE_PIXMAPS"
	ln -s "$PIXMAPS" "$KDEDIR/$KDE_PIXMAPS"

	echo Symlinking $KDEDIR/$KDE_DOCS to ./docs ...
	rm -f "$KDEDIR/$KDE_DOCS"
	ln -s "$PWD/docs" "$KDEDIR/$KDE_DOCS"

	echo Installing messages in $LOCALE_DIR and "$KDEDIR/$KDE_LOCALE_DIR" ...
else
	echo Installing messages in $LOCALE_DIR..
fi
for i in LC_MESSAGES/*.mo; do
	lang=`basename $i .mo`
	mkdirhier "$LOCALE_DIR/$lang"
	cp $i "$LOCALE_DIR/$lang/LC_MESSAGES/rebooter.mo"
	if "$KEDIR" != "" ] ; then
		mkdirhier "$KDEDIR/$KDE_LOCALE_DIR/$lang"
		cp $i "$KDEDIR/$KDE_LOCALE_DIR/$lang/LC_MESSAGES/krebooter.mo"
	fi
done

echo 	"Installation complete."
echo
echo	"Remember to create /etc/rebooter.allow and/or /etc/rebooter.deny files."
echo
