#!/bin/sh
#
#	KBInstall: Installation program for KBackup
#
#	Copyright (C) 1995,1996 by Karsten Ballueder
#			see manual for copyright details
#
#	$Header: /home/kbackup/CVSROOT/KBackup/kbinstall,v 1.26 1997/09/19 19:49:15 kbackup Exp $

KBACKUP_VERSION="1.2.11"

DIALOG_SRC_FILE=src/dialog

if [ "$1" = --ttymode ]
then
	echo "Entering tty-mode..."
	TTYMODE=YES
fi

. src/paths
. src/checkprogs

check_progs

DIALOGTITLE="KBackup Installation Program               (C) 1995, 1996 by Karsten Ballueder"

ready()
{
  $DIALOG --title  " KBackup Installation " --yesno \
"
Ready to continue with the installation of
the $* ?

Select \"No\" to skip this point.
" 12 49
}

# show copyright:
$DIALOG --title " KBackup Installation: Copyright and Conditions of use" --textbox COPYING 22 77 


# check for being root:
if [ "$UID" != "0" ]
then
	if ! $DIALOG --title " personal installation? " --yesno \
"
It seems that you are not the superuser (root). To
install KBackup and its support files properly, you
should have root privileges. 
Of course, as a normal user, you can also install
KBackup in your own directories, but this is not
recommended.

           Continue with installation?
" 14 56
	then
		exit 0
	fi
fi

# report missing programs:
if [ "$HasNot" != "" ]
then
	if ! $DIALOG --title " Error! " --yesno \
"
KBackup requires some other programs to be installed on your system.
It seems that the following programs are not yet installed:
$HasNot

If they should already be installed, you can edit the 'paths' file in
this directory to make sure KBackup can find them. Otherwise, you should
install them, or KBackup will not work properly.

In the manual you can find further information on where to get those
programs. You can also check the WWW KBackup homepage at:
http://www.uni-karlsruhe.de/~Karsten.Ballueder

                    Continue with installation?
" 18 77
	then
		exit 0
	fi
fi


# ask for directories:

if $DIALOG --title " KBackup data directory " --inputbox "
KBackup maintains several user defined configurations and creates
rather big logfiles during operation. 
As it is able to read backups without access to these files, they
can be safely put on a mounted filesystem. 
A reasonable place for them would be \"$kbackdir\".

Press ENTER to confirm this default, or enter a path of your
choice:
" 18 76 2>/tmp/.tmp$$
then
	ddir=`cat /tmp/.tmp$$`
	if [ "$ddir" != "" ]
	then
		kbackdir=$ddir
	fi
fi
datadir="$kbackdir/Data"

if $DIALOG --title " KBackup program directory " --inputbox "
Where do you want to install the \"kbackup\" program itself?

A reasonable place for this would be \"$progdir\".

Press ENTER to confirm this default, or enter a path of your 
choice:
" 15 76 2>/tmp/.tmp$$
then
	pdir=`cat /tmp/.tmp$$`
	if [ "$pdir" != "" ]
	then
		progdir=$pdir
	fi
fi

if $DIALOG --title " KBackup config directory " --inputbox "
KBackup needs a place where to store its configuration files
and some of its source. These files should be available whenever
it is run, so they should be put somewhere on the root filesystem.

A reasonable place for them would be \"$srcdir\".

Press ENTER to confirm this default, or enter a path of your 
choice:
" 18 76 2>/tmp/.tmp$$
then
	sdir=`cat /tmp/.tmp$$`
	if [ "$sdir" != "" ]
	then
		srcdir=$sdir
	fi
fi


# Documentation directory:
if $DIALOG --title " KBackup documentation directory " --inputbox "
KBackup comes with an extensive indexed manual in different formats
which is also available as online help if installed.
It will also install a directory with the HTML version of the
manual.

Where do you want this documentation to go? The recommended place is
\"$docdir\".

Press ENTER to confirm this default or enter a path of your choice:
" 18 76 2>/tmp/.tmp$$
then
	sdir=`cat /tmp/.tmp$$`
	if [ "$sdir" != "" ]
	then
		docdir=$sdir
	fi
fi
ready Documentation
if [ $? = 0 ]
then
  $DIALOG --title " KBackup Installation " --infobox "
Installing documentation in 
\"$docdir\"..." 6 40

   install -d $docdir
   install -d $docdir/html
   install -m 0644 docs/* $docdir 2>/dev/null
   install -m 0644 docs/html/* $docdir/html 
fi


# MultiBuf:

#if ! [ -x multibuf/multibuf ]
#then
$DIALOG --title " KBackup: Installation of MultiBuf" --infobox "
For handling multi-volume archives and for double-buffering, 
KBackup uses the MultiBuf program included in this 
distribution. It will now be compiled from its source. 

Compiling MultiBuf program...  (should take just few seconds)

" 9 67


cd multibuf 
if ! make multibuf >/dev/null 2>/dev/null
then
	$DIALOG --title " Installation error! " --msgbox "

Couldn't compile multibuf program!

KBackup needs it for its operation, so
you have to go to the multibuf/ directory,
compile it yourself and install somewhere
in your binaries path (e.g. /bin).

Sorry.    (Please, report this bug!)" 15 60
fi
cd ..

#fi

# create directories:
$DIALOG --title " KBackup Installation " --infobox "
Creating directories...  " 5 40

install -m 0755 -d $kbackdir

if [ -d $kbackdir/Default ]
then
	$DIALOG --title " KBackup Installation " --yesno "
Old KBackup data files found 
(Configuration-/Log-Files).

Do you want to keep them?"  9  35
	if [ $? = 0 ]
	then	
		install -m 0755 -d $datadir
		tmp=`pwd`
		( cd $kbackdir; for i in * ; do install -m 0755 -d $datadir/$i.old && cp -ar $kbackdir/$i $datadir/$i.old && rm -rf $i ; done ) 
		cd "$tmp"
	else
		rm -rf $kbackdir/*
	fi
fi
install -m 0755 -d $kbackdir
install -m 0755 -d $datadir
cd data
for i in * ; do install -m 0755 -d $datadir/$i ; done
cd ..
install -d $progdir
install -d $srcdir


# install subroutines/src:

cd src

$DIALOG --title " KBackup Installation " --infobox "
Configuring source..." 5 40 

echo "# settings added by kbinstall:
datadir=\"$datadir\"
docdir=\"$docdir\"
progdir=\"$progdir\"
srcdir=\"$srcdir\"
kbackdir=\"$kbackdir\"
" | cat paths - >tmp$$ && mv tmp$$ paths

$DIALOG --title " KBackup Installation " --infobox "
Installing config files / source..." 5 40 

install -m 0644 * $srcdir
cd ..



# installing programs:

$DIALOG --title " KBackup Installation " --infobox "
Installing Programs..." 5 40 

echo -e "#!/bin/sh\nSRCDIR=$srcdir\n" | cat - kbackup >.tmp$$ 
mv kbackup kbackup.bak
mv .tmp$$ kbackup
install    -m a=rx kbackup $progdir
mv kbackup.bak kbackup

rm -f $progdir/multibuf	# otherwise file gets longer and longer, bug in install?
install -s multibuf/multibuf $progdir

ready "manpages to /usr/man/man1"
if [ $? = 0 ]
then
  install -m 0644 multibuf/multibuf.1 /usr/man/man1
  install -m 0644 docs/kbackup.1 /usr/man/man1
fi

ready "sample configurations"
if [ $? = 0 ]
then
  $DIALOG --title " KBackup Installation " --infobox "
Installing sample configurations...  " 5 40

   cd data
   for i in * ; do install -m 0644 $i/* $datadir/$i ; done
   cd ..
fi

$DIALOG --title " KBackup Installation " --infobox "
Writing $HOME/.kbackrc ... " 5 40

cat >$HOME/.kbackrc <<_EOF_
#
# KBackup rc file
#
kbackdir=$kbackdir
datadir=$datadir
configname=Default
_EOF_


if [ "$HasAFIO" = "NO" ]
then
	if $DIALOG --title " KBackup Installation " --yesno "
It seems that you don't have the afio(1) program installed.

Do you want to use the binary included in this package?
(This is HIGHLY recommended! It's in ELF format.)
" 10 70
	then
		$DIALOG --title " KBackup Installation " --infobox "
Installing afio in /bin, /usr/man/man1
" 6 45
		install -m 0755 tools/bin/afio /bin
		install -m 0644 tools/man/afio.1 /usr/man/man1
	fi
fi

rm -f /tmp/.tmp$$

$DIALOG --title " KBackup installation " --msgbox "
Starting from release 1.2.9 of KBackup, the way the
MultiBuf program works has changed.

If you have been using an older version of KBackup,
please check your configuration:

The former configuration option \"double buffering
block size\" has disappeared and been replaced by
the \"number of blocks for multibuffering\".
" 22 63



$DIALOG --title " KBackup Installation " --msgbox "
Installation of KBackup is complete.

Its documentation can be found under \"$docdir\".
For further information, latest notes and the
newest releases, you can refer to the KBackup
home page in the WWW:

http://www.uni-karlsruhe.de/~Karsten.Ballueder

The newest public releases of KBackup can also
be found on:

ftp://ftp.rz.uni-karlsruhe.de/pub/local/linux/soft
ftp://sunsite.unc.edu/pub/Linux/system/Backup/

To start the program, type \"kbackup\".
" 22 63
clear



