diff options
author | John Ankarström <john@ankarstrom.se> | 2021-07-27 17:56:32 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-07-27 17:56:32 +0200 |
commit | a6926740758524f2c10db70b851d8fc6809e9242 (patch) | |
tree | 89beebf3da00924ec2344303376a9468b8b23fce /bin/pkgwcp | |
parent | c1f551e00db12429b9df006ec200a56845d0f753 (diff) | |
download | patches-a6926740758524f2c10db70b851d8fc6809e9242.tar.gz |
Add pkgwcp script
Diffstat (limited to 'bin/pkgwcp')
-rwxr-xr-x | bin/pkgwcp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/bin/pkgwcp b/bin/pkgwcp new file mode 100755 index 0000000..164101c --- /dev/null +++ b/bin/pkgwcp @@ -0,0 +1,36 @@ +#!/bin/sh -e + +# pkgwcp -- create a working copy of modified files + +if [ $# -eq 0 ]; then + echo "usage: ${0##*/} name" 1>&2 + exit 1 +fi + +if [ -e "$1" ]; then + echo "${0##*/}: $1 already exists" 1>&2 + exit 1 +fi + +wd=${1%.pkgwcp}.pkgwcp +mkdir "$wd" + +find . -name '*.orig' -type f | { + i=0 + trap ' + echo "${0##*/}: $i pairs copied" 1>&2 + [ $i -eq 0 ] && { rm -r "$wd"; exit 1; } + echo "$wd" + trap - + ' INT QUIT EXIT + while read -r o; do + o=${o#./} + o=${o%.orig}.orig + n=${o%.orig} + dir="$(dirname "$wd/$o")" + [ -d "$dir" ] || mkdir -p "$dir" + cp "$o" "$wd/$o" + cp "$n" "$wd/$n" + : $((i++)) + done +} |