#!/bin/sh

CONFIG=.config

if [ -r $CONFIG ]; then
    . $CONFIG
else
    KDIR=/usr/src/linux
    CRYPTODIR=
    PREFIX=/usr/local
fi

echo "Before you can compile and install ipsec_tunnel, you must enter the"
echo "paths to the directories containing the source code of the Linux"
echo "kernel and the CryptoAPI, as well as the directory prefix where the"
echo "programs and manual pages will be installed.  To accept the default"
echo "choice in brackets, just press enter."
echo

while [ 1 ]; do
    echo -n "Linux kernel source directory [$KDIR]: "
    read dir
    if [ -z "$dir" ]; then
	dir=$KDIR
    fi
    if [ -d "$dir/include" ]; then
	break
    fi
    echo "That directory is not a Linux kernel source directory."
done
KDIR=$dir

if [ -f "$KDIR/include/linux/crypto.h" ]; then
    echo "CryptoAPI patched Linux kernel directory detected."
    CRYPTODIR="$KDIR"
else
    while [ 1 ]; do
	echo -n "CryptoAPI source directory [$CRYPTODIR]: "
	read dir
	if [ -z "$dir" ]; then
	    dir=$CRYPTODIR
	fi
	if [ -f "$dir/linux/crypto.h" ]; then
	    CRYPTODIR="$dir"
	    break
	fi
	if [ -f "$dir/kernel/include/linux/crypto.h" ]; then
	    CRYPTODIR="$dir/kernel/include"
	    break
	fi
	echo "That directory is not a CryptoAPI source directory."
    done
fi

while [ 1 ]; do
    echo -n "Installation prefix [$PREFIX]: "
    read dir
    if [ -z "$dir" ]; then
	dir=$PREFIX
    fi
    if [ -d "$dir" ]; then
	break
    fi
    echo "That directory does not exist."
done

echo "# Automatically generated by configure." > $CONFIG
echo "KDIR=$KDIR" >> $CONFIG
echo "CRYPTODIR=$CRYPTODIR" >> $CONFIG
echo "PREFIX=$PREFIX" >> $CONFIG

echo
echo "Configuration is now complete."
echo
echo "Run \"make\" to compile and then \"make install\" to install."
