#!/usr/local/bin/cbsd
#v10.0.3
MYARG=""
MYOPTARG="jname"
MYDESC="Upgrade jail base data when baserw=1"
CBSDMODULE="jail"

. ${subrdir}/nc.subr
. ${strings}
. ${subrdir}/universe.subr
readconf buildworld.conf

. ${cbsdinit}

[ -z "${jname}" -a -n "${1}" ] && jname=$1
[ -z "${jname}" ] && err 1 "${N1_COLOR}Give me jname${N0_COLOR}"

. ${subrdir}/rcconf.subr

[ $? -eq 1 ] && err 1 "${N1_COLOR}No such jail: ${N2_COLOR}${jname}${N0_COLOR}"
[ "${emulator}" = "bhyve" ] && err 1 "${N1_COLOR}Not for bhyve mode${N0_COLOR}"

if [ ${baserw} -ne 1 ]; then
	${ECHO} "${N1_COLOR}Jail is ${N2_COLOR}basero${N1_COLOR} mode. Therefore if you want to update the base version to another one, just change ${N2_COLOR}ver${N1_COLOR} params in ${N2_COLOR}cbsd jconfig${N1_COLOR}"
	err 1 "${N1_COLOR}If you want to update base files (for all jails in basero mode and current base version), please use: ${N2_COLOR}cbsd repo action=get sources=base mode=upgrade${N0_COLOR}"
fi

. ${system}
init_target_arch
init_basedir
get_base -v ${ver}

switch_baserw ${data} 2
switch_baserw ${data} 1
