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