#!/bin/bash
#
# Guralp Configuration System
#   Copyright (c) 2008-2009 Guralp Systems Ltd. All rights reserved.
#
#   Services top level menu

if [ "X$1" == "X--navbar" ]
then
	echo "servicestop	Services"
	exit 0
fi


# Load support functions
script_dir=$(dirname $0)
. $script_dir/functions.sh


# List the services
for file in $SERVDIR/*/info
do
	if [ -f "$file" ]
	then
	    name="$(basename "$(dirname "${file}")")"
	    desc="${name} -- $(gcs_get_varf DESC "${file}")"
            category="$(gcs_get_varf CATEGORY "${file}")"

	    # This is a special case for gdi2dbi because we don't want to show
	    # it by default to a general user.  There are two checks for both
	    # the binary existing and a config file which can be 0 length so
	    # that only someone who knows what to do can see the config page.
	    if [ ${name} == "gdi2dbi" ]
	    then
		# No binary - don't show
		if [ ! -s "/usr/bin/gdi2dbi" ]
		then
		    continue
		fi
		# No config file - don't show
		if [ ! -e "/etc/gdi2dbi/0.local" ]
		then
		    continue
		fi
	    fi

            [ -z "${category}" ] && category="default"
            count="count_${category/-/_}"

            [ -z "${!count}" ] && let "${count} = 0"
            echo "select_service_${category}${!count}=${name} ${desc}"
            let "$count += 1"
	fi
done

exit 0
