Automation patch script

so i havent done any quilting yet on patches, before i do i was curious if anyone had created a script for automating the patching procedure. can someone help me better understand how some people get the latest patches for optimization or relevant issues on the latest snapshots?

Are you asking about creating patches of your own? Or applying patches to your builds?

Also, snapsots have the latest versions, unless you are referring to external patches.

external patches to apply to latest snapshots
such as the ones in this build https://github.com/shunjou/openwrt-optimized-archer-c7-v2

i use quilt... but there are some caveats...

  1. quilt does not handle executable permissions for new files
  2. patches which contain PATCHES need to be applied after some packages source is unpacked... with the exception of general buildroot patches...

git is better... in many ways... but using it well, kind of needs good git understanding and buildroot understanding... it can be really hard for a beginner to keep/apply/test multiple patch sets unless you already have a grasp of how branches / tags / ignore work/s...

the best option is to do things manually.... at different levels... so you get to grips with the build stages... source locations... and what a "patch containing a patch" really translates to....

sample-excerpt-patchimport-by-fstring
patchbyfstring() { FN="patchbyfstring"; #1-fstring #2flagfile

if [ -f "$2" ]; then
	echo "       flagfile: $2 [present]" && return 1
fi

patchnum="`find $fstring -maxdepth 0 -mindepth 0 -type f -exec echo {} \; 2>/dev/null | wc -l`"
if [ $patchnum -eq 0 ]; then
	echo "$FN string-${fstring} patchnum:${patchnum} flagfile:${2} [none-found]" 3 0
else
	echo "$FN string-${fstring} patchnum:${patchnum} flagfile:${2} [found]" 3 0
	for f in `find $fstring -maxdepth 0 -mindepth 0 -type f -exec echo {} \;`; do
		if [ -f "./patches/`basename $f`" ]; then
			echo " [applied]"
		else
			echo "$f $msg"
			#quiltpatchapply "$f" # quilt import $f; quilt push #etc
			touch "${2}"
		fi
	done
fi

}

fstring="../somefolder/${rELEASE}-addbr-device-*-generic-*"
patchbyfstring "$fstring" "./.firstrun.patch.addbr.device"

tl;dr as others have indicated, it depends on what your trying to accomplish.

i've used both quilt and git... what I've done depends on the patch and what I'm trying to do. I've used quilt for editing kernel code (the openwrt wiki has sufficient instructions to get started) but I've only done this "manually."

Below is an excerpt from a automated bash script I use to "cherry pick" a git patch, apply my own patches (some of which I've done with quilt) and build an image with a custom kernel.

This excerpt won't run by itself but you'll get an idea of the steps...

k419() {
    cd ~/openwrt

    printf "#\n# make clean || distclean && create .config \n#\n"
    #$make clean
    $make distclean
    cp ~/openwrt/r7500v2/diffconfig.r7500v2 ~/openwrt/.config
    printf "#\n# END make clean && create .config \n#\n"
    
    #$git remote add -f chunkeey https://git.openwrt.org/openwrt/staging/chunkeey.git
    k419_commit_rem=c487a3680b0df8aa95391bbca14e07f429c3b130
    if [ $update_patch -eq 1 ]; then
	k419_commit_old=d5ab88c44c2fd94c369ad287e1af814202ddb8a6
	k419_commit_old_fn="./r7500v2/k419/ipq806x-k419-${k419_commit_old:0:10}.patch"
	#$git format-patch -1 <sha1> # export commit with <sha1> as patch
	#$git format-patch -3 HEAD --stdout > 0001-last-3-commits.patch
	$git format-patch -1 $k419_commit_old --stdout > $k419_commit_old_fn
    fi
    printf "#\n# git update from openwrt, push to nmrh master && update chunkeey\n#\n"
    $git checkout k419
    $git reset --hard origin/master
    $git checkout master
    $git fetch upstream
    $git rebase upstream/master
    $git push
    $git checkout k419 
    $git rebase master
    $git fetch chunkeey
    $git cherry-pick $k419_commit_rem
    if [ $update_patch -eq 1 ]; then
	newCommit=$($git rev-parse HEAD)
	k419_commit_new_fn="./r7500v2/k419/ipq806x-k419-${newCommit:0:10}.patch"
	$git format-patch -1 $newCommit --stdout > $k419_commit_new_fn
	printf "#\n# git diff k419 chunkeey patch\n#\n"
	$git diff $k419_commit_old_fn $k419_commit_new_fn
	printf "#\n# END git diff k419 chunkeey patch\n#\n"
    fi
    printf "#\n# END git update from openwrt\n#\n"

    #$rm $k419_commit_new_fn
    printf "#\n# git patching for k419\n#\n"
    #git format-patch -1 HEAD --stdout > 0000-ipq806x-k419-usb-dep-fix.patch
    $git am < ./r7500v2/k419/0000-ipq806x-k419-usb-dep-fix.patch
    $git am < ./r7500v2/k419/0001-ipq806x-k419-r7500v2-extend-overlay.patch
    $git am < ./r7500v2/k419/0002-ipq806x-k419-r7500v2-usb-fix.patch
    $git am < ./r7500v2/k419/0003-ipq806x-k419-r7800-usb-fix.patch
    $git am < ./r7500v2/k419/0004-ipq806x-k419-0067-patch-fix.patch
    $git am < ./r7500v2/k419/0005-ipq806x-k419-cpuidle-fix.patch
    $git am < ./r7500v2/k419/0006-ipq806x-k419-tsens-fix.patch
    $git am < ./r7500v2/k419/0007-ipq806x-r7500v2-force-ath10k-ct-htt-firmware.patch
    printf "#\n# END git patching for k419\n#\n"

    printf "#\n# git push to nmrh k419\n#\n"
    $git push --force origin k419
    printf "#\n# END git push to nmrh k419\n#\n"

    printf "#\n# feeds update && install\n#\n"
    ./scripts/feeds update -a
    ./scripts/feeds install -a    
    printf "#\n# END feeds update && install\n#\n"
    #$git remote rm chunkeey

    printf "#\n# menuconfig\n#\n"
    $make menuconfig
    printf "#\n# END menuconfig\n#\n"

    printf "#\n# defconfig \n#\n"
    $make defconfig
    #./scripts/diffconfig.sh > ./r7500v2/k419/diffconfig-`date +"%Y%m%d-%H%M"`
    printf "#\n# END defconfig && create diffconfig\n#\n"
    printf "#\n# download\n#\n"
    $make download
    printf "#\n# END download\n#\n"
    build
}

thanks @anon98444528 and @anon50098793 thats what i was looking for. i use to build em for a bit, then i got into cross compiling.