#!/usr/local/bin/cbsd
#v9.2.2
CBSDMODULE="node"
MYARG="file"
MYOPTARG="mode editor"
MYDESC="Show or modify node description"
ADDHELP="mode=update for update information\n\
editor=mcedit for altrnative editor\n\
file= file for update: descr, role, domain, notes, location\n"
EXTHELP="wf_ndescr"

. ${subrdir}/nc.subr

. ${cbsdinit}

[ -z "${editor}" ] && editor="${EDITOR}"

FILES="descr role domain notes location"

validfile=0

for i in ${FILES}; do
	if [ "${file}" = "${i}" ]; then
		validfile=$(( validfile + 1 ))
		editfile="${workdir}/node.${i}"
		break
	fi
done

[ ${validfile} -eq 0 ] && err 0 "${N1_COLOR}Valid file: ${N2_COLOR}${FILES}${N0_COLOR}"

if [ "${mode}" = "update" ]; then
	echo "edit description"
	${editor} "${editfile}"
	${CHOWN_CMD} ${cbsduser}:${cbsduser} ${editfile}
else
	[ ! -f "${nodedescr}" ] && err 1 "${N1_COLOR}No such node file: ${N2_COLOR}${editfile}${N0_COLOR}"
	${CAT_CMD} ${editfile}
fi
