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