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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#!/bin/bash
# autoepatch - Automatic patch scripting
# Copyright (C) 2006 Gentoo Foundation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with autoepatch; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
main() {
# To allow installing on any prefix, make sure that
# the prefix is actually set
local PREFIX="@PREFIX@"
[[ ${PREFIX//@/|} == "|PREFIX|" ]] && PREFIX="/usr"
# When running out of SVN, load local modules and
# libraries only.
local basedir="$(dirname $0)"
[[ $0 == "${PREFIX}/bin/autoepatch.sh" ]] && \
basedir="${PREFIX}/share/autoepatch"
# Source baselayout functions.sh for einfo/ewarn and similar
# functions. If on an offset prefix, use the prefixed path.
[[ ${PREFIX} == "/usr" ]] && \
source "/sbin/functions.sh" || \
source "${PREFIX}/sbin/functions.sh"
source "${basedir}/lib/functions.sh"
[[ -z ${CHOST} ]] && CHOST="$(portageq envvar CHOST)"
[[ -z ${WORKDIR} ]] && WORKDIR="$(pwd)"
[[ -z ${T} ]] && T="/tmp"
for patchset in "${basedir}"/patches/*; do
(
source "${patchset}/${patchset##*/}.sh"
targets="$(patch_targets)"
[[ -z ${targets} ]] && exit 0
einfo "Testing ${patchset##*/} ..."
while read target; do
einfo " on ${target##$(pwd)/} ..."
for patch in "${patchset}"/*.patch; do
if try_patch "${target}" "${patch}"; then
PATCH_APPLIED="yes"
break
fi
done
if type patch_trigger_action &>/dev/null; then
patch_trigger_action "${target}"
fi
# Check if the patchset requires us to fail if the
# patch is not applied. By default, don't.
if ! type patch_required &>/dev/null; then
patch_required() { return 1; }
fi
if ! type patch_failed_msg &>/dev/null; then
patch_failed_msg() {
eerror "Failed patch ${patchset##*/}"
}
fi
if [[ -z ${PATCH_APPLIED} ]]; then
if patch_required; then
patch_failed_msg && exit 2
else
ewarn " failed, but patch not required, ignoring."
fi
fi
done <<<"${targets}"
rm -f "${T}"/autoepatch.$$.*
exit 0
)
case $? in
0) ;; # All gone well
1) eerror "Error in subshell"; return 1 ;; # Something didn't go well
2) return 1;; # The patch failed to apply, already announced.
esac
done
IFS="${save_IFS}"
}
main
|