#!/bin/bash
# Copyright ITIS AG, 2025
# Setting up two databases for container
#
ADMIN_PW=$(cat /etc/itiseasybusiness/openerp-server.conf | grep admin_passwd | cut -f2 -d"=" | tr -d ' ')
#
echo "Setting up the Demo Database for ITIS easy business"

# Create Test and Live DB using DB create command 
# PW: admin: admin

echo "Creating up the Test Database for ITIS easy business"

# Test DB
curl -X POST -F "master_pwd=$ADMIN_PW" -F 'name=ITISeasybusiness_TEST' -F 'login=admin' -F 'password=admin' -F 'lang=de_DE' -F 'country_code=de' -F 'phone=90690' -F 'demo=1'  http://127.0.0.1:8069/web/database/create

# Init DB
curl  http://127.0.0.1:8069/web?db=ITISeasybusiness_TEST
sleep 1 

echo "Creating up the Live Database for ITIS easy business"
# Live DB
curl -X POST -F "master_pwd=$ADMIN_PW" -F 'name=ITISeasybusiness_LIVE' -F 'login=admin' -F 'password=admin' -F 'lang=de_DE' -F 'country_code=de' -F 'phone=90690'  http://127.0.0.1:8069/web/database/create

# Init DB
curl  http://127.0.0.1:8069/web?db=ITISeasybusiness_LIVE
sleep 1
 
# configuring LDAP for all databases
# run python script on ct
python3 /DB_Templates/configure_ldap.py

exit 0;