#!/bin/sh
set -e

case "$1" in
  abort-upgrade|abort-remove|abort-deconfigure)
    ;;

  configure)
    mandb
    [ ! -x /usr/bin/docker.io ] || ln -sf /usr/bin/docker.io /usr/local/bin/docker
    modprobe aufs || echo "WARNING: Restart server to finish installing dokku!"
    sshcommand create dokku /usr/local/bin/dokku
    egrep -i "^docker" /etc/group || groupadd docker
    usermod -aG docker dokku
    dokku plugins-install
    rm -f /home/dokku/VERSION
    cp /var/lib/dokku/STABLE_VERSION /home/dokku/VERSION

    if [ -f /etc/init/dokku-installer.conf ] && service dokku-installer status 2> /dev/null | grep waiting; then
        sudo service dokku-installer start
    fi
    ;;

  *)
    echo "postinst called with unknown argument \`$1'" >&2
    exit 1
    ;;
esac

exit 0
