#!/bin/sh -f

if [ $EUID != 0 ]; then
    echo "You must be root to run the Linux Glide installer"
    exit 1
fi

echo "Welcome the the Linux Glide installer"

echo ""
echo "Have you read and do you agree to all the terms of the license"
echo -n "included with this package? [no] "

read resp
resp=`echo "x$resp" | tr '[A-Z]' '[a-z]'`

if [ $resp != "xyes" ] ; then
    echo "We can not continue unless you agree to the license and answer yes"
    exit 1
fi

dfltdest="/usr/local/glide"

echo -n "Where would you like glide installed? [$dfltdest] "

read dest

if [ "x$dest" = x ]; then
    dest=$dfltdest
fi

echo "Installing in $dest"

if [ ! -d $dest ]; then
    echo -n "$dest does not exist. Should I create it? [Y] "
    read resp
    resp=`echo "x$resp" | tr '[A-Z]' '[a-z]'`
    if [ $resp != "x" -a $resp != "xy" -a $resp != "xyes" ]; then
	echo "We can't continue without a destination directory."
	exit 1
    fi
    mkdir -p $dest
fi

echo "Unpacking release"

cat dist.tar.gz | (cd $dest ; tar xvzf -)
cp README LICENSE $dest

echo -n "Would you like $dest added to the system library path? [Y] "

read resp
resp=`echo "x$resp" | tr '[A-Z]' '[a-z]'`
if [ $resp != "x" -a $resp != "xy" -a $resp != "xyes" ]; then
    echo "You may need to use the LD_LIBRARY_PATH environment variable"
    echo "to run your applications."
    echo "Installation complete."
    exit 0
fi

check=`grep $dest/lib /etc/ld.so.conf`
if [ "x$check" = "x" ]; then
    echo $dest/lib >> /etc/ld.so.conf
fi
/sbin/ldconfig

echo "Installation complete."
exit 0
