#! /bin/bash
# set -xv
#=========================================================================
# Copyright (C) GemTalk Systems 1986-2024.  All Rights Reserved.
#
# Name - setupstone.sh
#
# Purpose - Create setup and extent and netldi in the specified directory.
#=========================================================================

if [ -z "$GEMSTONE" ]; then
    echo "GEMSTONE must be set"
    exit 1
fi

if [ -z "$DEBUG_INSTALLGS" ]; then
    DEBUG_LOG="/dev/null"
else
    DEBUG_LOG="/dev/stdout"
fi

HELPER=$GEMSTONE/install/helper.sh

if [ ! -f $HELPER ]; then
    echo "[Error]: Cannot find $HELPER"
    exit 1
fi

. $HELPER

verifyIsNotRoot

$ECHO "createNewGemStoneRepository -- Setup a new GemStone/S 64 Bit data-conf repository"

usage(){
    echo "Usage: $0 <directory>"
    exit 1
}

DIR=$1
if [ "x$DIR" = "x" ]; then
    usage
fi

if [ -d $DIR ]; then
    verifyDirEmpty $DIR
    echo "[Info]: Using directory $DIR"
else
    makeDir $DIR
    doChmod "" 775 $DIR
    echo "[Info]: Created directory $DIR"
fi

doCp "" "$GEMSTONE/bin/extent0.dbf" "$DIR/extent0.dbf"
doChmod "" 775 "$DIR/extent0.dbf"
doCp "" "$GEMSTONE/bin/gemstone_data.conf" "$DIR/gemstone_data.conf"
doChmod "" 775 "$DIR/gemstone_data.conf"

ME=`whoami`

echo "[Info]: Setup completed. To start GemStone, execute the following commands:"
echo "\$GEMSTONE/bin/startstone -E $DIR/gemstone_data.conf"
echo "\$GEMSTONE/bin/startnetldi -E $DIR/gemstone_data.conf -g -a $ME"

exit 0

