#!/bin/sh
#
#
#    Scalix Public License
#
#
#    The contents of this file are subject to the Scalix Public License
#    Version 1.1 ("License"); you may not use this file except in
#    compliance with the License. You may obtain a copy of the License at
#
# 
#    http://www.scalix.com/community/licensing 
#
# 
#    Software distributed under the License is distributed on an "AS IS"
#    basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
#    the License for the specific language governing rights and limitations
#    under the License.
#
# 
#    The Original Code is Scalix Server. 
#    The Initial Developer of the Original Code is Scalix Corporation. 
#    Copyright (C) 2006 Scalix Corporation. 
#    All Rights Reserved.
#    Additional Copyrights may apply - see the notice in each file
#
#
#
#
#
#
# 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
