Bug #211949 - As suggested by vapier, tighten the variable filter to also
[portage.git] / bin / doins
1 #!/bin/bash
2 # Copyright 1999-2007 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Id$
5
6 source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh
7
8 if [ $# -lt 1 ] ; then
9         echo "${0##*/}: at least one argument needed" 1>&2
10         exit 1
11 fi
12
13 if [[ "$1" == "-r" ]] ; then
14         DOINSRECUR=y
15         shift
16 else
17         DOINSRECUR=n
18 fi
19 [[ -z ${INSDEPTH} ]] && declare -i INSDEPTH=0
20 if [[ ${INSDEPTH} -gt 30 ]] ; then
21         echo "${0##*/}: sanity check ... 30 directories is too much :(" 2>&1
22         exit 1
23 fi
24
25 if [[ ${INSDESTTREE#${D}} != "${INSDESTTREE}" ]]; then
26         vecho "-------------------------------------------------------" 1>&2
27         vecho "You should not use \${D} with helpers." 1>&2
28         vecho "  --> ${INSDESTTREE}" 1>&2
29         vecho "-------------------------------------------------------" 1>&2
30         exit 1
31 fi
32
33 [[ ! -d ${D}${INSDESTTREE} ]] && dodir "${INSDESTTREE}"
34
35 for x in "$@" ; do
36         if [ -L "$x" ] ; then
37                 cp "$x" "${T}"
38                 mysrc="${T}/$(/usr/bin/basename "${x}")"
39         elif [ -d "$x" ] ; then
40                 if [ "${DOINSRECUR}" == "n" ] ; then
41                         continue
42                 fi
43
44                 mydir="${INSDESTTREE}/$(basename "${x}")"
45                 find "${x}" -mindepth 1 -maxdepth 1 -exec \
46                         env \
47                                 INSDESTTREE="${mydir}" \
48                                 INSDEPTH=$((INSDEPTH+1)) \
49                                 doins -r {} \;
50                 continue
51         else
52                 mysrc="${x}"
53         fi
54         install ${INSOPTIONS} "${mysrc}" "${D}${INSDESTTREE}"
55 done