Blob Blame History Raw
#
# set +o errexit -o noglob is assumed.
#

pkgp_fetch_extract_type() {
	local _fname="${1}";
	if [ "${1##*.tar.}" != "${1}" ]; then
		echo "${1##*.tar.}";
	elif [ "${1##*.t}" != "${1}" ]; then
		echo "${1##*.t}";
	fi;
};

pkg_fetch_extract() {
	if [ -n "${PKG_URL}" ]\
	&& [ "${PKG_URL_TYPE:-wget}" = wget ]; then
		_oldpwd="${PWD}"; rtl_fileop cd "${PKG_BASE_DIR}" || return "${?}";
		rtl_fileop rm "${PKG_BASE_DIR}/${PKG_SUBDIR}" || return "${?}";
		case "$(pkgp_fetch_extract_type "${PKG_NAME}")" in
		bz2)	bunzip2 -d < "${BUILD_DLCACHEDIR}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf - || return "${?}"; ;;
		gz)	gunzip -d < "${BUILD_DLCACHEDIR}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf - || return "${?}"; ;;
		lz)	lzip -d < "${BUILD_DLCACHEDIR}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf - || return "${?}"; ;;
		xz)	xz -d < "${BUILD_DLCACHEDIR}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf - || return "${?}"; ;;
		*)	tar -C "${PKG_BASE_DIR}" -xf "${BUILD_DLCACHEDIR}/${PKG_FNAME}" || return "${?}"; ;;
		esac;
		rtl_fileop cd "${_oldpwd}" || return "${?}";
	fi;
};

# vim:filetype=sh