#! /bin/sh

#
# Copyright Rainer Wichmann (2005)
#
# License Information:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

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

