#### This is the default appNG installation script.

# Execute in WEB-INF/bin: appng batch -f install.list
# The installer uses the database configuration settings (root connection) in appNG.properties.
# Please make sure that the database exists and the APPNG_HOME environment variable is set.

# Some variable declarations
def INSTALL_OPTS=-f
def MANAGER_VERSION=1.20.0
def AUTH_VERSION=1.13.2
def SCHEDULER_VERSION=1.16.2
def TEMPLATE_VERSION=1.14.4
def TEMPLATE_NAME=appng-template

def ADMIN_SUBJECT=admin
def ADMIN_GROUP=Administrators
def MANAGER_SITE=manager

def MANAGER_APP=appng-manager
def AUTH_APP=appng-authentication
def SCHEDULER_APP=appng-scheduler

def REPO_PATH=https://appng.org/service/manager/appng-manager/soap/repositoryService
def REPO_NAME=appng.org Stable
def REPO_REMOTE_NAME=appNG-Stable

# Initialize database. The database will be managed by appNG.
-initdatabase -m

# Create admin user. The admin group "Administrators" is created by appNG on database schema creation
create-subject -u ${ADMIN_SUBJECT} -p "@ppNG$42" -n "appNG Administrator" -l en -e admin@example.com
list-subjects -v

# add admin user to admin group
add-group -u ${ADMIN_SUBJECT} -g ${ADMIN_GROUP}

# create repositories
create-repository -n ${REPO_NAME} -u ${REPO_PATH} -t REMOTE -r ${REPO_REMOTE_NAME}
list-repositories -v

# create manager site
create-site -n ${MANAGER_SITE} -h localhost -d http://localhost:8080 -e
list-sites -v

# install core applications
install-application -n ${MANAGER_APP} -v ${MANAGER_VERSION} -r ${REPO_NAME} -p ${INSTALL_OPTS}
install-application -n ${AUTH_APP} -v ${AUTH_VERSION} -r ${REPO_NAME} -p -h ${INSTALL_OPTS}
install-application -n ${SCHEDULER_APP} -v ${SCHEDULER_VERSION} -r ${REPO_NAME} -p ${INSTALL_OPTS}
list-applications -v

# activate privileged applications
activate-application -s ${MANAGER_SITE} -a ${MANAGER_APP}
activate-application -s ${MANAGER_SITE} -a ${AUTH_APP}
activate-application -s ${MANAGER_SITE} -a ${SCHEDULER_APP}
list-roles -v

# Install default appNG template
install-template -n ${TEMPLATE_NAME} -v ${TEMPLATE_VERSION} -r ${REPO_NAME}

# Enable development mode
update-property -n platform.devMode -v true
