#! /bin/sh

echo "This script is designed to determine the layout of your Linux system"
echo "and to build a configuration header file to suit it."
echo
echo "Once it has finished running, and you have doubts about the decisions"
echo "that it has made, check the contents of the file lib/config.h and the"
echo "Makefiles in the sub-directories and edit them to match your system."
echo

rm -f lib/config.h

echo -n "Checking for the existence of ncurses... "

FOUND=0

if [ -f /usr/include/curses.h -o -d /usr/include/ncurses ]; then
    if [ ! -d /usr/include/ncurses ]; then
        grep __NCURSES_H /usr/include/curses.h > /dev/null

        if [ $? = 0 ]; then
            echo "found"
            FOUND=1
        fi
    else
        echo "found"
        FOUND=1
    fi
fi

if [ $FOUND = 0 ]; then
    echo "not found"
    echo
    echo "Your system has not got ncurses installed. To compile the call program"
    echo "you need this package. Therefore go and get ncurses and install it."
    echo "Then re-run configure."
    echo
    echo "Terminating configuration"
    exit 1
fi

echo

echo -n "Checking for the existence of /usr/local/etc/axports... "

if [ -f /usr/local/etc/axports ]; then
    echo "found"
    echo
    echo "The existence of a previous version of the AX.25 Utilities has been"
    echo "found. This release uses the FSSTND layout for its files and as such"
    echo "uses completely different locations for everything. Doing a make and"
    echo "install and an installconf will not overwrite existing files, the new"
    echo "locations go like this:"
    echo
    echo "    configuration files  -> /etc/ax25"
    echo "    binary files         -> /usr/bin"
    echo "    system binary files  -> /usr/sbin"
    echo "    manual pages         -> /usr/man/..."
    echo "    support files        -> /usr/lib/ax25/..."
    echo "    variable data files  -> /var/ax25/..."
    echo
    echo "Please move existing files to the new locations, using the newly"
    echo "installed configuration files as a guide."
else
    echo "not found"
fi

echo

echo -n "Checking for location for serial lock files... "

if [ -d /var/lock ]; then
    LOCKDIR=/var/lock
else
    if [ -d /var/spool/locks ]; then
        LOCKDIR=/var/spool/locks
    else
        if [ -d /usr/spool/uucp ]; then
            LOCKDIR=/usr/spool/uucp
        else
            echo "not found"
            echo
            echo "Your system does not appear to have a directory to store your serial"
            echo "lock files in. Not sure how to proceed."
            echo
            echo "Terminating configuration"
            exit 1
        fi
    fi
fi

echo $LOCKDIR

echo

echo "Creating config.h"

sed -e "s~@LOCKDIR@~$LOCKDIR~g" < lib/config.h.in > lib/config.h

echo

echo "Configuration finished"

exit 0
