]> git.ipfire.org Git - people/ms/pakfire.git/blob - tools/patch
Add a missing command in clean section of a Makefile.
[people/ms/pakfire.git] / tools / patch
1 #!/bin/bash
2 # Script that automatically applies patches.
3
4 paths=
5 patches=
6
7 while [ $# -gt 0 ]; do
8 case "${1}" in
9 --search-path=*)
10 paths="${paths} ${1#--search-path=}"
11 ;;
12 *)
13 patches="${patches} ${1}"
14 ;;
15 esac
16 shift
17 done
18
19 if [ -n "${patches}" ]; then
20 echo "Applying patches..."
21 fi
22
23 # Apply all patches given on command line.
24 for patch in ${patches}; do
25 case "${patch}" in
26 /*)
27 ;;
28 *)
29 for path in ${paths}; do
30 if [ -e "${path}/${patch}" ]; then
31 patch="${path}/${patch}"
32 break
33 fi
34 done
35 ;;
36 esac
37
38 # Check if patch file does exist.
39 if ! [ -e "${patch}" ]; then
40 echo >&2 " ERROR: Patch file does not exist: ${patch}"
41 exit 1
42 fi
43
44 # Options applied to patch command.
45 options="-N"
46
47 # Get right -p1 option.
48 case "${patch}" in
49 *.patch[0-9])
50 # Get patch level from file name.
51 level=${patch:$(( ${#patch} - 1))}
52 options="${options} -p${level}"
53 ;;
54 *.patch|*.diff)
55 # Default is -p1.
56 options="${options} -p1"
57 ;;
58 *)
59 echo >&2 " WARNING: Ignoring unknown file: ${patch}"
60 continue
61 ;;
62 esac
63
64 echo " Applying ${patch} (${options})..."
65 patch ${options} -i ${patch} || exit $?
66 done
67
68 exit 0