#!/bin/sh

TTAHOME="/opt/tarantella"
TTA=$TTAHOME"/bin/tarantella"
msg_name="Nombre"
msg_alias="Alias"
msg_default="Por defecto"
msg_dbcreate="Creando Base de Datos"
msg_sttaFiles="Creando Definiciones de Grupos"
msg_orgname="de la Organizacion: "
msg_usergrp=" USUARIOS de la Organizacion:"
msg_hostsgrp="de Grupo (ou) para SERVIDORES de la Organizacion:"
msg_appsgrp="de Grupo (ou) para APLICACIONES de la Organizacion:"


STTA_defs="/opt/tarantella/defs"
STTA_oulist=ou_list
STTA_appslist=apps_list
STTA_grpappslist=grpapps_list
STTA_hostslist=hosts_list
STTA_grphostslist=grphosts_list
STTA_domainslist=domain_list

CreateOrg() {
    echo -n -e "$msg_name $msg_orgname" 
    read ouname
    outcmd=`$TTA object rename  --name o=organization  --newname o=$ouname ` 
    [ -n $outcmd ] && echo "$outcmd"  && exit 1
}

CreateGroups() {
  echo "$msg_sttaFiles $msg_default ..."
  echo "BASE::Root Organization::::::9999::Start-up group::" >$STTA_defs/$STTA_oulist
  echo "BASE::Root Organization::::::9999::Start-up group::" >$STTA_defs/$STTA_grpappslist
  echo "BASE::Root Organization::::::9999::Start-up group::" >$STTA_defs/$STTA_grphostslist
  echo "BASE::Root Organization::::::9999::Start-up group::" >$STTA_defs/$STTA_domainslist
}


CreateDefaultDB(){
#/opt/tarantella/bin/scripts/install_scripts/vendor/SCO/Tarantella/SCO.defaults
#/opt/tarantella/bin/scripts/install_scripts/pip/vendor/SCO/Tarantella/SCO.defaults

echo "$msg_dbcreate $msg_default ..."

INSTDIR=$TTAHOME ; export INSTDIR
TTAINSTSCRIPTS=$INSTDIR/bin/scripts/install_scripts
cd $TTAINSTSCRIPTS

        for dir in vendor */vendor; do
        (
            cd $dir
            # script names are <vendor>/<product>/<vendor>.defaults
            # (eg SCO/Tarantella/SCO.defaults)
            for DefaultsScript in */*/*.defaults; do
                sh $xflag $DefaultsScript >>$INSTDIR/var/log/setup.log 2>&1
            done
        )
        done

}

tta stop
CreateDefaultDB
tta start

CreateOrg

CreateGroups
