#!/bin/sh

# little configure script for hdup
# author: Miek Gieben
# Copyright: GPL, Miek Gieben

# set the default location for the configuration file
HDUPCONF="/etc/hdup/hdup.conf"

###-- you should not have to touch anything below this line --###

# this is a litte configure script that
# tries to guess the location of some
# of the utilities hdup depends on
SSH=`which ssh 2>/dev/null`
SCP=`which scp 2>/dev/null`
TAR=`which tar 2>/dev/null`
MCRYPT=`which mcrypt 2>/dev/null`
MDECRYPT=`which mdecrypt 2>/dev/null`

# extra check to avoid wrong 'which'es ie Solaris gives:
#no mcrypt in /home/infstud/bin /usr/local/bin /usr....
if [ "`echo ${MCRYPT} |  cut -b1`" != "/" ]; then MCRYPT=""; fi
if [ "`echo ${MDECRYPT} | cut -b1`" != "/" ]; then MDECRYPT=""; fi
if [ "`echo ${TAR} | cut -b1`" != "/" ]; then TAR=""; fi
if [ "`echo ${SSH} | cut -b1`" != "/" ]; then SSH=""; fi
if [ "`echo ${SCP} | cut -b1`" != "/" ]; then SCP=""; fi

echo "Checking for the default locations:"
echo
echo "hdup.conf: ${HDUPCONF}"
echo "ssh      : ${SSH}"
echo "scp      : ${SCP}"
echo "tar      : ${TAR}"
echo "mcrypt   : ${MCRYPT}"
echo "mdecrypt : ${MDECRYPT}"
echo

if [ "x$TAR" = "x" ]; then
        echo "  tar not found -- hdup will not work without it!";
        exit;
fi
if [ "x$SSH" = "x" -o "x$SCP" = "x" ]; then
        echo "  ssh not found -- remote backups will not work!";
        echo "  inserting defaults";
        SSH="/usr/bin/ssh";
        SCP="/usr/bin/scp";
fi
if [ "x$MCRYPT" = "x" -o "x$MDECRYPT" = "x" ]; then
        echo "  mcrypt not found -- encrypted backups will not work!";
        echo "  inserting defaults";
        MCRYPT="/usr/bin/mcrypt";
        MDECRYPT="/usr/bin/mdecrypt";
fi


# substitute the stuff in hdup.in.h
cat hdup.in.h | \
sed "s%##HDUPCONF##%${HDUPCONF}%"  | \
sed "s%##TAR##%${TAR}%"  | \
sed "s%##MCRYPT##%${MCRYPT}%" | \
sed "s%##MDECRYPT##%${MDECRYPT}%" | \
sed "s%##SCP##%${SCP}%"  | \
sed "s%##SSH##%${SSH}%"  > hdup.h
