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