# vim: set syntax=sh
#
# Copyright 2014 Calculate Ltd. http://www.calculate-linux.org
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0

CL_UPDATE_PROG=/usr/sbin/cl-core-setup

post_setup_package() {
	if [[ -f  /var/lib/calculate/-postmerge ]] && check_skip
	then
		OLDIFS=$IFS
		IFS=/
		while read category pkgname;do
			[ -d /var/db/pkg/${category}/${pkgname}-* ] || continue
			IFS=$OLDIFS
			CTARGET=${CTARGET} GCC_CONFIG_VER=${GCC_CONFIG_VER} ${CL_UPDATE_PROG} --no-progress --pkg-name $pkgname --pkg-category $category --pkg-path "/"
			IFS=/
		done < <(sort /var/lib/calculate/-postmerge | uniq)
		IFS=$OLDIFS
	fi
	rm -f /var/lib/calculate/-postmerge
}

post_pkg_postinst() {
	post_setup_package
}
