/[autoepatch]/trunk/lib/functions.sh
Gentoo

Contents of /trunk/lib/functions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 19 - (show annotations) (download) (as text)
Mon Dec 18 21:45:32 2006 UTC (7 years, 6 months ago) by flameeyes
File MIME type: text/x-sh
File size: 3401 byte(s)
Fix typo: autepatch -> autoepatch.
1 # autoepatch - Automatic patch scripting
2 # Copyright (C) 2006 Gentoo Foundation
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with autoepatch; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18 # Check for gpatch present and use that if available; if not
19 # and patch is not GNU patch, warn that autoepatch might not
20 # work as intended
21 gpatch() {
22 if [[ -n ${GNU_PATCH} ]]; then
23 "${GNU_PATCH}" "$@"
24 return $?
25 fi
26
27 GNU_PATCH=$(type -p gpatch)
28 if [[ -z ${GNU_PATCH} ]]; then
29 if ! type -p patch; then
30 eerror "Unable to find a patch command to use"
31 return 1
32 fi
33
34 GNU_PATCH=$(type -p patch)
35 if ! "${GNU_PATCH}" --version </dev/null | grep -q "Free Software Foundation" &>/dev/null; then
36 ewarn "The ${GNU_PATCH} binary is not a GNU patch version, autoepatch might misbehave"
37 fi
38 fi
39
40 gpatch "${@}"
41 return $?
42 }
43
44 # Simple wrapper around debianutils mktemp and BSD mktemp,
45 # based on the emktemp function in eutils.eclass by
46 # Mike Frysinger (vapier@gentoo.org)
47 #
48 # Takes just 1 optional parameter (the directory to create tmpfile in)
49 emktemp() {
50 local exe="touch"
51 if [[ $1 == -d ]]; then
52 exe="mkdir"
53 shift
54 fi
55 local topdir=$1
56
57 if [[ -z ${topdir} ]] ; then
58 # ${T} is an ebuild variable, respect it
59 [[ -z ${T} ]] \
60 && topdir="/tmp" \
61 || topdir=${T}
62 fi
63
64 if [[ -z $(type -p mktemp) ]] ; then
65 local tmp=/
66 while [[ -e ${tmp} ]] ; do
67 tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM}
68 done
69 ${exe} "${tmp}" || ${exe} -p "${tmp}"
70 echo "${tmp}"
71 else
72 local mktemptype
73 mktemp -V &>/dev/null && \
74 mktemptype="debianutils" || \
75 mktemptype="bsd"
76
77 if [[ ${exe} == "touch" ]] ; then
78 [[ ${mktemptype} == "debianutils" ]] \
79 && mktemp -p "${topdir}" \
80 || TMPDIR="${topdir}" mktemp -t tmp
81 else
82 [[ ${mktemptype} == "debianutils" ]] \
83 && mktemp -d "${topdir}" \
84 || TMPDIR="${topdir}" mktemp -dt tmp
85 fi
86 fi
87 }
88
89 #
90 # See if we can apply $2 on $1, and if so, do it
91 #
92 try_patch() {
93 local target=$1
94 local patch=$2
95 local ret
96
97 local patchname="$(basename "$(dirname "${patch}")")-${patch##*/}"
98 if [[ -d "${target}" ]]; then
99 pushd "${target}" &>/dev/null
100
101 gpatch -g0 -p0 --dry-run <"${patch}" &> "${T}/autoepatch.$$.${patchname}.log" || \
102 return 1
103
104 ebegin " Applying ${patchname} ..."
105 patch -g0 -p0 --no-backup-if-mismatch "${patch}" &> "${T}/autoepatch.$$.${patchname}.log"
106 ret=$?
107 eend ${ret}
108
109 popd &>/dev/null
110 return ${ret}
111 else
112 gpatch -g0 --dry-run "${target}" "${patch}" &> "${T}/autoepatch.$$.${patchname}.log" || \
113 return 1
114
115 ebegin " Applying ${patchname} ..."
116 patch -g0 --no-backup-if-mismatch "${target}" "${patch}" &> "${T}/autoepatch.$$.${patchname}.log"
117 ret=$?
118 eend ${ret}
119
120 popd &>/dev/null
121 return ${ret}
122 fi
123
124 # Should never happen
125 return 1
126 }

  ViewVC Help
Powered by ViewVC 1.1.20