]> git.ipfire.org Git - people/stevee/pakfire.git/blame - tools/patch
Translation updates.
[people/stevee/pakfire.git] / tools / patch
CommitLineData
49e0e073
MT
1#!/bin/bash
2# Script that automatically applies patches.
3
24992eab
MT
4paths=
5patches=
6
7while [ $# -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
17done
18
19if [ -n "${patches}" ]; then
49e0e073
MT
20 echo "Applying patches..."
21fi
22
23# Apply all patches given on command line.
24992eab
MT
24for 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
49e0e073
MT
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
4e652a76
MT
49 *.patch[0-9]|*.patch[0-9]R)
50 _patch="${patch}"
49e0e073 51 # Get patch level from file name.
4e652a76
MT
52 while [ ${#_patch} -gt 0 ]; do
53 last_pos=$(( ${#_patch} - 1 ))
54 last_char=${_patch:${last_pos}}
55 _patch=${_patch:0:${last_pos}}
56
57 case "${last_char}" in
58 [0-9])
59 options="${options} -p${last_char}"
60 break
61 ;;
62 R)
63 options="${options} -R"
64 ;;
65 esac
66 done
49e0e073
MT
67 ;;
68 *.patch|*.diff)
69 # Default is -p1.
70 options="${options} -p1"
71 ;;
49e0e073 72 *)
e620c728
MT
73 echo >&2 " WARNING: Ignoring unknown file: ${patch}"
74 continue
49e0e073
MT
75 ;;
76 esac
77
78 echo " Applying ${patch} (${options})..."
79 patch ${options} -i ${patch} || exit $?
80done
81
82exit 0