#!/usr/bin/env cbsd
#v10.1.3
CIXARG=""
CIXOPTARG="jname"
MYDESC="Show group list"
ADDHELP="
${H3_COLOR}Description${N0_COLOR}:

 Display group list from the specified jail or the host system.

${H3_COLOR}Options${N0_COLOR}:

 ${N2_COLOR}jname=${N0_COLOR} - target jail. If omitted, displays host groups.

${H3_COLOR}Examples${N0_COLOR}:

 # cbsd grouplist
 # cbsd grouplist jname=myjail

${H3_COLOR}See also${N0_COLOR}:

 cbsd adduser --help

"

. ${subrdir}/nc.subr
cixinit

if [ -n "${jname}" ]; then
	. ${subrdir}/rcconf.subr
	[ $? -eq 1 ] && err 1 "${N1_COLOR}No such jail: ${N2_COLOR}${jname}${N0_COLOR}"
	[ ! -f "${data}/etc/group" ] && err 1 "${N1_COLOR}grouplist: bad data dir for jail: ${N2_COLOR}${jname}${N0_COLOR}"
fi

${GREP_CMD} -v '^#' ${data}/etc/group | ${AWK_CMD} -F":" '{print $1}'

exit 0
