#!/usr/local/bin/cbsd
#v12.2.4
MYARG="arch ver"
MYOPTARG="platform target_arch"
MYDESC="Unregister kernel (without removing from storage) from databases"
CBSDMODULE="build"

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

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

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

. ${subrdir}/universe.subr

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

if [ -n "${idx}" ]; then
	cbsdsqlrw local "DELETE FROM bsdkernel WHERE idx=\"${idx}\""
	err 0 "${N1_COLOR}unregistered${N0_COLOR}"
else
	err 1 "${N1_COLOR}unregister_kernel: no idx for platform:${platform}, arch:${arch}, target_arch:${target_arch}, ver:${ver}, stable:${stable}${N0_COLOR}"
fi

exit 0
