Blame pkgtool.sh

Lucio Andrés Illanes Albornoz 8a27f9
#!/bin/sh
185480
# Copyright (c) 2020, 2021, 2022, 2023 LucĂ­a Andrea Illanes Albornoz <lucia@luciaillanes.de>
Lucio Andrés Illanes Albornoz 8a27f9
#
Lucio Andrés Illanes Albornoz 8a27f9
e9fa07
# {{{ pkgtoolp_init($_rstatus)
e9fa07
pkgtoolp_init() {
e9fa07
	local	_pi_rstatus="${1#\$}"						\
e9fa07
		_pi_args_long=""						\
e9fa07
		_pi_name_base="pkgtool"						\
e9fa07
		_pi_optstring="a:b:him:M:rRtv"					\
e9fa07
		_pi_prereqs="
e9fa07
			awk bzip2 cat chmod cp date find grep hostname mkdir
e9fa07
			mktemp mv paste printf readlink rm sed sort tar test
e9fa07
			touch tr uniq"						\
e9fa07
		_pi_fname="" _pi_rc=0;
e9fa07
	shift;
e9fa07
e9fa07
	if ! . "${0%/*}/subr.ex/ex_init.subr"; then
e9fa07
		_pi_rc=1;
e9fa07
		_pi_status='failed to source \`'"${0%/*}/subr/ex_init.subr"\';
e9fa07
		eval ${_pi_rstatus}=\"${_pi_status}\";
e9fa07
	elif ! ex_init_help						\
e9fa07
			"${_pi_rstatus}" "${_pi_args_long}"		\
e9fa07
			"${_pi_name_base}" "${_pi_optstring}" "${@}"	\
e9fa07
	  || ! ex_init_env						\
e9fa07
	  		"${_pi_rstatus}" \$BUILD_HNAME \$BUILD_USER	\
e9fa07
			"${_pi_name_base}"				\
e9fa07
	  || ! ex_init_getopts						\
e9fa07
	  		"${_pi_rstatus}" "pkgtoolp_init_getopts_fn"	\
e9fa07
			"${_pi_optstring}" "${@}"			\
e9fa07
	  || ! ex_init_prereqs "${_pi_rstatus}" "${_pi_prereqs}"	\
f6f7f2
	  || ! ex_pkg_load_vars						\
1aa81c
	  		"${_pi_rstatus}" \$ARCH \$BUILD_KIND		\
e9fa07
	  || ! pkgtoolp_init_args "${_pi_rstatus}";
e9fa07
	then
e9fa07
		_pi_rc=1;
e9fa07
	fi;
e9fa07
	return "${_pi_rc}";
e9fa07
};
e9fa07
# }}}
e9fa07
# {{{ pkgtoolp_init_args($_rstatus)
e9fa07
pkgtoolp_init_args() {
e9fa07
	local	_ppia_rstatus="${1#\$}"	\
e9fa07
		_ppia_rc=0;
e9fa07
e9fa07
	if [ "$((${ARG_INFO:-0}
e9fa07
	   + ${ARG_MIRROR:-0}
e9fa07
	   + ${ARG_RDEPENDS:-0}
e9fa07
	   + ${ARG_RDEPENDS_FULL:-0}
e9fa07
	   + ${ARG_TARBALL:-0}))" -gt 1 ];
e9fa07
	then
e9fa07
		cat etc/pkgtool.usage;
e9fa07
		_ppia_rc=1;
e9fa07
		rtl_setrstatus "${_ppia_rstatus}" 'only one of -i, -m and/or -M, -r, -R, -s, or -t must be specified.';
e9fa07
	elif [ "$((${ARG_INFO:-0}
e9fa07
	     + ${ARG_MIRROR:-0}
e9fa07
	     + ${ARG_RDEPENDS:-0}
e9fa07
	     + ${ARG_RDEPENDS_FULL:-0}
e9fa07
	     + ${ARG_TARBALL:-0}))" -eq 0 ];
e9fa07
	then
e9fa07
		cat etc/pkgtool.usage;
e9fa07
		_ppia_rc=1;
e9fa07
		rtl_setrstatus "${_ppia_rstatus}" 'one of -i, -m and/or -M, -r, -R, -s, or -t must be specified.';
e9fa07
	else
e9fa07
		_ppia_rc=0;
e9fa07
		export TMP="${BUILD_WORKDIR}" TMPDIR="${BUILD_WORKDIR}";
e9fa07
	fi;
e9fa07
e9fa07
	return "${_ppia_rc}";
e9fa07
};
e9fa07
# }}}
e9fa07
# {{{ pkgtoolp_init_getopts_fn(...)
e9fa07
pkgtoolp_init_getopts_fn() {
e9fa07
	local _ppigf_rc=0 _ppigf_shiftfl=0;
e9fa07
e9fa07
	case "${1}" in
e9fa07
	init)
e9fa07
		local	_ppigf_verb="${1}" _ppigf_rstatus="${2#\$}";
e9fa07
e9fa07
		: ${ARCH:="nt64"};
e9fa07
		: ${BUILD_KIND:="debug"};
e9fa07
e9fa07
		ARG_INFO=0; ARG_MIRROR=0; ARG_MIRROR_DNAME=""; ARG_MIRROR_DNAME_GIT="";
e9fa07
		ARG_RDEPENDS=0; ARG_RDEPENDS_FULL=0; ARG_TARBALL=0; ARG_VERBOSE=0;
e9fa07
		;;
e9fa07
e9fa07
	longopt)
e9fa07
		_ppigf_rc=1;
e9fa07
		;;
e9fa07
e9fa07
	opt)
e9fa07
		local	_ppigf_verb="${1}" _ppigf_rstatus="${2#\$}"	\
e9fa07
			_ppigf_opt="${3}" _ppigf_optarg="${4:-}";
e9fa07
		shift 4;
e9fa07
e9fa07
		case "${_ppigf_opt}" in
e9fa07
		a)	ARCH="${OPTARG}"; _ppigf_shiftfl=2; ;;
e9fa07
		b)	BUILD_KIND="${OPTARG}"; _ppigf_shiftfl=2; ;;
e9fa07
		h)	cat etc/pkgtool.usage; exit 0; ;;
e9fa07
		i)	ARG_INFO=1; _ppigf_shiftfl=1; ;;
e9fa07
		m)	ARG_MIRROR=1; ARG_MIRROR_DNAME="${OPTARG}"; _ppigf_shiftfl=2; ;;
e9fa07
		M)	ARG_MIRROR=1; ARG_MIRROR_DNAME_GIT="${OPTARG}"; _ppigf_shiftfl=2; ;;
e9fa07
		r)	ARG_RDEPENDS=1; _ppigf_shiftfl=1; ;;
e9fa07
		R)	ARG_RDEPENDS_FULL=1; _ppigf_shiftfl=1; ;;
e9fa07
		t)	ARG_TARBALL=1; _ppigf_shiftfl=1; ;;
e9fa07
		v)	ARG_VERBOSE=1; _ppigf_shiftfl=1; ;;
e9fa07
		*)	cat etc/pkgtool.usage; exit 1; ;;
e9fa07
		esac;
e9fa07
		;;
e9fa07
e9fa07
	nonopt)
e9fa07
		local _ppigf_verb="${1}" _ppigf_rstatus="${2#\$}";
e9fa07
		shift 2;
e9fa07
e9fa07
		case "${1}" in
f6f7f2
		*=*)	rtl_set_var_from_cmdline "${_ppigf_rstatus}" "${1}";
f6f7f2
			_ppigf_rc="${?}"; ;;
e9fa07
		*)	PKGTOOL_PKG_NAME="${1}"; ;;
e9fa07
		esac;
f6f7f2
f6f7f2
		if [ "${_ppigf_rc}" -ne 0 ]; then
f6f7f2
			return "${_ppigf_rc}";
f6f7f2
		else
f6f7f2
			_ppigf_shiftfl=1;
f6f7f2
		fi;
e9fa07
		;;
e9fa07
e9fa07
	done)
e9fa07
		local _ppigf_verb="${1}" _ppigf_rstatus="${2#\$}";
e9fa07
e9fa07
		if [ "${PKGTOOL_PKG_NAME:+1}" != 1 ]\
e9fa07
		&& [ "${ARG_MIRROR:-0}" -eq 0 ]; then
e9fa07
			_ppigf_rc=1;
e9fa07
			rtl_setrstatus "${_ppigf_rstatus}" 'missing package name.';
e9fa07
		else
e9fa07
			export PKGTOOL_PKG_NAME;
e9fa07
			case "${ARG_VERBOSE:-0}" in
e9fa07
e9fa07
			0)	rtl_log_enable_tags "${LOG_TAGS_normal}"; ;;
e9fa07
			1)	rtl_log_enable_tags "${LOG_TAGS_verbose}"; ;;
e9fa07
			*)	_ppigf_rc=1;
e9fa07
				rtl_setrstatus "${_ppigf_rstatus}" 'invalid verbosity level (max. -v)';
e9fa07
				;;
e9fa07
e9fa07
			esac;
e9fa07
		fi;
e9fa07
e9fa07
		if [ "${_ppigf_rc}" -ne 0 ]; then
e9fa07
			return "${_ppigf_rc}";
e9fa07
		fi;
e9fa07
		;;
e9fa07
e9fa07
	*)
e9fa07
		return 1;
e9fa07
		;;
e9fa07
	esac;
e9fa07
e9fa07
	if [ "${_ppigf_shiftfl}" -ge 1 ]; then
e9fa07
		return "$((${_ppigf_shiftfl} + 1))";
e9fa07
	else
e9fa07
		return 0;
e9fa07
	fi;
e9fa07
e9fa07
	return "${_ppigf_rc}";
e9fa07
};
e9fa07
# }}}
e9fa07
e9fa07
# {{{ pkgtoolp_info($_rstatus, $_pkg_name)
Lucio Andrés Illanes Albornoz 60fba6
pkgtoolp_info() {
e9fa07
	local	_ppi_rstatus="${1}" _ppi_pkg_name="${2}"				\
e9fa07
		_ppi_fname="" _ppi_group_name="" _ppi_groups="" _ppi_groups_noauto=""	\
e9fa07
		_ppi_pkg_disabled="" _ppi_pkg_finished="" _ppi_pkg_name_uc=""		\
e9fa07
		_ppi_pkg_names="" _ppi_rc=0;
e9fa07
	rtl_toupper2 \$_ppi_pkg_name \$_ppi_pkg_name_uc;
e9fa07
e9fa07
	if ! ex_pkg_load_groups \$_ppi_groups \$_ppi_groups_noauto \$GROUP_AUTO \$GROUP_TARGET; then
e9fa07
		_ppi_rc=1;
e9fa07
		rtl_setrstatus "${_ppi_rstatus}" 'Error: failed to load build groups.';
e9fa07
	elif ! ex_pkg_find_package \$_ppi_group_name "${_ppi_groups}" "${_ppi_pkg_name}"; then
e9fa07
		_ppi_rc=1;
e9fa07
		rtl_setrstatus "${_ppi_rstatus}" 'Error: unknown package \`'"${_ppi_pkg_name}'"'.';
e9fa07
	elif ! ex_pkg_get_packages \$_ppi_pkg_names "${_ppi_group_name}"; then
e9fa07
		_ppi_rc=1;
e9fa07
		rtl_setrstatus "${_ppi_rstatus}" 'Error: failed to expand package list of build group \`'"${_ppi_group_name}'"'.';
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}"\
e9fa07
			"${_ppi_group_name}" "${_ppi_pkg_name}" "" "${BUILD_WORKDIR}"; then
e9fa07
		_ppi_rc=1;
e9fa07
		rtl_setrstatus "${_ppi_rstatus}" 'Error: failed to set package environment for \`'"${_ppi_pkg_name}'"'.';
e9fa07
	else
e9fa07
		rtl_get_var_unsafe \$_ppi_pkg_version -u "PKG_${_ppi_pkg_name}_VERSION";
e9fa07
		rtl_log_env_vars "verbose" "package" $(rtl_get_vars_fast "^PKG_${_ppi_pkg_name_uc}");
e9fa07
		rtl_log_msg "info" "${MSG_pkgtool_build_group}" "${_ppi_group_name}";
e9fa07
e9fa07
		if [ "${PKG_DEPENDS:+1}" != 1 ]; then
e9fa07
			rtl_log_msg "info" "${MSG_pkgtool_pkg_no_deps}" "${_ppi_pkg_name}";
e9fa07
		else
e9fa07
			rtl_log_msg "info" "${MSG_pkgtool_pkg_direct_deps}" "${_ppi_pkg_name}" "${PKG_DEPENDS}";
e9fa07
			if ! ex_pkg_unfold_depends					\
e9fa07
					\$_ppi_pkg_disabled \$_ppi_pkg_finished		\
e9fa07
					\$_ppi_pkg_names 1 1 "${_ppi_group_name}"	\
e9fa07
					"${_ppi_pkg_names}" "${_ppi_pkg_name}" 0	\
e9fa07
					"${BUILD_WORKDIR}";
e9fa07
			then
e9fa07
				rtl_log_msg "warning" "${MSG_pkgtool_pkg_deps_fail}" "${_ppi_pkg_name}";
e9fa07
			else
e9fa07
				rtl_lfilter \$_ppi_pkg_names "${_ppi_pkg_name}";
e9fa07
e9fa07
				if [ "${_ppi_pkg_names:+1}" = 1 ]; then
Lucio Andrés Illanes Albornoz e493dc
					rtl_log_msg "info" "${MSG_pkgtool_pkg_deps_full}"\
e9fa07
							"${_ppi_pkg_name}" "$(rtl_lsort "${_ppi_pkg_names}")";
Lucio Andrés Illanes Albornoz 60fba6
				fi;
e9fa07
e9fa07
				if [ "${_ppi_pkg_disabled:+1}" = 1 ]; then
Lucio Andrés Illanes Albornoz e493dc
					rtl_log_msg "info" "${MSG_pkgtool_pkg_deps_full_disabled}"\
e9fa07
							"${_ppi_pkg_name}" "$(rtl_lsort "${_ppi_pkg_disabled}")";
Lucio Andrés Illanes Albornoz 60fba6
				fi;
Lucio Andrés Illanes Albornoz 60fba6
			fi;
Lucio Andrés Illanes Albornoz 60fba6
		fi;
e9fa07
Lucio Andrés Illanes Albornoz 1dd6a3
		set +o noglob;
e9fa07
		for _ppi_fname in													\
e9fa07
				"vars/${_ppi_pkg_name}.vars"										\
e9fa07
				"patches/${_ppi_pkg_name}/"*.patch									\
e9fa07
				"patches/${_ppi_pkg_name}${_ppi_pkg_version:+-${_ppi_pkg_version}}.local.patch"				\
e9fa07
				"patches/${_ppi_pkg_name}${_ppi_pkg_version:+-${_ppi_pkg_version}}.local@${BUILD_HNAME}.patch"		\
e9fa07
				"patches/${_ppi_pkg_name}${_ppi_pkg_version:+-${_ppi_pkg_version}}_ppi_pre.local.patch"			\
e9fa07
				"patches/${_ppi_pkg_name}${_ppi_pkg_version:+-${_ppi_pkg_version}}_ppi_pre.local@${BUILD_HNAME}.patch"	\
e9fa07
				"${BUILD_WORKDIR}/chainport/patches/${_ppi_pkg_name%%_ppi_*}/${_ppi_pkg_name%%_ppi_*}-${_ppi_pkg_version}.midipix.patch";
e9fa07
		do
e9fa07
			if [ -e "${_ppi_fname}" ]; then
e9fa07
				sha256sum "${_ppi_fname}";
Lucio Andrés Illanes Albornoz 1dd6a3
			fi;
Lucio Andrés Illanes Albornoz 1dd6a3
		done;
Lucio Andrés Illanes Albornoz 1dd6a3
		set -o noglob;
Lucio Andrés Illanes Albornoz 60fba6
e9fa07
	fi;
e9fa07
e9fa07
	return "${_ppi_rc}";
e9fa07
};
e9fa07
# }}}
e9fa07
# {{{ pkgtoolp_mirror($_rstatus, $_mirror_dname, $_mirror_dname_git)
Lucio Andrés Illanes Albornoz b63b9b
pkgtoolp_mirror() {
e9fa07
	local	_ppm_rstatus="${1}" _ppm_mirror_dname="${2}" _ppm_mirror_dname_git="${3}"	\
e9fa07
		_ppm_group_name="" _ppm_groups="" _ppm_groups_noauto="" _ppm_pkg_name=""	\
24c714
		_ppm_pkg_names="" _ppm_pkg_parent="" _ppm_pkgs_failed="" _ppm_rc=0;
Lucio Andrés Illanes Albornoz 368962
Lucio Andrés Illanes Albornoz 22d139
	umask 022;
e9fa07
	rtl_subst \$_ppm_mirror_dname "~" "${HOME}";
e9fa07
	rtl_subst \$_ppm_mirror_dname_git "~" "${HOME}";
e9fa07
e9fa07
	if ! ex_pkg_load_groups \$_ppm_groups \$_ppm_groups_noauto \$GROUP_AUTO \$GROUP_TARGET; then
e9fa07
		_ppm_rc=1;
e9fa07
		rtl_setrstatus "${_ppm_rstatus}" 'Error: failed to load build groups.';
e9fa07
	elif [ "${_ppm_mirror_dname:+1}" = 1 ]\
e9fa07
	&& ! rtl_fileop mkdir "${_ppm_mirror_dname}"; then
e9fa07
		_ppm_rc=1;
e9fa07
		rtl_setrstatus "${_ppm_rstatus}" 'Error: failed to create \`${_ppm_mirror_dname}'"'"'.';
e9fa07
	elif [ "${_ppm_mirror_dname_git:+1}" = 1 ]\
e9fa07
	&& ! rtl_fileop mkdir "${_ppm_mirror_dname_git}"; then
e9fa07
		_ppm_rc=1;
e9fa07
		rtl_setrstatus "${_ppm_rstatus}" 'Error: failed to create \`${_ppm_mirror_dname_git}'"'"'.';
e9fa07
	else
e9fa07
		for _ppm_group_name in ${_ppm_groups}; do
e9fa07
			ex_pkg_get_packages \$_ppm_pkg_names "${_ppm_group_name}";
e9fa07
e9fa07
			for _ppm_pkg_name in ${_ppm_pkg_names}; do
e9fa07
				rtl_get_var_unsafe \$_ppm_pkg_parent -u "PKG_${_ppm_pkg_name}_INHERIT_FROM";
e9fa07
				if ! pkgtoolp_mirror_fetch					\
e9fa07
						"${_ppm_rstatus}" "${_ppm_mirror_dname}"	\
e9fa07
						"${_ppm_mirror_dname_git}" "${_ppm_pkg_name}"	\
24c714
						"${_ppm_pkg_parent:-${_ppm_pkg_name}}"		\
24c714
						\$_ppm_pkgs_failed;
e9fa07
				then
e9fa07
					_ppm_rc=1;
24c714
					rtl_setrstatus "${_ppm_rstatus}" 'Warning: failed to mirror one or more packages: '"${_ppm_pkgs_failed}";
Lucio Andrés Illanes Albornoz 368962
				fi;
Lucio Andrés Illanes Albornoz b63b9b
			done;
Lucio Andrés Illanes Albornoz b63b9b
		done;
e9fa07
	fi;
Lucio Andrés Illanes Albornoz b63b9b
e9fa07
	return "${_ppm_rc}";
e9fa07
};
e9fa07
# }}}
24c714
# {{{ pkgtoolp_mirror_fetch($_rstatus, $_mirror_dname, $_mirror_dname_git, $_pkg_name, $_pkg_name_real, $_rpkgs_failed)
Lucio Andrés Illanes Albornoz b63b9b
pkgtoolp_mirror_fetch() {
e9fa07
	local	_ppmf_rstatus="${1}" _ppmf_mirror_dname="${2}" _ppmf_mirror_dname_git="${3}" _ppmf_pkg_name="${4}"	\
24c714
		_ppmf_pkg_name_real="${5}" _ppmf_rpkgs_failed="${6#\$}"							\
e9fa07
		_ppmf_fname="" _ppmf_pkg_disabled=0 _ppmf_pkg_fname="" _ppmf_pkg_mirrors_git="" _ppmf_pkg_sha256sum=""	\
e9fa07
		_ppmf_pkg_url="" _ppmf_pkg_urls_git="" _ppmf_rc=0;
e9fa07
e9fa07
	if rtl_get_var_unsafe \$_ppmf_pkg_disabled -u "PKG_${_ppmf_pkg_name_real}_DISABLED"\
e9fa07
	&& [ "${_ppmf_pkg_disabled:-0}" -eq 1 ]; then
e9fa07
		rtl_log_msg "verbose" "${MSG_pkgtool_pkg_disabled}" "${_ppmf_pkg_name}" "${_ppmf_pkg_name_real}";
e9fa07
	else
e9fa07
		if rtl_get_var_unsafe \$_ppmf_pkg_url -u "PKG_${_ppmf_pkg_name_real}_URL"\
7869da
		&& rtl_get_var_unsafe \$_ppmf_pkg_sha256sum -u "PKG_${_ppmf_pkg_name_real}_SHA256SUM"\
7869da
		&& [ "${_ppmf_pkg_url:+1}" = 1 ]\
7869da
		&& [ "${_ppmf_pkg_sha256sum:+1}" = 1 ];
7869da
		then
7869da
e9fa07
			if [ "${_ppmf_mirror_dname:+1}" != 1 ]; then
e9fa07
				_ppmf_rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_archive_mirror}" "${_ppmf_pkg_name}";
7869da
e9fa07
			elif [ "${_ppmf_pkg_name}" != "${_ppmf_pkg_name_real}" ]; then
e9fa07
				rtl_log_msg "info" "${MSG_pkgtool_pkg_archive_mirroring_parent}" "${_ppmf_pkg_name}" "${_ppmf_pkg_name_real}" "${_ppmf_pkg_url}";
e9fa07
				if ! rtl_fileop ln_symbolic "${_ppmf_pkg_name_real}" "${_ppmf_mirror_dname}/${_ppmf_pkg_name}"; then
e9fa07
					_ppmf_rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_link_fail}"\
e9fa07
							"${_ppmf_mirror_dname}/${_ppmf_pkg_name}" "${_ppmf_pkg_name}" "${_ppmf_pkg_name_real}";
Lucio Andrés Illanes Albornoz 368962
				fi;
7869da
Lucio Andrés Illanes Albornoz a50e83
			else
aec528
				if rtl_get_var_unsafe \$_ppmf_pkg_fname -u "PKG_${_ppmf_pkg_name_real}_FNAME"\
aec528
				&& [ "${_ppmf_pkg_fname:+1}" != 1 ]; then
e9fa07
					_ppmf_pkg_fname="${_ppmf_pkg_url##*/}";
Lucio Andrés Illanes Albornoz fe3fd1
				fi;
e9fa07
				rtl_log_msg "info" "${MSG_pkgtool_pkg_archive_mirroring}" "${_ppmf_pkg_name}" "${_ppmf_pkg_url}";
aec528
e9fa07
				if ! rtl_fileop mkdir "${_ppmf_mirror_dname}/${_ppmf_pkg_name}"\
aec528
				|| ! rtl_fetch_url_wget						\
aec528
						"${_ppmf_pkg_url}"				\
aec528
						"${_ppmf_pkg_sha256sum}"			\
aec528
						"${_ppmf_mirror_dname}/${_ppmf_pkg_name}"	\
aec528
						"${_ppmf_pkg_fname}" "${_ppmf_pkg_name_real}"	\
aec528
						"";
aec528
				then
24c714
					_ppmf_rc=1;
24c714
					rtl_log_msg "warning" "${MSG_pkgtool_pkg_mirror_fail}" "${_ppmf_pkg_name}";
24c714
					rtl_lconcat "${_ppmf_rpkgs_failed}" "${_ppmf_pkg_name}";
Lucio Andrés Illanes Albornoz 5daef9
				else
aec528
					rtl_fetch_clean_dlcache		\
aec528
					       "${_ppmf_mirror_dname}"	\
aec528
					       "${_ppmf_pkg_name}"	\
aec528
					       "${_ppmf_pkg_fname}"	\
aec528
					       "${_ppmf_pkg_urls_git}";
Lucio Andrés Illanes Albornoz 368962
				fi;
Lucio Andrés Illanes Albornoz a50e83
			fi;
7869da
Lucio Andrés Illanes Albornoz 2c5ce2
		fi;
e9fa07
7869da
		if rtl_get_var_unsafe \$_ppmf_pkg_urls_git -u "PKG_${_ppmf_pkg_name_real}_URLS_GIT"\
7869da
		&& [ "${_ppmf_pkg_urls_git:+1}" = 1 ];
7869da
		then
7869da
e9fa07
			if [ "${_ppmf_mirror_dname_git:+1}" != 1 ]; then
e9fa07
				_ppmf_rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_git_mirror}" "${_ppmf_pkg_name}";
7869da
e9fa07
			elif rtl_get_var_unsafe \$_ppmf_pkg_mirrors_git -u "PKG_${_ppmf_pkg_name_real}_MIRRORS_GIT"\
e9fa07
			&&   [ "${_ppmf_pkg_mirrors_git}" = "skip" ]; then
e9fa07
				_ppmf_rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_git_mirror_disabled}" "${_ppmf_pkg_name}";
7869da
e9fa07
			elif [ "${_ppmf_pkg_name}" != "${_ppmf_pkg_name_real}" ]; then
e9fa07
				rtl_log_msg "info" "${MSG_pkgtool_pkg_git_mirroring_parent}" "${_ppmf_pkg_name}" "${_ppmf_pkg_name_real}" "${_ppmf_pkg_urls_git}";
e9fa07
				if ! rtl_fileop ln_symbolic "${_ppmf_pkg_name_real}" "${_ppmf_mirror_dname_git}/${_ppmf_pkg_name}"; then
24c714
					_ppmf_rc=1;
24c714
					rtl_log_msg "warning" "${MSG_pkgtool_pkg_link_fail}"	\
24c714
						"${_ppmf_mirror_dname_git}/${_ppmf_pkg_name}" "${_ppmf_pkg_name}" "${_ppmf_pkg_name_real}";
24c714
					rtl_lconcat "${_ppmf_rpkgs_failed}" "${_ppmf_pkg_name}";
Lucio Andrés Illanes Albornoz 368962
				fi;
7869da
Lucio Andrés Illanes Albornoz a50e83
			else
e9fa07
				rtl_log_msg "info" "${MSG_pkgtool_pkg_git_mirroring}" "${_ppmf_pkg_name}" "${_ppmf_pkg_urls_git}";
e9fa07
				if ! rtl_fileop mkdir "${_ppmf_mirror_dname_git}/${_ppmf_pkg_name}"\
e9fa07
				|| ! rtl_fetch_mirror_urls_git "${DEFAULT_GIT_ARGS}" "${_ppmf_mirror_dname_git}/${_ppmf_pkg_name}" ${_ppmf_pkg_urls_git}; then
24c714
					_ppmf_rc=1;
24c714
					rtl_log_msg "warning" "${MSG_pkgtool_pkg_mirror_fail}" "${_ppmf_pkg_name}";
24c714
					rtl_lconcat "${_ppmf_rpkgs_failed}" "${_ppmf_pkg_name}";
Lucio Andrés Illanes Albornoz 2c5ce2
				else
e9fa07
					rtl_fetch_clean_dlcache "${_ppmf_mirror_dname_git}" "${_ppmf_pkg_name}" "${_ppmf_pkg_fname}" "${_ppmf_pkg_urls_git}";
Lucio Andrés Illanes Albornoz 368962
				fi;
Lucio Andrés Illanes Albornoz a50e83
			fi;
7869da
Lucio Andrés Illanes Albornoz 2c5ce2
		fi;
e9fa07
e9fa07
		if [ "${_ppmf_pkg_url:+1}" != 1 ]\
e9fa07
		&& [ "${_ppmf_pkg_sha256sum:+1}" != 1 ]\
e9fa07
		&& [ "${_ppmf_pkg_urls_git:+1}" != 1 ]; then
e9fa07
			_ppmf_rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_no_urls}" "${_ppmf_pkg_name}";
Lucio Andrés Illanes Albornoz b63b9b
		fi;
e9fa07
	fi;
Lucio Andrés Illanes Albornoz b63b9b
e9fa07
	return "${_ppmf_rc}";
Lucio Andrés Illanes Albornoz 8a27f9
};
e9fa07
# }}}
e9fa07
# {{{ pkgtoolp_rdepends($_rstatus, $_pkg_name, $_full_rdependsfl)
Lucio Andrés Illanes Albornoz 60fba6
pkgtoolp_rdepends() {
e9fa07
	local	_ppr_rstatus="${1}" _ppr_pkg_name="${2}" _ppr_full_rdependsfl="${3}"	\
e9fa07
		_ppr_depends="" _ppr_group_name="" _ppr_groups="" _ppr_groups_noauto=""	\
e9fa07
		_ppr_pkg_depends="" _ppr_pkg_disabled="" _ppr_pkg_finished=""		\
e9fa07
		_ppr_pkg_name_rdepend="" _ppr_pkg_names="" _ppr_pkg_rdepends=""		\
e9fa07
		_ppr_pkg_rdepends_direct="" _ppr_rc=0;
e9fa07
e9fa07
	if ! ex_pkg_load_groups \$_ppr_groups \$_ppr_groups_noauto \$GROUP_AUTO \$GROUP_TARGET; then
e9fa07
		_ppr_rc=1;
e9fa07
		rtl_setrstatus "${_ppr_rstatus}" 'Error: failed to load build groups.';
e9fa07
	elif ! ex_pkg_find_package \$_ppr_group_name "${_ppr_groups}" "${_ppr_pkg_name}"; then
e9fa07
		_ppr_rc=1;
e9fa07
		rtl_setrstatus "${_ppr_rstatus}" 'Error: unknown package \`'"${_ppr_pkg_name}'"'.';
e9fa07
	elif ! ex_pkg_get_packages \$_ppr_pkg_names "${_ppr_group_name}"; then
e9fa07
		_ppr_rc=1;
e9fa07
		rtl_setrstatus "${_ppr_rstatus}" 'Error: failed to expand package list of build group \`'"${_ppr_group_name}'"'.';
e9fa07
	elif ! ex_pkg_unfold_rdepends					\
e9fa07
			\$_ppr_pkg_disabled \$_ppr_pkg_finished		\
e9fa07
			\$_ppr_pkg_rdepends_direct			\
e9fa07
			"${_ppr_group_name}" "${_ppr_pkg_names}"	\
e9fa07
			"${_ppr_pkg_name}" 1 "${BUILD_WORKDIR}";
e9fa07
	then
e9fa07
		_ppr_rc=1;
e9fa07
		rtl_setrstatus "${_ppr_rstatus}" 'Error: failed to unfold reverse dependency-expanded package name list for \`'"${_ppr_pkg_name}'"'.';
e9fa07
	elif [ "${_ppr_pkg_disabled:+1}" != 1 ]\
e9fa07
	  && [ "${_ppr_pkg_finished:+1}" != 1 ]\
e9fa07
	  && [ "${_ppr_pkg_rdepends_direct:+1}" != 1 ];
e9fa07
	then
e9fa07
		rtl_log_msg "info" "${MSG_pkgtool_pkg_deps_rev_none}" "${_ppr_pkg_name}";
e9fa07
	else
e9fa07
		for _ppr_pkg_name_rdepend in $(rtl_lsort	\
e9fa07
				${_ppr_pkg_finished}		\
e9fa07
				${_ppr_pkg_rdepends_direct});
e9fa07
		do
e9fa07
			rtl_lconcat \$_ppr_pkg_rdepends "${_ppr_pkg_name_rdepend}";
e9fa07
e9fa07
			if [ "${_ppr_full_rdependsfl}" -eq 1 ]; then
e9fa07
				rtl_get_var_unsafe \$_ppr_depends -u "PKG_"${_ppr_pkg_name}"_DEPENDS";
e9fa07
				if rtl_lunfold_depends 'PKG_${_rld_name}_DEPENDS' \$_ppr_pkg_depends ${_ppr_depends}\
e9fa07
				&& [ "${_ppr_pkg_depends:+1}" = 1 ]; then
e9fa07
					rtl_lconcat \$_ppr_pkg_rdepends "?[33m${_ppr_pkg_depends}?[93m";
e9fa07
				fi;
Lucio Andrés Illanes Albornoz 57b30d
			fi;
Lucio Andrés Illanes Albornoz 57b30d
		done;
e9fa07
e9fa07
		if [ "${_ppr_pkg_rdepends:+1}" = 1 ]; then
e9fa07
			rtl_log_msg "info" "${MSG_pkgtool_pkgs_deps_rev}" "${_ppr_pkg_name}" "${_ppr_pkg_rdepends}";
Lucio Andrés Illanes Albornoz 60fba6
		fi;
e9fa07
e9fa07
		if [ "${_ppr_pkg_disabled:+1}" = 1 ]; then
e9fa07
			rtl_log_msg "info" "${MSG_pkgtool_pkgs_deps_rev_disabled}" "${_ppr_pkg_name}" "$(rtl_lsort "${_ppr_pkg_disabled}")";
Lucio Andrés Illanes Albornoz 60fba6
		fi;
e9fa07
	fi;
Lucio Andrés Illanes Albornoz 60fba6
e9fa07
	return "${_ppr_rc}";
Lucio Andrés Illanes Albornoz 8a27f9
};
e9fa07
# }}}
e9fa07
# {{{ pkgtoolp_tarball($_rstatus, $_pkg_name)
Lucio Andrés Illanes Albornoz 60fba6
pkgtoolp_tarball() {
e9fa07
	local	_ppt_rstatus="${1}" _ppt_pkg_name="${2}"				\
e9fa07
		_ppt_date="" _ppt_group_name="" _ppt_groups="" _ppt_groups_noauto=""	\
e9fa07
		_ppt_hname="" _ppt_pkg_name_full="" _ppt_pkg_version="" _ppt_rc=0	\
e9fa07
		_ppt_tarball_fname="";
Lucio Andrés Illanes Albornoz e493dc
e9fa07
	if ! ex_pkg_load_groups \$_ppt_groups \$_ppt_groups_noauto \$GROUP_AUTO \$GROUP_TARGET; then
e9fa07
		_ppt_rc=1;
e9fa07
		rtl_setrstatus "${_ppt_rstatus}" 'Error: failed to load build groups.';
e9fa07
	elif ! ex_pkg_find_package \$_ppt_group_name "${_ppt_groups}" "${_ppt_pkg_name}"; then
e9fa07
		_ppt_rc=1;
e9fa07
		rtl_setrstatus "${_ppt_rstatus}" 'Error: unknown package \`'"${_ppt_pkg_name}'"'.';
Lucio Andrés Illanes Albornoz 60fba6
	elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}"	\
e9fa07
			"${_ppt_group_name}" 0 "${_ppt_pkg_name}" "" "${BUILD_WORKDIR}";
e9fa07
	then
e9fa07
		_ppt_rc=1;
e9fa07
		rtl_setrstatus "${_ppt_rstatus}" 'Error: failed to set package environment for \`'"${_ppt_pkg_name}'"'.';
e9fa07
	elif ! _ppt_date="$(date +%Y%m%d_%H%M%S)"; then
e9fa07
		_ppt_rc=1;
e9fa07
		rtl_setrstatus "${_ppt_rstatus}" 'Error: failed to call date(1).';
e9fa07
	elif ! _ppt_hname="$(hostname -f)"; then
e9fa07
		_ppt_rc=1;
e9fa07
		rtl_setrstatus "${_ppt_rstatus}" 'Error: failed to call hostname(1).';
e9fa07
	else
e9fa07
		if [ "${PKG_VERSION:+1}" = 1 ]; then
e9fa07
			_ppt_pkg_name_full="${_ppt_pkg_name}-${PKG_VERSION}";
Lucio Andrés Illanes Albornoz 60fba6
		else
e9fa07
			_ppt_pkg_name_full="${_ppt_pkg_name}";
Lucio Andrés Illanes Albornoz 60fba6
		fi;
Lucio Andrés Illanes Albornoz 60fba6
e9fa07
		_ppt_tarball_fname="${_ppt_pkg_name_full}@${_ppt_hname}-${_ppt_date}.tbz2";
e9fa07
		rtl_log_msg "info" "${MSG_pkgtool_tarball_creating}" "${PKG_BASE_DIR}" "${_ppt_pkg_name}";
Lucio Andrés Illanes Albornoz e493dc
e9fa07
		if ! tar -C "${BUILD_WORKDIR}" -cpf -			\
e9fa07
				"${PKG_BASE_DIR#${BUILD_WORKDIR%/}/}"	\
e9fa07
				"${_ppt_pkg_name}_stderrout.log"	|\
e9fa07
					bzip2 -c -9 - > "${_ppt_tarball_fname}";
e9fa07
		then
e9fa07
			_ppt_rc=1;
e9fa07
			rtl_setrstatus "${_ppt_rstatus}" 'Error: failed to create compressed tarball of \`'"${PKG_BASE_DIR}'"' and \`'"${_ppt_pkg_name}"'_stderrout.log'"'"'.';
Lucio Andrés Illanes Albornoz b6a9a1
		else
e9fa07
			rtl_log_msg "info" "${MSG_pkgtool_tarball_created}" "${PKG_BASE_DIR}" "${_ppt_pkg_name}";
Lucio Andrés Illanes Albornoz b6a9a1
		fi;
e9fa07
	fi;
e9fa07
e9fa07
	return "${_ppt_rc}";
Lucio Andrés Illanes Albornoz 8a27f9
};
e9fa07
# }}}
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 8a27f9
pkgtool() {
e9fa07
	local	_rc=0 _status=""		\
e9fa07
		BUILD_GROUPS="" ARCH BUILD_KIND	\
e9fa07
		BUILD_WORKDIR PKGTOOL_PKGNAME PREFIX;
e9fa07
e9fa07
	if ! pkgtoolp_init \$_status "${@}"; then
e9fa07
		_rc=1;
e9fa07
		_status="Error: ${_status}";
e9fa07
	else
e9fa07
		case "1" in
e9fa07
		"${ARG_INFO:-0}")		pkgtoolp_info \$_status "${PKGTOOL_PKG_NAME}"; ;;
e9fa07
		"${ARG_MIRROR:-0}")		pkgtoolp_mirror \$_status "${ARG_MIRROR_DNAME}" "${ARG_MIRROR_DNAME_GIT}"; ;;
e9fa07
		"${ARG_RDEPENDS:-0}")		pkgtoolp_rdepends \$_status "${PKGTOOL_PKG_NAME}" 0; ;;
e9fa07
		"${ARG_RDEPENDS_FULL:-0}")	pkgtoolp_rdepends \$_status "${PKGTOOL_PKG_NAME}" 1; ;;
e9fa07
		"${ARG_TARBALL:-0}")		pkgtoolp_tarball \$_status "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		esac; _rc="${?}";
Lucio Andrés Illanes Albornoz b6a9a1
	fi;
e9fa07
Lucio Andrés Illanes Albornoz b6a9a1
	if [ "${_rc}" -ne 0 ]; then
e9fa07
		rtl_log_enable_tags "${LOG_TAGS_all}";
Lucio Andrés Illanes Albornoz dc07ba
		rtl_log_msg "fatalexit" "0;${_status}";
e9fa07
	elif [ "${_status:+1}" = 1 ]; then
e9fa07
		rtl_log_enable_tags "${LOG_TAGS_all}";
Lucio Andrés Illanes Albornoz dc07ba
		rtl_log_msg "info" "0;${_status}";
Lucio Andrés Illanes Albornoz 8a27f9
	fi;
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz e493dc
set +o errexit -o noglob -o nounset; pkgtool "${@}";
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 8a27f9
# vim:filetype=sh textwidth=0