summaryrefslogtreecommitdiffhomepage
path: root/subr/pkg_fetch_extract.subr
blob: 8802a9506242c3ced12765e9e56b2bb4e564a8a8 (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
#
# 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}" ]; 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