aboutsummaryrefslogtreecommitdiff
path: root/bin/pkgwcp
blob: 164101c5e6b5c9635611e41d73d54cceff1639b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
}