#!/bin/sh -e

action="$1"
oldversion="$2"

if ! id grapevine > /dev/null 2>&1 ; then
  adduser --quiet --system --no-create-home --home /var/state/grapevine grapevine
fi

chown grapevine /var/state/grapevine

if [ ! -e /etc/grapevine-config.xml ] ; then
  cp /usr/share/grapevine/grapevine-config.xml.template /etc/grapevine-config.xml
fi

more /usr/share/doc/grapevine/WARNING
echo -n "> "
read answer

if [[ "$answer" = "yes" ]] ; then

    if [ -e /etc/init.d/grapevine ] ; then
      update-rc.d grapevine defaults >/dev/null
      /etc/init.d/grapevine restart
    fi

    exit 0

else
    echo '** You have chosen not to install Grapevine.'
    exit 1
fi
