#! /bin/sh
#----------------------------------------------------------------------------
# template-restore-bconf - restore config file from /etc/backup.d
#
# Copyright (c) 2001-2003 Ansgar Püster <Ansgar.Puester@T-Online.de>
#
# Creation:	24.12.2003  ap
# Last Update:  $Id$
#
# 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.
#----------------------------------------------------------------------------

# include eislib
. /var/install/include/eislib

header()
{
    clrhome
    mecho -info "Restore configuration file from $backupd directory"
    mecho
    [ $act_count -lt $fcount ] && mecho "Avaliable backups for package $package:"
}

footer()
{
    mecho
    mecho
    anykey
}

question()
(
    mecho
    mecho
    mecho "Enter number to select a file, return to continue, q to quit:           \b\b\b\b\b\b\b\b\b\b\c"
)

overwrite_hint()
{
    mecho -info "Attention: this will overwrite your current configuration"
    mecho -info "           file for package $package with an older"
    mecho -info "           configuation file named"
    mecho -info "           $restfile"
    mecho -info "           that was saved in $backupd."
}

restore_file()
{
    act_count=`expr $fcount + 1`
    header
    eval restfile=\${bfile[$fnumber]}
    mecho
    overwrite_hint
    if /var/install/bin/ask "Continue"; then
       mecho
      # echo "TEST cp -p $restfile $configd/$package"
        cp -p $restfile $configd/$package
        activate_hint
    else
        mecho -info "Configuration file $configd/$package was not changed."
    fi
}

# include function library
. /var/install/bin/config_shlib

#----------------------------------------------------------------------------

# get package name from filename PACKAGE-restore-bconf
filename=`basename $0`
package=`echo $filename | sed "s|-restore-bconf$||"`

select_file

if [ $selected = 'true' ]; then
    case $fnumber in
        [0-9]*)  restore_file;;
        Q|q)  ;;
    esac
fi

footer