#! /bin/bash
#=========================================================================
# Copyright (C) GemTalk Systems 1986-2024.  All Rights Reserved..
#
# Name - lsstone
# Installed as - lsstone
#
# Written By: Martin McClure and Nols Green
#
# Purpose - lists all stones configured

# Requirements -
#
# The following environment variables must be defined:
#
# GEMSTONE_CERT_DIR - A directory where newly created certificates and
#                     subdirectories will be placed.
#
#=========================================================================

cmd=`basename $0`

usage(){
    echo "Usage: $cmd [-h]" >&2
    echo "      -h - show this help screen" >&2
    exit 1
}

while getopts "h" opt; do
    case $opt in
	h)
	    usage
	    ;;
        \?)
          usage
          ;;
    esac
done
shift $((OPTIND-1))

# 47501 - handle symlinks
fullPath=`readlink -e -n $0`
scriptDir=`dirname $fullPath`
if [ ! -f $scriptDir/environment.sh ]; then
    echo "[Error]: Cannot find environment.sh setup script"
    exit 1
fi
. ${scriptDir}/environment.sh

if [ -d ${stonesDir} ]; then
    numDirs=`ls -lR $stonesDir | grep ^d | wc -l`
    if [ $numDirs -gt 0 ]; then
	ls -1 ${stonesDir}
	exit $?
    fi
fi

echo "No stones exist. Use 'newstone' to create one." >&2
exit 0
