#!/bin/bash . /etc/init.d/functions.sh autopatch() { local diff level p patches patched [[ ! -d "$PATCH_OVERLAY" ]] && return 0 patches=$(ls -1 ${PATCH_OVERLAY}/${CATEGORY}/${PN}/{${PN},${P},${PF}}--*.{patch,diff} 2>/dev/null) [[ $patches == "" ]] && return 0 if ! cd ${S}; then eerror "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 ebegin "auto patching (-p${level}) ${p}" patch -g0 -p${level} < $diff > /dev/null && patched=1 eend $? touch ${S}/.${p} fi fi done [[ $patched != 1 ]] && eerror "FAILED auto patching $p" else [[ ! -e $diff ]] && eerror "$diff does not exist, unable to auto patch" fi done cd $OLDPWD } #ewarn "at $EBUILD_PHASE" case $EBUILD_PHASE in compile) ebegin "Checking for auto patches in ${PATCH_OVERLAY}/${CATEGORY}/${PN}" if [[ ! -d "$PATCH_OVERLAY" ]]; then eend 1 eerror "PATCH_OVERLAY=$PATCH_OVERLAY is not a dir" else PATH=$PATH:/usr/sbin:/usr/bin:/bin:/sbin autopatch eend 0 fi ;; esac