From a6926740758524f2c10db70b851d8fc6809e9242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 27 Jul 2021 17:56:32 +0200 Subject: Add pkgwcp script --- bin/pkgwcp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 bin/pkgwcp (limited to 'bin/pkgwcp') 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 +} -- cgit v1.2.3