#!/bin/sh set -eu usage='Update the source tree according to DIR.freshen, and if doing so creates the directory for the first time, apply all *.patch files in DIR.patches.' eval "$(args freshen-and-patch dir -u "$usage" -- "$@")" [ -f $dir.freshen ] || { echo "can't find freshen file: $dir.freshen" >&2 exit 2 } if [ -d $dir -o ! -d $dir.patches ]; then apply_patches=false else apply_patches=true fi freshen $dir if $apply_patches; then if [ -d $dir.patches ]; then for patch in $dir.patches/*.patch; do echo "freshen-and-patch: applying patch $patch" (cd $dir; patch --batch -p0 < $patch) done else echo "freshen-and-patch: no patch directory: $dir.patches" fi else echo "freshen-and-patch: source directory already existed; assumed patched" fi