-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrypatch
executable file
·56 lines (47 loc) · 990 Bytes
/
trypatch
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
#
# trypatch is supposed to be drop-in replacement for patch
# The main purpose is to try applying the patch to see if it's
# applicable or fail w/o leaving you with reject files spread across
# the sources. You can run it against compressed patches
# most popular extensions are supported so you don't need to unpack
# the patch before you go.
#
TMP_FQN="/tmp/patch-$$.tmp"
my_OPTS=''
#: Del all -o -p -t -ions from command line
while :; do
case $1 in
-*)
my_OPTS="$my_OPTS $1"
shift
;;
--*)
my_OPTS="$my_OPTS $1"
shift
;;
--)
shift
break
;;
*)
break
;;
esac
done
CAT=cat
CATFILE="$1"
case "$1" in
*.bz2) CAT=bzcat ;;
*.gz) CAT=zcat ;;
*.xz) CAT=xzcat ;;
*.patch) CAT=cat ;;
*) CATFILE='-' ;;
esac
"$CAT" "$CATFILE" | tee "$TMP_FQN" | patch -s --dry-run $my_OPTS 1>&- 2>&- || {
echo 'Patch is not applicable... exiting' > /dev/stderr
rm "$TMP_FQN"
exit 1
}
patch -s $my_OPTS -i "$TMP_FQN" && echo Ok
rm "$TMP_FQN"