summaryrefslogtreecommitdiffhomepage
path: root/subr/pkg_fetch_extract.subr
blob: 66e516692d4d578f63208a79a4563b491e8b5487 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#
# 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}"; ex_rtl_fileop cd "${PKG_BASE_DIR}" || return "${?}";
		ex_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;
		ex_rtl_fileop cd "${_oldpwd}" || return "${?}";
	fi;
};

# vim:filetype=sh