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