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