#!/usr/local/bin/cbsd
#v15.0.5
CIXARG="file"
CIXOPTARG=""
MYDESC="Create empty jail VM sqlite3 file"
ADDHELP="
${H3_COLOR}Description${N0_COLOR}:

 Create empty SQLite3 structure for jail VM

${H3_COLOR}Options${N0_COLOR}:

 ${N2_COLOR}file - destination file

${H3_COLOR}Examples${N0_COLOR}:

 # cbsd bsqlite-cache-create file=/tmp/jail.sqlite

"

. ${subrdir}/nc.subr
. ${subrdir}/tools.subr
cixinit

[ -z "${CIX_BIN}" ] && CIX_BIN="/usr/local/bin/cbsd"
_tmpfile="${file}.$$"
[ -r "${_tmpfile}" ] && ${RM_CMD} -f ${_tmpfile}
${TOUCH_CMD} ${_tmpfile}
_ret=$?
[ ${_ret} -ne 0 ] && err 1 "${W1_COLOR}${CIX_APP} error: ${N1_COLOR}unable to write: ${N2_COLOR}${_tmpfile}${N0_COLOR}"

${CIX_BIN} ${miscdir}/updatesql ${_tmpfile} ${CIX_DISTDIR}/share/local-jailnic.schema jailnic

# atomic rename
${MV_CMD} ${_tmpfile} ${file}
_ret=$?
[ ${_ret} -ne 0 ] && err 1 "${W1_COLOR}${CIX_APP} error: ${N1_COLOR}unable to write: ${N2_COLOR}${_tmpfile}${N0_COLOR}"

exit 0
