summaryrefslogtreecommitdiffstats
path: root/bin/doins
blob: 57a21c4bb29a91dd3f11773e51f914725fb620b4 (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
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh

if [ $# -lt 1 ] ; then
	echo "${0##*/}: at least one argument needed" 1>&2
	exit 1
fi

if [[ "$1" == "-r" ]] ; then
	DOINSRECUR=y
	shift
else
	DOINSRECUR=n
fi

if [[ ${INSDESTTREE#${D}} != "${INSDESTTREE}" ]]; then
	vecho "-------------------------------------------------------" 1>&2
	vecho "You should not use \${D} with helpers." 1>&2
	vecho "  --> ${INSDESTTREE}" 1>&2
	vecho "-------------------------------------------------------" 1>&2
	exit 1
fi

[[ ! -d ${D}${INSDESTTREE} ]] && dodir "${INSDESTTREE}"

_doins() {
	local mysrc="$1" mydir="$2" cleanup="" rval

	if [ -L "$mysrc" ] ; then
		cp "$mysrc" "${T}"
		mysrc="${T}/${mysrc##*/}"
		cleanup=${mysrc}
	fi

	install ${INSOPTIONS} "${mysrc}" "${D}${INSDESTTREE}/${mydir}"
	rval=$?
	[[ -n ${cleanup} ]] && rm -f "${cleanup}"
	return $rval
}

_xdoins() {
	while read -d $'\0' x ; do
		_doins "$x" "${x%/*}"
	done
}

success=0

for x in "$@" ; do
	if [ -d "$x" ] ; then
		if [ "${DOINSRECUR}" == "n" ] ; then
			continue
		fi

		while [ "$x" != "${x%/}" ] ; do
			x=${x%/}
		done
		if [ "$x" = "${x%/*}" ] ; then
			pushd "$PWD" >/dev/null
		else
			pushd "${x%/*}" >/dev/null
		fi
		find "${x##*/}" -type d -exec dodir "${INSDESTTREE}/{}" \;
		find "${x##*/}" \( -type f -or -type l \) -print0 | _xdoins
		popd >/dev/null
		((++success))
	else
		_doins "${x}" && ((++success))
	fi
done

[ $success -gt 0 ] && exit 0 || exit 1