#!/bin/sh

## Copyright (C) 2006-2013 Daniel Baumann <mail@daniel-baumann.ch>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.


set -e

. /usr/share/lxc/lxc.functions

_LXC_DIRECTORY="${lxc_path}"

_OPTIONS="$(getopt -o P: -l lxcpath: -- "${@}")"

if [ "${?}" -ne 0 ]
then
	echo "Usage: $(basename ${0}) [-P|--lxcpath DIRECTORY]" >&2
	exit 1
fi

eval set -- "${_OPTIONS}"

while true
do
	case "${1}" in
	        -P|--lxcpath)
			_LXC_DIRECTORY="${2}"
			shift 2
			;;

		--)
			shift
			break
			;;

		*)
			echo "E: $(basename ${0}): internal error ${0}" >&2
			exit 1
			;;
	esac
done

if [ ! -d "${_LXC_DIRECTORY}" ]
then
	echo "E: ${_LXC_DIRECTORY}: no such directory." >&2
	exit 1
fi

cd "${_LXC_DIRECTORY}"

_DIRECTORIES="$(find . -maxdepth 1 -type d -and -not -name ".*" -and -not -name lost+found | sort)"

for _DIRECTORY in ${_DIRECTORIES}
do
	ls -d ${@} $(basename ${_DIRECTORY})
done
