]>
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 | |
0907f1eb ER |
366 | php-pear-Services_Digg/ |
367 | --upgrade-version - upgrade to specified version in try-upgrade | |
f8dba812 | 368 | --use-greed-sources |
369 | - try download source from tag head if don't find it in | |
f5141bbc | 370 | current tag |
deccc50e | 371 | -U, --update - refetch sources, don't use distfiles, and update md5 comments |
cd445739 AM |
372 | -Upi, --update-poldek-indexes |
373 | - refresh or make poldek package index files. | |
c890b916 | 374 | -np, --nopatch <patchnumber> |
bed98670 | 375 | - don't apply <patchnumber> |
dfe2cb9a MK |
376 | --show-bconds - show available conditional builds, which can be used |
377 | - with --with and/or --without switches. | |
9b78be50 ER |
378 | --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by |
379 | ./repackage.sh script. in other words, the output is | |
380 | parseable by scripts. | |
24a97174 | 381 | --show-avail-bconds - show available bconds |
cd445739 AM |
382 | --with/--without <feature> |
383 | - conditional build package depending on %_with_<feature>/ | |
384 | %_without_<feature> macro switch. You may now use | |
385 | --with feat1 feat2 feat3 --without feat4 feat5 --with feat6 | |
386 | constructions. Set GROUP_BCONDS to yes to make use of it. | |
6dd19291 | 387 | --target <platform>, --target=<platform> |
3621e588 ER |
388 | - build for platform <platform>. |
389 | --init-rpm-dir - initialize ~/rpm directory structure | |
5a491465 | 390 | " |
391 | } | |
392 | ||
31d2bd0b ER |
393 | # change dependency to specname |
394 | # common changes: | |
395 | # - perl(Package::Name) -> perl-Package-Name | |
396 | depspecname() { | |
397 | local package="$1" | |
398 | ||
560c4b1a | 399 | package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' ) |
31d2bd0b ER |
400 | echo "$package" |
401 | } | |
402 | ||
c890b916 | 403 | update_shell_title() { |
a0d6396b | 404 | [ -t 1 ] || return |
0b65d15e | 405 | local len=${COLUMNS:-80} |
5c795f16 | 406 | local msg="$(echo "$*" | cut -c-$len)" |
0b65d15e | 407 | |
e225de91 ER |
408 | if [ -n "$BE_VERBOSE" ]; then |
409 | echo >&2 "$(date +%s.%N) $*" | |
410 | fi | |
411 | ||
5c795f16 | 412 | if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then |
138bbc98 ER |
413 | local pkg |
414 | if [ -n "$PACKAGE_NAME" ]; then | |
415 | pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE} | |
416 | else | |
417 | pkg=${SPECFILE} | |
418 | fi | |
419 | ||
420 | msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg" | |
a8c9a155 | 421 | msg=$(echo $msg | tr -d '\n\r') |
982e358c MP |
422 | case "$TERM" in |
423 | cygwin|xterm*) | |
424 | echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007" | |
425 | ;; | |
426 | screen*) | |
427 | echo >&2 -ne "\033]0;$msg\007" | |
428 | ;; | |
429 | esac | |
430 | fi | |
c890b916 ER |
431 | } |
432 | ||
7e40520f ER |
433 | # set TARGET from BuildArch: from SPECFILE |
434 | set_spec_target() { | |
ce40491a | 435 | if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then |
b45a3b2a | 436 | tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE) |
ce40491a | 437 | if [ "$tmp" ]; then |
f9109a96 | 438 | target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}') |
7e40520f ER |
439 | TARGET="$tmp" |
440 | case "$RPMBUILD" in | |
441 | "rpmbuild") | |
f9109a96 | 442 | TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;; |
7e40520f | 443 | "rpm") |
ce40491a | 444 | TARGET_SWITCH="--target=$TARGET" ;; |
7e40520f | 445 | esac |
ce40491a ER |
446 | fi |
447 | fi | |
7e40520f ER |
448 | } |
449 | ||
ace3fd80 ER |
450 | # runs rpm with minimal macroset |
451 | minirpm() { | |
fa4bf1df | 452 | # we reset macros not to contain macros.build as all the %() macros are |
559d511f | 453 | # executed here, while none of them are actually needed. |
559d511f | 454 | # at the time of this writing macros.build + macros contained 70 "%(...)" macros. |
525bf240 | 455 | safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ') |
ace3fd80 ER |
456 | |
457 | # TODO: move these to /usr/lib/rpm/macros | |
20117088 | 458 | cat > $BUILDER_MACROS <<'EOF' |
5b5e5f7f | 459 | %x8664 x86_64 amd64 ia32e |
f78a0bb7 | 460 | %alt_kernel %{nil} |
461 | %_alt_kernel %{nil} | |
5ff15c97 | 462 | %bootstrap_release() %{1} |
407b204b ER |
463 | %requires_releq_kernel_up(s:n:) %{nil} |
464 | %requires_releq_kernel_smp(s:n:) %{nil} | |
465 | %requires_releq_kernel(s:n:) %{nil} | |
6b8134e3 | 466 | %requires_releq() %{nil} |
bb01dee9 | 467 | %pyrequires_eq() %{nil} |
559d511f | 468 | %requires_eq() %{nil} |
c13be3d1 | 469 | %requires_eq_to() %{nil} |
99c05e13 | 470 | %requires_ge() %{nil} |
500b0eb8 ER |
471 | %requires_ge_to() %{nil} |
472 | %requires_ge() %{nil} | |
407b204b ER |
473 | %releq_kernel_up(n:) ERROR |
474 | %releq_kernel_smp(n:) ERROR | |
475 | %releq_kernel(n:) ERROR | |
74d9fd14 | 476 | %kgcc_package ERROR |
237bd3f1 | 477 | %_fontsdir ERROR |
7141278d | 478 | %ruby_version ERROR |
479 | %ruby_ver_requires_eq() %{nil} | |
480 | %ruby_mod_ver_requires_eq() %{nil} | |
c13be3d1 | 481 | %__php_api_requires() %{nil} |
7141278d | 482 | %php_major_version ERROR |
483 | %php_api_version ERROR | |
99f819cf AM |
484 | %requires_xorg_xserver_extension %{nil} |
485 | %requires_xorg_xserver_xinput %{nil} | |
486 | %requires_xorg_xserver_font %{nil} | |
487 | %requires_xorg_xserver_videodrv %{nil} | |
7141278d | 488 | %py_ver ERROR |
41035426 ER |
489 | %perl_vendorarch ERROR |
490 | %perl_vendorlib ERROR | |
703ae20b ER |
491 | # damn. need it here! - copied from /usr/lib/rpm/macros.build |
492 | %tmpdir %(echo "${TMPDIR:-/tmp}") | |
1f28fcb7 ER |
493 | %patchset_source(f:b:) %( |
494 | base=%{-b*}%{!-b*:10000}; | |
495 | start=$(expr $base + %1); | |
496 | end=$(expr $base + %{?2}%{!?2:%{1}}); | |
497 | # we need to call seq twice as it doesn't allow two formats | |
498 | seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1; | |
499 | seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2; | |
500 | paste %{tmpdir}/__ps{1,2}; | |
501 | rm -f %{tmpdir}/__ps{1,2}; | |
502 | ) \ | |
503 | %{nil} | |
991f09a5 ER |
504 | %add_etc_shells(p) %{p:<lua>} |
505 | %remove_etc_shells(p) %{p:<lua>} | |
709995c4 ER |
506 | %lua_add_etc_shells() %{nil} |
507 | %lua_remove_etc_shells() %{nil} | |
0ca65fa4 JK |
508 | %required_jdk %{nil} |
509 | %buildrequires_jdk %{nil} | |
f9063abe | 510 | %pear_package_print_optionalpackages %{nil} |
fb198857 | 511 | EOF |
3d12d055 | 512 | if [ "$NOINIT" = "yes" ] ; then |
20117088 | 513 | cat >> $BUILDER_MACROS <<'EOF' |
3d12d055 JR |
514 | %_specdir ./ |
515 | %_sourcedir ./ | |
516 | EOF | |
c039643c | 517 | fi |
fff1b991 | 518 | eval $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1 |
ace3fd80 ER |
519 | } |
520 | ||
521 | cache_rpm_dump() { | |
522 | if [ -n "$DEBUG" ]; then | |
523 | set -x | |
524 | set -v | |
525 | fi | |
526 | ||
d1d24c14 | 527 | if [ -x /usr/bin/rpm-specdump ]; then |
525bf240 | 528 | update_shell_title "cache_rpm_dump using rpm-specdump command" |
fff1b991 | 529 | rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND $SPECFILE) |
d1d24c14 | 530 | else |
525bf240 | 531 | update_shell_title "cache_rpm_dump using rpmbuild command" |
d1d24c14 ER |
532 | local rpm_dump |
533 | rpm_dump=` | |
534 | # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES. | |
535 | dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump' | |
536 | case "$RPMBUILD" in | |
537 | rpm) | |
538 | ARGS='-bp' | |
539 | ;; | |
540 | rpmbuild) | |
541 | ARGS='--nodigest --nosignature --nobuild' | |
542 | ;; | |
543 | esac | |
544 | minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE | |
545 | ` | |
546 | if [ $? -gt 0 ]; then | |
547 | error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p') | |
548 | echo "$error" >&2 | |
549 | Exit_error err_build_fail | |
550 | fi | |
d05e8080 | 551 | |
d1d24c14 ER |
552 | # make small dump cache |
553 | rpm_dump_cache=`echo "$rpm_dump" | awk ' | |
554 | $2 ~ /^SOURCEURL/ {print} | |
555 | $2 ~ /^PATCHURL/ {print} | |
556 | $2 ~ /^nosource/ {print} | |
557 | $2 ~ /^PACKAGE_/ {print} | |
558 | '` | |
559 | fi | |
d05e8080 | 560 | |
13974367 | 561 | update_shell_title "cache_rpm_dump: OK!" |
cd445739 AM |
562 | } |
563 | ||
ace3fd80 | 564 | rpm_dump() { |
cd445739 | 565 | if [ -z "$rpm_dump_cache" ] ; then |
45e2a818 | 566 | echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)" |
cd445739 AM |
567 | fi |
568 | echo "$rpm_dump_cache" | |
569 | } | |
570 | ||
f6711e2a | 571 | get_icons() { |
d05e8080 | 572 | update_shell_title "get icons" |
9d99a240 | 573 | ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE}) |
d05e8080 ER |
574 | if [ -z "$ICONS" ]; then |
575 | return | |
576 | fi | |
577 | ||
975d7b23 | 578 | rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS |
d05e8080 ER |
579 | } |
580 | ||
f6711e2a | 581 | parse_spec() { |
af4d5315 | 582 | update_shell_title "parsing specfile" |
cd445739 | 583 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
584 | set -x |
585 | set -v | |
cd445739 | 586 | fi |
b2975fc3 | 587 | |
d05e8080 | 588 | # icons are needed for successful spec parse |
518ff1fb | 589 | get_icons |
d05e8080 | 590 | |
9c909460 | 591 | cd $PACKAGE_DIR |
cd445739 | 592 | cache_rpm_dump |
00fcec7e | 593 | |
cd445739 AM |
594 | if (rpm_dump | grep -qEi ":.*nosource.*1"); then |
595 | FAIL_IF_NO_SOURCES="no" | |
596 | fi | |
597 | ||
7cbc2d88 ER |
598 | if [ "$NOSRCS" != "yes" ]; then |
599 | SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}') | |
600 | PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}') | |
601 | ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE}) | |
602 | fi | |
603 | ||
dfe2b2d9 ER |
604 | PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}') |
605 | PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}') | |
606 | PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}') | |
78eab2a1 | 607 | |
0b4119a2 | 608 | if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then |
7854d40c | 609 | echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)" |
0b4119a2 JR |
610 | fi |
611 | ||
cd445739 AM |
612 | if [ -n "$BE_VERBOSE" ]; then |
613 | echo "- Sources : `nourl $SOURCES`" | |
614 | if [ -n "$PATCHES" ]; then | |
615 | echo "- Patches : `nourl $PATCHES`" | |
616 | else | |
617 | echo "- Patches : *no patches needed*" | |
618 | fi | |
619 | if [ -n "$ICONS" ]; then | |
620 | echo "- Icon : `nourl $ICONS`" | |
621 | else | |
622 | echo "- Icon : *no package icon*" | |
623 | fi | |
624 | echo "- Name : $PACKAGE_NAME" | |
625 | echo "- Version : $PACKAGE_VERSION" | |
626 | echo "- Release : $PACKAGE_RELEASE" | |
627 | fi | |
13974367 ER |
628 | |
629 | update_shell_title "parse_spec: OK!" | |
cd445739 AM |
630 | } |
631 | ||
f6711e2a | 632 | Exit_error() { |
cd445739 | 633 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
634 | set -x |
635 | set -v | |
cd445739 AM |
636 | fi |
637 | ||
638 | cd "$__PWD" | |
639 | ||
640 | case "$1" in | |
641 | "err_no_spec_in_cmdl" ) | |
642 | remove_build_requires | |
45e2a818 | 643 | echo >&2 "ERROR: spec file name not specified." |
cd445739 | 644 | exit 2 ;; |
a08d92fc | 645 | "err_invalid_cmdline" ) |
45e2a818 | 646 | echo >&2 "ERROR: invalid command line arg ($2)." |
a08d92fc | 647 | exit 2 ;; |
cd445739 AM |
648 | "err_no_spec_in_repo" ) |
649 | remove_build_requires | |
45e2a818 | 650 | echo >&2 "Error: spec file not stored in CVS repo." |
cd445739 AM |
651 | exit 3 ;; |
652 | "err_no_source_in_repo" ) | |
653 | remove_build_requires | |
45e2a818 | 654 | echo >&2 "Error: some source, patch or icon files not stored in CVS repo. ($2)" |
cd445739 AM |
655 | exit 4 ;; |
656 | "err_build_fail" ) | |
657 | remove_build_requires | |
45e2a818 | 658 | echo >&2 "Error: package build failed. (${2:-no more info})" |
cd445739 | 659 | exit 5 ;; |
78eab2a1 AM |
660 | "err_no_package_data" ) |
661 | remove_build_requires | |
45e2a818 | 662 | echo >&2 "Error: couldn't get out package name/version/release from spec file." |
78eab2a1 | 663 | exit 6 ;; |
ce40491a | 664 | "err_tag_exists" ) |
50321881 | 665 | remove_build_requires |
45e2a818 | 666 | echo >&2 "Tag ${2} already exists (spec release: ${3})." |
50321881 | 667 | exit 9 ;; |
ce40491a | 668 | "err_fract_rel" ) |
50321881 | 669 | remove_build_requires |
45e2a818 | 670 | echo >&2 "Release ${2} not integer and not a snapshot." |
50321881 | 671 | exit 10 ;; |
fb96e0b5 AM |
672 | "err_branch_exists" ) |
673 | remove_build_requires | |
45e2a818 | 674 | echo >&2 "Tree branch already exists (${2})." |
fb96e0b5 | 675 | exit 11 ;; |
cfc497c0 ER |
676 | "err_acl_deny" ) |
677 | remove_build_requires | |
45e2a818 | 678 | echo >&2 "Error: conditions reject building this spec (${2})." |
cfc497c0 | 679 | exit 12 ;; |
cd445739 | 680 | esac |
45e2a818 | 681 | echo >&2 "Unknown error." |
73848362 | 682 | exit 100 |
cd445739 AM |
683 | } |
684 | ||
f6711e2a | 685 | init_builder() { |
cd445739 | 686 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
687 | set -x |
688 | set -v | |
0dd6320d | 689 | fi |
cd445739 | 690 | |
4aeb9973 | 691 | if [ "$NOINIT" != "yes" ] ; then |
9c909460 | 692 | TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}') |
b7cc0c94 | 693 | |
09bf17c9 | 694 | local macros_ver=$(rpm -E %?rpm_build_macros) |
b7cc0c94 ER |
695 | if [ -z "$macros_ver" ]; then |
696 | REPO_DIR=$TOP_DIR/packages | |
697 | PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME | |
698 | else | |
699 | if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then | |
700 | echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER" | |
701 | exit 1 | |
702 | fi | |
703 | REPO_DIR=$TOP_DIR | |
704 | PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME | |
705 | fi | |
29e90b02 | 706 | else |
9c909460 AM |
707 | REPO_DIR="." |
708 | PACKAGE_DIR="." | |
29e90b02 | 709 | fi |
cd445739 | 710 | |
a8c9a155 | 711 | __PWD=$(pwd) |
00fcec7e | 712 | } |
713 | ||
f6711e2a | 714 | get_spec() { |
c890b916 | 715 | |
2e5be021 | 716 | update_shell_title "get_spec" |
c890b916 | 717 | |
cd445739 | 718 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
719 | set -x |
720 | set -v | |
cd445739 AM |
721 | fi |
722 | ||
9c909460 AM |
723 | cd "$REPO_DIR" |
724 | if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then | |
6277f15f ER |
725 | # XXX: still needed? |
726 | SPECFILE=$(basename $SPECFILE) | |
cd445739 | 727 | fi |
cd445739 | 728 | |
1ef6f5de | 729 | if [ "$NOCVSSPEC" != "yes" ]; then |
049ab214 ER |
730 | if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then |
731 | echo "Warning: No CVS access defined - using local .spec file" | |
732 | NOCVSSPEC="yes" | |
cd445739 AM |
733 | fi |
734 | ||
1ef6f5de | 735 | if [ -d "$ASSUMED_NAME" -a -s "$ASSUMED_NAME/CVS/Root" ]; then |
9c909460 AM |
736 | cvsup "$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo |
737 | else | |
1ef6f5de ER |
738 | cvsup -c -d $ASSUMED_NAME "packages/$ASSUMED_NAME/$SPECFILE" || { |
739 | # softfail if new package, i.e not yet added to cvs | |
740 | [ ! -f "$ASSUMED_NAME/$SPECFILE" ] && Exit_error err_no_spec_in_repo | |
741 | echo "Warning: package not in CVS - assuming new package" | |
742 | NOCVSSPEC="yes" | |
743 | NOCVS="yes" | |
744 | } | |
f123bcb5 ER |
745 | |
746 | # remove Entries.Static -- so 'cvs up' would update all files in a repo | |
1ef6f5de | 747 | rm -f "$ASSUMED_NAME/CVS/Entries.Static" |
80cef3c1 | 748 | cvsignore_df .cvsignore |
f123bcb5 | 749 | |
0c3beb90 ER |
750 | # add default log format to .cvsignore if it is relative |
751 | if [ "$LOGFILE" == $(basename "$LOGFILE") ]; then | |
752 | # substitute known "macros" to glob | |
753 | local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\),*,g') | |
754 | if [ "$logfile" ]; then | |
755 | cvsignore_df "$logfile" | |
756 | fi | |
757 | fi | |
758 | ||
f123bcb5 | 759 | # create symlinks for tools |
daeab113 | 760 | if [ "$SYMLINK_TOOLS" != "no" ]; then |
cacef28c | 761 | for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do |
daeab113 | 762 | [ -f $a ] || continue |
1ef6f5de | 763 | ln -sf ../$a $ASSUMED_NAME |
daeab113 JR |
764 | cvsignore_df $a |
765 | done | |
766 | fi | |
9c909460 | 767 | fi |
cd445739 | 768 | fi |
049ab214 | 769 | |
9c909460 | 770 | if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then |
518ff1fb | 771 | Exit_error err_no_spec_in_repo |
cd445739 AM |
772 | fi |
773 | ||
774 | if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then | |
9c909460 | 775 | chmod $CHMOD_MODE $ASSUMED_NAME/$SPECFILE |
cd445739 AM |
776 | fi |
777 | unset OPTIONS | |
9c909460 | 778 | [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $ASSUMED_NAME/$SPECFILE |
7e40520f | 779 | |
ce40491a | 780 | set_spec_target |
cd445739 AM |
781 | } |
782 | ||
f6711e2a | 783 | find_mirror() { |
9c909460 | 784 | cd "$REPO_DIR" |
782518da | 785 | local url="$1" |
cd445739 | 786 | if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then |
939f2c12 | 787 | $CVS_COMMAND update mirrors >&2 |
cd445739 AM |
788 | fi |
789 | ||
790 | IFS="|" | |
782518da ER |
791 | local origin mirror name rest ol prefix |
792 | while read origin mirror name rest; do | |
793 | # skip comments and empty lines | |
2faa4c32 | 794 | if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then |
782518da ER |
795 | continue |
796 | fi | |
a8c9a155 ER |
797 | ol=$(echo -n "$origin" | wc -c) |
798 | prefix=$(echo -n "$url" | head -c $ol) | |
cd445739 | 799 | if [ "$prefix" = "$origin" ] ; then |
a8c9a155 | 800 | suffix=$(echo "$url" | cut -b $((ol+1))-) |
cd445739 AM |
801 | echo -n "$mirror$suffix" |
802 | return 0 | |
803 | fi | |
804 | done < mirrors | |
805 | echo "$url" | |
806 | } | |
807 | ||
e7e0d4ec | 808 | # Warning: unpredictable results if same URL used twice |
f6711e2a | 809 | src_no() { |
9c909460 | 810 | cd $PACKAGE_DIR |
cd445739 AM |
811 | rpm_dump | \ |
812 | grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \ | |
813 | sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \ | |
814 | head -n 1 | xargs | |
1471f6d6 | 815 | } |
816 | ||
f6711e2a | 817 | src_md5() { |
e7e0d4ec | 818 | [ "$NO5" = "yes" ] && return |
cd445739 AM |
819 | no=$(src_no "$1") |
820 | [ -z "$no" ] && return | |
9c909460 | 821 | cd $PACKAGE_DIR |
e7e0d4ec ER |
822 | local md5 |
823 | ||
824 | if [ -f additional-md5sums ]; then | |
825 | local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::) | |
826 | if [ -z "$spec_rev" ]; then | |
a8c9a155 | 827 | spec_rev=$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/') |
e7e0d4ec ER |
828 | fi |
829 | local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')" | |
830 | md5=$(grep -s -v '^#' additional-md5sums | \ | |
831 | grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \ | |
832 | sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \ | |
833 | grep -E '^[0-9a-f]{32}$') | |
834 | ||
835 | if [ "$md5" ]; then | |
836 | if [ $(echo "$md5" | wc -l) != 1 ] ; then | |
837 | echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2 | |
838 | fi | |
839 | echo "$md5" | tail -n 1 | |
840 | return | |
841 | fi | |
cd445739 | 842 | fi |
e7e0d4ec | 843 | |
657d488b | 844 | source_md5=`grep -i "^#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` |
e7e0d4ec ER |
845 | if [ -n "$source_md5" ]; then |
846 | echo $source_md5 | |
cd445739 | 847 | else |
7805dcb4 PZ |
848 | source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'` |
849 | if [ -n "$source_md5" ]; then | |
850 | echo $source_md5 | |
851 | else | |
852 | # we have empty SourceX-md5, but it is still possible | |
853 | # that we have NoSourceX-md5 AND NoSource: X | |
657d488b | 854 | nosource_md5=`grep -i "^#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` |
7805dcb4 PZ |
855 | if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then |
856 | echo $nosource_md5 | |
857 | fi | |
cd445739 | 858 | fi |
cd445739 AM |
859 | fi |
860 | } | |
861 | ||
f6711e2a | 862 | distfiles_path() { |
06541433 JR |
863 | echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")" |
864 | } | |
865 | ||
f6711e2a | 866 | distfiles_url() { |
06541433 | 867 | echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")" |
cd445739 AM |
868 | } |
869 | ||
f6711e2a | 870 | distfiles_attic_url() { |
06541433 | 871 | echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")" |
cd445739 AM |
872 | } |
873 | ||
f6711e2a | 874 | good_md5() { |
cd445739 AM |
875 | md5=$(src_md5 "$1") |
876 | [ "$md5" = "" ] || \ | |
877 | [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ] | |
8ba5cdda PG |
878 | } |
879 | ||
f6711e2a | 880 | good_size() { |
a8c9a155 | 881 | size=$(find $(nourl "$1") -printf "%s" 2>/dev/null) |
ce40491a | 882 | [ -n "$size" -a "$size" -gt 0 ] |
a4b50627 AF |
883 | } |
884 | ||
f6711e2a | 885 | cvsignore_df() { |
947025e5 | 886 | if [ "$CVSIGNORE_DF" != "yes" ]; then |
887 | return | |
888 | fi | |
9c909460 | 889 | cvsignore=${PACKAGE_DIR}/.cvsignore |
7dc8d095 ER |
890 | |
891 | # add only if not yet there | |
aa189b05 | 892 | if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then |
947025e5 | 893 | echo "$1" >> $cvsignore |
894 | fi | |
895 | } | |
896 | ||
f6711e2a | 897 | cvsup() { |
ce40491a ER |
898 | update_shell_title "cvsup" |
899 | local OPTIONS="up " | |
9c909460 AM |
900 | |
901 | if [ "$1" = "-c" ]; then | |
902 | OPTIONS="co " | |
903 | shift | |
904 | fi | |
ce40491a ER |
905 | if [ -n "$CVSROOT" ]; then |
906 | OPTIONS="-d $CVSROOT $OPTIONS" | |
907 | fi | |
b1c6aace | 908 | |
ce40491a ER |
909 | if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then |
910 | OPTIONS="$OPTIONS -A" | |
911 | else | |
912 | if [ -n "$CVSDATE" ]; then | |
913 | OPTIONS="$OPTIONS -D $CVSDATE" | |
914 | fi | |
915 | if [ -n "$CVSTAG" ]; then | |
916 | OPTIONS="$OPTIONS -r $CVSTAG" | |
917 | fi | |
918 | fi | |
e7fa3b9f | 919 | |
ce40491a ER |
920 | local result=1 |
921 | local retries_counter=0 | |
922 | if [ $# = 1 ]; then | |
923 | update_shell_title "cvsup: $*" | |
924 | else | |
925 | update_shell_title "cvsup: $# files" | |
926 | fi | |
927 | while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do | |
928 | retries_counter=$(( $retries_counter + 1 )) | |
939f2c12 | 929 | output=$(LC_ALL=C $CVS_COMMAND $OPTIONS "$@" 2>&1) |
ce40491a ER |
930 | result=$? |
931 | [ -n "$output" ] && echo "$output" | |
932 | 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 | |
933 | echo "Trying again [$*]... ($retries_counter)" | |
934 | update_shell_title "cvsup: retry #$retries_counter" | |
935 | sleep 2 | |
936 | continue | |
937 | else | |
938 | break | |
939 | fi | |
940 | done | |
941 | update_shell_title "cvsup: done!" | |
942 | return $result | |
e7fa3b9f ER |
943 | } |
944 | ||
71f8e908 | 945 | # returns true if "$1" is ftp, http or https protocol url |
f6711e2a | 946 | is_url() { |
71f8e908 ER |
947 | case "$1" in |
948 | ftp://*|http://*|https://*) | |
949 | return 0 | |
950 | ;; | |
951 | esac | |
952 | return 1 | |
953 | } | |
954 | ||
f6711e2a | 955 | update_md5() { |
ecba6ad5 ER |
956 | if [ $# -eq 0 ]; then |
957 | return | |
958 | fi | |
959 | ||
960 | update_shell_title "update md5" | |
961 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
962 | set -x |
963 | set -v | |
ecba6ad5 ER |
964 | fi |
965 | ||
9c909460 | 966 | cd "$PACKAGE_DIR" |
ecba6ad5 ER |
967 | |
968 | # pass 1: check files to be fetched | |
969 | local todo | |
970 | local need_files | |
971 | for i in "$@"; do | |
972 | local fp=$(nourl "$i") | |
973 | local srcno=$(src_no "$i") | |
6392b5fd ER |
974 | if [ -n "$ADD5" ]; then |
975 | [ "$fp" = "$i" ] && continue # FIXME what is this check doing? | |
9c909460 AM |
976 | grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue |
977 | grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue | |
6392b5fd | 978 | else |
9c909460 | 979 | grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue |
ecba6ad5 ER |
980 | fi |
981 | if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then | |
982 | need_files="$need_files $i" | |
983 | fi | |
984 | done | |
985 | ||
986 | # pass 1a: get needed files | |
987 | if [ "$need_files" ]; then | |
988 | get_files $need_files | |
989 | fi | |
990 | ||
991 | # pass 2: proceed with md5 adding or updating | |
992 | for i in "$@"; do | |
993 | local fp=$(nourl "$i") | |
994 | local srcno=$(src_no "$i") | |
9c909460 | 995 | local md5=$(grep -iE '^#[ ]*(No)?Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE ) |
e19ad799 | 996 | if [ -z "$md5" ]; then |
9c909460 | 997 | md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE ) |
6c1b2e7d | 998 | fi |
71f8e908 | 999 | if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then |
6c1b2e7d | 1000 | local tag="# Source$srcno-md5:\t" |
71f8e908 | 1001 | if [[ "$md5" == *NoSource* ]]; then |
6c1b2e7d PZ |
1002 | tag="# NoSource$srcno-md5:\t" |
1003 | elif [ -n "$USEDIGEST" ]; then | |
1004 | tag="BuildRequires:\tdigest(%SOURCE$srcno) = " | |
71f8e908 | 1005 | fi |
ecba6ad5 | 1006 | md5=$(md5sum "$fp" | cut -f1 -d' ') |
15bf3e99 | 1007 | echo "Updating Source$srcno ($md5: $fp)." |
ecba6ad5 | 1008 | perl -i -ne ' |
6c1b2e7d PZ |
1009 | print unless (/^\s*#\s*(No)?Source'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i); |
1010 | print "'"$tag$md5"'\n" if /^Source'$srcno'\s*:\s+/; | |
ecba6ad5 | 1011 | ' \ |
9c909460 | 1012 | $PACKAGE_DIR/$SPECFILE |
ecba6ad5 ER |
1013 | fi |
1014 | done | |
1015 | } | |
1016 | ||
f6711e2a | 1017 | check_md5() { |
60499e54 | 1018 | local bad |
3fbff8b8 ER |
1019 | [ "$NO5" = "yes" ] && return |
1020 | ||
ecba6ad5 ER |
1021 | update_shell_title "check md5" |
1022 | ||
1023 | for i in "$@"; do | |
60499e54 AM |
1024 | bad=0 |
1025 | if ! good_md5 "$i"; then | |
1026 | echo -n "MD5 sum mismatch." | |
1027 | bad=1 | |
1028 | fi | |
1029 | if ! good_size "$i"; then | |
1030 | echo -n "0 sized file." | |
1031 | bad=1 | |
ecba6ad5 ER |
1032 | fi |
1033 | ||
60499e54 AM |
1034 | if [ $bad -eq 1 ]; then |
1035 | echo " Use -U to refetch sources," | |
1036 | echo "or -5 to update md5 sums, if you're sure files are correct." | |
1037 | Exit_error err_no_source_in_repo $i | |
1038 | fi | |
ecba6ad5 ER |
1039 | done |
1040 | } | |
1041 | ||
f6711e2a | 1042 | get_files() { |
7cb24972 | 1043 | update_shell_title "get_files" |
cd445739 AM |
1044 | |
1045 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
1046 | set -x |
1047 | set -v | |
cd445739 AM |
1048 | fi |
1049 | ||
f09c0772 | 1050 | if [ $# -gt 0 ]; then |
9c909460 | 1051 | cd "$PACKAGE_DIR" |
cd445739 | 1052 | |
b1c6aace | 1053 | if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then |
049ab214 | 1054 | echo "Warning: No CVS access defined for SOURCES" |
b1c6aace ER |
1055 | NOCVS="yes" |
1056 | fi | |
1057 | ||
f2e42a41 | 1058 | local nc=0 |
e7fa3b9f | 1059 | local get_files_cvs="" |
3815b69a | 1060 | for i in "$@"; do |
f2e42a41 | 1061 | nc=$((nc + 1)) |
dcebdffb | 1062 | local cvsup=0 |
3815b69a | 1063 | SHELL_TITLE_PREFIX="get_files[$nc/$#]" |
f2e42a41 | 1064 | update_shell_title "$i" |
f09c0772 | 1065 | local fp=`nourl "$i"` |
ecba6ad5 | 1066 | if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then |
ce40491a | 1067 | continue |
18e5347d | 1068 | fi |
ecba6ad5 | 1069 | |
cd445739 | 1070 | FROM_DISTFILES=0 |
e7e0d4ec | 1071 | local srcmd5=$(src_md5 "$i") |
ecba6ad5 ER |
1072 | |
1073 | # we know if source/patch is present in cvs/distfiles | |
1074 | # - has md5 (in distfiles) | |
1075 | # - in cvs... ideas? | |
1076 | ||
1077 | # CHECK: local file didn't exist or always cvs up (first) requested. | |
f09c0772 | 1078 | if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then |
cd445739 AM |
1079 | if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then |
1080 | echo "Warning: no URL given for $i" | |
1081 | fi | |
08908161 | 1082 | target="$fp" |
cd445739 | 1083 | |
e7e0d4ec | 1084 | if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then |
a4b50627 | 1085 | if good_md5 "$i" && good_size "$i"; then |
e7e0d4ec | 1086 | echo "$fp having proper md5sum already exists" |
cd445739 AM |
1087 | continue |
1088 | fi | |
28b34560 | 1089 | |
bc10f694 | 1090 | # optionally prefer mirror over distfiles if there's mirror |
28b34560 | 1091 | # TODO: build url list and then try each url from the list |
bc10f694 | 1092 | if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then |
28b34560 ER |
1093 | url="$im" |
1094 | else | |
1095 | url=$(distfiles_url "$i") | |
1096 | fi | |
1097 | ||
cd445739 AM |
1098 | url_attic=$(distfiles_attic_url "$i") |
1099 | FROM_DISTFILES=1 | |
ecba6ad5 ER |
1100 | # is $url local file? |
1101 | if [[ "$url" = [./]* ]]; then | |
18a52930 | 1102 | update_shell_title "${GETLOCAL%% *}: $url" |
cd445739 AM |
1103 | ${GETLOCAL} $url $target |
1104 | else | |
1105 | if [ -z "$NOMIRRORS" ]; then | |
9e9f8920 | 1106 | url=$(find_mirror "$url") |
cd445739 | 1107 | fi |
9e9f8920 ER |
1108 | |
1109 | local uri=${url} | |
1110 | # make shorter message for distfiles urls | |
1111 | if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then | |
1112 | uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/} | |
1113 | uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/} | |
1114 | uri="df: $uri" | |
1115 | fi | |
1116 | update_shell_title "${GETURI%% *}: $uri" | |
ca2e6c31 | 1117 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
33da77c4 | 1118 | if [ "`echo $url | grep -E 'ftp://'`" ]; then |
18a52930 | 1119 | update_shell_title "${GETURI2%% *}: $url" |
ca2e6c31 | 1120 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
cd445739 AM |
1121 | fi |
1122 | fi | |
ecba6ad5 ER |
1123 | |
1124 | # is it empty file? | |
1125 | if [ ! -s "$target" ]; then | |
cd445739 AM |
1126 | rm -f "$target" |
1127 | if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then | |
18a52930 | 1128 | update_shell_title "${GETLOCAL%% *}: $url_attic" |
cd445739 AM |
1129 | ${GETLOCAL} $url_attic $target |
1130 | else | |
1131 | if [ -z "$NOMIRRORS" ]; then | |
a8c9a155 | 1132 | url_attic=$(find_mirror "$url_attic") |
cd445739 | 1133 | fi |
18a52930 | 1134 | update_shell_title "${GETURI%% *}: $url_attic" |
ca2e6c31 | 1135 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
33da77c4 | 1136 | if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then |
ce40491a | 1137 | update_shell_title "${GETURI2%% *}: $url_attic" |
ca2e6c31 | 1138 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
cd445739 | 1139 | fi |
1cd7fc57 | 1140 | test -s "$target" || rm -f "$target" |
cd445739 AM |
1141 | fi |
1142 | fi | |
ecba6ad5 ER |
1143 | |
1144 | if [ -s "$target" ]; then | |
947025e5 | 1145 | cvsignore_df $target |
1146 | else | |
cd445739 AM |
1147 | rm -f "$target" |
1148 | FROM_DISTFILES=0 | |
1149 | fi | |
e7e0d4ec | 1150 | elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then |
d05e8080 ER |
1151 | if [ $# -gt 1 ]; then |
1152 | get_files_cvs="$get_files_cvs $fp" | |
1153 | update_shell_title "$fp (will cvs up later)" | |
1154 | cvsup=1 | |
1155 | else | |
1156 | cvsup $fp | |
1157 | fi | |
cd445739 AM |
1158 | fi |
1159 | ||
f09c0772 | 1160 | if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then |
cd445739 | 1161 | if [ -z "$NOMIRRORS" ]; then |
a8c9a155 | 1162 | im=$(find_mirror "$i") |
cd445739 AM |
1163 | else |
1164 | im="$i" | |
1165 | fi | |
ce40491a | 1166 | update_shell_title "${GETURI%% *}: $im" |
08908161 | 1167 | ${GETURI} "$im" ${OUTFILEOPT} "$target" || \ |
33da77c4 | 1168 | if [ "`echo $im | grep -E 'ftp://'`" ]; then |
ce40491a | 1169 | update_shell_title "${GETURI2%% *}: $im" |
08908161 | 1170 | ${GETURI2} "$im" ${OUTFILEOPT} "$target" |
7e365483 | 1171 | fi |
1cd7fc57 | 1172 | test -s "$target" || rm -f "$target" |
cd445739 AM |
1173 | fi |
1174 | ||
dcebdffb ER |
1175 | if [ "$cvsup" = 1 ]; then |
1176 | continue | |
1177 | fi | |
1178 | ||
cd445739 | 1179 | fi |
ecba6ad5 ER |
1180 | |
1181 | # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong. | |
f09c0772 | 1182 | if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then |
cdbd30e8 | 1183 | if [ -n "GREEDSRC" ]; then |
1184 | get_greed_sources $i | |
1185 | else | |
1186 | Exit_error err_no_source_in_repo $i | |
1187 | fi | |
cd445739 | 1188 | fi |
2a5f078d | 1189 | |
ecba6ad5 | 1190 | # we check md5 here just only to refetch immediately |
a4b50627 | 1191 | if good_md5 "$i" && good_size "$i"; then |
cd445739 AM |
1192 | : |
1193 | elif [ "$FROM_DISTFILES" = 1 ]; then | |
deccc50e | 1194 | # wrong md5 from distfiles: remove the file and try again |
cd445739 | 1195 | # but only once ... |
deccc50e | 1196 | echo "MD5 sum mismatch. Trying full fetch." |
cd445739 AM |
1197 | FROM_DISTFILES=2 |
1198 | rm -f $target | |
18a52930 | 1199 | update_shell_title "${GETURI%% *}: $url" |
ca2e6c31 | 1200 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
33da77c4 | 1201 | if [ "`echo $url | grep -E 'ftp://'`" ]; then |
ce40491a | 1202 | update_shell_title "${GETURI2%% *}: $url" |
ca2e6c31 | 1203 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
cd445739 | 1204 | fi |
ecba6ad5 | 1205 | if [ ! -s "$target" ]; then |
cd445739 | 1206 | rm -f "$target" |
18a52930 | 1207 | update_shell_title "${GETURI%% *}: $url_attic" |
ca2e6c31 | 1208 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
33da77c4 | 1209 | if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then |
ce40491a | 1210 | update_shell_title "${GETURI2%% *}: $url_attic" |
ca2e6c31 | 1211 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
cd445739 AM |
1212 | fi |
1213 | fi | |
1214 | test -s "$target" || rm -f "$target" | |
1215 | fi | |
cd445739 | 1216 | done |
e7fa3b9f ER |
1217 | SHELL_TITLE_PREFIX="" |
1218 | ||
1219 | if [ "$get_files_cvs" ]; then | |
ce40491a | 1220 | cvsup $get_files_cvs |
e7fa3b9f | 1221 | fi |
cd445739 AM |
1222 | |
1223 | if [ "$CHMOD" = "yes" ]; then | |
a8c9a155 | 1224 | CHMOD_FILES=$(nourl "$@") |
cd445739 AM |
1225 | if [ -n "$CHMOD_FILES" ]; then |
1226 | chmod $CHMOD_MODE $CHMOD_FILES | |
1227 | fi | |
1228 | fi | |
cd445739 AM |
1229 | fi |
1230 | } | |
1231 | ||
1232 | make_tagver() { | |
ce40491a | 1233 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
1234 | set -x |
1235 | set -v | |
ce40491a | 1236 | fi |
78eab2a1 | 1237 | |
ce40491a ER |
1238 | # Check whether first character of PACKAGE_NAME is legal for tag name |
1239 | if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then | |
1240 | TAG_PREFIX=tag_ | |
1241 | fi | |
d712cc12 ER |
1242 | |
1243 | # NOTE: CVS tags may must not contain the characters `$,.:;@' | |
392187d9 | 1244 | TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE | tr '[.@]' '[_#]') |
d712cc12 | 1245 | |
ce40491a ER |
1246 | # Remove #kernel.version_release from TAGVER because tagging sources |
1247 | # could occur with different kernel-headers than kernel-headers used at build time. | |
d712cc12 ER |
1248 | # besides, %{_kernel_ver_str} is not expanded. |
1249 | ||
1250 | # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1#%{_kernel_ver_str} | |
1251 | # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1 | |
1252 | ||
1253 | TAGVER=${TAGVER%#*} | |
ce40491a | 1254 | echo -n "$TAGVER" |
cd445739 AM |
1255 | } |
1256 | ||
c713aac3 AG |
1257 | # bool is_tag_a_branch(tag) |
1258 | # | |
1259 | # returns 1 if a tag is a branch set on SPECFILE | |
1260 | is_tag_a_branch() { | |
1261 | if [ -n "$DEBUG" ]; then | |
1262 | set -x | |
1263 | set -v | |
1264 | fi | |
1265 | ||
1266 | if [ $# -ne 1 ]; then | |
1267 | return 0; | |
1268 | fi | |
1269 | ||
1270 | TAG=$1 | |
f5141bbc | 1271 | |
9c909460 | 1272 | cd "$PACKAGE_DIR" |
939f2c12 | 1273 | $CVS_COMMAND status -v $SPECFILE | grep -Eiq "${TAG}.+(branch: [0-9.]+)" |
c713aac3 AG |
1274 | return $? |
1275 | } | |
1276 | ||
f6711e2a | 1277 | tag_files() { |
cd445739 AM |
1278 | TAG_FILES="$@" |
1279 | ||
1280 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
1281 | set -x |
1282 | set -v | |
cd445739 AM |
1283 | fi |
1284 | ||
73ef63d8 ER |
1285 | echo "Version: $PACKAGE_VERSION" |
1286 | echo "Release: $PACKAGE_RELEASE" | |
cd445739 | 1287 | |
a18a9761 | 1288 | local TAGVER |
73ef63d8 | 1289 | if [ "$TAG_VERSION" = "yes" ]; then |
a18a9761 | 1290 | TAGVER=`make_tagver` |
73ef63d8 ER |
1291 | echo "CVS tag: $TAGVER" |
1292 | fi | |
1293 | if [ -n "$TAG" ]; then | |
1294 | echo "CVS tag: $TAG" | |
1295 | fi | |
cd445739 | 1296 | |
39dcc7de | 1297 | local OPTIONS="tag $CVS_FORCE" |
73ef63d8 ER |
1298 | if [ -n "$CVSROOT" ]; then |
1299 | OPTIONS="-d $CVSROOT $OPTIONS" | |
1300 | fi | |
cd445739 | 1301 | |
c713aac3 AG |
1302 | # if a tagname we are about to set already exists |
1303 | # and happens to be a branch (common case with AC-branch) | |
1304 | # pass -B (allows -F to disturb branch tag) | |
1305 | local _tag=$TAG | |
1306 | if [ "$TAG_VERSION" = "yes" ]; then | |
1307 | _tag=$TAGVER | |
1308 | fi; | |
1309 | is_tag_a_branch $_tag | |
28c23a72 | 1310 | if [ $? -eq 0 -a $CVS_NSERVER -eq 0 ]; then |
c713aac3 AG |
1311 | OPTIONS="$OPTIONS -B" |
1312 | fi; | |
1313 | ||
9c909460 | 1314 | cd "$PACKAGE_DIR" |
73ef63d8 ER |
1315 | local tag_files |
1316 | for i in $TAG_FILES; do | |
1317 | # don't tag files stored on distfiles | |
1318 | [ -n "`src_md5 $i`" ] && continue | |
1319 | local fp=`nourl "$i"` | |
1320 | if [ -f "$fp" ]; then | |
1321 | tag_files="$tag_files $fp" | |
cdbd30e8 | 1322 | elif [ -n "GREEDSRC" ]; then |
1323 | get_greed_sources $i | |
73ef63d8 ER |
1324 | else |
1325 | Exit_error err_no_source_in_repo $i | |
03db3356 | 1326 | fi |
73ef63d8 | 1327 | done |
03db3356 | 1328 | |
73ef63d8 | 1329 | if [ "$tag_files" ]; then |
cd445739 | 1330 | if [ "$TAG_VERSION" = "yes" ]; then |
73ef63d8 | 1331 | update_shell_title "tag sources: $TAGVER" |
19ca62ef | 1332 | printf "Tagging %d files\n" $(echo $tag_files | wc -w) |
939f2c12 | 1333 | $CVS_COMMAND $OPTIONS $TAGVER $tag_files || exit |
cd445739 AM |
1334 | fi |
1335 | if [ -n "$TAG" ]; then | |
73ef63d8 | 1336 | update_shell_title "tag sources: $TAG" |
c4ff623e ER |
1337 | |
1338 | while [ "$tag_files" ]; do | |
1339 | local chunk=$(echo $tag_files | tr ' ' '\n' | head -n 100) | |
1340 | printf "Tagging %d files\n" $(echo $chunk | wc -w) | |
939f2c12 | 1341 | $CVS_COMMAND $OPTIONS $TAG $chunk || exit |
c4ff623e ER |
1342 | tag_files=$(echo $tag_files | tr ' ' '\n' | tail +101) |
1343 | done | |
cd445739 | 1344 | fi |
73ef63d8 ER |
1345 | fi |
1346 | ||
9c909460 | 1347 | cd "$PACKAGE_DIR" |
73ef63d8 ER |
1348 | if [ "$TAG_VERSION" = "yes" ]; then |
1349 | update_shell_title "tag spec: $TAGVER" | |
939f2c12 | 1350 | $CVS_COMMAND $OPTIONS $TAGVER $SPECFILE || exit |
73ef63d8 ER |
1351 | fi |
1352 | if [ -n "$TAG" ]; then | |
1353 | update_shell_title "tag spec: $TAG" | |
939f2c12 | 1354 | $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit |
73ef63d8 | 1355 | fi |
cd445739 AM |
1356 | } |
1357 | ||
f6711e2a | 1358 | branch_files() { |
cd445739 AM |
1359 | TAG=$1 |
1360 | echo "CVS branch tag: $TAG" | |
518ff1fb | 1361 | shift |
cd445739 AM |
1362 | |
1363 | TAG_FILES="$@" | |
1364 | ||
1365 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
1366 | set -x |
1367 | set -v | |
cd445739 AM |
1368 | fi |
1369 | ||
78a5a506 | 1370 | local OPTIONS="tag $CVS_FORCE -b" |
ec6b5dfc AG |
1371 | |
1372 | # branch exists? | |
1373 | is_tag_a_branch $TAG | |
1374 | if [ $? -eq 1 ]; then | |
1375 | OPTIONS="$OPTIONS -B" | |
1376 | fi | |
1377 | ||
78a5a506 ER |
1378 | if [ -n "$CVSROOT" ]; then |
1379 | OPTIONS="-d $CVSROOT $OPTIONS" | |
1380 | fi | |
9c909460 | 1381 | cd "$PACKAGE_DIR" |
78a5a506 ER |
1382 | local tag_files |
1383 | for i in $TAG_FILES; do | |
1384 | local fp=`nourl "$i"` | |
1385 | if [ -f "$fp" ]; then | |
1386 | tag_files="$tag_files $fp" | |
cdbd30e8 | 1387 | elif [ -n "GREEDSRC" ]; then |
1388 | get_greed_sources $i | |
78a5a506 ER |
1389 | else |
1390 | Exit_error err_no_source_in_repo $i | |
c10fa4fa | 1391 | fi |
78a5a506 ER |
1392 | done |
1393 | if [ "$tag_files" ]; then | |
939f2c12 | 1394 | $CVS_COMMAND $OPTIONS $TAG $tag_files || exit |
78a5a506 | 1395 | fi |
c10fa4fa | 1396 | |
9c909460 | 1397 | cd "$PACKAGE_DIR" |
939f2c12 | 1398 | $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit |
cd445739 AM |
1399 | } |
1400 | ||
1401 | ||
3009b80d ER |
1402 | # this function should exit early if package can't be built for this arch |
1403 | # this avoids unneccessary BR filling. | |
1404 | check_buildarch() { | |
1405 | local out ret | |
13c3c336 | 1406 | out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1) |
3009b80d ER |
1407 | ret=$? |
1408 | if [ $ret -ne 0 ]; then | |
1409 | echo >&2 "$out" | |
1410 | exit $ret | |
1411 | fi | |
1412 | } | |
1413 | ||
9d99a240 ER |
1414 | # from relup.sh |
1415 | set_release() { | |
1416 | local specfile="$1" | |
1417 | local rel="$2" | |
1418 | local newrel="$3" | |
1419 | sed -i -e " | |
1420 | s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/ | |
1421 | s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/ | |
1422 | " $specfile | |
1423 | } | |
1424 | ||
1425 | set_version() { | |
1426 | local specfile="$1" | |
bc8502e6 ER |
1427 | local ver="$2" subver=$ver |
1428 | local newver="$3" newsubver=$newver | |
1429 | ||
1430 | # try handling subver, everything that's not numeric-dotted in version | |
1431 | if grep -Eq '%define\s+subver' $specfile; then | |
1432 | subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,') | |
1433 | ver=${ver%$subver} | |
1434 | newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,') | |
1435 | newver=${newver%$newsubver} | |
1436 | fi | |
9d99a240 ER |
1437 | sed -i -e " |
1438 | s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/ | |
bc8502e6 | 1439 | s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/ |
9d99a240 ER |
1440 | s/^\(Version:[ \t]\+\)$ver\$/\1$newver/ |
1441 | " $specfile | |
1442 | } | |
1443 | ||
cacef28c | 1444 | try_upgrade() { |
cd445739 | 1445 | if [ -n "$TRY_UPGRADE" ]; then |
9d99a240 | 1446 | local TNOTIFY TNEWVER TOLDVER |
ce40491a | 1447 | update_shell_title "build_package: try_upgrade" |
9d99a240 | 1448 | |
cacef28c | 1449 | cd "$PACKAGE_DIR" |
1450 | ||
0907f1eb ER |
1451 | if [ "$UPGRADE_VERSION" ]; then |
1452 | TNEWVER=$UPGRADE_VERSION | |
cd445739 | 1453 | else |
0907f1eb ER |
1454 | if [ -n "$FLOAT_VERSION" ]; then |
1455 | TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1 | |
1456 | else | |
1457 | TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1 | |
1458 | fi | |
cd445739 | 1459 | |
0907f1eb ER |
1460 | TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }') |
1461 | fi | |
cd445739 AM |
1462 | |
1463 | if [ -n "$TNEWVER" ]; then | |
1464 | TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'` | |
9d99a240 | 1465 | echo "New version found, updating spec file from $TOLDVER to version $TNEWVER" |
257af81b ER |
1466 | if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then |
1467 | cp -f $SPECFILE $SPECFILE.bak | |
1468 | fi | |
cd445739 | 1469 | chmod +w $SPECFILE |
cacef28c | 1470 | set_release $SPECFILE $PACKAGE_RELEASE 1 |
9d99a240 | 1471 | set_version $SPECFILE $PACKAGE_VERSION $TNEWVER |
518ff1fb | 1472 | parse_spec |
cacef28c | 1473 | return 1 |
cd445739 AM |
1474 | fi |
1475 | fi | |
cacef28c | 1476 | return 0 |
1477 | } | |
1478 | ||
1479 | build_package() { | |
1480 | update_shell_title "build_package" | |
1481 | if [ -n "$DEBUG" ]; then | |
1482 | set -x | |
1483 | set -v | |
1484 | fi | |
1485 | ||
9c909460 | 1486 | cd "$PACKAGE_DIR" |
2a5f078d | 1487 | |
cd445739 AM |
1488 | case "$COMMAND" in |
1489 | build ) | |
1490 | BUILD_SWITCH="-ba" ;; | |
1491 | build-binary ) | |
1492 | BUILD_SWITCH="-bb" ;; | |
1493 | build-source ) | |
1494 | BUILD_SWITCH="-bs --nodeps" ;; | |
1495 | build-prep ) | |
1496 | BUILD_SWITCH="-bp --nodeps" ;; | |
6594293d AG |
1497 | build-build ) |
1498 | BUILD_SWITCH="-bc" ;; | |
1499 | build-install ) | |
1500 | BUILD_SWITCH="-bi" ;; | |
1501 | build-list ) | |
1502 | BUILD_SWITCH="-bl" ;; | |
1503 | ||
cd445739 | 1504 | esac |
c890b916 | 1505 | |
2e5be021 | 1506 | update_shell_title "build_package: $COMMAND" |
cd445739 AM |
1507 | if [ -n "$LOGFILE" ]; then |
1508 | LOG=`eval echo $LOGFILE` | |
1509 | if [ -d "$LOG" ]; then | |
1510 | echo "Log file $LOG is a directory." | |
1511 | echo "Parse error in the spec?" | |
518ff1fb | 1512 | Exit_error err_build_fail |
cd445739 AM |
1513 | fi |
1514 | if [ -n "$LASTLOG_FILE" ]; then | |
1515 | echo "LASTLOG=$LOG" > $LASTLOG_FILE | |
1516 | fi | |
525bf240 ER |
1517 | RES_FILE=$(mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM) |
1518 | ||
9c909460 | 1519 | (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 |
1520 | RETVAL=`cat $RES_FILE` |
1521 | rm $RES_FILE | |
1522 | if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then | |
1523 | if [ "$RETVAL" -eq "0" ]; then | |
1524 | mv $LOG $LOGDIROK | |
1525 | else | |
1526 | mv $LOG $LOGDIRFAIL | |
1527 | fi | |
1528 | fi | |
8ba5cdda | 1529 | else |
9c909460 | 1530 | eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE |
cd445739 | 1531 | RETVAL=$? |
8ba5cdda | 1532 | fi |
cd445739 AM |
1533 | if [ "$RETVAL" -ne "0" ]; then |
1534 | if [ -n "$TRY_UPGRADE" ]; then | |
cacef28c | 1535 | echo "\nUpgrade package to new version failed." |
257af81b | 1536 | if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then |
cacef28c | 1537 | echo "Restoring old spec file." |
257af81b ER |
1538 | mv -f $SPECFILE.bak $SPECFILE |
1539 | fi | |
cacef28c | 1540 | echo "" |
cd445739 | 1541 | fi |
518ff1fb | 1542 | Exit_error err_build_fail |
cd445739 AM |
1543 | fi |
1544 | unset BUILD_SWITCH | |
1545 | } | |
1546 | ||
f6711e2a | 1547 | nourl() { |
cd445739 AM |
1548 | echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g' |
1549 | } | |
1550 | ||
f6711e2a | 1551 | install_required_packages() { |
cd445739 AM |
1552 | run_poldek -vi $1 |
1553 | return $? | |
1554 | } | |
1555 | ||
f6711e2a | 1556 | find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond |
fa4bf1df | 1557 | local SPEC="$1" |
fa4bf1df ER |
1558 | awk -F"\n" ' |
1559 | /^%changelog/ { exit } | |
fa4bf1df ER |
1560 | /^%bcond_with/{ |
1561 | match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/); | |
8ff97f39 ER |
1562 | bcond = substr($0, RSTART + 6, RLENGTH - 6); |
1563 | gsub(/[ \t]+/, "_", bcond); | |
fa4bf1df ER |
1564 | print bcond |
1565 | }' $SPEC | LC_ALL=C sort -u | |
1566 | } | |
1567 | ||
117d9861 | 1568 | process_bcondrc() { |
301cbfd4 ER |
1569 | # expand bconds from ~/.bcondrc |
1570 | # The file structure is like gentoo's package.use: | |
1571 | # --- | |
1572 | # * -selinux | |
1573 | # samba -mysql -pgsql | |
47a8df12 | 1574 | # w32codec-installer license_agreement |
301cbfd4 ER |
1575 | # php +mysqli |
1576 | # --- | |
fa4bf1df | 1577 | if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then |
117d9861 ER |
1578 | : |
1579 | else | |
1580 | return | |
1581 | fi | |
301cbfd4 | 1582 | |
117d9861 | 1583 | SN=${SPECFILE%%\.spec} |
c8a3e2ac | 1584 | |
117d9861 ER |
1585 | local bcondrc=$HOME/.bcondrc |
1586 | [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc | |
301cbfd4 | 1587 | |
117d9861 | 1588 | local bcond_avail=$(find_spec_bcond $SPECFILE) |
301cbfd4 | 1589 | |
117d9861 ER |
1590 | while read pkg flags; do |
1591 | # ignore comments | |
1592 | [[ "$pkg" == \#* ]] && continue | |
1593 | ||
1594 | # any package or current package? | |
1595 | if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then | |
1596 | for flag in $flags; do | |
1597 | local opt=${flag#[+-]} | |
1598 | ||
1599 | # use only flags which are in this package. | |
1600 | if [[ $bcond_avail = *${opt}* ]]; then | |
1601 | if [[ $flag = -* ]]; then | |
1602 | if [[ $BCOND != *--with?${opt}* ]]; then | |
1603 | BCOND="$BCOND --without $opt" | |
1604 | fi | |
1605 | else | |
1606 | if [[ $BCOND != *--without?${opt}* ]]; then | |
1607 | BCOND="$BCOND --with $opt" | |
301cbfd4 ER |
1608 | fi |
1609 | fi | |
117d9861 ER |
1610 | fi |
1611 | done | |
1612 | fi | |
1613 | done < $bcondrc | |
1614 | update_shell_title "parse ~/.bcondrc: DONE!" | |
1615 | } | |
1616 | ||
8ff97f39 | 1617 | set_bconds_values() { |
117d9861 ER |
1618 | update_shell_title "set bcond values" |
1619 | ||
1620 | AVAIL_BCONDS_WITHOUT="" | |
1621 | AVAIL_BCONDS_WITH="" | |
8ff97f39 ER |
1622 | |
1623 | if egrep -q '^# *_with' ${SPECFILE}; then | |
1624 | echo >&2 "ERROR: This spec has old style bconds." | |
1625 | exit 1 | |
1626 | fi | |
1627 | ||
1628 | if ! grep -q '^%bcond' ${SPECFILE}; then | |
117d9861 | 1629 | return |
301cbfd4 ER |
1630 | fi |
1631 | ||
117d9861 ER |
1632 | local bcond_avail=$(find_spec_bcond $SPECFILE) |
1633 | process_bcondrc "$SPECFILE" | |
1634 | ||
fa4bf1df | 1635 | update_shell_title "parse bconds" |
2a5f078d | 1636 | |
8ff97f39 ER |
1637 | local opt bcond |
1638 | for opt in $bcond_avail; do | |
1639 | case "$opt" in | |
1640 | without_*) | |
1641 | bcond=${opt#without_} | |
10d92f71 ER |
1642 | case "$BCOND" in |
1643 | *--without?${bcond}*) | |
8ff97f39 | 1644 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>" |
10d92f71 ER |
1645 | ;; |
1646 | *) | |
8ff97f39 | 1647 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond" |
10d92f71 ER |
1648 | ;; |
1649 | esac | |
cd445739 | 1650 | ;; |
8ff97f39 ER |
1651 | with_*) |
1652 | bcond=${opt#with_} | |
10d92f71 ER |
1653 | case "$BCOND" in |
1654 | *--with?${bcond}*) | |
8ff97f39 | 1655 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>" |
10d92f71 ER |
1656 | ;; |
1657 | *) | |
8ff97f39 | 1658 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond" |
10d92f71 ER |
1659 | ;; |
1660 | esac | |
cd445739 | 1661 | ;; |
8ff97f39 ER |
1662 | *) |
1663 | echo >&2 "ERROR: unexpected '$opt' in set_bconds_values" | |
1664 | exit 1 | |
1665 | ;; | |
1666 | esac | |
1667 | done | |
cd445739 AM |
1668 | } |
1669 | ||
f6711e2a | 1670 | run_sub_builder() { |
cd445739 | 1671 | package_name="${1}" |
af6b168f | 1672 | update_shell_title "run_sub_builder $package_name" |
cd445739 AM |
1673 | # |
1674 |