#!/bin/bash -x
#
# Uninstalls app
# This will completely remove database and files
. /etc/federated
. /federated/lib/functions.sh
trap cleanup `seq 1 15`

usage() {
cat << EOF
UnInstall application
Usage: $0 appname
Arguments:
    appname         Application to remove. bookstack,espocrm,freescout,etc
                    This will completely remove database and files

EOF
exit 2;
}

[ $# != 1 ] && usage
APP=$1

[ ! -f /federated/lib/$APP.sh ] && failcheck "/federated/lib/$APP.sh doesn't exist."
[ ! -d /federated/apps/$APP ] && failcheck "/federated/apps/$APP doesn't exist. $APP is already uninstalled?"
. /federated/lib/$APP.sh
. /federated/apps/$APP/.env
uninstall_$APP
