#!/bin/sh

## Copyright (C) 2006-2012 Daniel Baumann <daniel.baumann@progress-technologies.net>
##
## 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

if [ ! -x "$(which lxc-info 2>/dev/null)" ]
then
	echo "E: lxc-info - no such file" >&2
	exit 1
fi

for _STATUS in RUNNING FROZEN STOPPED
do
	echo ${_STATUS}

	for _CONTAINER in $(lxc-ls)
	do
		if lxc-info -n ${_CONTAINER} 2>&1 | grep -qs "${_STATUS}"
		then
			echo -n "  ${_CONTAINER}"

			if [ -e /etc/lxc/auto/${_CONTAINER} ]
			then
				echo " (auto)"
			else
				echo
			fi
		fi
	done

	echo
done
