summaryrefslogtreecommitdiffhomepage
path: root/subr/pkg_install.subr
blob: a37849929e8aefa9f2df539f6f4d54b410e895eb (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
#
# set +o errexit -o noglob -o nounset is assumed.
#

pkgp_install_perms() {
	local _destdir="${1}" _fname="" IFS;
	rtl_set_IFS_nl;
	for _fname in $(find "${_destdir}" -type d); do
		if ! rtl_fileop chmod 0755 "${_fname}"; then
			return 1;
		fi;
	done;
	for _fname in $(find "${_destdir}" \( -not -perm /0111 \) -type f); do
		if ! rtl_fileop chmod 0644 "${_fname}"; then
			return 1;
		fi;
	done;
	for _fname in $(find "${_destdir}" -perm /0111 -type f); do
		if ! rtl_fileop chmod 0755 "${_fname}"; then
			return 1;
		fi;
	done;
};

pkg_install() {
	local _destdir="" _destdir_prefix="" _pkglist_name="";
	if ! rtl_fileop mkdir "${PKG_PREFIX}"; then
		return 1;
	else	for _destdir in "${PKG_DESTDIR}:${PKG_PREFIX}" "${PKG_DESTDIR_HOST}:${PREFIX}"; do
			rtl_lassign "_destdir _destdir_prefix" ":" "${_destdir}";
			if [ -e "${_destdir}" ]; then
				pkgp_install_perms "${_destdir}";
				(set +o errexit -o noglob; rtl_flock_acquire 4 || exit "${?}"; date;
				trap "rm -f \"${BUILD_WORKDIR}/install.lock\"" EXIT;
				if ! tar -C "${_destdir}" -cpf - . | tar -C "${_destdir_prefix}" --overwrite -xpf -; then
					exit 1;
				fi) 4<>"${BUILD_WORKDIR}/install.lock";
			fi;
		done;
		if [ "${?}" -ne 0 ]; then
			return 1;
		elif [ "${PKG_PKGLIST_DISABLE:-0}" -eq 0 ]; then
			if [ ! -e "${PREFIX}/pkglist.${PKG_BUILD_TYPE}" ]\
			&& ! touch "${PREFIX}/pkglist.${PKG_BUILD_TYPE}"; then
				return 1;
			else
				_pkglist_name="${PKG_BASE_DIR##*/}"; _pkglist_name="${_pkglist_name%%-*}";
				if ! printf "%s\n" "${_pkglist_name}" >> "${PREFIX}/pkglist.${PKG_BUILD_TYPE}"; then
					return 1;
				fi;
			fi;
		fi;
	fi;
};

# vim:filetype=sh