diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-03-12 00:28:45 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-03-12 00:28:45 +0000 |
commit | c9cf1a3a0bb3dc6ca5f801e6886fb4f0be90c767 (patch) | |
tree | 5e55a40e4c13d8c9ddd779ea6c4d395117d1fa99 /bin/ebuild-helpers/doins | |
parent | bc188208fd239d4f9f2be6ad5ab1ebdac3706572 (diff) | |
download | portage-c9cf1a3a0bb3dc6ca5f801e6886fb4f0be90c767.tar.gz portage-c9cf1a3a0bb3dc6ca5f801e6886fb4f0be90c767.tar.bz2 portage-c9cf1a3a0bb3dc6ca5f801e6886fb4f0be90c767.zip |
Move ebuild helpers into an ebuild-helpers subdirectory.
svn path=/main/trunk/; revision=13063
Diffstat (limited to 'bin/ebuild-helpers/doins')
-rwxr-xr-x | bin/ebuild-helpers/doins | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/bin/ebuild-helpers/doins b/bin/ebuild-helpers/doins new file mode 100755 index 000000000..8c06bfd9a --- /dev/null +++ b/bin/ebuild-helpers/doins @@ -0,0 +1,98 @@ +#!/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 + +export TMP=$T/.doins_tmp +# Use separate directories to avoid potential name collisions. +mkdir -p "$TMP"/{1,2} + +[[ ! -d ${D}${INSDESTTREE} ]] && dodir "${INSDESTTREE}" + +_doins() { + local mysrc="$1" mydir="$2" cleanup="" rval + + if [ -L "$mysrc" ] ; then + cp "$mysrc" "$TMP/2" + mysrc="$TMP/2/${mysrc##*/}" + cleanup=${mysrc} + fi + + install ${INSOPTIONS} "${mysrc}" "${D}${INSDESTTREE}/${mydir}" + rval=$? + [[ -n ${cleanup} ]] && rm -f "${cleanup}" + [ $rval -ne 0 ] && echo "!!! ${0##*/}: $mysrc does not exist" 1>&2 + 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 + x=${x##*/} + x_orig=$x + # Follow any symlinks recursively until we've got + # a normal directory for 'find' to traverse. + while [ -L "$x" ] ; do + pushd "$(readlink "$x")" >/dev/null + x=${PWD##*/} + pushd "${PWD%/*}" >/dev/null + done + if [[ $x != $x_orig ]] ; then + mv "$x" "$TMP/1/$x_orig" + pushd "$TMP/1" >/dev/null + fi + find "$x_orig" -type d -exec dodir "${INSDESTTREE}/{}" \; + find "$x_orig" \( -type f -or -type l \) -print0 | _xdoins + if [[ $x != $x_orig ]] ; then + popd >/dev/null + mv "$TMP/1/$x_orig" "$x" + fi + while popd >/dev/null 2>&1 ; do true ; done + ((++success)) + else + _doins "${x}" && ((++success)) + fi +done +rm -rf "$TMP" +[ $success -gt 0 ] && exit 0 || exit 1 |