]> git.ipfire.org Git - people/stevee/pakfire.git/blame - scripts/patch
Merge branch 'master' of ssh://git.ipfire.org/pub/git/oddments/pakfire
[people/stevee/pakfire.git] / scripts / 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
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 *.off)
59 # Ignore disabled patches.
60 continue
61 ;;
62 *)
63 echo >&2 " ERROR: Unknown filetype: ${patch}"
64 exit 1
65 ;;
66 esac
67
68 echo " Applying ${patch} (${options})..."
69 patch ${options} -i ${patch} || exit $?
70done
71
72exit 0