#!/bin/bash
# error
eecho() {
case "x${NOCOLOR}" in
x[y,Y][e,E][s,S]|x-[t,T][r,R][u,U][e,E]|x)
echo -ne '\e[1;31m * \e[0m';;
x*)
echo -n " * ";;
esac
echo "$*"
}
# warning
wecho() {
case "x${NOCOLOR}" in
x[y,Y][e,E][s,S]|x-[t,T][r,R][u,U][e,E]|x)
echo -ne '\e[1;33m * \e[0m';;
x*)
echo -n " * ";;
esac
echo "$*"
}
# positiv echo
pecho() {
case "x${NOCOLOR}" in
x[y,Y][e,E][s,S]|x-[t,T][r,R][u,U][e,E]|x)
echo -ne '\e[1;32m * \e[0m';;
x*)
echo -n " * ";;
esac
echo "$*"
}
# info
iecho() {
echo ">>> $*"
}
autopatch() {
local diff level p patches patched
[[ ! -d "$PATCH_OVERLAY" ]] && return 0
patches=$(ls -1 ${PATCH_OVERLAY}/${CATEGORY}/${PN}/${PN}-*.{patch,diff} 2>/dev/null)
[[ $patches == "" ]] && return 0
if ! cd ${S}; then
eecho "FAILED TO cd $S"
return 1
fi
for p in ${patches}; do
p=$(basename $p)
diff=${PATCH_OVERLAY}/${CATEGORY}/${PN}/${p}
if [[ -e $diff ]] && [ ! -e ${S}/.${p} ]; then
patched=0
for level in 0 1 2 3 4; do
if [[ $patched == 0 ]]; then
patch -g0 --dry -p${level} >/dev/null < $diff
if [ $? = 0 ]; then
pecho "auto patching (-p${level}) ${p}"
patch -g0 -p${level} < $diff > /dev/null && patched=1
touch ${S}/.${p}
fi
fi
done
[[ $patched != 1 ]] && eecho "FAILED auto patching $p"
else
[[ ! -e $diff ]] && eecho "$diff does not exist, unable to auto patch"
fi
done
cd $OLDPWD
}
wecho "at $EBUILD_PHASE"
case $EBUILD_PHASE in
compile)
if [[ ! -d "$PATCH_OVERLAY" ]]; then
eecho "PATCH_OVERLAY=$PATCH_OVERLAY is not a dir"
else
iecho "Checking for auto patches in ${PATCH_OVERLAY}/${CATEGORY}/${PN} ..."
PATH=$PATH:/usr/sbin:/usr/bin:/bin:/sbin
autopatch
fi
;;
post_sync)
OVERLAY_CONFIG_DIR="$(update-eix --print EIXCFGDIR)/overlays"
PORTDIR_OVERLAY="$(sed -ne 's/LOCATION="\([^"]*\)"/\1 /;t print; d; :print p' ${OVERLAY_CONFIG_DIR}/* | xargs echo)"
;;
esac