#!/usr/bin/env pkgcore-ebuild-helper
# Copyright: 2011 Brian Harring <ferringb@gmail.com>
# License: GPL2/BSD 3 clause

check_args 1 -

pattern="s:${ED}::g"

for x in "$@"; do
	trg=${ED}${x}
	if [[ ! -e ${trg} ]]; then
		pattern=${x}
		continue
	fi
	if [[ ! -f ${trg} ]]; then
		error "'${trg}' is not a regular file!";
		continue
	fi
	tmp_file=${T}/${trg##*/}
	if check_command cp "${trg}" "${tmp_file}"; then
		check_command sed -e "${pattern}" "${tmp_file}" > "${trg}"
		rm -f "${tmp_file}"
	fi
done
