summaryrefslogtreecommitdiffhomepage
path: root/subr/pkg_fetch_download.subr
blob: 0affb358576a1cc2d477a84d84670d9390847daa (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
54
55
56
57
58
59
60
61
62
63
64
65
66
#
# set +o errexit -o noglob -o nounset is assumed.
#

pkg_fetch_download_clean_dlcache() {
	local	_dlcachedir="${1}" _pkg_name="${2}" _pkg_fname="${3}" _pkg_urls_git="${4}"\
		_fname="" _pkg_urls_git_dname="";

	if [ -n "${_pkg_urls_git}" ]; then
		_pkg_urls_git_dname="${_pkg_urls_git%%=*}";
		_pkg_urls_git_dname="${_pkg_urls_git_dname##*/}";
	fi;
	for _fname in $(cd "${_dlcachedir}/${_pkg_name}" && find		\
			-mindepth 1						\
			${_pkg_fname:+-not -name "${_pkg_fname}"}		\
			${_pkg_fname:+-not -name "${_pkg_fname}.fetched"}	\
			${_pkg_urls_git_dname:+					\
			-not -path "./${_pkg_urls_git_dname}"			\
			-not -path "./${_pkg_urls_git_dname}/*"			\
			-not -path "./${_pkg_urls_git_dname}.git"		\
			-not -path "./${_pkg_urls_git_dname}.git/*"}); do
		_fname="${_dlcachedir}/${_pkg_name}/${_fname#./}"
		rtl_log_msg notice "Deleting redundant file \`%s' for package \`%s'." "${_fname}" "${_pkg_name}";
		rtl_fileop rm "${_fname}";
	done;
};

pkg_fetch_download_dlcache_subdir() {
	if [ -n "${PKG_INHERIT_FROM:-}" ]\
	&& ! [ -e "${BUILD_DLCACHEDIR}/${PKG_NAME}" ]\
	&& ! rtl_fileop ln_symbolic "${PKG_INHERIT_FROM}" "${BUILD_DLCACHEDIR}/${PKG_NAME}"; then
		return 1;
	elif [ -z "${PKG_INHERIT_FROM:-}" ]\
	&& ! [ -e "${BUILD_DLCACHEDIR}/${PKG_NAME}" ]\
	&& ! rtl_fileop mkdir "${BUILD_DLCACHEDIR}/${PKG_NAME}"; then
		return 1;
	else
		return 0;
	fi;
};

pkg_fetch_download() {
	if [ "${ARG_FETCH_FORCE:-}" != "offline" ]; then
		if [ -n "${PKG_URL:-}" ]; then
			if ! pkg_fetch_download_dlcache_subdir; then
				return 1;
			elif ! rtl_fetch_url_wget	\
					"${PKG_URL}" "${PKG_SHA256SUM}" "${BUILD_DLCACHEDIR}/${PKG_NAME}"\
					"${PKG_FNAME}" "${PKG_NAME}" "${PKG_MIRRORS:-}"; then
				return 1;
			fi;
		fi;
		if [ -n "${PKG_URLS_GIT:-}" ]; then
			if ! pkg_fetch_download_dlcache_subdir; then
				return 1;
			elif ! rtl_fetch_urls_git	\
					"${BUILD_DLCACHEDIR}/${PKG_NAME}" "${DEFAULT_GIT_ARGS}" "${PKG_BASE_DIR}"\
					"${PKG_NAME}" "${PKG_MIRRORS_GIT:-}" ${PKG_URLS_GIT}; then
				return 1;
			fi;
		fi;
		pkg_fetch_download_clean_dlcache "${BUILD_DLCACHEDIR}" "${PKG_NAME}" "${PKG_FNAME:-}" "${PKG_URLS_GIT:-}";
	fi;
};

# vim:filetype=sh