summaryrefslogtreecommitdiff
path: root/bin/doins
blob: c0a495aef29fd5a4bf99a6601ae3700696f8b1bf (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
#!/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
[[ -z ${INSDEPTH} ]] && declare -i INSDEPTH=0
if [[ ${INSDEPTH} -gt 30 ]] ; then
	echo "${0##*/}: sanity check ... 30 directories is too much :(" 2>&1
	exit 1
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}"

for x in "$@" ; do
	if [ -L "$x" ] ; then
		cp "$x" "${T}"
		mysrc="${T}/$(/usr/bin/basename "${x}")"
	elif [ -d "$x" ] ; then
		if [ "${DOINSRECUR}" == "n" ] ; then
			continue
		fi

		mydir="${INSDESTTREE}/$(basename "${x}")"
		find "${x}" -mindepth 1 -maxdepth 1 -exec \
			env \
				INSDESTTREE="${mydir}" \
				INSDEPTH=$((INSDEPTH+1)) \
				doins -r {} \;
		continue
	else
		mysrc="${x}"
	fi
	install ${INSOPTIONS} "${mysrc}" "${D}${INSDESTTREE}"
done