#
# set -o errexit -o noglob are assumed.
#

pkg_fetch_extract() {
	local _oldpwd="";
	if [ -n "${PKG_URL}" ]\
	&& [ "${PKG_URL_TYPE:-wget}" = wget ]; then
		_oldpwd="${PWD}"; ex_rtl_fileop cd "${PKG_BASE_DIR}";
		ex_rtl_fileop rm "${PKG_BASE_DIR}/${PKG_SUBDIR}";
		if [ "${PKG_FNAME##*.tar.}" = "bz2" ]\
		|| [ "${PKG_FNAME##*.t}" = "bz2" ]; then
			bunzip2 -d < "${BUILD_DLCACHEDIR}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -;
		elif [ "${PKG_FNAME##*.tar.}" = "gz" ]\
		|| [ "${PKG_FNAME##*.t}" = "gz" ]; then
			gunzip -d < "${BUILD_DLCACHEDIR}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -;
		elif [ "${PKG_FNAME##*.tar.}" = "xz" ]\
		|| [ "${PKG_FNAME##*.t}" = "xz" ]; then
			xz -d < "${BUILD_DLCACHEDIR}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -;
		else
			tar -C "${PKG_BASE_DIR}" -xf "${BUILD_DLCACHEDIR}/${PKG_FNAME}";
		fi;
		ex_rtl_fileop cd "${_oldpwd}";
	fi;
};

# vim:filetype=sh