#!/usr/local/bin/cbsd
#v11.1.0
MYARG="file hosts ips"
MYOPTARG="template"
MYDESC="Simple manage records in hosts file"
CBSDMODULE="sys"
ADDHELP="file = path to hosts file\n\
hosts= host entry, e.g: jail1.my.domain\n\
ips= IP address for host entry\n\
template= (optional) alternative template marker\n"

. ${subr}
. ${system}
. ${tools}

init $*

# sample: cbsd mkjhosts file=/hosts ips="192.168.0.11" hosts="test" template="TEST"

[ ! -r "${file}" ] && err 1 "${MAGENTA}mkjhosts: no ${GREEN}${file}${NORMAL}"
[ -z "${template}" ] && template="CBSD autotpl for mkhostsfile"

tmpfile="${ftmpdir}/hosts.$$"
/bin/cp -a ${file} ${tmpfile}
${GREP_CMD} -v "${template}" ${tmpfile} > ${file}
echo "${ips} ${hosts} # ${template}" >> ${file}
/bin/rm -f ${tmpfile}
