#!/bin/sh -e

# $Id: lr_config.in,v 1.58 2002/08/18 15:18:00 vanbaal Exp $

#
# Copyright (C) 2000-2001 Stichting LogReport Foundation LogReport@LogReport.org
#
#     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 (see COPYING); if not, check with
#     http://www.gnu.org/copyleft/gpl.html or write to the Free Software 
#     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
#

# lr_config - interactively configure Lire

# inspiration: texconfig,  configure-ntp, gpmconfig, paperconfig

# Build some functions, inspect what it looks like here

# build a portable echo
case `echo "testing\c"`,`echo -n testing` in
    *c*,-n*) echo_n=
	     # there's a literal newline here
             echo_c='
'
             ;;
    *c*,*)   echo_n=-n
             echo_c=
             ;;
    *)       echo_n=
             echo_c='\c'
             ;;
esac
# Any echo command after the shell fragment above, which shouldn't move the
# cursor to a new line, can now be written like so: 
# echo $echo_n "prompt:$echo_c"

echon () {
    echo $echo_n "$1$echo_c"
}

#
# ask_yn - Get an answer on a boolean question, set a to yes or no
# 
# ask_yn question default
#
ask_yn () {
    case "$2" in 
	yes)
	    def="[Yes/no]"
	    ;;
	no)
	    def="[yes/No]"
	    ;;
	*)
	    echo "PANIC: bug in script! (ask_yn called with arg '$2', should be 'yes' or 'no'). Please submit a bug to bugs@logreport.org. Thank you."
	    exit 1
	    ;;
    esac

    while true
    do
	echon "$1 $def "
    	read a
    	case "$a" in
    	    y*|Y*) 
    		a=yes
		break
    		;;
    	    n*|N*) 
    		a=no
		break
    		;;
	    '')
		a="$2"
		break
		;;
    	    *)
    		echo "Please enter yes, no or enter"
    		;;
	esac
    done
}

ask_string () {
    echon "$1 [$2] "
    read a
    test -n "$a" || a="$2"
}

prefix="/usr/local"
exec_prefix="${prefix}"
libdir="${exec_prefix}/libexec/lire"

#
# set to yes to debug
#
# debug=yes
debug=no

KEEP_default=
LR_SPOOLINTERVAL=300
LR_SPOOLINTERVAL_default=10

# call it LR_TMPDIR for now.  TMPDIR interferes with some sh's way
#  to create here documents.  This variable will be used as TMPDIR
#  in the to be created config files.
LR_TMPDIR="$HOME/tmp"

TMPDIR_default="/usr/local/tmp"
LR_DISCLAIMERFILE="${prefix}/etc/lire/disclaimer"
DISCLAIMERFILE_default="${prefix}/etc/lire/disclaimer.local"
LR_LOGGING=stderr
LOGGING_default=syslog
DEBUG_default=
DEFAULT_OUTPUT_FORMAT_default="txt"
LR_IMAGE_FORMAT_default="png"
LR_SCALE_NUMBER_default="no"
LR_SCALE_SEC_default="yes"
LR_SCALE_BYTES_default="yes"
LR_TARGET_USER_default="sysadmin"
LR_USERLEVEL_default="advanced"
LR_WEEK_STARTS_ON_default="sun"
FROM_default="LogReport Responder <log@logreport.org>"

# when reimplenting this script, be sure to use Lire::Config to build
# these lists

# get from lr_check_service -l
superservices="database dialup dns dnszone email firewall ftp msgstore print proxy syslog www"
services_database="mysql"
services_dns="bind8_query bind9_query"
services_dnszone="bind8_named"
services_email="argomail exim postfix qmail sendmail nms"
services_msgstore="nmsmmp nmsstore"
services_www="common combined referer modgzip w3c_extended"
services_ftp="xferlog iis_ftp"
services_firewall="cisco_ios ipchains ipfilter iptables pix welf"
services_print="cups_pagelog lprng_account"
services_proxy="ms_isa squid_access welf_proxy"
services_syslog="syslog"

to_default_all_all="postmaster"
subject_default_all_all="\`hostname\` \`date +%Y%m%d\`"

log_default_database_mysql_1="/var/log/mysql.log.0"

log_default_dns_bind8_query_1="/var/log/named_querylog.0"
log_default_dns_bind9_query_1="/var/log/named_querylog.0"

log_default_dnszone_bind8_named_1="/var/log/named.log.0"

log_default_email_exim_1="/var/log/exim/mainlog.0"
log_default_email_postfix_1="/var/log/mail.log.0"
log_default_email_qmail_1="/service/qmail-send/log/main/current"
log_default_email_sendmail_1="/var/log/mail.log.0"
log_default_email_nms_1="/var/log/mail.log.0"

log_default_www_combined_1="/var/log/apache/combined.log.0"
log_default_www_common_1="/var/log/apache/common.log.0"
log_default_www_referer_1="/var/log/apache/referer.log.0"
log_default_www_modgzip_1="/var/log/apache/gzip.0"

log_default_ftp_xferlog_1="/var/log/xferlog.0"

log_default_firewall_cisco_ios_1="/var/log/messages.0"
log_default_firewall_ipchains_1="/var/log/messages.0"
log_default_firewall_ipfilter_1="/var/log/ipflog.0.gz"
log_default_firewall_iptables_1="/var/log/messages.0"
log_default_firewall_pix_1="/var/log/messages.0"
log_default_firewall_welf_1="/var/log/messages.0"

log_default_print_cups_pagelog_1="/var/log/cups/page_log"
log_default_print_lprgn_account_1="/var/log/lp-acct"

log_default_proxy_welf_proxy_1="/var/log/messages.0"
log_default_proxy_squid_1="/var/log/squid/access.log.0"

#  cat `ls /var/log/qmail/qmail-send/@* | tail -1` | tai64nfrac

# filter could be gzip -dc 

filter_default_dns_bind8_query="cat"
filter_default_dns_bind9_query="cat"

filter_default_dnszone_bind8_named="cat"

filter_default_email_exim="cat"
filter_default_email_postfix="grep 'postfix/'"
filter_default_email_qmail="tai64nfrac"
filter_default_email_sendmail="grep 'sendmail\['"
filter_default_email_nms="grep 'smtpd\['"

filter_default_www_common="cat"
filter_default_www_combined="cat"
filter_default_www_referer="cat"
filter_default_www_modgzip="cat"

filter_default_ftp_xferlog="cat"

filter_default_firewall_cisco_ios="cat"
filter_default_firewall_ipchains="grep 'Packet log: '"
filter_default_firewall_ipfilter="gzip -dc"
filter_default_firewall_iptables="grep 'kernel:.*IN='"
filter_default_firewall_pix="cat"
filter_default_firewall_welf="grep 'id=firewall'"

filter_default_print_cups_pagelog="cat"
filter_default_print_lprgn_account="cat"

filter_default_proxy_squid="cat"
filter_default_proxy_welf_proxy="grep 'id=firewall'"

defaultsfile="${prefix}/etc/lire/defaults"

# Environment tests

if test -x /usr/xpg4/bin/id
then
    # solaris' /usr/bin/id doesn't grok -u
    # don't you just love it...
    runid=/usr/xpg4/bin/id
else
    runid=id
fi

id=`$runid -u`
test "$id" = 0 && {
    echo "Error: don't run me as root, but as the user who's supposed to run the Lire scripts"
    exit 1
}

localcfgdir=""
testfile="${prefix}/etc/lire/foo.local"
if touch $testfile 2>/dev/null
then
    localcfgdir="${prefix}/etc/lire"
    localfile="${prefix}/etc/lire/defaults.local"
    LR_ARCHIVEDIR_default="${prefix}/var/lib/lire/data"
    rm $testfile
else
    localcfgdir="$HOME/.lire/etc"
    localfile="$HOME/.lire/etc/defaults"
    LR_ARCHIVEDIR_default="$HOME/.lire/data"
    # To fix the warning even if the user answers no to the
    # LR_ARCHIVE question.
    use_LR_ARCHIVEDIR="yes"
    LR_ARCHIVEDIR="$HOME/.lire/data"
    if ! test -d $HOME/.lire
    then
	echo "Creating $HOME/.lire directory"
	if ! mkdir $HOME/.lire 
	then
	    echo "Error: you can't create directories in your HOME directory"
	    echo "($HOME)! Please fix this before running this script again."
	    exit 1
	fi
	if ! test -d $HOME/.lire/etc
	then
	    echo "Creating $HOME/.lire/etc directory"
	    mkdir $HOME/.lire/etc || exit 1
	fi
    fi
    testfile="$localcfgdir/foo"
    if touch "$testfile" 2>/dev/null
    then
	rm $testfile
    else
	echo "Error: you can't create files in you $HOME/ directory."
        echo "  Please fix this before running this script again."
	exit 1
    fi
fi


# General introduction

cat <<EOT
This script enables you to configure your installation of LogReport's Lire 
(see http://www.logreport.org/).  Lire converts various services' log files
to human readable reports.  First I'll ask you some questions about
the systems preferred general setup, later I'll ask you about preferences
for specific services.  I'll create local configuration files 
under $localcfgdir, and 
save the answers in these files.  These files are shellscripts; if needed,
you can give shellcode as answer to questions.

This script can be used by any user to set his or her preferences
regarding Lire. It can also be used by the Lire's administrator to set
site wide defaults for the Lire installation.

Pressing enter as answer will select the default, which is displayed in
[these brackets].  When [Yes/no] is displayed, the default is yes.  
Pressing just n<enter> will select no.

You can abort this script at any time by pressing ^C .

I assume your terminal's size is 80 x 24 (or bigger).  You might like to pipe
this script's output to

  tee /tmp/lr_config.log

, or run it under script(1).  (Restart this script now if needed.)

EOT

# '

echon "[press enter to continue] "
read foo

if test -f $localfile
then
    cat <<EOT
There are local Lire configuration files on this system.  This probably means 
your Lire system is already configured.  
Move the file $localfile
out of the way if you want to reconfigure your system using this script.
EOT
    exit 0
fi

# Build a list of available format
formats="txt docbookx html html_page xhtml xhtml_page pdf rtf logml excel95"
avail_fmt=""
for i in $formats
do
    if $libdir/lr_check_prereq $i 2> /dev/null
    then
	avail_fmt="$avail_fmt $i"
    fi
done
ask_string "Lire can generate reports in several format: 
    $avail_fmt
  (those are the ones available on your system). In which format do you want
  to generate reports by default?" $DEFAULT_OUTPUT_FORMAT_default
if echo " $avail_fmt " | grep " $a " > /dev/null 2> /dev/null
then
    use_LR_DEFAULT_OUTPUT_FORMAT=yes
    LR_DEFAULT_OUTPUT_FORMAT="$a"
else
    echo "$a isn't an available format. Will use $DEFAULT_OUTPUT_FORMAT_default."
fi

ask_yn "Lire can scale bytes in reports to a more human readable form
 (22.1M, 10k, etc.).  Do you want bytes fields to be scaled?" $LR_SCALE_BYTES_default
use_LR_SCALE_BYTES=yes
if test "$a" = yes
then
    LR_SCALE_BYTES=1
else
    LR_SCALE_BYTES=0
fi

ask_yn "Lire can scale seconds in reports to a more human readable form
 (1.1d, 5h, 30s, etc.).  Do you want duration fields to be scaled?" $LR_SCALE_SEC_default
use_LR_SCALE_SEC=yes
if test "$a" = yes
then
    LR_SCALE_SEC=1
else
    LR_SCALE_SEC=0
fi


ask_yn "Lire can scale numbers in reports to a more human readable form
 (5M, 3.1k, etc.).  Do you want numeric fields to be scaled?" $LR_SCALE_NUMBER_default
use_LR_SCALE_NUMBER=yes
if test "$a" = yes
then
    LR_SCALE_NUMBER=1
else
    LR_SCALE_NUMBER=0
fi

ask_string "Lire can tune its report's descriptions according to the
  report's reader profile. Currently, there are descriptions tailored for
  sysadmin or manager types of user. For which kind of users are the reports
  intended ?" $LR_TARGET_USER_default
case "$a" in 
    sysadmin|manager)
	use_LR_TARGET_USER=yes
	LR_TARGET_USER="$a"
	;;
    *)
	echo "$a isn't a valid target user. Will use $LR_TARGET_USER_default."
	;;
esac

ask_string "Lire can tune the details in its report's descriptions according
  to the reader's profile. Two level of details are supported : 
  normal or advanced. Which level to you want ?" $LR_USERLEVEL_default
case "$a" in 
    normal|advanced)
	use_LR_USERLEVEL=yes
	LR_USERLEVEL="$a"
	;;
    *)
	echo "$a isn't a valid user level. Will use $LR_USERLEVEL_default."
	;;
esac

ask_string "On which day does the week starts? Monday (mon) and Sunday (sun) 
are supported as starting week day." $LR_WEEK_STARTS_ON_default
case "$a" in 
    sun|mon)
	use_LR_WEEK_STARTS_ON=yes
	LR_WEEK_STARTS_ON="$a"
	;;
    *)
	echo "$a isn't a value. Will use $LR_WEEK_STARTS_ON_default."
	;;
esac

#   Only offer LR_INCLUDEIMAGES if GD::Graph is available
if /usr/bin/perl -MGD::Graph -e 'exit 0' 2>/dev/null
then
    ask_yn "Lire can generate charts for some reports. Do you want charts 
  to be generated whenever possible ?" yes
    if test "$a" = yes
    then
	use_LR_INCLUDEIMAGES=yes
	LR_INCLUDEIMAGES=1
    fi

    formats="png gif jpeg"
    avail_fmt=""
    for i in $formats
    do
	if /usr/bin/perl -MGD::Graph -e 'exit 0 if grep { lc $_ eq "'$i'"} GD::Graph->export_format(); exit 1'
	then
	    avail_fmt="$avail_fmt $i"
	fi
    done
    ask_string "Lire can generate charts in several format: 
    $avail_fmt
  (those are the ones available on your system). In which format do you want
  to generate charts by default?" $LR_IMAGE_FORMAT_default
    if echo " $avail_fmt " | grep " $a " > /dev/null 2> /dev/null
    then
	use_LR_IMAGE_FORMAT=yes
	LR_IMAGE_FORMAT="$a"
    else
	echo "$a isn't an available format. Will use $LR_IMAGE_FORMAT_default."
    fi
fi


ask_yn "Lire can keep in an archive reports you generated in their XML 
  intermediary format. This can be useful for eventual merging of reports.
  Do you want to enable archiving?" no
if test "$a" = yes
then
    use_LR_ARCHIVE=yes
    LR_ARCHIVE=1

    ask_yn "By default, archives are stored in 
    $LR_ARCHIVEDIR_default 
  (If needed, this directory is created on the fly.)  Do you want to 
  change this?" no
    if test "$a" = yes
    then
	use_LR_ARCHIVEDIR=yes
	ask_string "Where should archives get stored?" $LR_ARCHIVEDIR_default
	LR_ARCHIVEDIR="$a"
    fi
fi


ask_yn "Temporary files are by default not kept.  Do you want to keep these
  files (e.g. for debugging purposes)?" no
if test "$a" = yes
then
    use_LR_KEEP=yes
    LR_KEEP=1
fi

ask_yn "Are you planning to run an online responder? (you need to manually tune
  your system to support this)" no
if test "$a" = yes
then
    ask_yn "By default, the system waits $LR_SPOOLINTERVAL seconds between 
  consecutive spoolruns.  Do you want to change this?" no
    if test "$a" = yes
    then
	use_LR_SPOOLINTERVAL=yes
	ask_string "How many seconds should the system wait between 
  consecutive spoolruns?" $LR_SPOOLINTERVAL_default
	LR_SPOOLINTERVAL="$a"
    fi

    ask_yn "Would you like to overwrite the from address as constructed
  by your MTA? (Say no if you don't know what this means.)" no
    if test "$a" = yes
    then
	ask_string "What from-address would you like to use?" "$FROM_default"
	use_LR_FROM=yes
	LR_FROM="$a"
    fi
fi

ask_yn "By default, temporary files are stored in $LR_TMPDIR. (If 
  needed, this directory is created on the fly.)  This directory MUST NOT
  be located on a NFS mount. Do you want to change it?" no
if test "$a" = yes
then
    use_TMPDIR=yes
    ask_string "Where should temporary files get stored?" $TMPDIR_default
    LR_TMPDIR="$a"
fi

ask_yn "Do you want to sent a disclaimer with the generated reports? (In 
  case you're automatically sending generated reports by email.)" no
if test "$a" = yes
then
    use_LR_DISCLAIMERFILE=yes
    ask_string "Where is the file containing the disclamer stored?" $DISCLAIMERFILE_default
    LR_DISCLAIMERFILE="$a"
fi

ask_yn "By default, status and errormessages are sent to $LR_LOGGING.  Do you 
  want to change this to $LOGGING_default? (You need syslog's logger(1) 
  for this.)" no
if test "$a" = yes
then
    use_LR_LOGGING=yes
    LR_LOGGING=$LOGGING_default
fi

ask_yn "By default, informative and debug messages are suppressed.  Do you want
  to run the system in debug mode?  (The amount of debug messages is quite 
  impressive.)" no
if test "$a" = yes
then
    use_LR_DEBUG=yes
    LR_DEBUG=1
fi

cat <<EOT

We're done now with the general questions.  We've reached the final part: I'll 
ask you questions about the way various services' log files will get processed.
The services are categorised in 'superservices'.  The superservices and their 
services are:
EOT

# '

for superservice in $superservices
do
    eval services=\$services_$superservice
    echo "for superservice $superservice, services are"
    for service in $services
    do
        echo "  $service"
    done
    echo
done

echon "[press enter to continue] "
read foo

cat <<EOT
For each service, log files can get processed by a cronjob.  Such a cronjob
converts a log file to a report, and sends the report to some emailaddress.
I'm gonna build these cronjobs.  (Don't worry, I'm not gonna activate them. 
I'll tell you how to do that yourself later.)  Therefore, I need to know 
which services you're running, and I need to know the names of the log files.
EOT

# work around vim syntax highligting bug :-/
# '

deffile="$localcfgdir/cron.defaults.local"
if test -f $deffile
then
    echo "Global defaults file $deffile already exists, not regenerating"
else
    # Global defaults file
    ask_yn "Do you want to use some default settings for all services, like 
  the email address to send the report to?" yes
    if test "$a" = yes
    then
    	use_all=yes
    	use_all_all=yes

    	ask_yn "Would you like to use a default to-address?" yes
    	if test "$a" = yes
    	then
    	    ask_string "Please enter your default to-address." \
		"$to_default_all_all"
    	    to_all_all="$a"
    	fi

    	ask_yn "Would you like to use a default subject stem for the generated 
  email? (A string like '[LogReport] www / apache report' will get added
  to this stem.)" yes
    	if test "$a" = yes
    	then
    	    ask_string "Please enter your default subject." \
		"$subject_default_all_all"
    	    subject_all_all="$a"
    	fi

    fi
fi

for superservice in $superservices
do
    eval services=\$services_$superservice
    ask_yn "Are you collecting $superservice log files on this host ($services)
  which you'd like to get processed?" "no"
    if test "$a" = yes
    then
    	eval use_$superservice=yes
    	# build <superservice>/defaults.local

    	for service in $services
    	do

    	    f="$localcfgdir/$superservice.$period.$service"
    	    test -f $f && {
    		echo "Info: File $f already exists,"
		echo "  skipping service $service"
    		continue
    	    }

    	    ask_yn "Are you collecting $service log files on this host 
  which you'd like to get processed?" "no"
	    test "$a" = yes || continue

	    for period in weekly daily
	    do
		eval nof_${superservice}_${service}_$period=0
		ask_yn "Are any of your $service log files rotated $period?" no
		test "$a" = yes || continue
		more=yes
		i=0
		while test $more = yes
		do
		    i=`expr $i + 1`
		    eval log_default=\$log_default_${superservice}_${service}_$i
		    while true 
		    do
			ask_string "Where is your $period rotated $service log file?" \
			    "$log_default"
			test -r "$a" && break
			echo "Error: Log file '$a' is unreadable."
			echo "  Fix permissions or filename."
		    done
		    eval log_${superservice}_${service}_${period}_$i="\"$a\""

		    eval filter_default=\$filter_default_${superservice}_$service
		    ask_string "Which filter would you like to run on this log?" \
			"$filter_default"
		    if echo $a | grep "\\|\'"
		    then
			# use eval here: it's the only way to get quoting
			# doing what it's supposed to do.
			# FIXME: will all of this will bomb if the use enter 
			# quotes "" ?
			eval filter_${superservice}_${service}_${period}_$i="\"eval $a\""
		    else
			eval filter_${superservice}_${service}_${period}_$i="\"$a\""
		    fi

		    a=no
		    if test -n "$to_all_all"
		    then
			ask_yn "Would you like to overwrite the to-address 
  '$to_all_all' for this log file's report?" no
		    else
			a=yes
		    fi

		    if test "$a" = yes
		    then
			# get a to-adress
    			ask_string "To which address should this log files's \
report get sent?" "$to_default_all_all"
			eval to_${superservice}_${service}_${period}_$i="\"$a\""
		    fi

		    a=no
		    if test -n "$subject_all_all"
		    then
			ask_yn "Would you like to overwrite the subject 
  '$subject_all_all' for this log file's report?" no
		    else
			a=yes
		    fi

		    if test "$a" = yes
		    then
			ask_string "Which subject would you like to use for \
the email containing 
  this log file's report?" "$subject_default_all_all"
			eval subject_${superservice}_${service}_${period}_$i="\"\$a\""
		    fi

		    ask_yn "Would you like to process another $period rotated $service log file?" "no"
		    more=$a
		done
		eval nof_${superservice}_${service}_${period}=$i
	    done
	done
    fi
done

test $debug = yes && { 
    echo DEBUG START
    set | grep use_
    set | grep nof_
    set | grep log_
    set | grep filter_
    echo DEBUG END
}



touch $localfile || {
    echo "Error: Cannot create file '$localfile'.  Check if directory exists, and check permissions." &&
    exit 1
}

cat > $localfile <<EOT
# $localfile - local settings for Lire 
#   system on `hostname`
# to be sourced by $defaultsfile
# automatically generated by lr_config(1) on `date`

EOT

if test "$use_TMPDIR" = yes
then
    echo "TMPDIR=$LR_TMPDIR" >> $localfile
fi

# cannot get LR_TMPDIR in this loop, since what we call LR_TMPDIR gets
# called TMPDIR in $localfile
for gen in LR_KEEP LR_SPOOLINTERVAL LR_FROM LR_DISCLAIMERFILE LR_LOGGING LR_DEBUG LR_DEFAULT_OUTPUT_FORMAT LR_TARGET_USER LR_USERLEVEL LR_WEEK_STARTS_ON LR_INCLUDEIMAGES LR_SCALE_BYTES LR_SCALE_NUMBER LR_SCALE_SEC LR_ARCHIVE LR_ARCHIVEDIR LR_IMAGE_FORMAT
do
    eval use=\$use_$gen
    test "$use" = yes || continue
    eval val=\${$gen}
    echo "$gen=$val" >> $localfile
done

#
# go writing collected data
#
if test "$use_all_all" = yes
then
    touch $deffile || {
	echo "Error: Cannot create file '$deffile'.  Check if directory exists, and check permissions." && 
	exit 1
    }

    test -n "$subject_all_all" && echo "test -z \"\$subject\" && subject=\"$subject_all_all\"" >> $deffile
    test -n "$to_all_all" && echo "test -z \"\$to\" && to=\"$to_all_all\"" >> $deffile

    echo "Wrote file '$deffile'."
fi

for superservice in $superservices
do
    eval use=\$use_$superservice

    test "$use" = yes || continue

    eval services=\$services_$superservice
    for service in $services
    do
	for period in weekly daily
	do
    	    eval nof=\$nof_${superservice}_${service}_$period
	    test -z "$nof" && continue
    	    test "$nof" = 0 && continue

	    i=0
	    while test $i -lt $nof
	    do
		i=`expr $i + 1`
	       	f="$localcfgdir/${superservice}.${period}.${service}.${i}.local"

	      	touch $f || { 
	    	    echo "Error: Cannot create $f.  Check if directory exists, and check permissions." &&
	    	    exit 1
	       	}

	      	echo "# $f - $superservice $service $period" > $f
	        echo "#   cron config file" >> $f
	    	echo "# to be sourced by lr_cron(1)" >> $f
	       	echo "# automatically generated by lr_config(1) on `date`" >> $f

	       	eval log="\$log_${superservice}_${service}_${period}_$i"
	      	eval filter="\"\$filter_${superservice}_${service}_${period}_$i\""
	     	eval subject="\"\$subject_${superservice}_${service}_${period}_$i\""
	       	eval to="\"\$to_${superservice}_${service}_${period}_$i\""

		cat >> $f <<EOT
superservice="$superservice"
service="$service"
log="$log"
filter="$filter"
subject="$subject"
to="$to"

# Load common settings
if test -r $deffile
then
    . $deffile
fi

EOT

		echo "Wrote file '$f'."
		# $localfile
		eval lr_jobfiles_$period="\"\$lr_jobfiles_$period $f\""
	    done
	done
    done
done

for period in weekly daily
do
    eval lr_jobfiles=\$lr_jobfiles_$period
    echo "lr_jobfiles_$period=\"$lr_jobfiles\"" >> $localfile
done

echo "Wrote file '$localfile'."

echo
echon "[press enter to continue] "
read foo

exec_prefix=${prefix}

cat <<EOT

Congratulations, your Lire system is configured!  To activate the system,
run

{ echo '0 10 * * * ${exec_prefix}/bin/lr_cron daily'; echo '0 10 * * 0 ${exec_prefix}/bin/lr_cron weekly'; } | crontab -

(that's one line).  (I assume your crontab was empty untill now.)  Once
activated like this, report(s) will be sent on a weekly and/or daily basis.
You can finetune your configuration, by editing the files I just wrote.  Refer
to the Lire User Manual in user-manual.txt for information on syntax and
such,  and for hints on how to set a whole bunch of report-specific parameters.

Have fun!

                                The LogReport team <logreport@logreport.org>

EOT


