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