#! /bin/sh

Usage() {
cat <<EOF >&2
Install incremental release which is ftp'ed from MSI as
one comressed encrypted tar-file:
	&0 <encrypted-tar-file>
This script will install files in the current directory
EOF
exit 1
}

echon() {
echo "$*" | awk '{printf "%s",$0}'
}

from=$1
[ -z "$from" -o -n "$2" ] && Usage
[ ! -r $from ] && echo "$from is unreadable" >&2 && Usage

if [ -z "$C2DIR" ]
then
   echon "Enter Cerius2 Installation directory: "
   read C2DIR
fi
while [ ! -d "$C2DIR" ]
do
   echo "$C2DIR is not Cerius2 Installation directory" >&2
   echon "Enter Cerius2 Installation directory: "
   read C2DIR
done

decrypt=$C2DIR/install/crypt
if [ ! -x $decrypt ]
then
   echo "Cannot find the decryption program. Contact MSI representative." >&2
   exit 3
fi
$decrypt -decrypt -key1 95 -key2 2 -in $from -out - | uudecode
decoded=`basename $from`.uu
zcat $decoded | tar xvf -
rm -f $decoded
