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