#!/bin/sh

check_lurker() {
	conf="/etc/lurker/lurker.conf.mm"
	if [ -w $conf ]; then
	  if ! grep -q "list[[:space:]]*=[[:space:]]*$list" /etc/lurker/lurker.conf*; then
	    listhost=`grep "^#[[:space:]]*listhost" $conf | awk -F "=[[:space:]]*" {'print $2'}`
	    listurl=`grep "^#[[:space:]]*listurl" $conf | awk -F "=[[:space:]]*" {'print $2'}`
	    [ -e $listhost ] && listhost="lists.not-configured.yet"
	    [ -e $listurl ] && listurl="http://lists.not-configured.yet/path/to"
	    cat >> /etc/lurker/lurker.conf.mm <<EOF

  list = $list
        title       = $list
	link        = $listurl/$list
	address     = $list@$listhost
  	description = $list (no description added yet)
EOF
	  fi
	else
	  echo "Lurker Mailman Wrapper: No possibility to archive this unconfigured list!" && exit 1
	fi
}

for i in $*; do
  if [ "$next" == "list" ]; then
    next=""
    list=`echo $i | tr "[:upper:]" "[:lower:]"`
    check_lurker;
  elif [ "$i" == "-l" ]; then
    next="list"
  else
    args="$args $i"
  fi
done
exec /usr/bin/lurker-index -l $list $args
