#! /bin/sh

name=`./samhain-install.sh --print-config name`
sbin=`./samhain-install.sh --print-config sbin_dir`
rcfi=`./samhain-install.sh --print-config config_file`
passwd=$1

setpwd="./${name}_setpwd"

# Install the prepared configuration file.
#
test -f ./prepared_samhainrc || exit 1
./samhain-install.sh --install-sh -m 600 ./prepared_samhainrc "$rcfi" || exit 1

# Gentoo noise
#
rm -f /etc/init.d/._cfg????_${name}
rm -f /etc/._cfg????_${name}rc

# Set the password within the executable.
#
if test "x${passwd}" = "xDUMMY"
then
    rm -f "$sbin/${name}_setpwd"
else
    current=`pwd`
    cd "$sbin" || exit 1
    eval "$setpwd" "$name" new "$passwd" || exit 1
    if test -f "${name}.new"
    then
	rm "$name" || exit 1
	mv "${name}.new" "$name" || exit 1
	rm -f "./${name}_setpwd"
    fi
    cd "$current"
fi

exit 0

