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