#!/bin/sh
# STTA Rev. 1.3 Copyright (c) 2001-2002 Jesús Pérez Lorenzo  --- license GNU GPL 

# Environment ...
lang="es";
is_STTA=true;

TTAHOME="/opt/tarantella"
TTA=$TTAHOME"/bin/tarantella"

case "$lang" in 
   es|ES)
          msg_default="Por defecto"
          msg_dbcreate="Creando Base de Datos"
          msg_dbdelete="Borrando Directorio de Base de Datos"
          msg_orgname="Nombre de la Organizacion: "
          ;;       
   *) 
          msg_default="by default"
          msg_dbcreate="Making Data Base"
          msg_dbdelete="Deleting Data Basei Directory"
          msg_orgname="Organization Name: "
          ;;       
esac


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

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 --force
echo "$msg_dbdelete ..."
rm -r $TTAHOME/var/ens 
CreateDefaultDB
tta start

RenameOrg $*
