summaryrefslogtreecommitdiffhomepage
path: root/subr/ex_pkg_exec.subr
blob: 76294763498af3693602b17928395cc938abc75b (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
67
#
# set -o errexit -o noglob are assumed.
#

exp_pkg_exec_pre() {
	local _pkg_name="${1}" _tgt_name="${2}" _restart_at="${3}";
	if [ -z "${PKG_URL}" ]\
	&& [ -z "${PKG_URLS_GIT}" ]\
	&& [ -z "${PKG_VERSION}" ]\
	&& ! ex_rtl_test_cmd "pkg_${_pkg_name}_all"; then
		"${_dispatch_fn}" exec_missing "${_pkg_name}" "${_tgt_name}";
		return 1;
	elif ! ex_pkg_state_test "${_pkg_name}" "start" "${_restart_at}"; then
		if [ "${PKG_NO_CLEAN_BASE_DIR:-0}" -eq 0 ]; then
			ex_rtl_fileop rm "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}";
			ex_rtl_fileop mkdir "${PKG_BASE_DIR}";
		fi;
		ex_rtl_fileop mkdir "${PKG_BUILD_DIR}" "${PKG_DESTDIR}";
		ex_pkg_state_set "${_pkg_name}" "start";
	fi;
	ex_rtl_fileop cd "${PKG_BUILD_DIR}";
};

ex_pkg_exec() {
	local _pkg_name="${1}" _tgt_name="${2}" _restart_at="${3}"			\
		_step _step_cmd _step_cmd_pfx _step_rc;
	trap "if [ \${?} -eq 0 ]; then							\
		echo \"done ${_pkg_name} ${_tgt_name}\" >&3;				\
	      else									\
		echo \"fail ${_pkg_name} ${_tgt_name}\" >&3;				\
		pkill -U "${$}";							\
	      fi;" EXIT HUP INT TERM USR1 USR2;
	exp_pkg_exec_pre "${_pkg_name}" "${_tgt_name}" "${_restart_at}";
	"${_dispatch_fn}" exec_start "${_pkg_name}" "${_tgt_name}";
	if ex_rtl_test_cmd "pkg_${_pkg_name}_all"; then
		"pkg_${_pkg_name}_all" "${_restart_at}";
	else	set -- ${PKG_BUILD_STEPS};
		while [ ${#} -gt 0 ]; do
			_step="${1}"; shift;
			if ex_pkg_state_test "${_pkg_name}" "${_step}"			\
					"${_restart_at}"; then
				continue;
			else	ex_rtl_try_run						\
					"pkg_${_pkg_name}_${_step}_pre"			\
					"${_pkg_name}" "${_tgt_name}" "${_restart_at}";
				if ex_rtl_test_cmd "pkg_${_pkg_name}_${_step}"; then
					ex_rtl_try_run "pkg_${_pkg_name}_${_step}"	\
						"${_pkg_name}" "${_tgt_name}" "${_restart_at}";
				else
					ex_rtl_try_run "pkg_${_step}"			\
						"${_pkg_name}" "${_tgt_name}" "${_restart_at}";
				fi;
				ex_rtl_try_run						\
					"pkg_${_pkg_name}_${_step}_post"		\
					"${_pkg_name}" "${_tgt_name}" "${_restart_at}";

			fi;
			echo "step ${_pkg_name} ${_tgt_name} ${_step}" >&3;
			"${_dispatch_fn}" exec_step "${_pkg_name}" "${_tgt_name}" "${_step}";
			ex_pkg_state_set "${_pkg_name}" "${_step}" "${1:+-${1}}";
		done;
	fi;
	"${_dispatch_fn}" exec_finish "${_pkg_name}" "${_tgt_name}";
	ex_pkg_state_set "${_pkg_name}" finish;
};

# vim:filetype=sh