isdn4k-utils/isdnlog/install/genconf

97 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
## $Id: genconf,v 1.3 1997/04/15 22:37:05 luethje Exp $
##
## ISDN accounting for isdn4linux.
##
## Copyright 1997 by Stefan Luethje (luethje@sl-gw.lake.de)
##
## 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, 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.
##
## $Log: genconf,v $
## Revision 1.3 1997/04/15 22:37:05 luethje
## allows the character `"' in the program argument like the shell.
## some bugfixes.
##
## Revision 1.2 1997/04/08 21:20:02 luethje
## primitive changes
##
## Revision 1.1 1997/04/08 21:18:50 luethje
## File to generate the config file `isdn.conf'
##
CONFFILE=$1
RESFILE=/tmp/`basename $0`.res.$$
setentry() {
SECTION=$1
ENTRY=$2
VALUE=$3
AWKFILE=/tmp/`basename $0`.$$
grep $ENTRY $CONFFILE >/dev/null 2>&1
if [ $? -eq 1 ]
then
cat >$AWKFILE << EOF
{
if (\$0 == "$SECTION")
printf ( "%s\n%s\t= %s\n", \$0, "$ENTRY", "$VALUE" )
else
print
}
EOF
awk -f $AWKFILE $CONFFILE >$RESFILE
cp $RESFILE $CONFFILE
fi
rm -f $AWKFILE $RESFILE
}
if [ ! -f $CONFFILE ]
then
echo -n "Creating config file \"$CONFFILE\"..."
cat >$CONFFILE << EOF
############################################################################
#
# File $CONFFILE generated by `basename $0` on `date`
#
############################################################################
[GLOBAL]
[VARIABLES]
[ISDNLOG]
EOF
else
echo -n "Adding some entries to the config file \"$CONFFILE\"..."
fi
setentry "[GLOBAL]" "AREACODE" "$AREACODE"
setentry "[GLOBAL]" "AREAPREFIX" "$AREAPREFIX"
setentry "[GLOBAL]" "COUNTRYCODE" "$COUNTRYCODE"
setentry "[GLOBAL]" "COUNTRYPREFIX" "$COUNTRYPREFIX"
setentry "[ISDNLOG]" "CHARGEMAX" "$CHARGEMAX"
setentry "[ISDNLOG]" "OLABEL" "$OLABEL"
setentry "[ISDNLOG]" "ILABEL" "$ILABEL"
setentry "[ISDNLOG]" "LOGFILE" "$LOGFILE"
sed -e "s/\([^\]\)\$\([0-9][ ]\)/\1\\\\$\2/g" $CONFFILE >$RESFILE
cp $RESFILE $CONFFILE
rm -f $RESFILE
echo " Ready."