#!/bin/bash
if [ -s $GEMSTONE/seaside/etc/gemstone.secret ]; then
    . $GEMSTONE/seaside/etc/gemstone.secret
else
    echo 'Missing password file $GEMSTONE/seaside/etc/gemstone.secret'
    exit 1
fi

$GEMSTONE/bin/topaz -l << EOF

set user DataCurator pass $GEMSTONE_CURATOR_PASS gems $GEMSTONE_NAME

iferror where

login

run
| config |
GsFile gciLogServer: 'Starting initialization...'.

WADispatcher initialize.
WADispatcherEditor initialize.

config := WADispatcher default entryPoints at: 'config'.
config preferenceAt: #password put: ''$GEMSTONE_CONFIG_PASS'.


"set to false if you don't want to initialize the examples"
true ifTrue: [
  WACounter initialize. 
  WAMultiCounter initialize.
  WAAllTests initialize. 
  WAExampleBrowser initialize.
].

"set to false if you don't want to initialize the sushi store example"
true ifTrue: [
  WAStore initialize.
  false ifTrue: [
    false ifTrue: [WAStoreRepository resetUsers].
    false ifTrue: [WAStoreRepository resetOrders].
    false ifTrue: [WAStoreRepository resetInventory].
    true ifTrue: [WAStoreRepository resetRepository].
  ].
  true ifTrue: [ | cust address |
    "Add default user"
    (WAStoreRepository userNameExists: 'daleh')
      ifFalse: [
        cust := WACustomer new.
        cust userName: 'joe'; password: 'swordfish'.
        address := WAStoreAddress new.
        address name: 'joe user'; street: 'elm streed'; city: 'Anytown'; country: 'USA'.
        cust shippingAddress: address.
        WAStoreRepository users add: cust. 
      ].
  ].
].

System commitTransaction.

GsFile gciLogServer: 'Finished initialization.'.

%

logout
errorCount
EOF
