# Calculate run=/bin/bash pkg(sys-apps/calculate-utils)>=3.6.6 ini(overlay-calculate.revision)>=20191116.3

is_old_path() {
	/usr/libexec/calculate/cl-variable --value main.cl_template_path | grep -q var/lib/layman
}

if is_old_path
then
	current_profile="$(readlink -f /etc/portage/make.profile)"
	if [[ -d "${current_profile}/20" ]]
	then
		echo "Changing profile"
		ln -sfT $(realpath --relative-to /etc/portage "${current_profile}/20") /etc/portage/make.profile 
	fi
fi

if ! is_old_path && [[ -d /var/lib/layman ]]
then
#?pkg(app-portage/layman)==#
	echo "Removing /var/lib/layman"
	rm -rf /var/lib/layman
#!pkg#
	if find /var/lib/layman -maxdepth 1 -type l &>/dev/null
	then
		find /var/lib/layman -maxdepth 1 -type l -delete
	fi
#pkg#
	rm -f /etc/portage/make.conf/0-base
fi

exit 0
