#!/bin/sh
#
# Prints names of all mounted instances
#

OMCHECKGC=/opt/scalix/bin/omcheckgc
OMREALPATH=/opt/scalix/bin/omrealpath

INSTFILE=/etc/opt/scalix/instance.cfg

if [ -x $OMCHECKGC -a -f $INSTFILE ] ; then
    all_instances=`$OMCHECKGC -l`
    for instance in $all_instances ; do
        # test if the instance exists; if it does, print its name
        export OMCURRENT=$instance
        if [ -f `$OMREALPATH '~/sys/sysdata'` ] ; then
            echo $instance
        fi
    done
else
    # print the default instance name if the server is not installed
    echo ${OMCURRENT:-$(hostname -s)}
fi
