#!/usr/bin/env sh

if ! [ -e settings ]; then OUTFILE="settings"; else OUTFILE="settings.new"; fi

cat > $OUTFILE << EOF
# SHORT DESCRIPTION
#
#
# first of all you have to configure the pathes to the dnet logfiles
#
# Example:
#
# LOGPATH=/var/log/rc5
# LOGNAME_RC5=pproxyrc5
# LOGNAME_DES=pproxydes
# LOGNAME_CSC=pproxycsc
# LOGNAME_OGR=pproxyogr
#
EOF

if [ "$OUTFILE" = "settings.new" ]; then
  cat settings | grep "^LOG.*=" >> $OUTFILE
else
  cat >> $OUTFILE <<EOF
LOGPATH=/var/log/rc5
LOGNAME_RC5=pproxyrc5
LOGNAME_DES=pproxydes
LOGNAME_CSC=pproxycsc
LOGNAME_OGR=pproxyogr
EOF
  fi

cat >> $OUTFILE <<EOF

# Then you may define one or more networks or hosts to be shown separately
#
#
# NETWORK=<name>:<network1>,<network2>, ...
#
# each network may be a single host or a network
# each network has to be terminated by a dot.
#
# ATTENTION! with "network" i mean a network-address
# with the last part cleared out ... well let me give you a hint:
# 192.168.1.    would be 192.168.1.0/24
# 192.168.      would be 192.168.0.0/16
#
# sorry, but my module does not yet understand netmasks :(
# but i intend to edit the whole thing some day when time is my friend again...
#
# Example:
#
# NETWORK=other:*
# NETWORK=unknown_local:192.168.1.
# NETWORK=host1:192.168.1.1.
# NETWORK=host2:192.168.1.20.
# NETWORK=some_hosts:192.168.1.30.,192.168.1.31.,192.168.1.32.
#
EOF

if [ "$OUTFILE" = "settings.new" ]; then
  cat settings | grep "^NETWORK=" >> $OUTFILE
  echo >> $OUTFILE
else
  cat >> $OUTFILE <<EOF
NETWORK=other:*
NETWORK=local:192.168.1.

EOF
  fi

echo
echo "Please check the settings file and adapt it to satisfy your needs."
if [ "$OUTFILE" = "settings.new" ]; then
  mkdir -p backup
  NOW=`date +%Y%m%d-%H%M%S`
  mv -f settings backup/settings-$NOW
  mv -f settings.new settings
  echo "a backup of the previous settings has been saved."
  fi
echo

