#!/bin/bash

# Run as root, since many things depend on root privileges:
#   deluser
#   delgroup
#   rm -fr
#   cp ...conf/
#   doloforge config --update
# usage:
#   sudo perl ./src/doloforge --config ./t/doloforge.yaml project --client jim --name clicodrome --update

DOLOFORGE='perl ./src/doloforge --config ./t/doloforge.yaml --stage devl'
set -x

( # Redirects stdout/stderr to a log file. "exec > log" works but does not allow to see the progress using "tee")
for client in internal colibrix mpg jim uptime; do
    deluser --remove-home $client
    delgroup $client
done

rm -fr ./t/conf.d/* ./t/srv/doloforge/*/*/

$DOLOFORGE client --add --name internal --description 'Platform-wide internal services' --email 'webmaster@doloforge.com' --password test
#    $DOLOFORGE project --add --name sandbox --client internal --description 'Sandbox project for developer training' --services 'apache,mason,postgres7' --backends mason --database postgres7
#    $DOLOFORGE project --add --name fallback --client internal --description 'Ready to use project in case of failure on any client/project' --services 'apache,mason,postgres7' --backends mason --database postgres7
    $DOLOFORGE project --add --name sandbox --client internal --description 'Sandbox project for developer training' --services 'apache,mason' --backends mason
    $DOLOFORGE project --add --name fallback --client internal --description 'Ready to use project in case of failure on any client/project' --services 'apache,mason' --backends mason
    $DOLOFORGE project --add --name default --client internal --description '"Main" server configuration' --services apache
$DOLOFORGE client --add --name colibrix --description 'Colibrix' --email 'patrick.bousso@colibrix.fr' --password test
#    $DOLOFORGE project --add --name luxor --client colibrix --description 'Version alpha site de tourisme' --services 'apache,mason,postgres7' --backends mason --database postgres7
    $DOLOFORGE project --add --name luxor --client colibrix --description 'Version alpha site de tourisme' --services 'apache,mason' --backends mason
$DOLOFORGE client --add --name mpg --description 'Michael P. Geraghty' --email 'mpg@michaelgeraghty.com' --password test
    $DOLOFORGE project --add --name accountinginportugal --client mpg --services 'apache,ftp'
    $DOLOFORGE project --add --name digitalport --client mpg --services 'apache,ftp'
    $DOLOFORGE project --add --name michaelgeraghty --client mpg --services 'apache,ftp'
$DOLOFORGE client --add --name jim --description 'JIM' --email 'webmaster@jim.fr'
    $DOLOFORGE project --add --name clicodrome --client jim --description 'Clicodrome envoi de newsletters' --services 'apache,mason' --backends mason
$DOLOFORGE client --add --name uptime --description 'Uptime Conseil' --email 'sgendrel@uptimeconseil.com' --password test
    $DOLOFORGE project --add --name picinguaba --client uptime --description 'La Pousada Picinguaba' --services 'apache,mason,php5' --backends 'mason,php5'

$DOLOFORGE config --update

cp example/default/conf/apache_httpd.conf.tmpl ./t/srv/doloforge/shared/internal/default/conf/
$DOLOFORGE config --update

) 2>&1 | tee ./t/test.log
