summaryrefslogtreecommitdiffhomepage
path: root/subr.pkg/pkg_fetch_extract.subr
blob: 14839ce54c7076a9377b089297c84ac175ef79ac (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Lucía Andrea Illanes Albornoz <lucia@luciaillanes.de>
# set +o errexit -o noglob -o nounset is assumed.
#

pkgp_fetch_extract_type() {
	local _ppfet_fname="${1}" _ppfet_rtype="${2#\$}";

	if [ "${1##*.tar.}" != "${1}" ]; then
		eval ${_ppfet_rtype}='${1##*.tar.}';
	elif [ "${1##*.t}" != "${1}" ]; then
		eval ${_ppfet_rtype}='${1##*.t}';
	fi;
	return 0;
};

pkg_fetch_extract() {
	local	_pfe_group_name="${1}" _pfe_pkg_name="${2}" _pfe_restart_at="${3}"	\
		_pfe_type="";

	if [ "${PKG_URL:+1}" = 1 ]; then
		_pfe_oldpwd="${PWD}";

		if ! rtl_fileop cd "${PKG_BASE_DIR}"\
		|| ! rtl_fileop rm "${PKG_BASE_DIR}/${PKG_SUBDIR}"; then
			rtl_fileop cd "${_pfe_oldpwd}"; return 1;
		else
			pkgp_fetch_extract_type "${PKG_NAME}" \$_pfe_type;

			case "${_pfe_type}" in
			bz2)	bunzip2 -d < "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -; ;;
			gz)	gunzip -d < "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -; ;;
			lz)	lzip -d < "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -; ;;
			xz)	xz -d < "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -; ;;
			*)	tar -C "${PKG_BASE_DIR}" -xf "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}"; ;;
			esac;

			if [ "${?}" -ne 0 ]; then
				rtl_fileop cd "${_pfe_oldpwd}"; return 1;
			else
				rtl_fileop cd "${_pfe_oldpwd}";
			fi;
		fi;
	fi;

	if [ -x "${PKG_BASE_DIR}/${PKG_SUBDIR}/srcprep.sh" ]; then
		"${PKG_BASE_DIR}/${PKG_SUBDIR}/srcprep.sh";
	fi;

	return 0;
};

# vim:filetype=sh textwidth=0