]>
Commit | Line | Data |
---|---|---|
6b8daffa JB |
1 | #!/bin/sh |
2 | # ----------- | |
3 | # $Id$ | |
4 | # Exit codes: | |
7cede445 ER |
5 | # 0 - succesful |
6 | # 1 - help displayed | |
7 | # 2 - no spec file name in cmdl parameters | |
8 | # 3 - spec file not stored in repo | |
9 | # 4 - some source, patch or icon files not stored in repo | |
10 | # 5 - package build failed | |
11 | # 6 - spec file with errors | |
12 | # 7 - wrong source in /etc/poldek.conf | |
13 | # 8 - Failed installing buildrequirements and subrequirements | |
14 | # 9 - Requested tag already exist | |
15 | # 10 - Refused to build fractional release | |
16 | # 100 - Unknown error (should not happen) | |
6b8daffa JB |
17 | |
18 | # Notes (todo): | |
3144da10 | 19 | # - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?) |
6b8daffa | 20 | # - when Icon: field is present, -5 and -a5 doesn't work |
3144da10 | 21 | # - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice) |
6b8daffa JB |
22 | |
23 | VERSION="\ | |
3144da10 | 24 | Build package utility from PLD Linux CVS repository |
a638dc19 | 25 | v0.16 (C) 1999-2006 Free Penguins". |
6b8daffa JB |
26 | PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin" |
27 | ||
28 | COMMAND="build" | |
cba064d4 | 29 | TARGET="" |
6b8daffa JB |
30 | |
31 | SPECFILE="" | |
32 | BE_VERBOSE="" | |
33 | QUIET="" | |
34 | CLEAN="" | |
35 | DEBUG="" | |
36 | NOURLS="" | |
37 | NOCVS="" | |
38 | NOCVSSPEC="" | |
39 | NODIST="" | |
a638dc19 | 40 | NOINIT="" |
6b8daffa JB |
41 | UPDATE="" |
42 | UPDATE5="" | |
43 | ADD5="" | |
44 | NO5="" | |
45 | ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"} | |
46 | CVSROOT="" | |
47 | ||
48 | # It can be used i.e. in log file naming. | |
49 | # See LOGFILE example. | |
50 | DATE=`date +%Y-%m-%d_%H-%M-%S` | |
51 | ||
52 | # Example: LOGFILE='../log.$PACKAGE_NAME' | |
53 | # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE' | |
54 | # Yes, you can use variable name! Note _single_ quotes! | |
55 | LOGFILE='' | |
56 | ||
57 | LOGDIR="" | |
58 | LOGDIROK="" | |
59 | LOGDIRFAIL="" | |
60 | LASTLOG_FILE="" | |
61 | ||
62 | CHMOD="no" | |
63 | CHMOD_MODE="0444" | |
64 | RPMOPTS="" | |
a638dc19 | 65 | RPMBUILDOPTS="" |
6b8daffa JB |
66 | BCOND="" |
67 | GROUP_BCONDS="no" | |
7cede445 | 68 | CVSIGNORE_DF="no" |
6b8daffa JB |
69 | |
70 | PATCHES="" | |
71 | SOURCES="" | |
72 | ICONS="" | |
73 | PACKAGE_RELEASE="" | |
74 | PACKAGE_VERSION="" | |
75 | PACKAGE_NAME="" | |
76 | PROTOCOL="ftp" | |
77 | WGET_RETRIES=${MAX_WGET_RETRIES:-0} | |
78 | CVS_RETRIES=${MAX_CVS_RETRIES:-1000} | |
79 | ||
80 | CVSTAG="" | |
81 | RES_FILE="" | |
82 | ||
83 | CVS_SERVER="cvs.pld-linux.org" | |
84 | DISTFILES_SERVER="://distfiles.pld-linux.org" | |
7cede445 | 85 | ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org" |
6b8daffa | 86 | |
7cede445 | 87 | DEF_NICE_LEVEL=19 |
a638dc19 | 88 | SCHEDTOOL="auto" |
6b8daffa JB |
89 | |
90 | FAIL_IF_NO_SOURCES="yes" | |
91 | ||
3144da10 ER |
92 | # let get_files skip over files which are present to get those damn files fetched |
93 | SKIP_EXISTING_FILES="no" | |
94 | ||
7cede445 | 95 | if [ -x /usr/bin/rpm-getdeps ]; then |
a638dc19 | 96 | FETCH_BUILD_REQUIRES_RPMGETDEPS="yes" |
6b8daffa | 97 | else |
a638dc19 | 98 | FETCH_BUILD_REQUIRES_RPMGETDEPS="no" |
6b8daffa JB |
99 | fi |
100 | ||
6b8daffa JB |
101 | # Here we load saved user environment used to |
102 | # predefine options set above, or passed to builder | |
103 | # in command line. | |
104 | # This one reads global system environment settings: | |
105 | if [ -f ~/etc/builderrc ]; then | |
106 | . ~/etc/builderrc | |
107 | fi | |
108 | # And this one cascades settings using user personal | |
109 | # builder settings. | |
110 | # Example of ~/.builderrc: | |
111 | # | |
112 | #UPDATE_POLDEK_INDEXES="yes" | |
113 | #FETCH_BUILD_REQUIRES="yes" | |
114 | #REMOVE_BUILD_REQUIRES="force" | |
115 | #GROUP_BCONDS="yes" | |
116 | #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE' | |
a638dc19 | 117 | #TITLECHANGE=no |
6b8daffa | 118 | # |
7cede445 | 119 | SU_SUDO="" |
6b8daffa JB |
120 | if [ -n "$HOME_ETC" ]; then |
121 | USER_CFG="$HOME_ETC/.builderrc" | |
122 | else | |
123 | USER_CFG=~/.builderrc | |
124 | fi | |
125 | ||
126 | [ -f "$USER_CFG" ] && . "$USER_CFG" | |
127 | ||
a638dc19 ER |
128 | if [ "$SCHEDTOOL" = "auto" ]; then |
129 | if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then | |
130 | SCHEDTOOL="schedtool -B -e" | |
131 | else | |
132 | SCHEDTOOL="no" | |
133 | fi | |
134 | fi | |
3144da10 | 135 | |
7cede445 ER |
136 | if [ -n "$USE_PROZILLA" ]; then |
137 | GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS" | |
138 | GETURI2="$GETURI" | |
139 | OUTFILEOPT="-O" | |
140 | elif [ -n "$USE_AXEL" ]; then | |
141 | GETURI="axel -a $AXEL_OPTS" | |
142 | GETURI2="$GETURI" | |
143 | OUTFILEOPT="-o" | |
144 | else | |
a638dc19 ER |
145 | wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate" |
146 | wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet" | |
147 | wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused" | |
3144da10 | 148 | |
7cede445 ER |
149 | GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS" |
150 | GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS" | |
151 | OUTFILEOPT="-O" | |
152 | fi | |
153 | ||
154 | GETLOCAL="cp -a" | |
155 | ||
156 | if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then | |
157 | RPM="rpm" | |
158 | RPMBUILD="rpm" | |
159 | else | |
160 | RPM="rpm" | |
161 | RPMBUILD="rpmbuild" | |
162 | fi | |
163 | ||
164 | POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/" | |
165 | POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask" | |
166 | ||
6b8daffa JB |
167 | run_poldek() |
168 | { | |
169 | RES_FILE=~/tmp/poldek-exit-status.$RANDOM | |
170 | if [ -n "$LOGFILE" ]; then | |
171 | LOG=`eval echo $LOGFILE` | |
172 | if [ -n "$LASTLOG_FILE" ]; then | |
173 | echo "LASTLOG=$LOG" > $LASTLOG_FILE | |
174 | fi | |
a638dc19 | 175 | (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG |
6b8daffa JB |
176 | return $exit_pldk |
177 | else | |
a638dc19 | 178 | (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null |
6b8daffa JB |
179 | return `cat ${RES_FILE}` |
180 | rm -rf ${RES_FILE} | |
181 | fi | |
182 | } | |
183 | ||
6b8daffa JB |
184 | #--------------------------------------------- |
185 | # functions | |
186 | ||
187 | usage() | |
188 | { | |
189 | if [ -n "$DEBUG" ]; then set -xv; fi | |
190 | echo "\ | |
191 | Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build] | |
192 | ||
193 | [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade] | |
194 | [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get] | |
195 | [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper] | |
196 | [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>] | |
197 | [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest] | |
198 | [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version] | |
199 | [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] | |
3144da10 ER |
200 | [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds] |
201 | [--with/--without <feature>] [--define <macro> <value>] <package>[.spec][:cvstag] | |
7cede445 | 202 | |
6b8daffa JB |
203 | -5, --update-md5 - update md5 comments in spec, implies -nd -ncs |
204 | -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs | |
205 | -n5, --no-md5 - ignore md5 comments in spec | |
7cede445 ER |
206 | -D, --debug - enable builder script debugging mode, |
207 | -debug - produce rpm debug package (same as --opts -debug) | |
6b8daffa JB |
208 | -V, --version - output builder version |
209 | -a, --as_anon - get files via pserver as cvs@$CVS_SERVER, | |
210 | -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package | |
211 | from <package>.spec, | |
212 | -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary | |
213 | only package from <package>.spec, | |
3144da10 ER |
214 | -bp, --build-prep - execute the %prep phase of <package>.spec, |
215 | -bc - reserved (not implemented) | |
216 | -bi reserved (not implemented) | |
6b8daffa JB |
217 | -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack |
218 | them into src.rpm, | |
3144da10 | 219 | --short-circuit - reserved (not implemented) |
6b8daffa JB |
220 | -B, --branch - add branch |
221 | -c, --clean - clean all temporarily created files (in BUILD, SOURCES, | |
222 | SPECS and \$RPM_BUILD_ROOT), | |
7cede445 | 223 | -d <cvsroot>, --cvsroot <cvsroot> |
6b8daffa JB |
224 | - setup \$CVSROOT, |
225 | --define <macro> <value> | |
226 | - define a macro <macro> with value <value>, | |
227 | --nodeps - rpm won't check any dependences | |
228 | -g, --get - get <package>.spec and all related files from CVS repo | |
229 | or HTTP/FTP, | |
230 | -h, --help - this message, | |
231 | --http - use http instead of ftp, | |
232 | -l <logfile>, --logtofile <logfile> | |
233 | - log all to file, | |
234 | -m, --mr-proper - only remove all files related to spec file and all work | |
235 | resources, | |
236 | -nc, --no-cvs - don't download sources from CVS, if source URL is given, | |
237 | -ncs, --no-cvs-specs | |
238 | - don't check specs in CVS | |
239 | -nd, --no-distfiles - don't download from distfiles | |
240 | -nm, --no-mirrors - don't download from mirror, if source URL is given, | |
241 | -nu, --no-urls - don't try to download from FTP/HTTP location, | |
242 | -ns, --no-srcs - don't download Sources | |
243 | -ns0, --no-source0 - don't download Source0 | |
244 | -nn, --no-net - don't download anything from the net | |
a638dc19 | 245 | --no-init - don't initialize builder paths (SPECS and SOURCES) |
3144da10 ER |
246 | -ske, |
247 | --skip-existing-files - skip existing files in get_files | |
6b8daffa JB |
248 | --opts <rpm opts> - additional options for rpm |
249 | -q, --quiet - be quiet, | |
250 | --date yyyy-mm-dd - build package using resources from specified CVS date, | |
251 | -r <cvstag>, --cvstag <cvstag> | |
252 | - build package using resources from specified CVS tag, | |
253 | -R, --fetch-build-requires | |
254 | - fetch what is BuildRequired, | |
255 | -RB, --remove-build-requires | |
256 | - remove all you fetched with -R or --fetch-build-requires | |
257 | remember, this option requires confirmation, | |
258 | -FRB, --force-remove-build-requires | |
259 | - remove all you fetched with -R or --fetch-build-requires | |
260 | remember, this option works without confirmation, | |
a638dc19 ER |
261 | -sd, --source-distfiles - list sources available from distfiles (intended for offline |
262 | operations; does not work when Icon field is present | |
263 | but icon file is absent), | |
264 | -sdp, --source-distfiles-paths - list sources available from distfiles - | |
265 | paths relative to distfiles directory (intended for offline | |
266 | operations; does not work when Icon field is present | |
267 | but icon file is absent), | |
7cede445 ER |
268 | -sf, --source-files - list sources - bare filenames (intended for offline |
269 | operations; does not work when Icon field is present | |
a638dc19 | 270 | but icon file is absent), |
7cede445 ER |
271 | -sp, --source-paths - list sources - filenames with full local paths (intended for |
272 | offline operations; does not work when Icon field is present | |
a638dc19 | 273 | but icon file is absent), |
3144da10 ER |
274 | -su, --source-urls - list urls - urls to sources and patches |
275 | intended for copying urls with spec with lots of macros in urls | |
6b8daffa JB |
276 | -T <cvstag> , --tag <cvstag> |
277 | - add cvs tag <cvstag> for files, | |
278 | -Tvs, --tag-version-stable | |
7cede445 | 279 | - add cvs tags STABLE and NAME-VERSION-RELEASE for files, |
6b8daffa | 280 | -Tvn, --tag-version-nest |
7cede445 | 281 | - add cvs tags NEST and NAME-VERSION-RELEASE for files, |
6b8daffa JB |
282 | -Ts, --tag-stable |
283 | - add cvs tag STABLE for files, | |
284 | -Tn, --tag-nest | |
285 | - add cvs tag NEST for files, | |
286 | -Tv, --tag-version | |
7cede445 | 287 | - add cvs tag NAME-VERSION-RELEASE for files, |
6b8daffa JB |
288 | -Tp, --tag-prefix <prefix> |
289 | - add <prefix> to NAME-VERSION-RELEASE tags, | |
290 | -tt, --test-tag <prefix> | |
291 | - fail if tag is already present, | |
7cede445 ER |
292 | -ir, --integer-release-only |
293 | - allow only integer and snapshot releases | |
6b8daffa JB |
294 | -v, --verbose - be verbose, |
295 | -u, --try-upgrade - check version, and try to upgrade package | |
296 | -un, --try-upgrade-with-float-version | |
297 | - as above, but allow float version | |
298 | -U, --update - refetch sources, don't use distfiles, and update md5 comments | |
299 | -Upi, --update-poldek-indexes | |
300 | - refresh or make poldek package index files. | |
3144da10 ER |
301 | -np, --nopatch <patchnumber> |
302 | - don't apply <patchnumber> | |
303 | --show-bconds - show available conditional builds, which can be used | |
304 | - with --with and/or --without switches. | |
6b8daffa JB |
305 | --with/--without <feature> |
306 | - conditional build package depending on %_with_<feature>/ | |
307 | %_without_<feature> macro switch. You may now use | |
308 | --with feat1 feat2 feat3 --without feat4 feat5 --with feat6 | |
309 | constructions. Set GROUP_BCONDS to yes to make use of it. | |
7cede445 | 310 | --target <platform>, --target=<platform> |
a638dc19 ER |
311 | - build for platform <platform>. |
312 | --init-rpm-dir - initialize ~/rpm directory structure | |
6b8daffa JB |
313 | " |
314 | } | |
315 | ||
3144da10 ER |
316 | update_shell_title() { |
317 | [ -t 1 ] || return | |
318 | local len=${COLUMNS:-80} | |
319 | local msg=$(echo "$*" | cut -c-$len) | |
320 | ||
321 | if [ -n "$BE_VERBOSE" ]; then | |
322 | echo >&2 "$(date +%s.%N) $*" | |
323 | fi | |
324 | ||
a638dc19 ER |
325 | if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then |
326 | local pkg | |
327 | if [ -n "$PACKAGE_NAME" ]; then | |
328 | pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE} | |
329 | else | |
330 | pkg=${SPECFILE} | |
331 | fi | |
332 | ||
333 | msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg" | |
334 | msg="$(echo $msg | tr -d '\n\r')" | |
335 | case "$TERM" in | |
336 | cygwin|xterm*) | |
337 | echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007" | |
338 | ;; | |
339 | screen*) | |
340 | echo >&2 -ne "\033]0;$msg\007" | |
341 | ;; | |
342 | esac | |
343 | fi | |
3144da10 ER |
344 | } |
345 | ||
346 | # set TARGET from BuildArch: from SPECFILE | |
347 | set_spec_target() { | |
a638dc19 ER |
348 | if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then |
349 | tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE) | |
350 | if [ "$tmp" ]; then | |
3144da10 ER |
351 | TARGET="$tmp" |
352 | case "$RPMBUILD" in | |
353 | "rpmbuild") | |
a638dc19 | 354 | TARGET_SWITCH="--target $TARGET" ;; |
3144da10 | 355 | "rpm") |
a638dc19 | 356 | TARGET_SWITCH="--target=$TARGET" ;; |
3144da10 | 357 | esac |
a638dc19 ER |
358 | fi |
359 | fi | |
3144da10 ER |
360 | } |
361 | ||
6b8daffa | 362 | cache_rpm_dump () { |
7cede445 ER |
363 | if [ -n "$DEBUG" ]; then |
364 | set -x; | |
365 | set -v; | |
366 | fi | |
3144da10 ER |
367 | |
368 | update_shell_title "cache_rpm_dump" | |
369 | local rpm_dump | |
370 | rpm_dump=` | |
371 | ||
372 | # we reset macros not to contain macros.build as all the %() macros are | |
373 | # executed here, while none of them are actually needed. | |
374 | # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES. | |
375 | # at the time of this writing macros.build + macros contained 70 "%(...)" macros. | |
a638dc19 | 376 | macrofiles="/usr/lib/rpm/macros:$SPECS_DIR/.builder-rpmmacros:~/etc/.rpmmacros:~/.rpmmacros" |
3144da10 ER |
377 | dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump' |
378 | # FIXME: better ideas than .rpmrc? | |
a638dc19 | 379 | printf 'include:/usr/lib/rpm/rpmrc\nmacrofiles:%s\n' $macrofiles > .builder-rpmrc |
3144da10 | 380 | # TODO: move these to /usr/lib/rpm/macros |
a638dc19 | 381 | cat > .builder-rpmmacros <<'EOF' |
3144da10 ER |
382 | %requires_releq_kernel_up %{nil} |
383 | %requires_releq_kernel_smp %{nil} | |
384 | %requires_releq() %{nil} | |
385 | %pyrequires_eq() %{nil} | |
386 | %requires_eq() %{nil} | |
387 | %requires_eq_to() %{nil} | |
388 | %releq_kernel_up ERROR | |
389 | %releq_kernel_smp ERROR | |
390 | %kgcc_package ERROR | |
391 | %_fontsdir ERROR | |
392 | %ruby_version ERROR | |
393 | %ruby_ver_requires_eq() %{nil} | |
394 | %ruby_mod_ver_requires_eq() %{nil} | |
395 | %__php_api_requires() %{nil} | |
396 | %php_major_version ERROR | |
397 | %php_api_version ERROR | |
398 | %py_ver ERROR | |
399 | EOF | |
6b8daffa | 400 | case "$RPMBUILD" in |
3144da10 ER |
401 | rpm) |
402 | ARGS='-bp' | |
403 | ;; | |
404 | rpmbuild) | |
405 | ARGS='--nodigest --nosignature --nobuild' | |
406 | ;; | |
407 | esac | |
a638dc19 ER |
408 | if [ "$NOINIT" = "yes" ] ; then |
409 | cat >> .builder-rpmmacros <<'EOF' | |
410 | %_specdir ./ | |
411 | %_sourcedir ./ | |
412 | EOF | |
413 | fi | |
414 | $RPMBUILD --rcfile .builder-rpmrc $ARGS $ARGDIRS --nodeps --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1 | |
3144da10 ER |
415 | ` |
416 | if [ $? -gt 0 ]; then | |
417 | error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p') | |
418 | echo "$error" >&2 | |
419 | Exit_error err_build_fail; | |
420 | fi | |
421 | ||
422 | # make small dump cache | |
423 | rpm_dump_cache=`echo "$rpm_dump" | awk ' | |
424 | $2 ~ /^SOURCEURL/ {print} | |
425 | $2 ~ /^PATCHURL/ {print} | |
426 | $2 ~ /^nosource/ {print} | |
427 | $2 ~ /^PACKAGE_/ {print} | |
428 | '` | |
429 | ||
430 | update_shell_title "cache_rpm_dump: OK!" | |
6b8daffa JB |
431 | } |
432 | ||
433 | rpm_dump () { | |
434 | if [ -z "$rpm_dump_cache" ] ; then | |
435 | echo "internal error: cache_rpm_dump not called!" 1>&2 | |
436 | fi | |
437 | echo "$rpm_dump_cache" | |
438 | } | |
439 | ||
3144da10 ER |
440 | get_icons() |
441 | { | |
442 | update_shell_title "get icons" | |
443 | ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`" | |
444 | if [ -z "$ICONS" ]; then | |
445 | return | |
446 | fi | |
447 | ||
a638dc19 | 448 | rpm_dump_cache="kalasaba" NODIST="yes" UPDATE5= get_files $ICONS |
3144da10 ER |
449 | } |
450 | ||
6b8daffa JB |
451 | parse_spec() |
452 | { | |
3144da10 | 453 | update_shell_title "parsing specfile" |
6b8daffa JB |
454 | if [ -n "$DEBUG" ]; then |
455 | set -x; | |
456 | set -v; | |
457 | fi | |
458 | ||
3144da10 ER |
459 | # icons are needed for successful spec parse |
460 | get_icons; | |
6b8daffa | 461 | |
3144da10 | 462 | cd $SPECS_DIR |
6b8daffa JB |
463 | cache_rpm_dump |
464 | ||
465 | if [ "$NOSRCS" != "yes" ]; then | |
466 | SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`" | |
467 | fi | |
3144da10 | 468 | |
6b8daffa JB |
469 | if (rpm_dump | grep -qEi ":.*nosource.*1"); then |
470 | FAIL_IF_NO_SOURCES="no" | |
471 | fi | |
472 | ||
473 | PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`" | |
474 | ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`" | |
3144da10 ER |
475 | PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3}') |
476 | PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3}') | |
477 | PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3}') | |
7cede445 | 478 | |
6b8daffa JB |
479 | if [ -n "$BE_VERBOSE" ]; then |
480 | echo "- Sources : `nourl $SOURCES`" | |
481 | if [ -n "$PATCHES" ]; then | |
482 | echo "- Patches : `nourl $PATCHES`" | |
483 | else | |
484 | echo "- Patches : *no patches needed*" | |
485 | fi | |
486 | if [ -n "$ICONS" ]; then | |
487 | echo "- Icon : `nourl $ICONS`" | |
488 | else | |
489 | echo "- Icon : *no package icon*" | |
490 | fi | |
491 | echo "- Name : $PACKAGE_NAME" | |
492 | echo "- Version : $PACKAGE_VERSION" | |
493 | echo "- Release : $PACKAGE_RELEASE" | |
494 | fi | |
3144da10 ER |
495 | |
496 | update_shell_title "parse_spec: OK!" | |
6b8daffa JB |
497 | } |
498 | ||
499 | Exit_error() | |
500 | { | |
501 | if [ -n "$DEBUG" ]; then | |
502 | set -x; | |
503 | set -v; | |
504 | fi | |
505 | ||
506 | cd "$__PWD" | |
507 | ||
508 | case "$1" in | |
509 | "err_no_spec_in_cmdl" ) | |
510 | remove_build_requires | |
511 | echo "ERROR: spec file name not specified."; | |
512 | exit 2 ;; | |
513 | "err_no_spec_in_repo" ) | |
514 | remove_build_requires | |
515 | echo "Error: spec file not stored in CVS repo."; | |
516 | exit 3 ;; | |
517 | "err_no_source_in_repo" ) | |
518 | remove_build_requires | |
519 | echo "Error: some source, patch or icon files not stored in CVS repo. ($2)"; | |
520 | exit 4 ;; | |
521 | "err_build_fail" ) | |
522 | remove_build_requires | |
523 | echo "Error: package build failed. (${2:-no more info})"; | |
524 | exit 5 ;; | |
7cede445 ER |
525 | "err_no_package_data" ) |
526 | remove_build_requires | |
527 | echo "Error: couldn't get out package name/version/release from spec file." | |
528 | exit 6 ;; | |
a638dc19 | 529 | "err_tag_exists" ) |
7cede445 ER |
530 | remove_build_requires |
531 | echo "Tag ${2} already exists (spec release: ${3})."; | |
532 | exit 9 ;; | |
a638dc19 | 533 | "err_fract_rel" ) |
7cede445 ER |
534 | remove_build_requires |
535 | echo "Release ${2} not integer and not a snapshot."; | |
536 | exit 10 ;; | |
3144da10 ER |
537 | "err_branch_exists" ) |
538 | remove_build_requires | |
539 | echo "Tree branch already exists (${2})."; | |
540 | exit 11 ;; | |
7cede445 | 541 | |
6b8daffa | 542 | esac |
7cede445 ER |
543 | echo "Unknown error." |
544 | exit 100 | |
6b8daffa JB |
545 | } |
546 | ||
547 | init_builder() | |
548 | { | |
549 | if [ -n "$DEBUG" ]; then | |
550 | set -x; | |
551 | set -v; | |
552 | fi | |
553 | ||
a638dc19 ER |
554 | if [ "$NOINIT" != "yes" ] ; then |
555 | SOURCE_DIR="`eval $RPM $RPMOPTS --eval '%{_sourcedir}'`" | |
556 | SPECS_DIR="`eval $RPM $RPMOPTS --eval '%{_specdir}'`" | |
557 | else | |
558 | SOURCE_DIR="." | |
559 | SPECS_DIR="." | |
560 | fi | |
6b8daffa JB |
561 | |
562 | __PWD="`pwd`" | |
563 | } | |
564 | ||
565 | get_spec() | |
566 | { | |
3144da10 ER |
567 | |
568 | update_shell_title "get_spec" | |
569 | ||
6b8daffa JB |
570 | if [ -n "$DEBUG" ]; then |
571 | set -x; | |
572 | set -v; | |
573 | fi | |
574 | ||
575 | cd "$SPECS_DIR" | |
3144da10 | 576 | if [ ! -f "$SPECFILE" ]; then |
6b8daffa JB |
577 | SPECFILE="`basename $SPECFILE .spec`.spec"; |
578 | fi | |
579 | if [ "$NOCVSSPEC" != "yes" ]; then | |
6b8daffa | 580 | |
3144da10 ER |
581 | if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then |
582 | echo "Warning: No CVS access defined - using local .spec file" | |
583 | NOCVSSPEC="yes" | |
6b8daffa JB |
584 | fi |
585 | ||
3144da10 | 586 | cvsup "$SPECFILE" || Exit_error err_no_spec_in_repo |
6b8daffa | 587 | fi |
3144da10 | 588 | |
6b8daffa JB |
589 | if [ ! -f "$SPECFILE" ]; then |
590 | Exit_error err_no_spec_in_repo; | |
591 | fi | |
592 | ||
593 | if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then | |
594 | chmod $CHMOD_MODE $SPECFILE | |
595 | fi | |
596 | unset OPTIONS | |
7cede445 | 597 | [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE |
3144da10 | 598 | |
a638dc19 | 599 | set_spec_target |
6b8daffa JB |
600 | } |
601 | ||
602 | find_mirror() | |
603 | { | |
604 | cd "$SPECS_DIR" | |
a638dc19 | 605 | local url="$1" |
6b8daffa JB |
606 | if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then |
607 | cvs update mirrors >&2 | |
608 | fi | |
609 | ||
610 | IFS="|" | |
a638dc19 ER |
611 | local origin mirror name rest ol prefix |
612 | while read origin mirror name rest; do | |
613 | # skip comments and empty lines | |
614 | if [ -z "$origin" ] || [[ $origin == \#* ]]; then | |
615 | continue | |
616 | fi | |
6b8daffa JB |
617 | ol=`echo -n "$origin"|wc -c` |
618 | prefix="`echo -n "$url" | head -c $ol`" | |
619 | if [ "$prefix" = "$origin" ] ; then | |
a638dc19 | 620 | suffix="`echo "$url"|cut -b $((ol+1))-`" |
6b8daffa JB |
621 | echo -n "$mirror$suffix" |
622 | return 0 | |
623 | fi | |
624 | done < mirrors | |
625 | echo "$url" | |
626 | } | |
627 | ||
628 | src_no () | |
629 | { | |
630 | cd $SPECS_DIR | |
631 | rpm_dump | \ | |
632 | grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \ | |
633 | sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \ | |
634 | head -n 1 | xargs | |
635 | } | |
636 | ||
637 | src_md5 () | |
638 | { | |
639 | [ X"$NO5" = X"yes" ] && return | |
640 | no=$(src_no "$1") | |
641 | [ -z "$no" ] && return | |
642 | cd $SPECS_DIR | |
7cede445 | 643 | spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::) |
6b8daffa JB |
644 | if [ -z "$spec_rev" ]; then |
645 | spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')" | |
646 | fi | |
647 | spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')" | |
648 | md5=$(grep -s -v '^#' additional-md5sums | \ | |
649 | grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \ | |
650 | sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \ | |
651 | grep -E '^[0-9a-f]{32}$') | |
652 | if [ X"$md5" = X"" ] ; then | |
7cede445 ER |
653 | source_md5=`grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` |
654 | if [ ! -z "$source_md5" ] ; then | |
655 | echo $source_md5; | |
656 | else | |
657 | # we have empty SourceX-md5, but it is still possible | |
658 | # that we have NoSourceX-md5 AND NoSource: X | |
659 | nosource_md5=`grep -i "#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` | |
660 | if [ ! -z "$nosource_md5" -a ! X"`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" = X"" ] ; then | |
661 | echo $nosource_md5; | |
662 | fi; | |
663 | fi; | |
6b8daffa JB |
664 | else |
665 | if [ $(echo "$md5" | wc -l) != 1 ] ; then | |
666 | echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2 | |
667 | fi | |
668 | echo "$md5" | tail -n 1 | |
669 | fi | |
670 | } | |
671 | ||
a638dc19 ER |
672 | distfiles_path () |
673 | { | |
674 | echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")" | |
675 | } | |
676 | ||
6b8daffa JB |
677 | distfiles_url () |
678 | { | |
a638dc19 | 679 | echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")" |
6b8daffa JB |
680 | } |
681 | ||
682 | distfiles_attic_url () | |
683 | { | |
a638dc19 | 684 | echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")" |
6b8daffa JB |
685 | } |
686 | ||
687 | good_md5 () | |
688 | { | |
689 | md5=$(src_md5 "$1") | |
690 | [ "$md5" = "" ] || \ | |
691 | [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ] | |
692 | } | |
693 | ||
7cede445 ER |
694 | good_size () |
695 | { | |
a638dc19 ER |
696 | size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)" |
697 | [ -n "$size" -a "$size" -gt 0 ] | |
7cede445 ER |
698 | } |
699 | ||
700 | cvsignore_df () | |
701 | { | |
702 | if [ "$CVSIGNORE_DF" != "yes" ]; then | |
703 | return | |
704 | fi | |
705 | cvsignore=${SOURCE_DIR}/.cvsignore | |
706 | if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then | |
707 | echo "$1" >> $cvsignore | |
708 | fi | |
709 | } | |
710 | ||
3144da10 ER |
711 | cvsup() |
712 | { | |
a638dc19 ER |
713 | update_shell_title "cvsup" |
714 | local OPTIONS="up " | |
715 | if [ -n "$CVSROOT" ]; then | |
716 | OPTIONS="-d $CVSROOT $OPTIONS" | |
717 | fi | |
3144da10 | 718 | |
a638dc19 ER |
719 | if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then |
720 | OPTIONS="$OPTIONS -A" | |
721 | else | |
722 | if [ -n "$CVSDATE" ]; then | |
723 | OPTIONS="$OPTIONS -D $CVSDATE" | |
724 | fi | |
725 | if [ -n "$CVSTAG" ]; then | |
726 | OPTIONS="$OPTIONS -r $CVSTAG" | |
727 | fi | |
728 | fi | |
3144da10 | 729 | |
a638dc19 ER |
730 | local result=1 |
731 | local retries_counter=0 | |
732 | if [ $# = 1 ]; then | |
733 | update_shell_title "cvsup: $*" | |
734 | else | |
735 | update_shell_title "cvsup: $# files" | |
736 | fi | |
737 | while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do | |
738 | retries_counter=$(( $retries_counter + 1 )) | |
739 | output=$(LC_ALL=C cvs $OPTIONS "$@" 2>&1) | |
740 | result=$? | |
741 | [ -n "$output" ] && echo "$output" | |
742 | 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 | |
743 | echo "Trying again [$*]... ($retries_counter)" | |
744 | update_shell_title "cvsup: retry #$retries_counter" | |
745 | sleep 2 | |
746 | continue | |
747 | else | |
748 | break | |
749 | fi | |
750 | done | |
751 | update_shell_title "cvsup: done!" | |
752 | return $result | |
3144da10 ER |
753 | } |
754 | ||
6b8daffa JB |
755 | get_files() |
756 | { | |
3144da10 | 757 | update_shell_title "get_files" |
6b8daffa JB |
758 | |
759 | if [ -n "$DEBUG" ]; then | |
760 | set -x; | |
761 | set -v; | |
762 | fi | |
763 | ||
3144da10 | 764 | if [ $# -gt 0 ]; then |
6b8daffa JB |
765 | cd "$SOURCE_DIR" |
766 | ||
3144da10 ER |
767 | if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then |
768 | echo "Warning: No CVS access defined for SOURCES" | |
769 | NOCVS="yes" | |
6b8daffa | 770 | fi |
3144da10 ER |
771 | |
772 | local nc=0 | |
773 | local get_files_cvs="" | |
774 | for i in "$@"; do | |
775 | nc=$((nc + 1)) | |
776 | local cvsup=0 | |
777 | SHELL_TITLE_PREFIX="get_files[$nc/$#]" | |
778 | update_shell_title "$i" | |
779 | local fp=`nourl "$i"` | |
780 | if [ -f "$fp" ] && [ "$SKIP_EXISTING_FILES" = "yes" ]; then | |
a638dc19 | 781 | continue |
6b8daffa | 782 | fi |
6b8daffa JB |
783 | if [ -n "$UPDATE5" ]; then |
784 | if [ -n "$ADD5" ]; then | |
3144da10 | 785 | [ "$fp" = "$i" ] && continue |
6b8daffa JB |
786 | grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue |
787 | else | |
788 | grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue | |
789 | fi | |
790 | fi | |
791 | FROM_DISTFILES=0 | |
3144da10 | 792 | if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then |
6b8daffa JB |
793 | if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then |
794 | echo "Warning: no URL given for $i" | |
795 | fi | |
796 | ||
3144da10 | 797 | if [ -z "$NODIST" ] && [ -n "$(src_md5 "$i")" ]; then |
7cede445 | 798 | if good_md5 "$i" && good_size "$i"; then |
6b8daffa JB |
799 | echo "$(nourl "$i") having proper md5sum already exists" |
800 | continue | |
801 | fi | |
3144da10 | 802 | target="$fp" |
6b8daffa JB |
803 | url=$(distfiles_url "$i") |
804 | url_attic=$(distfiles_attic_url "$i") | |
805 | FROM_DISTFILES=1 | |
3144da10 ER |
806 | if [ "`echo $url | grep -E '^(\.|/)'`" ]; then |
807 | update_shell_title "${GETLOCAL%% *}: $url" | |
6b8daffa JB |
808 | ${GETLOCAL} $url $target |
809 | else | |
810 | if [ -z "$NOMIRRORS" ]; then | |
811 | url="`find_mirror "$url"`" | |
812 | fi | |
3144da10 | 813 | update_shell_title "${GETURI%% *}: $url" |
7cede445 | 814 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
3144da10 ER |
815 | if [ "`echo $url | grep -E 'ftp://'`" ]; then |
816 | update_shell_title "${GETURI2%% *}: $url" | |
7cede445 | 817 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
6b8daffa JB |
818 | fi |
819 | fi | |
820 | if ! test -s "$target"; then | |
821 | rm -f "$target" | |
822 | if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then | |
3144da10 | 823 | update_shell_title "${GETLOCAL%% *}: $url_attic" |
6b8daffa JB |
824 | ${GETLOCAL} $url_attic $target |
825 | else | |
826 | if [ -z "$NOMIRRORS" ]; then | |
827 | url_attic="`find_mirror "$url_attic"`" | |
828 | fi | |
3144da10 | 829 | update_shell_title "${GETURI%% *}: $url_attic" |
7cede445 | 830 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
3144da10 | 831 | if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then |
a638dc19 | 832 | update_shell_title "${GETURI2%% *}: $url_attic" |
7cede445 | 833 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
6b8daffa JB |
834 | fi |
835 | fi | |
836 | fi | |
7cede445 ER |
837 | if test -s "$target"; then |
838 | cvsignore_df $target | |
839 | else | |
6b8daffa JB |
840 | rm -f "$target" |
841 | FROM_DISTFILES=0 | |
842 | fi | |
3144da10 ER |
843 | elif [ "$NOCVS" != "yes" -a -z "$(src_md5 "$i")" ]; then |
844 | if [ $# -gt 1 ]; then | |
845 | get_files_cvs="$get_files_cvs $fp" | |
846 | update_shell_title "$fp (will cvs up later)" | |
847 | cvsup=1 | |
848 | else | |
849 | cvsup $fp | |
850 | fi | |
6b8daffa JB |
851 | fi |
852 | ||
3144da10 | 853 | if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then |
6b8daffa JB |
854 | if [ -z "$NOMIRRORS" ]; then |
855 | im="`find_mirror "$i"`" | |
856 | else | |
857 | im="$i" | |
858 | fi | |
a638dc19 | 859 | update_shell_title "${GETURI%% *}: $im" |
6b8daffa | 860 | ${GETURI} "$im" || \ |
3144da10 | 861 | if [ "`echo $im | grep -E 'ftp://'`" ]; then |
a638dc19 | 862 | update_shell_title "${GETURI2%% *}: $im" |
6b8daffa | 863 | ${GETURI2} "$im" |
7cede445 | 864 | fi |
6b8daffa JB |
865 | fi |
866 | ||
3144da10 ER |
867 | if [ "$cvsup" = 1 ]; then |
868 | continue | |
869 | fi | |
870 | ||
6b8daffa JB |
871 | fi |
872 | srcno=$(src_no $i) | |
3144da10 | 873 | if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then |
6b8daffa JB |
874 | Exit_error err_no_source_in_repo $i; |
875 | elif [ -n "$UPDATE5" ] && \ | |
876 | ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \ | |
877 | [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \ | |
878 | grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE ) | |
879 | then | |
880 | echo "Updating source-$srcno md5." | |
3144da10 | 881 | md5=$(md5sum "$fp" | cut -f1 -d' ') |
6b8daffa JB |
882 | perl -i -ne ' |
883 | print unless /^\s*#\s*Source'$srcno'-md5\s*:/i; | |
884 | print "# Source'$srcno'-md5:\t'$md5'\n" | |
885 | if /^Source'$srcno'\s*:\s+/; | |
886 | ' \ | |
887 | $SPECS_DIR/$SPECFILE | |
888 | fi | |
7cede445 ER |
889 | |
890 | if good_md5 "$i" && good_size "$i"; then | |
6b8daffa JB |
891 | : |
892 | elif [ "$FROM_DISTFILES" = 1 ]; then | |
893 | # wrong md5 from distfiles: remove the file and try again | |
894 | # but only once ... | |
895 | echo "MD5 sum mismatch. Trying full fetch." | |
896 | FROM_DISTFILES=2 | |
897 | rm -f $target | |
3144da10 | 898 | update_shell_title "${GETURI%% *}: $url" |
7cede445 | 899 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
3144da10 | 900 | if [ "`echo $url | grep -E 'ftp://'`" ]; then |
a638dc19 | 901 | update_shell_title "${GETURI2%% *}: $url" |
7cede445 | 902 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
6b8daffa JB |
903 | fi |
904 | if ! test -s "$target"; then | |
905 | rm -f "$target" | |
3144da10 | 906 | update_shell_title "${GETURI%% *}: $url_attic" |
7cede445 | 907 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
3144da10 | 908 | if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then |
a638dc19 | 909 | update_shell_title "${GETURI2%% *}: $url_attic" |
7cede445 | 910 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
6b8daffa JB |
911 | fi |
912 | fi | |
913 | test -s "$target" || rm -f "$target" | |
914 | fi | |
915 | ||
7cede445 | 916 | if good_md5 "$i" && good_size "$i" ; then |
6b8daffa JB |
917 | : |
918 | else | |
7cede445 | 919 | echo "MD5 sum mismatch or 0 size. Use -U to refetch sources," |
6b8daffa JB |
920 | echo "or -5 to update md5 sums, if you're sure files are correct." |
921 | Exit_error err_no_source_in_repo $i | |
922 | fi | |
923 | done | |
3144da10 ER |
924 | SHELL_TITLE_PREFIX="" |
925 | ||
926 | if [ "$get_files_cvs" ]; then | |
a638dc19 | 927 | cvsup $get_files_cvs |
3144da10 | 928 | fi |
6b8daffa JB |
929 | |
930 | if [ "$CHMOD" = "yes" ]; then | |
3144da10 | 931 | CHMOD_FILES="`nourl "$@"`" |
6b8daffa JB |
932 | if [ -n "$CHMOD_FILES" ]; then |
933 | chmod $CHMOD_MODE $CHMOD_FILES | |
934 | fi | |
935 | fi | |
6b8daffa JB |
936 | fi |
937 | } | |
938 | ||
939 | make_tagver() { | |
a638dc19 ER |
940 | if [ -n "$DEBUG" ]; then |
941 | set -x; | |
942 | set -v; | |
943 | fi | |
7cede445 | 944 | |
a638dc19 ER |
945 | # Check whether first character of PACKAGE_NAME is legal for tag name |
946 | if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then | |
947 | TAG_PREFIX=tag_ | |
948 | fi | |
949 | TAGVER=$TAG_PREFIX$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"` | |
950 | # Remove #kernel.version_release from TAGVER because tagging sources | |
951 | # could occur with different kernel-headers than kernel-headers used at build time. | |
952 | TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g') | |
953 | echo -n "$TAGVER" | |
6b8daffa JB |
954 | } |
955 | ||
956 | tag_files() | |
957 | { | |
958 | TAG_FILES="$@" | |
959 | ||
960 | if [ -n "$DEBUG" ]; then | |
961 | set -x; | |
962 | set -v; | |
963 | fi | |
964 | ||
965 | if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then | |
966 | echo "Version: $PACKAGE_VERSION" | |
967 | echo "Release: $PACKAGE_RELEASE" | |
968 | ||
969 | TAGVER=`make_tagver` | |
970 | ||
971 | if [ "$TAG_VERSION" = "yes" ]; then | |
972 | echo "CVS tag: $TAGVER" | |
973 | fi | |
974 | if [ -n "$TAG" ]; then | |
975 | echo "CVS tag: $TAG" | |
976 | fi | |
977 | ||
978 | OPTIONS="tag -F" | |
979 | if [ -n "$CVSROOT" ]; then | |
980 | OPTIONS="-d $CVSROOT $OPTIONS" | |
981 | fi | |
982 | ||
983 | cd "$SOURCE_DIR" | |
984 | for i in $TAG_FILES | |
985 | do | |
986 | # don't tag files stored on distfiles | |
987 | [ -n "`src_md5 $i`" ] && continue | |
988 | if [ -f "`nourl $i`" ]; then | |
989 | if [ "$TAG_VERSION" = "yes" ]; then | |
990 | cvs $OPTIONS $TAGVER `nourl $i` | |
991 | fi | |
992 | if [ -n "$TAG" ]; then | |
993 | cvs $OPTIONS $TAG `nourl $i` | |
994 | fi | |
995 | else | |
996 | Exit_error err_no_source_in_repo $i | |
997 | fi | |
998 | done | |
999 | ||
1000 | cd "$SPECS_DIR" | |
1001 | if [ "$TAG_VERSION" = "yes" ]; then | |
1002 | cvs $OPTIONS $TAGVER $SPECFILE | |
1003 | fi | |
1004 | if [ -n "$TAG" ]; then | |
1005 | cvs $OPTIONS $TAG $SPECFILE | |
1006 | fi | |
1007 | ||
1008 | unset OPTIONS | |
1009 | fi | |
1010 | } | |
1011 | ||
1012 | branch_files() | |
1013 | { | |
1014 | TAG=$1 | |
1015 | echo "CVS branch tag: $TAG" | |
1016 | shift; | |
1017 | ||
1018 | TAG_FILES="$@" | |
1019 | ||
1020 | if [ -n "$DEBUG" ]; then | |
1021 | set -x; | |
1022 | set -v; | |
1023 | fi | |
1024 | ||
1025 | if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then | |
1026 | ||
1027 | OPTIONS="tag -b" | |
1028 | if [ -n "$CVSROOT" ]; then | |
1029 | OPTIONS="-d $CVSROOT $OPTIONS" | |
1030 | fi | |
1031 | cd "$SOURCE_DIR" | |
1032 | for i in $TAG_FILES | |
1033 | do | |
1034 | if [ -f `nourl $i` ]; then | |
1035 | cvs $OPTIONS $TAG `nourl $i` | |
1036 | else | |
1037 | Exit_error err_no_source_in_repo $i | |
1038 | fi | |
1039 | done | |
1040 | cd "$SPECS_DIR" | |
1041 | cvs $OPTIONS $TAG $SPECFILE | |
1042 | ||
1043 | unset OPTIONS | |
1044 | fi | |
1045 | } | |
1046 | ||
1047 | ||
1048 | ||
1049 | build_package() | |
1050 | { | |
3144da10 | 1051 | update_shell_title "build_package" |
6b8daffa JB |
1052 | if [ -n "$DEBUG" ]; then |
1053 | set -x; | |
1054 | set -v; | |
1055 | fi | |
1056 | ||
1057 | cd "$SPECS_DIR" | |
1058 | ||
1059 | if [ -n "$TRY_UPGRADE" ]; then | |
a638dc19 | 1060 | update_shell_title "build_package: try_upgrade" |
6b8daffa | 1061 | if [ -n "$FLOAT_VERSION" ]; then |
3144da10 | 1062 | TNOTIFY=`./pldnotify.awk $SPECFILE -n` || exit 1 |
6b8daffa | 1063 | else |
3144da10 | 1064 | TNOTIFY=`./pldnotify.awk $SPECFILE` || exit 1 |
6b8daffa JB |
1065 | fi |
1066 | ||
1067 | TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'` | |
1068 | ||
1069 | if [ -n "$TNEWVER" ]; then | |
1070 | TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'` | |
1071 | echo "New version found, updating spec file to version " $TNEWVER | |
1072 | cp -f $SPECFILE $SPECFILE.bak | |
1073 | chmod +w $SPECFILE | |
1074 | eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE" | |
3144da10 | 1075 | eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE" |
6b8daffa | 1076 | parse_spec; |
3144da10 | 1077 | NODIST="yes" UPDATE5="yes" get_files $SOURCES $PATCHES; |
6b8daffa JB |
1078 | unset TOLDVER TNEWVER TNOTIFY |
1079 | fi | |
1080 | fi | |
1081 | cd "$SPECS_DIR" | |
7cede445 | 1082 | |
6b8daffa JB |
1083 | case "$COMMAND" in |
1084 | build ) | |
1085 | BUILD_SWITCH="-ba" ;; | |
1086 | build-binary ) | |
1087 | BUILD_SWITCH="-bb" ;; | |
1088 | build-source ) | |
1089 | BUILD_SWITCH="-bs --nodeps" ;; | |
1090 | build-prep ) | |
1091 | BUILD_SWITCH="-bp --nodeps" ;; | |
1092 | esac | |
3144da10 ER |
1093 | |
1094 | update_shell_title "build_package: $COMMAND" | |
6b8daffa JB |
1095 | if [ -n "$LOGFILE" ]; then |
1096 | LOG=`eval echo $LOGFILE` | |
1097 | if [ -d "$LOG" ]; then | |
1098 | echo "Log file $LOG is a directory." | |
1099 | echo "Parse error in the spec?" | |
1100 | Exit_error err_build_fail; | |
1101 | fi | |
1102 | if [ -n "$LASTLOG_FILE" ]; then | |
1103 | echo "LASTLOG=$LOG" > $LASTLOG_FILE | |
1104 | fi | |
1105 | RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM | |
a638dc19 | 1106 | (time eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG |
6b8daffa JB |
1107 | RETVAL=`cat $RES_FILE` |
1108 | rm $RES_FILE | |
1109 | if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then | |
1110 | if [ "$RETVAL" -eq "0" ]; then | |
1111 | mv $LOG $LOGDIROK | |
1112 | else | |
1113 | mv $LOG $LOGDIRFAIL | |
1114 | fi | |
1115 | fi | |
1116 | else | |
a638dc19 | 1117 | eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE |
6b8daffa JB |
1118 | RETVAL=$? |
1119 | fi | |
1120 | if [ "$RETVAL" -ne "0" ]; then | |
1121 | if [ -n "$TRY_UPGRADE" ]; then | |
a638dc19 | 1122 | echo "\n!!! Package with new version cannot be built automagically\n" |
6b8daffa JB |
1123 | mv -f $SPECFILE.bak $SPECFILE |
1124 | fi | |
1125 | Exit_error err_build_fail; | |
1126 | fi | |
1127 | unset BUILD_SWITCH | |
1128 | } | |
1129 | ||
1130 | nourl() | |
1131 | { | |
1132 | echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g' | |
1133 | } | |
1134 | ||
6b8daffa JB |
1135 | install_required_packages() |
1136 | { | |
1137 | run_poldek -vi $1 | |
1138 | return $? | |
1139 | } | |
1140 | ||
3144da10 ER |
1141 | find_spec_bcond() { |
1142 | # taken from find-spec-bcond, but with just getting the list | |
1143 | local SPEC="$1" | |
1144 | # quick revert hint: '$RPMBUILD --bcond $SPEC' | |
1145 | awk -F"\n" ' | |
1146 | /^%changelog/ { exit } | |
1147 | /_with(out)?_[_a-zA-Z0-9]+/{ | |
1148 | match($0, /_with(out)?_[_a-zA-Z0-9]+/); | |
1149 | print substr($0, RSTART, RLENGTH); | |
1150 | } | |
1151 | /^%bcond_with/{ | |
1152 | match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/); | |
1153 | bcond = substr($0, RSTART +5 , RLENGTH -5); | |
1154 | gsub(/[ \t]+/,"_",bcond); | |
1155 | print bcond | |
1156 | }' $SPEC | LC_ALL=C sort -u | |
1157 | } | |
1158 | ||
6b8daffa JB |
1159 | set_bconds_values() |
1160 | { | |
3144da10 ER |
1161 | update_shell_title "set bcond values" |
1162 | ||
6b8daffa JB |
1163 | AVAIL_BCONDS_WITHOUT="" |
1164 | AVAIL_BCONDS_WITH="" | |
1165 | if `grep -q ^%bcond ${SPECFILE}`; then | |
1166 | BCOND_VERSION="NEW" | |
7cede445 | 1167 | elif `egrep -q ^#\ *_with ${SPECFILE}`; then |
6b8daffa JB |
1168 | BCOND_VERSION="OLD" |
1169 | else | |
3144da10 | 1170 | return |
6b8daffa | 1171 | fi |
7cede445 | 1172 | |
3144da10 ER |
1173 | local bcond_avail=$(find_spec_bcond $SPECFILE) |
1174 | ||
7cede445 ER |
1175 | # expand bconds from ~/.bcondrc |
1176 | # The file structure is like gentoo's package.use: | |
1177 | # --- | |
1178 | # * -selinux | |
1179 | # samba -mysql -pgsql | |
1180 | # w32codec-installer license_agreement | |
1181 | # php +mysqli | |
1182 | # --- | |
3144da10 ER |
1183 | if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then |
1184 | SN=${SPECFILE%%\.spec} | |
7cede445 | 1185 | |
3144da10 ER |
1186 | local bcondrc=$HOME/.bcondrc |
1187 | [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc | |
7cede445 ER |
1188 | |
1189 | while read pkg flags; do | |
1190 | # ignore comments | |
1191 | [[ "$pkg" == \#* ]] && continue | |
1192 | ||
1193 | # any package or current package? | |
3144da10 | 1194 | if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then |
7cede445 | 1195 | for flag in $flags; do |
3144da10 | 1196 | local opt=${flag#[+-]} |
7cede445 ER |
1197 | |
1198 | # use only flags which are in this package. | |
3144da10 | 1199 | if [[ $bcond_avail = *${opt}* ]]; then |
7cede445 ER |
1200 | if [[ $flag = -* ]]; then |
1201 | BCOND="$BCOND --without $opt" | |
1202 | else | |
1203 | BCOND="$BCOND --with $opt" | |
1204 | fi | |
1205 | fi | |
1206 | done | |
1207 | fi | |
3144da10 ER |
1208 | done < $bcondrc |
1209 | update_shell_title "parse ~/.bcondrc: DONE!" | |
7cede445 ER |
1210 | fi |
1211 | ||
3144da10 | 1212 | update_shell_title "parse bconds" |
6b8daffa | 1213 | case "${BCOND_VERSION}" in |
3144da10 | 1214 | NONE) |
7cede445 | 1215 | : |
6b8daffa | 1216 | ;; |
7cede445 | 1217 | OLD) |
6b8daffa | 1218 | echo "Warning: This spec has old style bconds. Fix it || die." |
3144da10 | 1219 | for opt in `echo "$bcond_avail" | grep ^_without_` |
6b8daffa | 1220 | do |
3144da10 ER |
1221 | AVAIL_BCOND_WITHOUT=${opt#_without_} |
1222 | if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then | |
6b8daffa JB |
1223 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>" |
1224 | else | |
1225 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT" | |
1226 | fi | |
1227 | done | |
7cede445 | 1228 | |
3144da10 | 1229 | for opt in `echo "$bcond_avail" | grep ^_with_` |
6b8daffa | 1230 | do |
3144da10 ER |
1231 | AVAIL_BCOND_WITH=${opt#_with_} |
1232 | if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then | |
6b8daffa JB |
1233 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>" |
1234 | else | |
1235 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH" | |
1236 | fi | |
1237 | done | |
1238 | ;; | |
1239 | NEW) | |
3144da10 ER |
1240 | local cond_type="" # with || without |
1241 | for opt in $bcond_avail; do | |
6b8daffa JB |
1242 | case "$opt" in |
1243 | _without) | |
1244 | cond_type="without" | |
1245 | ;; | |
1246 | _with) | |
1247 | cond_type="with" | |
1248 | ;; | |
7cede445 | 1249 | _without_*) |
3144da10 ER |
1250 | AVAIL_BCOND_WITHOUT=${opt#_without_} |
1251 | if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then | |
7cede445 ER |
1252 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>" |
1253 | else | |
1254 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT" | |
1255 | fi | |
1256 | ;; | |
1257 | _with_*) | |
3144da10 ER |
1258 | AVAIL_BCOND_WITH=${opt#_with_} |
1259 | if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then | |
7cede445 ER |
1260 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>" |
1261 | else | |
1262 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH" | |
1263 | fi | |
1264 | ;; | |
6b8daffa JB |
1265 | *) |
1266 | case "$cond_type" in | |
1267 | with) | |
1268 | cond_type='' | |
1269 | AVAIL_BCOND_WITH="$opt" | |
3144da10 | 1270 | if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then |
6b8daffa JB |
1271 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>" |
1272 | else | |
1273 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH" | |
1274 | fi | |
7cede445 | 1275 | ;; |
6b8daffa JB |
1276 | without) |
1277 | cond_type='' | |
1278 | AVAIL_BCOND_WITHOUT="$opt" | |
3144da10 | 1279 | if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then |
6b8daffa JB |
1280 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>" |
1281 | else | |
1282 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT" | |
1283 | fi | |
1284 | ;; | |
1285 | esac | |
1286 | ;; | |
1287 | esac | |
1288 | done | |
1289 | ;; | |
1290 | esac | |
1291 | } | |
1292 | ||
1293 | run_sub_builder() | |
1294 | { | |
1295 | package_name="${1}" | |
3144da10 | 1296 | update_shell_title "run_sub_builder $package_name" |
6b8daffa JB |
1297 | # |
1298 |