#!/bin/sh
#v9.2.2
globalconf="${workdir}/cbsd.conf";
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.html"

set -e
. ${globalconf}
set +e

. ${subr}

init $*

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

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 "${MAGENTA}Valid file: ${GREEN}${FILES}${NORMAL}"

if [ "${mode}" = "update" ]; then
	echo "edit description"
	${editor} "${editfile}"
	chown ${cbsduser}:${cbsduser} ${editfile}
else
	[ ! -f "${nodedescr}" ] && err 1 "${MAGENTA}No such node file: ${GREEN}${editfile}${NORMAL}"
	cat ${editfile}
fi
