#!/bin/sh
set -e
. /usr/share/debconf/confmodule
db_capb backup

CONFIGFILE="/etc/debian-devel-changes-bot.config"
if [ -e $CONFIGFILE ]
then
  . $CONFIGFILE || true

  db_set BTS/nickserv-password "$NICKSERV_PASSWORD"
  db_set BTS/admin-user "$ADMIN_USER"
  db_set BTS/admin-password "$ADMIN_PASSWORD"
fi

# Ask questions
STATE=1
while true
do
  case "$STATE" in
  1)
    db_input medium BTS/nickserv-password || true
    db_input medium BTS/admin-user || true
    ;;
  2)
    db_get BTS/admin-user
    if  [ -n "$RET" ]
    then
      db_input medium BTS/admin-password || true
    fi
    ;;
  *)
    break
  esac

  if db_go; then
    STATE=$(($STATE + 1))
  else
    STATE=$(($STATE - 1))
  fi
done

if [ $STATE -eq 0 ]; then
  exit 10
fi
