#!/usr/local/bin/cbsd
#v11.1.16
MYARG="arch ver stable"
MYOPTARG="platform target_arch"
MYDESC="Unregister bases (without removing from storage) for jails in the databases"
CBSDMODULE="build"

. ${subr}
init $*

. ${tools}
. ${strings}

[ -z "${target_arch}" ] && target_arch="${arch}"

if [ -z "${stable}" ]; then
	strpos --str="${ver}" --search="."
	# auto-detect for stable/release
	pos=$?
	if [ ${pos} -eq 0 ]; then
		stable=1
	else
		stable=0
	fi
fi

. ${workdir}/universe.subr

idx=$( get_baseidx -a ${arch} -p ${platform} -s ${stable} -t ${target_arch} -v ${ver} )

if [ -n "${idx}" ]; then
	cbsdsql local "DELETE FROM bsdbase WHERE idx=\"${idx}\""
	err 0 "${MAGENTA}Unregistered${NORMAL}"
else
	err 1 "${MAGENTA}unregister_base: No idx for platform:${platform}, arch:${arch}, target_arch:${target_arch}, ver:${ver}, stable:${stable}${NORMAL}"
fi
