summaryrefslogblamecommitdiffstats
path: root/bashrc
blob: a42b24b0e4e073fd6f49701a92a0b8c607f7e8c7 (plain) (tree)
1
2
3
4
5
6
7
8
9

           


                                      

             
                                           
 
                                             
 


                                                                                        
 
                                         
                                        
                      



                                
                                     
                                                              
                                                  








                                                                                

                                  

                                                        
                    
                                                                                               

                  

                        

 

                        

                                                                                       
                                                    
                                                                          
                    



                                                                

    
#!/bin/bash

if ! type einfo >/dev/null 2>&1 ; then
	. /etc/init.d/functions.sh
fi

autopatch() {
	local diff level p patches patchdir

	[[ ! -d "$PATCH_OVERLAY" ]] && return

	patchdir="${PATCH_OVERLAY}/${CATEGORY}/${PN}"
	patches=$(ls -1 ${patchdir}/{${PN},${P},${PF}}-[^0-9]*.{patch,diff} 2>/dev/null)
	[[ $patches == "" ]] && return

	if ! pushd ${S} &>/dev/null; then
		eerror "FAILED TO cd $S"
		return
	fi

	for p in ${patches}; do
		p=$(basename $p)
		diff=${patchdir}/${p}
		if [[ -e $diff ]] && [ ! -e ${S}/.${p} ]; then
			for level in 0 1 2 3 4; do
				patch -g0 --dry -p${level} >/dev/null < $diff

				if [ $? = 0 ]; then
					ebegin "auto patching (-p${level}) ${p}"
					patch -g0 -p${level} < $diff > /dev/null
					eend $?
					touch ${S}/.${p}

					continue 2
				fi
			done

			eerror "FAILED auto patching $p"
		else
			[[ ! -e $diff ]] && eerror "$diff does not exist, unable to auto patch"
		fi
	done

	popd &>/dev/null
}

case $EBUILD_PHASE in
	compile)	
		einfo "Checking for auto patches in ${PATCH_OVERLAY}/${CATEGORY}/${PN}"

		if [[ ! -d "$PATCH_OVERLAY" ]]; then
			eerror "PATCH_OVERLAY=$PATCH_OVERLAY is not a dir"
		else
			PATH=$PATH:/usr/sbin:/usr/bin:/bin:/sbin
			autopatch
		fi
	;;
esac