Support FEATURES=force-prefix.
[portage.git] / bin / ebuild-helpers / dosed
1 #!/bin/bash
2 # Copyright 1999-2011 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 if [[ $# -lt 1 ]] ; then
6         echo "!!! ${0##*/}: at least one argument needed" >&2
7         exit 1
8 fi
9
10 [[ " ${FEATURES} " == *" force-prefix "* ]] || \
11         case "$EAPI" in 0|1|2) ED=${D} ;; esac
12
13 ret=0
14 file_found=0
15 mysed="s:${ED}::g"
16
17 for x in "$@" ; do
18         y=$ED${x#/}
19         if [ -e "${y}" ] ; then
20                 if [ -f "${y}" ] ; then
21                         file_found=1
22                         sed -i -e "${mysed}" "${y}"
23                 else
24                         echo "${y} is not a regular file!" >&2
25                         false
26                 fi
27                 ((ret|=$?))
28         else
29                 mysed="${x}"
30         fi
31 done
32
33 if [ $file_found = 0 ] ; then
34         echo "!!! ${0##*/}: $y does not exist" 1>&2
35         ((ret|=1))
36 fi
37
38 exit $ret