set -e
SRCDIR=`pwd`
AgreeEULA="$1"
InstallDir="$2"
if [ ! -f "$SRCDIR/eula.txt" ]; then
1>&2 cat <<EOF
Could not find the End-User License Agreement. You must read the license
before installing this software product.
EOF
exit 1
fi
if [ "$AgreeEULA" != "agree" ]; then
echo "Please read and agree to the License Agreement before installing Swift."
more "$SRCDIR/eula.txt"
echo ""
printf "Do you agree to these terms? Enter -yes- to continue: "
read answer
echo ""
if [ "x$answer" != "xyes" ]; then
echo "Cancelling installation at your request."
exit 0
fi
fi
# Get the installation directory
while :; do
if [ ! "$InstallDir" ]; then
printf "Install into what directory? [/opt/swift] "
read prefix
else
prefix=$InstallDir
fi
if [ `uname -s` = "Linux" ]; then
prefix="`echo $prefix | awk -v h=$HOME '{gsub(/~/,h); print}'`"
fi
prefix=${prefix:-/opt/swift} # set default if none given
if [ ! "$InstallDir" ]; then
if [ ! \( -d "$prefix" -o -h "$prefix" \) ]; then
answer=
while [ "x$answer" != "xy" -a "x$answer" != "xn" ]; do
printf "$prefix does not exist. Create it? ([n]/y) "
read answer
done
if [ "x$answer" = "xy" ]; then
mkdir -p "$prefix"
fi
elif [ ! -d "$prefix" ]; then
echo "$prefix is not a directory!"
fi
if [ -d "$prefix" ]; then
break
fi
else
if [ ! \( -d "$prefix" -o -h "$prefix" \) ]; then
mkdir -p "$prefix"
elif [ ! -d "$prefix" ]; then
echo "$prefix is not a directory!"
exit 0
fi
if [ -d "$prefix" ]; then
break
fi
fi
done