# /etc/portage/bashrc
# put patches and .tar.gz archives in /etc/portage/patches/cate-gory_package/
# no versioning, if the patch fails to apply with a newer version it should not continue
# (the archive may fail to extract after an upgrade if the directory name changes :/)

[ "$EBUILD_PHASE" != "depend" ] && echo "bashrc: $EBUILD_PHASE"
if [ "$EBUILD_PHASE" = "compile" ]; then
	if [ -d /etc/portage/patches/"$CATEGORY"_"$PN"/ ]; then
		. /etc/portage/bashrc_eutils
		find /etc/portage/patches/"$CATEGORY"_"$PN"/ -name '*.sh' | sort -n | while read script; do
			cd "$WORKDIR"
			ebegin Running "$script"
			PATH="/bin:/usr/bin/:$PATH" bash "$script"
			RES=$?
			eend $RES
			[ "$RES" = "0" ] || die
		done
		find /etc/portage/patches/"$CATEGORY"_"$PN"/ -name '*.patch' | sort -n | while read patch; do
			cd "$WORKDIR"
			PATH="/bin:/usr/bin/:$PATH" epatch "$patch"
		done
		find /etc/portage/patches/"$CATEGORY"_"$PN"/ -name '*.tar.gz' | sort -n | while read archive; do
			cd "$WORKDIR"
			ebegin Extracting "$archive"
			PATH="/bin:/usr/bin/:$PATH" tar xzf "$archive"
			RES=$?
			eend $RES
			[ "$RES" = "0" ] || die
		done
		cd "$PORTAGE_BUILDDIR"
	fi
fi
