#!/usr/bin/env cbsd
#v9.2.2
CBSDMODULE="node"
CIXARG="file"
CIXOPTARG="mode editor"
MYDESC="Show or modify node description"
EXTHELP="wf_ndescr"
ADDHELP="
${H3_COLOR}Description${N0_COLOR}:

 Show or modify node description fields.

${H3_COLOR}Options${N0_COLOR}:

 ${N2_COLOR}file=${N0_COLOR}    - target file: descr, role, domain, notes, location.
 ${N2_COLOR}mode=${N0_COLOR}    - set 'update' to edit the file.
 ${N2_COLOR}editor=${N0_COLOR} - alternative editor, e.g.: mcedit. Default: \$EDITOR.

${H3_COLOR}Examples${N0_COLOR}:

 # cbsd ndescr file=descr
 # cbsd ndescr file=descr mode=update
 # cbsd ndescr file=role mode=update editor=mcedit

${H3_COLOR}See also${N0_COLOR}:

 cbsd sysrc --help

"

. ${subrdir}/nc.subr
cixinit
cixinit

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

case "${file}" in
	descr|domain|notes|location|role)
		editfile="${workdir}/node.${file}"
		;;
	*)
		err 0 "${N1_COLOR}Valid file: ${N2_COLOR}descr role domain notes location${N0_COLOR}"
		;;
esac

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

exit 0
