]>
Commit | Line | Data |
---|---|---|
1d7abbe3 | 1 | #!/bin/ksh |
44058243 | 2 | # |
dece74ed AM |
3 | # This program is free software, distributed under the terms of |
4 | # the GNU General Public License Version 2. | |
5 | # | |
cd445739 | 6 | # ----------- |
cd445739 | 7 | # Exit codes: |
2a5f078d | 8 | # 0 - succesful |
9 | # 1 - help displayed | |
10 | # 2 - no spec file name in cmdl parameters | |
11 | # 3 - spec file not stored in repo | |
12 | # 4 - some source, patch or icon files not stored in repo | |
13 | # 5 - package build failed | |
14 | # 6 - spec file with errors | |
15 | # 7 - wrong source in /etc/poldek.conf | |
16 | # 8 - Failed installing buildrequirements and subrequirements | |
17 | # 9 - Requested tag already exist | |
18 | # 10 - Refused to build fractional release | |
19 | # 100 - Unknown error (should not happen) | |
cd445739 AM |
20 | |
21 | # Notes (todo): | |
f7b91886 | 22 | # - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?) |
cd445739 | 23 | # - when Icon: field is present, -5 and -a5 doesn't work |
f3ada241 | 24 | # - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice) |
931a4acf | 25 | |
d43959a2 ER |
26 | RCSID='$Id$' |
27 | r=${RCSID#* * } | |
28 | rev=${r%% *} | |
2ce50eb7 | 29 | VERSION="v0.20/$rev" |
d43959a2 | 30 | VERSIONSTRING="\ |
c9acaed9 | 31 | Build package utility from PLD Linux CVS repository |
d43959a2 ER |
32 | $VERSION (C) 1999-2007 Free Penguins". |
33 | ||
d6a77ddb | 34 | PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin" |
b03f053b | 35 | |
cd445739 | 36 | COMMAND="build" |
64ea5308 | 37 | TARGET="" |
cd445739 | 38 | |
bde1c404 | 39 | SPECFILE="" |
d287305c | 40 | BE_VERBOSE="" |
4003ad8c | 41 | QUIET="" |
cd445739 AM |
42 | CLEAN="" |
43 | DEBUG="" | |
44 | NOURLS="" | |
45 | NOCVS="" | |
46 | NOCVSSPEC="" | |
47 | NODIST="" | |
47761337 | 48 | NOINIT="" |
bc10f694 | 49 | PREFMIRRORS="" |
cd445739 | 50 | UPDATE="" |
cd445739 AM |
51 | ADD5="" |
52 | NO5="" | |
53 | ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"} | |
c8f50498 | 54 | CVSROOT="" |
cdbd30e8 | 55 | GREEDSRC="" |
cd445739 | 56 | |
6c1b2e7d PZ |
57 | # use rpm 4.4.6+ digest format instead of comments if non-zero |
58 | USEDIGEST= | |
59 | ||
e3aa6f5e ER |
60 | # user agent when fetching files |
61 | USER_AGENT="PLD/Builder($VERSION)" | |
62 | ||
cd445739 AM |
63 | # It can be used i.e. in log file naming. |
64 | # See LOGFILE example. | |
65 | DATE=`date +%Y-%m-%d_%H-%M-%S` | |
66 | ||
67 | # Example: LOGFILE='../log.$PACKAGE_NAME' | |
68 | # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE' | |
69 | # Yes, you can use variable name! Note _single_ quotes! | |
70 | LOGFILE='' | |
71 | ||
72 | LOGDIR="" | |
73 | LOGDIROK="" | |
74 | LOGDIRFAIL="" | |
75 | LASTLOG_FILE="" | |
76 | ||
77 | CHMOD="no" | |
78 | CHMOD_MODE="0444" | |
79 | RPMOPTS="" | |
d1c5a9a7 | 80 | RPMBUILDOPTS="" |
cd445739 AM |
81 | BCOND="" |
82 | GROUP_BCONDS="no" | |
947025e5 | 83 | CVSIGNORE_DF="no" |
d287305c | 84 | |
85 | PATCHES="" | |
86 | SOURCES="" | |
cd445739 | 87 | ICONS="" |
d287305c | 88 | PACKAGE_RELEASE="" |
89 | PACKAGE_VERSION="" | |
90 | PACKAGE_NAME="" | |
14bead22 | 91 | ASSUMED_NAME="" |
cd445739 AM |
92 | PROTOCOL="ftp" |
93 | WGET_RETRIES=${MAX_WGET_RETRIES:-0} | |
94 | CVS_RETRIES=${MAX_CVS_RETRIES:-1000} | |
95 | ||
96 | CVSTAG="" | |
97 | RES_FILE="" | |
39dcc7de | 98 | CVS_FORCE="" |
cd445739 AM |
99 | |
100 | CVS_SERVER="cvs.pld-linux.org" | |
101 | DISTFILES_SERVER="://distfiles.pld-linux.org" | |
d4730dae | 102 | ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org" |
cd445739 | 103 | |
36d03934 | 104 | DEF_NICE_LEVEL=19 |
86aafdbe | 105 | SCHEDTOOL="auto" |
cd445739 AM |
106 | |
107 | FAIL_IF_NO_SOURCES="yes" | |
108 | ||
18e5347d ER |
109 | # let get_files skip over files which are present to get those damn files fetched |
110 | SKIP_EXISTING_FILES="no" | |
111 | ||
975d7b23 | 112 | TRY_UPGRADE="" |
257af81b ER |
113 | # should the specfile be restored if upgrade failed? |
114 | REVERT_BROKEN_UPGRADE="yes" | |
115 | ||
ab4a2b6e | 116 | if [ -x /usr/bin/rpm-getdeps ]; then |
ce40491a | 117 | FETCH_BUILD_REQUIRES_RPMGETDEPS="yes" |
ab4a2b6e | 118 | else |
ce40491a | 119 | FETCH_BUILD_REQUIRES_RPMGETDEPS="no" |
ab4a2b6e ER |
120 | fi |
121 | ||
cd445739 AM |
122 | # Here we load saved user environment used to |
123 | # predefine options set above, or passed to builder | |
124 | # in command line. | |
125 | # This one reads global system environment settings: | |
126 | if [ -f ~/etc/builderrc ]; then | |
127 | . ~/etc/builderrc | |
128 | fi | |
129 | # And this one cascades settings using user personal | |
130 | # builder settings. | |
131 | # Example of ~/.builderrc: | |
132 | # | |
133 | #UPDATE_POLDEK_INDEXES="yes" | |
134 | #FETCH_BUILD_REQUIRES="yes" | |
135 | #REMOVE_BUILD_REQUIRES="force" | |
136 | #GROUP_BCONDS="yes" | |
137 | #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE' | |
982e358c | 138 | #TITLECHANGE=no |
cd445739 | 139 | # |
a83e5405 | 140 | SU_SUDO="" |
cd445739 AM |
141 | if [ -n "$HOME_ETC" ]; then |
142 | USER_CFG="$HOME_ETC/.builderrc" | |
20117088 | 143 | BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros" |
cd445739 AM |
144 | else |
145 | USER_CFG=~/.builderrc | |
20117088 | 146 | BUILDER_MACROS=~/.builder-rpmmacros |
cd445739 AM |
147 | fi |
148 | ||
149 | [ -f "$USER_CFG" ] && . "$USER_CFG" | |
150 | ||
86aafdbe ER |
151 | if [ "$SCHEDTOOL" = "auto" ]; then |
152 | if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then | |
153 | SCHEDTOOL="schedtool -B -e" | |
154 | else | |
155 | SCHEDTOOL="no" | |
156 | fi | |
157 | fi | |
158 | ||
ca2e6c31 | 159 | if [ -n "$USE_PROZILLA" ]; then |
7e365483 KK |
160 | GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS" |
161 | GETURI2="$GETURI" | |
162 | OUTFILEOPT="-O" | |
ca2e6c31 | 163 | elif [ -n "$USE_AXEL" ]; then |
cede92b3 | 164 | GETURI="axel -a $AXEL_OPTS" |
7e365483 KK |
165 | GETURI2="$GETURI" |
166 | OUTFILEOPT="-o" | |
ca2e6c31 | 167 | else |
5700ee32 ER |
168 | wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate" |
169 | wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet" | |
170 | wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused" | |
e3aa6f5e | 171 | WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT" |
6f9a5d76 | 172 | |
7e365483 KK |
173 | GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS" |
174 | GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS" | |
175 | OUTFILEOPT="-O" | |
2bc5451f | 176 | fi |
11468b23 | 177 | |
11468b23 AM |
178 | GETLOCAL="cp -a" |
179 | ||
180 | if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then | |
181 | RPM="rpm" | |
182 | RPMBUILD="rpm" | |
183 | else | |
184 | RPM="rpm" | |
185 | RPMBUILD="rpmbuild" | |
186 | fi | |
187 | ||
188 | POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/" | |
a83e5405 | 189 | POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask" |
11468b23 | 190 | |
cd445739 AM |
191 | run_poldek() |
192 | { | |
193 | RES_FILE=~/tmp/poldek-exit-status.$RANDOM | |
194 | if [ -n "$LOGFILE" ]; then | |
195 | LOG=`eval echo $LOGFILE` | |
196 | if [ -n "$LASTLOG_FILE" ]; then | |
197 | echo "LASTLOG=$LOG" > $LASTLOG_FILE | |
198 | fi | |
86aafdbe | 199 | (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG |
cd445739 AM |
200 | return $exit_pldk |
201 | else | |
86aafdbe | 202 | (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null |
cd445739 AM |
203 | return `cat ${RES_FILE}` |
204 | rm -rf ${RES_FILE} | |
205 | fi | |
206 | } | |
207 | ||
cd445739 AM |
208 | #--------------------------------------------- |
209 | # functions | |
da946cd6 | 210 | |
5a491465 | 211 | usage() |
212 | { | |
cd445739 AM |
213 | if [ -n "$DEBUG" ]; then set -xv; fi |
214 | echo "\ | |
d43959a2 | 215 | Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|-ba|--build] |
6594293d | 216 | [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade] |
4efa0b98 | 217 | [{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] |
19dc5591 | 218 | [-g|--get] [-h|--help] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper] |
219 | [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>] | |
a7b2951c | 220 | [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version] |
f8dba812 | 221 | [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] [--use-greed-sources] |
6594293d | 222 | [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit] |
3009b80d | 223 | [--show-bconds] [--with/--without <feature>] [--define <macro> <value>] |
6594293d | 224 | <package>[.spec][:cvstag] |
2a5f078d | 225 | |
cd445739 AM |
226 | -5, --update-md5 - update md5 comments in spec, implies -nd -ncs |
227 | -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs | |
228 | -n5, --no-md5 - ignore md5 comments in spec | |
9243e80b ER |
229 | -D, --debug - enable builder script debugging mode, |
230 | -debug - produce rpm debug package (same as --opts -debug) | |
d43959a2 ER |
231 | -V, --version - output builder version string |
232 | --short-version - output builder short version | |
cd445739 AM |
233 | -a, --as_anon - get files via pserver as cvs@$CVS_SERVER, |
234 | -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package | |
235 | from <package>.spec, | |
236 | -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary | |
237 | only package from <package>.spec, | |
c56807e0 | 238 | -bp, --build-prep - execute the %prep phase of <package>.spec, |
6594293d AG |
239 | -bc - execute the %build phase of <package>.spec, |
240 | -bi - execute the %install phase of <package>.spec | |
241 | -bl - execute the %files phase of <package>.spec | |
cd445739 AM |
242 | -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack |
243 | them into src.rpm, | |
6594293d | 244 | --short-circuit - short-circuit build |
cd445739 AM |
245 | -B, --branch - add branch |
246 | -c, --clean - clean all temporarily created files (in BUILD, SOURCES, | |
6f10b394 ER |
247 | SPECS and \$RPM_BUILD_ROOT and CVS/Entries) after rpmbuild commands. |
248 | -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES, | |
249 | SPECS and \$RPM_BUILD_ROOT and CVS/Entries). Doesn't run | |
250 | any rpm building. | |
39dcc7de | 251 | -cf, --cvs-force - use -F when tagging (useful when moving branches) |
2a5f078d | 252 | -d <cvsroot>, --cvsroot <cvsroot> |
cd445739 AM |
253 | - setup \$CVSROOT, |
254 | --define <macro> <value> | |
255 | - define a macro <macro> with value <value>, | |
44058243 ER |
256 | --alt_kernel <kernel> |
257 | - same as --define 'alt_kernel <kernel>' | |
cd445739 AM |
258 | --nodeps - rpm won't check any dependences |
259 | -g, --get - get <package>.spec and all related files from CVS repo | |
260 | or HTTP/FTP, | |
261 | -h, --help - this message, | |
262 | --http - use http instead of ftp, | |
263 | -l <logfile>, --logtofile <logfile> | |
264 | - log all to file, | |
cd445739 AM |
265 | -nc, --no-cvs - don't download sources from CVS, if source URL is given, |
266 | -ncs, --no-cvs-specs | |
267 | - don't check specs in CVS | |
268 | -nd, --no-distfiles - don't download from distfiles | |
269 | -nm, --no-mirrors - don't download from mirror, if source URL is given, | |
270 | -nu, --no-urls - don't try to download from FTP/HTTP location, | |
271 | -ns, --no-srcs - don't download Sources | |
272 | -ns0, --no-source0 - don't download Source0 | |
273 | -nn, --no-net - don't download anything from the net | |
a93e8cdf | 274 | -pm, --prefer-mirrors - prefer mirrors (if any) over distfiles for SOURCES |
b572253e | 275 | --no-init - don't initialize builder paths (SPECS and SOURCES) |
18e5347d ER |
276 | -ske, |
277 | --skip-existing-files - skip existing files in get_files | |
cd445739 AM |
278 | --opts <rpm opts> - additional options for rpm |
279 | -q, --quiet - be quiet, | |
280 | --date yyyy-mm-dd - build package using resources from specified CVS date, | |
281 | -r <cvstag>, --cvstag <cvstag> | |
282 | - build package using resources from specified CVS tag, | |
5323fffd | 283 | -A - build package using CVS resources as any sticky tags/date/kopts being reset. |
cd445739 AM |
284 | -R, --fetch-build-requires |
285 | - fetch what is BuildRequired, | |
286 | -RB, --remove-build-requires | |
287 | - remove all you fetched with -R or --fetch-build-requires | |
288 | remember, this option requires confirmation, | |
289 | -FRB, --force-remove-build-requires | |
290 | - remove all you fetched with -R or --fetch-build-requires | |
291 | remember, this option works without confirmation, | |
06541433 JR |
292 | -sd, --source-distfiles - list sources available from distfiles (intended for offline |
293 | operations; does not work when Icon field is present | |
294 | but icon file is absent), | |
e15852ab | 295 | -sc, --source-cvs - list sources available from CVS |
06541433 JR |
296 | -sdp, --source-distfiles-paths - list sources available from distfiles - |
297 | paths relative to distfiles directory (intended for offline | |
298 | operations; does not work when Icon field is present | |
299 | but icon file is absent), | |
a7eefc54 | 300 | -sf, --source-files - list sources - bare filenames (intended for offline |
301 | operations; does not work when Icon field is present | |
3621e588 | 302 | but icon file is absent), |
a7eefc54 | 303 | -sp, --source-paths - list sources - filenames with full local paths (intended for |
304 | offline operations; does not work when Icon field is present | |
3621e588 | 305 | but icon file is absent), |
2dddf439 ER |
306 | -su, --source-urls - list urls - urls to sources and patches |
307 | intended for copying urls with spec with lots of macros in urls | |
cd445739 AM |
308 | -T <cvstag> , --tag <cvstag> |
309 | - add cvs tag <cvstag> for files, | |
310 | -Tvs, --tag-version-stable | |
094bd95b | 311 | - add cvs tags STABLE and NAME-VERSION-RELEASE for files, |
cd445739 AM |
312 | -Ts, --tag-stable |
313 | - add cvs tag STABLE for files, | |
cd445739 | 314 | -Tv, --tag-version |
1691a37b | 315 | - add cvs tag NAME-VERSION-RELEASE for files, |
cd445739 AM |
316 | -Tp, --tag-prefix <prefix> |
317 | - add <prefix> to NAME-VERSION-RELEASE tags, | |
318 | -tt, --test-tag <prefix> | |
319 | - fail if tag is already present, | |
50321881 JK |
320 | -ir, --integer-release-only |
321 | - allow only integer and snapshot releases | |
cd445739 AM |
322 | -v, --verbose - be verbose, |
323 | -u, --try-upgrade - check version, and try to upgrade package | |
324 | -un, --try-upgrade-with-float-version | |
325 | - as above, but allow float version | |
f8dba812 | 326 | --use-greed-sources |
327 | - try download source from tag head if don't find it in | |
328 | current tag | |
deccc50e | 329 | -U, --update - refetch sources, don't use distfiles, and update md5 comments |
cd445739 AM |
330 | -Upi, --update-poldek-indexes |
331 | - refresh or make poldek package index files. | |
c890b916 | 332 | -np, --nopatch <patchnumber> |
bed98670 | 333 | - don't apply <patchnumber> |
dfe2cb9a MK |
334 | --show-bconds - show available conditional builds, which can be used |
335 | - with --with and/or --without switches. | |
9b78be50 ER |
336 | --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by |
337 | ./repackage.sh script. in other words, the output is | |
338 | parseable by scripts. | |
cd445739 AM |
339 | --with/--without <feature> |
340 | - conditional build package depending on %_with_<feature>/ | |
341 | %_without_<feature> macro switch. You may now use | |
342 | --with feat1 feat2 feat3 --without feat4 feat5 --with feat6 | |
343 | constructions. Set GROUP_BCONDS to yes to make use of it. | |
6dd19291 | 344 | --target <platform>, --target=<platform> |
3621e588 ER |
345 | - build for platform <platform>. |
346 | --init-rpm-dir - initialize ~/rpm directory structure | |
5a491465 | 347 | " |
348 | } | |
349 | ||
c890b916 | 350 | update_shell_title() { |
a0d6396b | 351 | [ -t 1 ] || return |
0b65d15e ER |
352 | local len=${COLUMNS:-80} |
353 | local msg=$(echo "$*" | cut -c-$len) | |
354 | ||
e225de91 ER |
355 | if [ -n "$BE_VERBOSE" ]; then |
356 | echo >&2 "$(date +%s.%N) $*" | |
357 | fi | |
358 | ||
982e358c | 359 | if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then |
138bbc98 ER |
360 | local pkg |
361 | if [ -n "$PACKAGE_NAME" ]; then | |
362 | pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE} | |
363 | else | |
364 | pkg=${SPECFILE} | |
365 | fi | |
366 | ||
367 | msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg" | |
10c1e115 | 368 | msg="$(echo $msg | tr -d '\n\r')" |
982e358c MP |
369 | case "$TERM" in |
370 | cygwin|xterm*) | |
371 | echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007" | |
372 | ;; | |
373 | screen*) | |
374 | echo >&2 -ne "\033]0;$msg\007" | |
375 | ;; | |
376 | esac | |
377 | fi | |
c890b916 ER |
378 | } |
379 | ||
7e40520f ER |
380 | # set TARGET from BuildArch: from SPECFILE |
381 | set_spec_target() { | |
ce40491a ER |
382 | if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then |
383 | tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE) | |
384 | if [ "$tmp" ]; then | |
f9109a96 | 385 | target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}') |
7e40520f ER |
386 | TARGET="$tmp" |
387 | case "$RPMBUILD" in | |
388 | "rpmbuild") | |
f9109a96 | 389 | TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;; |
7e40520f | 390 | "rpm") |
ce40491a | 391 | TARGET_SWITCH="--target=$TARGET" ;; |
7e40520f | 392 | esac |
ce40491a ER |
393 | fi |
394 | fi | |
7e40520f ER |
395 | } |
396 | ||
ace3fd80 ER |
397 | # runs rpm with minimal macroset |
398 | minirpm() { | |
fa4bf1df | 399 | # we reset macros not to contain macros.build as all the %() macros are |
559d511f | 400 | # executed here, while none of them are actually needed. |
559d511f | 401 | # at the time of this writing macros.build + macros contained 70 "%(...)" macros. |
13c3c336 | 402 | safe_macrofiles=$(rpm --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ') |
ace3fd80 ER |
403 | |
404 | # TODO: move these to /usr/lib/rpm/macros | |
20117088 | 405 | cat > $BUILDER_MACROS <<'EOF' |
5b5e5f7f | 406 | %x8664 x86_64 amd64 ia32e |
f78a0bb7 | 407 | %alt_kernel %{nil} |
408 | %_alt_kernel %{nil} | |
fb198857 ER |
409 | %requires_releq_kernel_up %{nil} |
410 | %requires_releq_kernel_smp %{nil} | |
1b2bbc99 | 411 | %requires_releq_kernel %{nil} |
6b8134e3 | 412 | %requires_releq() %{nil} |
bb01dee9 | 413 | %pyrequires_eq() %{nil} |
559d511f | 414 | %requires_eq() %{nil} |
c13be3d1 | 415 | %requires_eq_to() %{nil} |
fb198857 ER |
416 | %releq_kernel_up ERROR |
417 | %releq_kernel_smp ERROR | |
1b2bbc99 | 418 | %releq_kernel ERROR |
74d9fd14 | 419 | %kgcc_package ERROR |
237bd3f1 | 420 | %_fontsdir ERROR |
7141278d | 421 | %ruby_version ERROR |
422 | %ruby_ver_requires_eq() %{nil} | |
423 | %ruby_mod_ver_requires_eq() %{nil} | |
c13be3d1 | 424 | %__php_api_requires() %{nil} |
7141278d | 425 | %php_major_version ERROR |
426 | %php_api_version ERROR | |
99f819cf AM |
427 | %requires_xorg_xserver_extension %{nil} |
428 | %requires_xorg_xserver_xinput %{nil} | |
429 | %requires_xorg_xserver_font %{nil} | |
430 | %requires_xorg_xserver_videodrv %{nil} | |
7141278d | 431 | %py_ver ERROR |
41035426 ER |
432 | %perl_vendorarch ERROR |
433 | %perl_vendorlib ERROR | |
703ae20b ER |
434 | # damn. need it here! - copied from /usr/lib/rpm/macros.build |
435 | %tmpdir %(echo "${TMPDIR:-/tmp}") | |
1f28fcb7 ER |
436 | %patchset_source(f:b:) %( |
437 | base=%{-b*}%{!-b*:10000}; | |
438 | start=$(expr $base + %1); | |
439 | end=$(expr $base + %{?2}%{!?2:%{1}}); | |
440 | # we need to call seq twice as it doesn't allow two formats | |
441 | seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1; | |
442 | seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2; | |
443 | paste %{tmpdir}/__ps{1,2}; | |
444 | rm -f %{tmpdir}/__ps{1,2}; | |
445 | ) \ | |
446 | %{nil} | |
fb198857 | 447 | EOF |
3d12d055 | 448 | if [ "$NOINIT" = "yes" ] ; then |
20117088 | 449 | cat >> $BUILDER_MACROS <<'EOF' |
3d12d055 JR |
450 | %_specdir ./ |
451 | %_sourcedir ./ | |
452 | EOF | |
c039643c | 453 | fi |
20117088 | 454 | eval $RPMBUILD --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $* 2>&1 |
ace3fd80 ER |
455 | } |
456 | ||
457 | cache_rpm_dump() { | |
458 | if [ -n "$DEBUG" ]; then | |
459 | set -x | |
460 | set -v | |
461 | fi | |
462 | ||
463 | update_shell_title "cache_rpm_dump" | |
464 | local rpm_dump | |
465 | rpm_dump=` | |
466 | # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES. | |
467 | dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump' | |
468 | case "$RPMBUILD" in | |
469 | rpm) | |
470 | ARGS='-bp' | |
471 | ;; | |
472 | rpmbuild) | |
473 | ARGS='--nodigest --nosignature --nobuild' | |
474 | ;; | |
475 | esac | |
476 | minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE | |
237bd3f1 | 477 | ` |
fb198857 | 478 | if [ $? -gt 0 ]; then |
237bd3f1 ER |
479 | error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p') |
480 | echo "$error" >&2 | |
518ff1fb | 481 | Exit_error err_build_fail |
fb198857 | 482 | fi |
d05e8080 ER |
483 | |
484 | # make small dump cache | |
485 | rpm_dump_cache=`echo "$rpm_dump" | awk ' | |
4e8c3089 ER |
486 | $2 ~ /^SOURCEURL/ {print} |
487 | $2 ~ /^PATCHURL/ {print} | |
488 | $2 ~ /^nosource/ {print} | |
489 | $2 ~ /^PACKAGE_/ {print} | |
d05e8080 ER |
490 | '` |
491 | ||
13974367 | 492 | update_shell_title "cache_rpm_dump: OK!" |
cd445739 AM |
493 | } |
494 | ||
ace3fd80 | 495 | rpm_dump() { |
cd445739 | 496 | if [ -z "$rpm_dump_cache" ] ; then |
d7b4d36e | 497 | echo "internal error: cache_rpm_dump not called! (missing %prep?)" 1>&2 |
cd445739 AM |
498 | fi |
499 | echo "$rpm_dump_cache" | |
500 | } | |
501 | ||
d05e8080 ER |
502 | get_icons() |
503 | { | |
504 | update_shell_title "get icons" | |
505 | ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`" | |
506 | if [ -z "$ICONS" ]; then | |
507 | return | |
508 | fi | |
509 | ||
975d7b23 | 510 | rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS |
d05e8080 ER |
511 | } |
512 | ||
59398507 | 513 | parse_spec() |
514 | { | |
af4d5315 | 515 | update_shell_title "parsing specfile" |
cd445739 | 516 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
517 | set -x |
518 | set -v | |
cd445739 | 519 | fi |
b2975fc3 | 520 | |
d05e8080 | 521 | # icons are needed for successful spec parse |
518ff1fb | 522 | get_icons |
d05e8080 | 523 | |
01fa66fc | 524 | cd $SPEC_DIR |
cd445739 | 525 | cache_rpm_dump |
00fcec7e | 526 | |
cd445739 AM |
527 | if [ "$NOSRCS" != "yes" ]; then |
528 | SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`" | |
529 | fi | |
7cb24972 | 530 | |
cd445739 AM |
531 | if (rpm_dump | grep -qEi ":.*nosource.*1"); then |
532 | FAIL_IF_NO_SOURCES="no" | |
533 | fi | |
534 | ||
535 | PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`" | |
536 | ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`" | |
dfe2b2d9 ER |
537 | PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}') |
538 | PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}') | |
539 | PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}') | |
78eab2a1 | 540 | |
0b4119a2 | 541 | if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then |
7854d40c | 542 | echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)" |
0b4119a2 JR |
543 | fi |
544 | ||
cd445739 AM |
545 | if [ -n "$BE_VERBOSE" ]; then |
546 | echo "- Sources : `nourl $SOURCES`" | |
547 | if [ -n "$PATCHES" ]; then | |
548 | echo "- Patches : `nourl $PATCHES`" | |
549 | else | |
550 | echo "- Patches : *no patches needed*" | |
551 | fi | |
552 | if [ -n "$ICONS" ]; then | |
553 | echo "- Icon : `nourl $ICONS`" | |
554 | else | |
555 | echo "- Icon : *no package icon*" | |
556 | fi | |
557 | echo "- Name : $PACKAGE_NAME" | |
558 | echo "- Version : $PACKAGE_VERSION" | |
559 | echo "- Release : $PACKAGE_RELEASE" | |
560 | fi | |
13974367 ER |
561 | |
562 | update_shell_title "parse_spec: OK!" | |
cd445739 AM |
563 | } |
564 | ||
565 | Exit_error() | |
566 | { | |
567 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
568 | set -x |
569 | set -v | |
cd445739 AM |
570 | fi |
571 | ||
572 | cd "$__PWD" | |
573 | ||
574 | case "$1" in | |
575 | "err_no_spec_in_cmdl" ) | |
576 | remove_build_requires | |
518ff1fb | 577 | echo "ERROR: spec file name not specified." |
cd445739 | 578 | exit 2 ;; |
a08d92fc ER |
579 | "err_invalid_cmdline" ) |
580 | echo "ERROR: invalid command line arg ($2)." | |
581 | exit 2 ;; | |
cd445739 AM |
582 | "err_no_spec_in_repo" ) |
583 | remove_build_requires | |
518ff1fb | 584 | echo "Error: spec file not stored in CVS repo." |
cd445739 AM |
585 | exit 3 ;; |
586 | "err_no_source_in_repo" ) | |
587 | remove_build_requires | |
518ff1fb | 588 | echo "Error: some source, patch or icon files not stored in CVS repo. ($2)" |
cd445739 AM |
589 | exit 4 ;; |
590 | "err_build_fail" ) | |
591 | remove_build_requires | |
518ff1fb | 592 | echo "Error: package build failed. (${2:-no more info})" |
cd445739 | 593 | exit 5 ;; |
78eab2a1 AM |
594 | "err_no_package_data" ) |
595 | remove_build_requires | |
596 | echo "Error: couldn't get out package name/version/release from spec file." | |
597 | exit 6 ;; | |
ce40491a | 598 | "err_tag_exists" ) |
50321881 | 599 | remove_build_requires |
518ff1fb | 600 | echo "Tag ${2} already exists (spec release: ${3})." |
50321881 | 601 | exit 9 ;; |
ce40491a | 602 | "err_fract_rel" ) |
50321881 | 603 | remove_build_requires |
518ff1fb | 604 | echo "Release ${2} not integer and not a snapshot." |
50321881 | 605 | exit 10 ;; |
fb96e0b5 AM |
606 | "err_branch_exists" ) |
607 | remove_build_requires | |
518ff1fb | 608 | echo "Tree branch already exists (${2})." |
fb96e0b5 | 609 | exit 11 ;; |
cfc497c0 ER |
610 | "err_acl_deny" ) |
611 | remove_build_requires | |
612 | echo "Error: conditions reject building this spec (${2})." | |
613 | exit 12 ;; | |
cd445739 | 614 | esac |
73848362 ER |
615 | echo "Unknown error." |
616 | exit 100 | |
cd445739 AM |
617 | } |
618 | ||
619 | init_builder() | |
620 | { | |
621 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
622 | set -x |
623 | set -v | |
0dd6320d | 624 | fi |
cd445739 | 625 | |
4aeb9973 | 626 | if [ "$NOINIT" != "yes" ] ; then |
a08cc47e ER |
627 | local extra |
628 | if [ "$ASSUMED_NAME" ]; then | |
629 | extra="--define 'name $ASSUMED_NAME'" | |
630 | fi | |
631 | SOURCE_DIR="`eval $RPM $RPMOPTS $extra --eval '%{_sourcedir}'`" | |
01fa66fc | 632 | SPEC_DIR="`eval $RPM $RPMOPTS $extra --eval '%{_specdir}'`" |
29e90b02 JR |
633 | else |
634 | SOURCE_DIR="." | |
01fa66fc | 635 | SPEC_DIR="." |
29e90b02 | 636 | fi |
cd445739 AM |
637 | |
638 | __PWD="`pwd`" | |
00fcec7e | 639 | } |
640 | ||
d6a77ddb | 641 | get_spec() |
1471f6d6 | 642 | { |
c890b916 | 643 | |
2e5be021 | 644 | update_shell_title "get_spec" |
c890b916 | 645 | |
cd445739 | 646 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
647 | set -x |
648 | set -v | |
cd445739 AM |
649 | fi |
650 | ||
01fa66fc | 651 | cd "$SPEC_DIR" |
049ab214 | 652 | if [ ! -f "$SPECFILE" ]; then |
518ff1fb | 653 | SPECFILE="`basename $SPECFILE .spec`.spec" |
cd445739 AM |
654 | fi |
655 | if [ "$NOCVSSPEC" != "yes" ]; then | |
cd445739 | 656 | |
049ab214 ER |
657 | if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then |
658 | echo "Warning: No CVS access defined - using local .spec file" | |
659 | NOCVSSPEC="yes" | |
cd445739 AM |
660 | fi |
661 | ||
049ab214 | 662 | cvsup "$SPECFILE" || Exit_error err_no_spec_in_repo |
cd445739 | 663 | fi |
049ab214 | 664 | |
cd445739 | 665 | if [ ! -f "$SPECFILE" ]; then |
518ff1fb | 666 | Exit_error err_no_spec_in_repo |
cd445739 AM |
667 | fi |
668 | ||
669 | if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then | |
670 | chmod $CHMOD_MODE $SPECFILE | |
671 | fi | |
672 | unset OPTIONS | |
a7eefc54 | 673 | [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE |
7e40520f | 674 | |
ce40491a | 675 | set_spec_target |
cd445739 AM |
676 | } |
677 | ||
678 | find_mirror() | |
679 | { | |
01fa66fc | 680 | cd "$SPEC_DIR" |
782518da | 681 | local url="$1" |
cd445739 AM |
682 | if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then |
683 | cvs update mirrors >&2 | |
684 | fi | |
685 | ||
686 | IFS="|" | |
782518da ER |
687 | local origin mirror name rest ol prefix |
688 | while read origin mirror name rest; do | |
689 | # skip comments and empty lines | |
690 | if [ -z "$origin" ] || [[ $origin == \#* ]]; then | |
691 | continue | |
692 | fi | |
cd445739 AM |
693 | ol=`echo -n "$origin"|wc -c` |
694 | prefix="`echo -n "$url" | head -c $ol`" | |
695 | if [ "$prefix" = "$origin" ] ; then | |
782518da | 696 | suffix="`echo "$url"|cut -b $((ol+1))-`" |
cd445739 AM |
697 | echo -n "$mirror$suffix" |
698 | return 0 | |
699 | fi | |
700 | done < mirrors | |
701 | echo "$url" | |
702 | } | |
703 | ||
e7e0d4ec | 704 | # Warning: unpredictable results if same URL used twice |
cd445739 AM |
705 | src_no () |
706 | { | |
01fa66fc | 707 | cd $SPEC_DIR |
cd445739 AM |
708 | rpm_dump | \ |
709 | grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \ | |
710 | sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \ | |
711 | head -n 1 | xargs | |
1471f6d6 | 712 | } |
713 | ||
e7e0d4ec | 714 | src_md5() |
8ba5cdda | 715 | { |
e7e0d4ec | 716 | [ "$NO5" = "yes" ] && return |
cd445739 AM |
717 | no=$(src_no "$1") |
718 | [ -z "$no" ] && return | |
01fa66fc | 719 | cd $SPEC_DIR |
e7e0d4ec ER |
720 | local md5 |
721 | ||
722 | if [ -f additional-md5sums ]; then | |
723 | local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::) | |
724 | if [ -z "$spec_rev" ]; then | |
725 | spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')" | |
726 | fi | |
727 | local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')" | |
728 | md5=$(grep -s -v '^#' additional-md5sums | \ | |
729 | grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \ | |
730 | sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \ | |
731 | grep -E '^[0-9a-f]{32}$') | |
732 | ||
733 | if [ "$md5" ]; then | |
734 | if [ $(echo "$md5" | wc -l) != 1 ] ; then | |
735 | echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2 | |
736 | fi | |
737 | echo "$md5" | tail -n 1 | |
738 | return | |
739 | fi | |
cd445739 | 740 | fi |
e7e0d4ec ER |
741 | |
742 | source_md5=`grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` | |
743 | if [ -n "$source_md5" ]; then | |
744 | echo $source_md5 | |
cd445739 | 745 | else |
7805dcb4 PZ |
746 | source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'` |
747 | if [ -n "$source_md5" ]; then | |
748 | echo $source_md5 | |
749 | else | |
750 | # we have empty SourceX-md5, but it is still possible | |
751 | # that we have NoSourceX-md5 AND NoSource: X | |
752 | nosource_md5=`grep -i "#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` | |
753 | if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then | |
754 | echo $nosource_md5 | |
755 | fi | |
cd445739 | 756 | fi |
cd445739 AM |
757 | fi |
758 | } | |
759 | ||
06541433 JR |
760 | distfiles_path () |
761 | { | |
762 | echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")" | |
763 | } | |
764 | ||
cd445739 AM |
765 | distfiles_url () |
766 | { | |
06541433 | 767 | echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")" |
cd445739 AM |
768 | } |
769 | ||
770 | distfiles_attic_url () | |
771 | { | |
06541433 | 772 | echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")" |
cd445739 AM |
773 | } |
774 | ||
775 | good_md5 () | |
776 | { | |
777 | md5=$(src_md5 "$1") | |
778 | [ "$md5" = "" ] || \ | |
779 | [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ] | |
8ba5cdda PG |
780 | } |
781 | ||
a4b50627 AF |
782 | good_size () |
783 | { | |
ce40491a ER |
784 | size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)" |
785 | [ -n "$size" -a "$size" -gt 0 ] | |
a4b50627 AF |
786 | } |
787 | ||
947025e5 | 788 | cvsignore_df () |
789 | { | |
790 | if [ "$CVSIGNORE_DF" != "yes" ]; then | |
791 | return | |
792 | fi | |
793 | cvsignore=${SOURCE_DIR}/.cvsignore | |
794 | if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then | |
795 | echo "$1" >> $cvsignore | |
796 | fi | |
797 | } | |
798 | ||
e7fa3b9f ER |
799 | cvsup() |
800 | { | |
ce40491a ER |
801 | update_shell_title "cvsup" |
802 | local OPTIONS="up " | |
803 | if [ -n "$CVSROOT" ]; then | |
804 | OPTIONS="-d $CVSROOT $OPTIONS" | |
805 | fi | |
b1c6aace | 806 | |
ce40491a ER |
807 | if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then |
808 | OPTIONS="$OPTIONS -A" | |
809 | else | |
810 | if [ -n "$CVSDATE" ]; then | |
811 | OPTIONS="$OPTIONS -D $CVSDATE" | |
812 | fi | |
813 | if [ -n "$CVSTAG" ]; then | |
814 | OPTIONS="$OPTIONS -r $CVSTAG" | |
815 | fi | |
816 | fi | |
e7fa3b9f | 817 | |
ce40491a ER |
818 | local result=1 |
819 | local retries_counter=0 | |
820 | if [ $# = 1 ]; then | |
821 | update_shell_title "cvsup: $*" | |
822 | else | |
823 | update_shell_title "cvsup: $# files" | |
824 | fi | |
825 | while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do | |
826 | retries_counter=$(( $retries_counter + 1 )) | |
827 | output=$(LC_ALL=C cvs $OPTIONS "$@" 2>&1) | |
828 | result=$? | |
829 | [ -n "$output" ] && echo "$output" | |
830 | if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then | |
831 | echo "Trying again [$*]... ($retries_counter)" | |
832 | update_shell_title "cvsup: retry #$retries_counter" | |
833 | sleep 2 | |
834 | continue | |
835 | else | |
836 | break | |
837 | fi | |
838 | done | |
839 | update_shell_title "cvsup: done!" | |
840 | return $result | |
e7fa3b9f ER |
841 | } |
842 | ||
71f8e908 ER |
843 | # returns true if "$1" is ftp, http or https protocol url |
844 | is_url() | |
845 | { | |
846 | case "$1" in | |
847 | ftp://*|http://*|https://*) | |
848 | return 0 | |
849 | ;; | |
850 | esac | |
851 | return 1 | |
852 | } | |
853 | ||
ecba6ad5 ER |
854 | update_md5() |
855 | { | |
856 | if [ $# -eq 0 ]; then | |
857 | return | |
858 | fi | |
859 | ||
860 | update_shell_title "update md5" | |
861 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
862 | set -x |
863 | set -v | |
ecba6ad5 ER |
864 | fi |
865 | ||
866 | cd "$SOURCE_DIR" | |
867 | ||
868 | # pass 1: check files to be fetched | |
869 | local todo | |
870 | local need_files | |
871 | for i in "$@"; do | |
872 | local fp=$(nourl "$i") | |
873 | local srcno=$(src_no "$i") | |
6392b5fd ER |
874 | if [ -n "$ADD5" ]; then |
875 | [ "$fp" = "$i" ] && continue # FIXME what is this check doing? | |
01fa66fc | 876 | grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $SPEC_DIR/$SPECFILE && continue |
6c1b2e7d | 877 | grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $SPEC_DIR/$SPECFILE && continue |
6392b5fd | 878 | else |
6c1b2e7d | 879 | grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $SPEC_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $SPEC_DIR/$SPECFILE || continue |
ecba6ad5 ER |
880 | fi |
881 | if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then | |
882 | need_files="$need_files $i" | |
883 | fi | |
884 | done | |
885 | ||
886 | # pass 1a: get needed files | |
887 | if [ "$need_files" ]; then | |
888 | get_files $need_files | |
889 | fi | |
890 | ||
891 | # pass 2: proceed with md5 adding or updating | |
892 | for i in "$@"; do | |
893 | local fp=$(nourl "$i") | |
894 | local srcno=$(src_no "$i") | |
01fa66fc | 895 | local md5=$(grep -iE '^#[ ]*(No)?Source'$srcno'-md5[ ]*:' $SPEC_DIR/$SPECFILE ) |
6c1b2e7d PZ |
896 | if [ -z "$md5"]; then |
897 | md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $SPEC_DIR/$SPECFILE ) | |
898 | fi | |
71f8e908 | 899 | if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then |
6c1b2e7d | 900 | local tag="# Source$srcno-md5:\t" |
71f8e908 | 901 | if [[ "$md5" == *NoSource* ]]; then |
6c1b2e7d PZ |
902 | tag="# NoSource$srcno-md5:\t" |
903 | elif [ -n "$USEDIGEST" ]; then | |
904 | tag="BuildRequires:\tdigest(%SOURCE$srcno) = " | |
71f8e908 | 905 | fi |
ecba6ad5 | 906 | md5=$(md5sum "$fp" | cut -f1 -d' ') |
4efa0b98 | 907 | echo "Updating $tag ($md5: $fp)." |
ecba6ad5 | 908 | perl -i -ne ' |
6c1b2e7d PZ |
909 | print unless (/^\s*#\s*(No)?Source'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i); |
910 | print "'"$tag$md5"'\n" if /^Source'$srcno'\s*:\s+/; | |
ecba6ad5 | 911 | ' \ |
01fa66fc | 912 | $SPEC_DIR/$SPECFILE |
ecba6ad5 ER |
913 | fi |
914 | done | |
915 | } | |
916 | ||
917 | check_md5() | |
918 | { | |
919 | update_shell_title "check md5" | |
920 | ||
921 | for i in "$@"; do | |
922 | if good_md5 "$i" && good_size "$i"; then | |
923 | continue | |
924 | fi | |
925 | ||
926 | echo "MD5 sum mismatch or 0 size. Use -U to refetch sources," | |
927 | echo "or -5 to update md5 sums, if you're sure files are correct." | |
928 | Exit_error err_no_source_in_repo $i | |
929 | done | |
930 | } | |
931 | ||
cd445739 AM |
932 | get_files() |
933 | { | |
7cb24972 | 934 | update_shell_title "get_files" |
cd445739 AM |
935 | |
936 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
937 | set -x |
938 | set -v | |
cd445739 AM |
939 | fi |
940 | ||
f09c0772 | 941 | if [ $# -gt 0 ]; then |
cd445739 AM |
942 | cd "$SOURCE_DIR" |
943 | ||
b1c6aace | 944 | if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then |
049ab214 | 945 | echo "Warning: No CVS access defined for SOURCES" |
b1c6aace ER |
946 | NOCVS="yes" |
947 | fi | |
948 | ||
f2e42a41 | 949 | local nc=0 |
e7fa3b9f | 950 | local get_files_cvs="" |
3815b69a | 951 | for i in "$@"; do |
f2e42a41 | 952 | nc=$((nc + 1)) |
dcebdffb | 953 | local cvsup=0 |
3815b69a | 954 | SHELL_TITLE_PREFIX="get_files[$nc/$#]" |
f2e42a41 | 955 | update_shell_title "$i" |
f09c0772 | 956 | local fp=`nourl "$i"` |
ecba6ad5 | 957 | if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then |
ce40491a | 958 | continue |
18e5347d | 959 | fi |
ecba6ad5 | 960 | |
cd445739 | 961 | FROM_DISTFILES=0 |
e7e0d4ec | 962 | local srcmd5=$(src_md5 "$i") |
ecba6ad5 ER |
963 | |
964 | # we know if source/patch is present in cvs/distfiles | |
965 | # - has md5 (in distfiles) | |
966 | # - in cvs... ideas? | |
967 | ||
968 | # CHECK: local file didn't exist or always cvs up (first) requested. | |
f09c0772 | 969 | if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then |
cd445739 AM |
970 | if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then |
971 | echo "Warning: no URL given for $i" | |
972 | fi | |
973 | ||
e7e0d4ec | 974 | if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then |
a4b50627 | 975 | if good_md5 "$i" && good_size "$i"; then |
e7e0d4ec | 976 | echo "$fp having proper md5sum already exists" |
cd445739 AM |
977 | continue |
978 | fi | |
4ea1c265 | 979 | target="$fp" |
28b34560 | 980 | |
bc10f694 | 981 | # optionally prefer mirror over distfiles if there's mirror |
28b34560 | 982 | # TODO: build url list and then try each url from the list |
bc10f694 | 983 | if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then |
28b34560 ER |
984 | url="$im" |
985 | else | |
986 | url=$(distfiles_url "$i") | |
987 | fi | |
988 | ||
cd445739 AM |
989 | url_attic=$(distfiles_attic_url "$i") |
990 | FROM_DISTFILES=1 | |
ecba6ad5 ER |
991 | # is $url local file? |
992 | if [[ "$url" = [./]* ]]; then | |
18a52930 | 993 | update_shell_title "${GETLOCAL%% *}: $url" |
cd445739 AM |
994 | ${GETLOCAL} $url $target |
995 | else | |
996 | if [ -z "$NOMIRRORS" ]; then | |
9e9f8920 | 997 | url=$(find_mirror "$url") |
cd445739 | 998 | fi |
9e9f8920 ER |
999 | |
1000 | local uri=${url} | |
1001 | # make shorter message for distfiles urls | |
1002 | if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then | |
1003 | uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/} | |
1004 | uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/} | |
1005 | uri="df: $uri" | |
1006 | fi | |
1007 | update_shell_title "${GETURI%% *}: $uri" | |
ca2e6c31 | 1008 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
33da77c4 | 1009 | if [ "`echo $url | grep -E 'ftp://'`" ]; then |
18a52930 | 1010 | update_shell_title "${GETURI2%% *}: $url" |
ca2e6c31 | 1011 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
cd445739 AM |
1012 | fi |
1013 | fi | |
ecba6ad5 ER |
1014 | |
1015 | # is it empty file? | |
1016 | if [ ! -s "$target" ]; then | |
cd445739 AM |
1017 | rm -f "$target" |
1018 | if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then | |
18a52930 | 1019 | update_shell_title "${GETLOCAL%% *}: $url_attic" |
cd445739 AM |
1020 | ${GETLOCAL} $url_attic $target |
1021 | else | |
1022 | if [ -z "$NOMIRRORS" ]; then | |
1023 | url_attic="`find_mirror "$url_attic"`" | |
1024 | fi | |
18a52930 | 1025 | update_shell_title "${GETURI%% *}: $url_attic" |
ca2e6c31 | 1026 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
33da77c4 | 1027 | if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then |
ce40491a | 1028 | update_shell_title "${GETURI2%% *}: $url_attic" |
ca2e6c31 | 1029 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
cd445739 AM |
1030 | fi |
1031 | fi | |
1032 | fi | |
ecba6ad5 ER |
1033 | |
1034 | if [ -s "$target" ]; then | |
947025e5 | 1035 | cvsignore_df $target |
1036 | else | |
cd445739 AM |
1037 | rm -f "$target" |
1038 | FROM_DISTFILES=0 | |
1039 | fi | |
e7e0d4ec | 1040 | elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then |
d05e8080 ER |
1041 | if [ $# -gt 1 ]; then |
1042 | get_files_cvs="$get_files_cvs $fp" | |
1043 | update_shell_title "$fp (will cvs up later)" | |
1044 | cvsup=1 | |
1045 | else | |
1046 | cvsup $fp | |
1047 | fi | |
cd445739 AM |
1048 | fi |
1049 | ||
f09c0772 | 1050 | if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then |
cd445739 AM |
1051 | if [ -z "$NOMIRRORS" ]; then |
1052 | im="`find_mirror "$i"`" | |
1053 | else | |
1054 | im="$i" | |
1055 | fi | |
ce40491a | 1056 | update_shell_title "${GETURI%% *}: $im" |
cd445739 | 1057 | ${GETURI} "$im" || \ |
33da77c4 | 1058 | if [ "`echo $im | grep -E 'ftp://'`" ]; then |
ce40491a | 1059 | update_shell_title "${GETURI2%% *}: $im" |
cd445739 | 1060 | ${GETURI2} "$im" |
7e365483 | 1061 | fi |
cd445739 AM |
1062 | fi |
1063 | ||
dcebdffb ER |
1064 | if [ "$cvsup" = 1 ]; then |
1065 | continue | |
1066 | fi | |
1067 | ||
cd445739 | 1068 | fi |
ecba6ad5 ER |
1069 | |
1070 | # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong. | |
f09c0772 | 1071 | if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then |
cdbd30e8 | 1072 | if [ -n "GREEDSRC" ]; then |
1073 | get_greed_sources $i | |
1074 | else | |
1075 | Exit_error err_no_source_in_repo $i | |
1076 | fi | |
cd445739 | 1077 | fi |
2a5f078d | 1078 | |
ecba6ad5 | 1079 | # we check md5 here just only to refetch immediately |
a4b50627 | 1080 | if good_md5 "$i" && good_size "$i"; then |
cd445739 AM |
1081 | : |
1082 | elif [ "$FROM_DISTFILES" = 1 ]; then | |
deccc50e | 1083 | # wrong md5 from distfiles: remove the file and try again |
cd445739 | 1084 | # but only once ... |
deccc50e | 1085 | echo "MD5 sum mismatch. Trying full fetch." |
cd445739 AM |
1086 | FROM_DISTFILES=2 |
1087 | rm -f $target | |
18a52930 | 1088 | update_shell_title "${GETURI%% *}: $url" |
ca2e6c31 | 1089 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
33da77c4 | 1090 | if [ "`echo $url | grep -E 'ftp://'`" ]; then |
ce40491a | 1091 | update_shell_title "${GETURI2%% *}: $url" |
ca2e6c31 | 1092 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
cd445739 | 1093 | fi |
ecba6ad5 | 1094 | if [ ! -s "$target" ]; then |
cd445739 | 1095 | rm -f "$target" |
18a52930 | 1096 | update_shell_title "${GETURI%% *}: $url_attic" |
ca2e6c31 | 1097 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
33da77c4 | 1098 | if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then |
ce40491a | 1099 | update_shell_title "${GETURI2%% *}: $url_attic" |
ca2e6c31 | 1100 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
cd445739 AM |
1101 | fi |
1102 | fi | |
1103 | test -s "$target" || rm -f "$target" | |
1104 | fi | |
cd445739 | 1105 | done |
e7fa3b9f ER |
1106 | SHELL_TITLE_PREFIX="" |
1107 | ||
1108 | if [ "$get_files_cvs" ]; then | |
ce40491a | 1109 | cvsup $get_files_cvs |
e7fa3b9f | 1110 | fi |
cd445739 AM |
1111 | |
1112 | if [ "$CHMOD" = "yes" ]; then | |
3815b69a | 1113 | CHMOD_FILES="`nourl "$@"`" |
cd445739 AM |
1114 | if [ -n "$CHMOD_FILES" ]; then |
1115 | chmod $CHMOD_MODE $CHMOD_FILES | |
1116 | fi | |
1117 | fi | |
cd445739 AM |
1118 | fi |
1119 | } | |
1120 | ||
1121 | make_tagver() { | |
ce40491a | 1122 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
1123 | set -x |
1124 | set -v | |
ce40491a | 1125 | fi |
78eab2a1 | 1126 | |
ce40491a ER |
1127 | # Check whether first character of PACKAGE_NAME is legal for tag name |
1128 | if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then | |
1129 | TAG_PREFIX=tag_ | |
1130 | fi | |
d712cc12 ER |
1131 | |
1132 | # NOTE: CVS tags may must not contain the characters `$,.:;@' | |
392187d9 | 1133 | TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE | tr '[.@]' '[_#]') |
d712cc12 | 1134 | |
ce40491a ER |
1135 | # Remove #kernel.version_release from TAGVER because tagging sources |
1136 | # could occur with different kernel-headers than kernel-headers used at build time. | |
d712cc12 ER |
1137 | # besides, %{_kernel_ver_str} is not expanded. |
1138 | ||
1139 | # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1#%{_kernel_ver_str} | |
1140 | # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1 | |
1141 | ||
1142 | TAGVER=${TAGVER%#*} | |
ce40491a | 1143 | echo -n "$TAGVER" |
cd445739 AM |
1144 | } |
1145 | ||
1146 | tag_files() | |
1147 | { | |
1148 | TAG_FILES="$@" | |
1149 | ||
1150 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
1151 | set -x |
1152 | set -v | |
cd445739 AM |
1153 | fi |
1154 | ||
73ef63d8 ER |
1155 | echo "Version: $PACKAGE_VERSION" |
1156 | echo "Release: $PACKAGE_RELEASE" | |
cd445739 | 1157 | |
a18a9761 | 1158 | local TAGVER |
73ef63d8 | 1159 | if [ "$TAG_VERSION" = "yes" ]; then |
a18a9761 | 1160 | TAGVER=`make_tagver` |
73ef63d8 ER |
1161 | echo "CVS tag: $TAGVER" |
1162 | fi | |
1163 | if [ -n "$TAG" ]; then | |
1164 | echo "CVS tag: $TAG" | |
1165 | fi | |
cd445739 | 1166 | |
39dcc7de | 1167 | local OPTIONS="tag $CVS_FORCE" |
73ef63d8 ER |
1168 | if [ -n "$CVSROOT" ]; then |
1169 | OPTIONS="-d $CVSROOT $OPTIONS" | |
1170 | fi | |
cd445739 | 1171 | |
73ef63d8 ER |
1172 | cd "$SOURCE_DIR" |
1173 | local tag_files | |
1174 | for i in $TAG_FILES; do | |
1175 | # don't tag files stored on distfiles | |
1176 | [ -n "`src_md5 $i`" ] && continue | |
1177 | local fp=`nourl "$i"` | |
1178 | if [ -f "$fp" ]; then | |
1179 | tag_files="$tag_files $fp" | |
cdbd30e8 | 1180 | elif [ -n "GREEDSRC" ]; then |
1181 | get_greed_sources $i | |
73ef63d8 ER |
1182 | else |
1183 | Exit_error err_no_source_in_repo $i | |
03db3356 | 1184 | fi |
73ef63d8 | 1185 | done |
03db3356 | 1186 | |
73ef63d8 | 1187 | if [ "$tag_files" ]; then |
cd445739 | 1188 | if [ "$TAG_VERSION" = "yes" ]; then |
73ef63d8 | 1189 | update_shell_title "tag sources: $TAGVER" |
19ca62ef | 1190 | printf "Tagging %d files\n" $(echo $tag_files | wc -w) |
c7e6ee9b | 1191 | cvs $OPTIONS $TAGVER $tag_files || exit |
cd445739 AM |
1192 | fi |
1193 | if [ -n "$TAG" ]; then | |
73ef63d8 | 1194 | update_shell_title "tag sources: $TAG" |
c4ff623e ER |
1195 | |
1196 | while [ "$tag_files" ]; do | |
1197 | local chunk=$(echo $tag_files | tr ' ' '\n' | head -n 100) | |
1198 | printf "Tagging %d files\n" $(echo $chunk | wc -w) | |
1199 | cvs $OPTIONS $TAG $chunk || exit | |
1200 | tag_files=$(echo $tag_files | tr ' ' '\n' | tail +101) | |
1201 | done | |
cd445739 | 1202 | fi |
73ef63d8 ER |
1203 | fi |
1204 | ||
01fa66fc | 1205 | cd "$SPEC_DIR" |
73ef63d8 ER |
1206 | if [ "$TAG_VERSION" = "yes" ]; then |
1207 | update_shell_title "tag spec: $TAGVER" | |
c7e6ee9b | 1208 | cvs $OPTIONS $TAGVER $SPECFILE || exit |
73ef63d8 ER |
1209 | fi |
1210 | if [ -n "$TAG" ]; then | |
1211 | update_shell_title "tag spec: $TAG" | |
c7e6ee9b | 1212 | cvs $OPTIONS $TAG $SPECFILE || exit |
73ef63d8 | 1213 | fi |
cd445739 AM |
1214 | } |
1215 | ||
1216 | branch_files() | |
1217 | { | |
1218 | TAG=$1 | |
1219 | echo "CVS branch tag: $TAG" | |
518ff1fb | 1220 | shift |
cd445739 AM |
1221 | |
1222 | TAG_FILES="$@" | |
1223 | ||
1224 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
1225 | set -x |
1226 | set -v | |
cd445739 AM |
1227 | fi |
1228 | ||
78a5a506 ER |
1229 | local OPTIONS="tag $CVS_FORCE -b" |
1230 | if [ -n "$CVSROOT" ]; then | |
1231 | OPTIONS="-d $CVSROOT $OPTIONS" | |
1232 | fi | |
1233 | cd "$SOURCE_DIR" | |
1234 | local tag_files | |
1235 | for i in $TAG_FILES; do | |
1236 | local fp=`nourl "$i"` | |
1237 | if [ -f "$fp" ]; then | |
1238 | tag_files="$tag_files $fp" | |
cdbd30e8 | 1239 | elif [ -n "GREEDSRC" ]; then |
1240 | get_greed_sources $i | |
78a5a506 ER |
1241 | else |
1242 | Exit_error err_no_source_in_repo $i | |
c10fa4fa | 1243 | fi |
78a5a506 ER |
1244 | done |
1245 | if [ "$tag_files" ]; then | |
c7e6ee9b | 1246 | cvs $OPTIONS $TAG $tag_files || exit |
78a5a506 | 1247 | fi |
c10fa4fa | 1248 | |
01fa66fc | 1249 | cd "$SPEC_DIR" |
c7e6ee9b | 1250 | cvs $OPTIONS $TAG $SPECFILE || exit |
cd445739 AM |
1251 | } |
1252 | ||
1253 | ||
3009b80d ER |
1254 | # this function should exit early if package can't be built for this arch |
1255 | # this avoids unneccessary BR filling. | |
1256 | check_buildarch() { | |
1257 | local out ret | |
13c3c336 | 1258 | out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1) |
3009b80d ER |
1259 | ret=$? |
1260 | if [ $ret -ne 0 ]; then | |
1261 | echo >&2 "$out" | |
1262 | exit $ret | |
1263 | fi | |
1264 | } | |
1265 | ||
cd445739 | 1266 | |
59398507 | 1267 | build_package() |
1268 | { | |
2e5be021 | 1269 | update_shell_title "build_package" |
cd445739 | 1270 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
1271 | set -x |
1272 | set -v | |
cd445739 | 1273 | fi |
5a491465 | 1274 | |
01fa66fc | 1275 | cd "$SPEC_DIR" |
cd445739 AM |
1276 | |
1277 | if [ -n "$TRY_UPGRADE" ]; then | |
ce40491a | 1278 | update_shell_title "build_package: try_upgrade" |
cd445739 | 1279 | if [ -n "$FLOAT_VERSION" ]; then |
cc538c24 | 1280 | TNOTIFY=`./pldnotify.awk $SPECFILE -n` || exit 1 |
cd445739 | 1281 | else |
cc538c24 | 1282 | TNOTIFY=`./pldnotify.awk $SPECFILE` || exit 1 |
cd445739 AM |
1283 | fi |
1284 | ||
1285 | TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'` | |
1286 | ||
1287 | if [ -n "$TNEWVER" ]; then | |
1288 | TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'` | |
1289 | echo "New version found, updating spec file to version " $TNEWVER | |
257af81b ER |
1290 | if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then |
1291 | cp -f $SPECFILE $SPECFILE.bak | |
1292 | fi | |
cd445739 AM |
1293 | chmod +w $SPECFILE |
1294 | eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE" | |
f7b91886 | 1295 | eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE" |
518ff1fb ER |
1296 | parse_spec |
1297 | NODIST="yes" get_files $SOURCES $PATCHES | |
6392b5fd | 1298 | update_md5 $SOURCES |
975d7b23 | 1299 | |
cd445739 AM |
1300 | unset TOLDVER TNEWVER TNOTIFY |
1301 | fi | |
1302 | fi | |
01fa66fc | 1303 | cd "$SPEC_DIR" |
2a5f078d | 1304 | |
cd445739 AM |
1305 | case "$COMMAND" in |
1306 | build ) | |
1307 | BUILD_SWITCH="-ba" ;; | |
1308 | build-binary ) | |
1309 | BUILD_SWITCH="-bb" ;; | |
1310 | build-source ) | |
1311 | BUILD_SWITCH="-bs --nodeps" ;; | |
1312 | build-prep ) | |
1313 | BUILD_SWITCH="-bp --nodeps" ;; | |
6594293d AG |
1314 | build-build ) |
1315 | BUILD_SWITCH="-bc" ;; | |
1316 | build-install ) | |
1317 | BUILD_SWITCH="-bi" ;; | |
1318 | build-list ) | |
1319 | BUILD_SWITCH="-bl" ;; | |
1320 | ||
cd445739 | 1321 | esac |
c890b916 | 1322 | |
2e5be021 | 1323 | update_shell_title "build_package: $COMMAND" |
cd445739 AM |
1324 | if [ -n "$LOGFILE" ]; then |
1325 | LOG=`eval echo $LOGFILE` | |
1326 | if [ -d "$LOG" ]; then | |
1327 | echo "Log file $LOG is a directory." | |
1328 | echo "Parse error in the spec?" | |
518ff1fb | 1329 | Exit_error err_build_fail |
cd445739 AM |
1330 | fi |
1331 | if [ -n "$LASTLOG_FILE" ]; then | |
1332 | echo "LASTLOG=$LOG" > $LASTLOG_FILE | |
1333 | fi | |
1334 | RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM | |
86aafdbe | 1335 | (time eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG |
cd445739 AM |
1336 | RETVAL=`cat $RES_FILE` |
1337 | rm $RES_FILE | |
1338 | if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then | |
1339 | if [ "$RETVAL" -eq "0" ]; then | |
1340 | mv $LOG $LOGDIROK | |
1341 | else | |
1342 | mv $LOG $LOGDIRFAIL | |
1343 | fi | |
1344 | fi | |
8ba5cdda | 1345 | else |
86aafdbe | 1346 | eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE |
cd445739 | 1347 | RETVAL=$? |
8ba5cdda | 1348 | fi |
cd445739 AM |
1349 | if [ "$RETVAL" -ne "0" ]; then |
1350 | if [ -n "$TRY_UPGRADE" ]; then | |
796a8a95 | 1351 | echo "\n!!! Package with new version cannot be built automagically\n" |
257af81b ER |
1352 | if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then |
1353 | mv -f $SPECFILE.bak $SPECFILE | |
1354 | fi | |
cd445739 | 1355 | fi |
518ff1fb | 1356 | Exit_error err_build_fail |
cd445739 AM |
1357 | fi |
1358 | unset BUILD_SWITCH | |
1359 | } | |
1360 | ||
1361 | nourl() | |
1362 | { | |
1363 | echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g' | |
1364 | } | |
1365 | ||
cd445739 AM |
1366 | install_required_packages() |
1367 | { | |
1368 | run_poldek -vi $1 | |
1369 | return $? | |
1370 | } | |
1371 | ||
fa4bf1df ER |
1372 | find_spec_bcond() { |
1373 | # taken from find-spec-bcond, but with just getting the list | |
1374 | local SPEC="$1" | |
1375 | # quick revert hint: '$RPMBUILD --bcond $SPEC' | |
1376 | awk -F"\n" ' | |
1377 | /^%changelog/ { exit } | |
1378 | /_with(out)?_[_a-zA-Z0-9]+/{ | |
1379 | match($0, /_with(out)?_[_a-zA-Z0-9]+/); | |
1380 | print substr($0, RSTART, RLENGTH); | |
1381 | } | |
1382 | /^%bcond_with/{ | |
1383 | match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/); | |
1384 | bcond = substr($0, RSTART +5 , RLENGTH -5); | |
1385 | gsub(/[ \t]+/,"_",bcond); | |
1386 | print bcond | |
1387 | }' $SPEC | LC_ALL=C sort -u | |
1388 | } | |
1389 | ||
117d9861 | 1390 | process_bcondrc() { |
301cbfd4 ER |
1391 | # expand bconds from ~/.bcondrc |
1392 | # The file structure is like gentoo's package.use: | |
1393 | # --- | |
1394 | # * -selinux | |
1395 | # samba -mysql -pgsql | |
47a8df12 | 1396 | # w32codec-installer license_agreement |
301cbfd4 ER |
1397 | # php +mysqli |
1398 | # --- | |
fa4bf1df | 1399 | if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then |
117d9861 ER |
1400 | : |
1401 | else | |
1402 | return | |
1403 | fi | |
301cbfd4 | 1404 | |
117d9861 | 1405 | SN=${SPECFILE%%\.spec} |
c8a3e2ac | 1406 | |
117d9861 ER |
1407 | local bcondrc=$HOME/.bcondrc |
1408 | [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc | |
301cbfd4 | 1409 | |
117d9861 | 1410 | local bcond_avail=$(find_spec_bcond $SPECFILE) |
301cbfd4 | 1411 | |
117d9861 ER |
1412 | while read pkg flags; do |
1413 | # ignore comments | |
1414 | [[ "$pkg" == \#* ]] && continue | |
1415 | ||
1416 | # any package or current package? | |
1417 | if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then | |
1418 | for flag in $flags; do | |
1419 | local opt=${flag#[+-]} | |
1420 | ||
1421 | # use only flags which are in this package. | |
1422 | if [[ $bcond_avail = *${opt}* ]]; then | |
1423 | if [[ $flag = -* ]]; then | |
1424 | if [[ $BCOND != *--with?${opt}* ]]; then | |
1425 | BCOND="$BCOND --without $opt" | |
1426 | fi | |
1427 | else | |
1428 | if [[ $BCOND != *--without?${opt}* ]]; then | |
1429 | BCOND="$BCOND --with $opt" | |
301cbfd4 ER |
1430 | fi |
1431 | fi | |
117d9861 ER |
1432 | fi |
1433 | done | |
1434 | fi | |
1435 | done < $bcondrc | |
1436 | update_shell_title "parse ~/.bcondrc: DONE!" | |
1437 | } | |
1438 | ||
1439 | set_bconds_values() | |
1440 | { | |
1441 | update_shell_title "set bcond values" | |
1442 | ||
1443 | AVAIL_BCONDS_WITHOUT="" | |
1444 | AVAIL_BCONDS_WITH="" | |
1445 | if `grep -q ^%bcond ${SPECFILE}`; then | |
1446 | BCOND_VERSION="NEW" | |
1447 | elif `egrep -q ^#\ *_with ${SPECFILE}`; then | |
1448 | BCOND_VERSION="OLD" | |
1449 | else | |
1450 | return | |
301cbfd4 ER |
1451 | fi |
1452 | ||
117d9861 ER |
1453 | local bcond_avail=$(find_spec_bcond $SPECFILE) |
1454 | process_bcondrc "$SPECFILE" | |
1455 | ||
fa4bf1df | 1456 | update_shell_title "parse bconds" |
cd445739 | 1457 | case "${BCOND_VERSION}" in |
fa4bf1df | 1458 | NONE) |
7e365483 | 1459 | : |
cd445739 | 1460 | ;; |
7e365483 | 1461 | OLD) |
cd445739 | 1462 | echo "Warning: This spec has old style bconds. Fix it || die." |
fa4bf1df | 1463 | for opt in `echo "$bcond_avail" | grep ^_without_` |
cd445739 | 1464 | do |
fa4bf1df ER |
1465 | AVAIL_BCOND_WITHOUT=${opt#_without_} |
1466 | if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then | |
cd445739 AM |
1467 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>" |
1468 | else | |
1469 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT" | |
1470 | fi | |
1471 | done | |
2a5f078d | 1472 | |
fa4bf1df | 1473 | for opt in `echo "$bcond_avail" | grep ^_with_` |
cd445739 | 1474 | do |
fa4bf1df ER |
1475 | AVAIL_BCOND_WITH=${opt#_with_} |
1476 | if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then | |
cd445739 AM |
1477 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>" |
1478 | else | |
1479 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH" | |
1480 | fi | |
1481 | done | |
1482 | ;; | |
1483 | NEW) | |
fa4bf1df ER |
1484 | local cond_type="" # with || without |
1485 | for opt in $bcond_avail; do | |
cd445739 AM |
1486 | case "$opt" in |
1487 | _without) | |
1488 | cond_type="without" | |
1489 | ;; | |
1490 | _with) | |
1491 | cond_type="with" | |
1492 | ;; | |
f8d24cee | 1493 | _without_*) |
fa4bf1df ER |
1494 | AVAIL_BCOND_WITHOUT=${opt#_without_} |
1495 | if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then | |
f8d24cee | 1496 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>" |
1497 | else | |
1498 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT" | |
1499 | fi | |
1500 | ;; | |
1501 | _with_*) | |
fa4bf1df ER |
1502 | AVAIL_BCOND_WITH=${opt#_with_} |
1503 | if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then | |
f8d24cee | 1504 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>" |
1505 | else | |
1506 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH" | |
1507 | fi | |
1508 | ;; | |
cd445739 AM |
1509 | *) |
1510 | case "$cond_type" in | |
1511 | with) | |
1512 | cond_type='' | |
1513 | AVAIL_BCOND_WITH="$opt" | |
fa4bf1df | 1514 | if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then |
cd445739 AM |
1515 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>" |
1516 | else | |
1517 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH" | |
1518 | fi | |
7e365483 | 1519 | ;; |
cd445739 AM |
1520 | without) |
1521 | cond_type='' | |
1522 | AVAIL_BCOND_WITHOUT="$opt" | |
fa4bf1df | 1523 | if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then |
cd445739 AM |
1524 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>" |
1525 | else | |
1526 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT" | |
1527 | fi | |
1528 | ;; | |
1529 | esac | |
1530 | ;; | |
1531 | esac | |
1532 | done | |
1533 | ;; | |
1534 | esac | |
1535 | } | |
1536 | ||
1537 | run_sub_builder() | |
1538 | { | |
1539 | package_name="${1}" | |
af6b168f | 1540 | update_shell_title "run_sub_builder $package_name" |
cd445739 AM |
1541 | # |
1542 |