#!/bin/sh
#
#ident "$Header: /net/projects/S2.6/cvs/os_net/src_ws/usr/src/tadcmd/locations/lsloc.sh,v 1.4 1997/12/05 12:32:05 ang Exp $"
#
LOCROOT=${LOCROOT:-/var/locations}
export LOCROOT
pNAME=`basename $0`
VERBOSE=0

usage() {
    echo "Usage: $pNAME [-v] [ locations.. ]" 1>&2
    exit 2
}

print_loc() {
    LOC=$1
    echo $LOC
    if [ $VERBOSE -eq 1 ]
    then
	for N in "" 1 2 3 4 5 6 7 8 9
	do
	    if [ -d $LOCROOT/$LOC/rc${N}.d ]
	    then
		if [ -z "$N" ]
		then
		    echo "  Basic Level:"
		else
		    echo "  Level $N:"
		fi
		if [ -f $LOCROOT/$LOC/INFO${N} ]
		then
		    (echo "Desc - \c"; cat $LOCROOT/$LOC/INFO${N}) | paste -d" " /dev/null /dev/null /dev/null -
		fi
		grep "^#LocINFO " $LOCROOT/$LOC/rc${N}.d/S* | sed "s/.*#LocINFO//" | paste -d"	" /dev/null -
	    fi
	done
    fi
}

if [ ! -f /etc/location ]
then
    echo "There is no \"/etc/location\" file - has the system been initialized"
    echo "for locations? See the initloc(1m) man page."
    exit 1
fi

while getopts v c
do
    case $c in
    v)
	VERBOSE=1
	;;
    \?)
	usage
    esac
done
shift `expr $OPTIND - 1`
NARGS=$#

if [ -s /etc/location ]
then
    oIFS="$IFS"
    IFS=":"
    set `cat /etc/location`
    CLOC=$1
    CLOCLEV=$2
    IFS="$oIFS"
else
    CLOC=
    CLOCLEV=
fi

if [ $NARGS -gt 0 ]
then
    for LOC
    do
	if [ -d $LOCROOT/$LOC/rc.d ]
	then
	    print_loc $LOC
	else
            echo "No such location \"$LOC\"" 1>&2
	    exit 3
	fi
    done
else
    if [ -n "$CLOC" ]
    then
	echo "Current Location \"$CLOC:${CLOCLEV:+Level }${CLOCLEV:-Basic}\""
    else
	echo "Location Not set"
    fi

    for L in $LOCROOT/*/rc.d
    do
	if [ ! -d $L ]
	then
	    continue
	fi
	LOC=`dirname $L`
	print_loc `basename $LOC`
    done
fi

