#!/usr/local/bin/cbsd
#v10.0.6
CBSDMODULE="sys"
MYARG="file dst mode"
MYOPTARG=""
MYDESC="Mount GELI-based image"

. ${subrdir}/nc.subr
. ${system}
. ${cbsdinit}

is_mounted ${dst} && err 0 "${N1_COLOR}Already mounted: ${N2_COLOR}${dst}${N0_COLOR}"

dev=$( env NOCOLOR=yes /usr/local/bin/cbsd geli mode=init file=${file} 2>&1 )

[ $? -ne 0 ] && err 1 "${N1_COLOR}error: ${dev}"

[ ! -c "${dev}" ] && err 1 "${N1_COLOR}No such ${dev}${N0_COLOR}"

#${ECHO} "${N1_COLOR}Running fsck on the image. Please wait${N0_COLOR}"
res=$( /sbin/fsck -t ufs -y "${dev}" > /dev/null 2>&1 )
[ $? -ne 0 ] && err 1 "${N1_COLOR}Unrecovery error: ${N0_COLOR}${res}"
/sbin/mount -o${mode} ${dev} ${dst}
