]>
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 || { | |
588cb3a9 | 772 | # softfail if new package, i.e not yet added to PLD rep |
3189511a KK |
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 | |
6a9f8358 | 786 | CVSTAG=${CVSTAG:-"master"} |
3189511a KK |
787 | fi |
788 | git fetch "$DEPTH" origin ${CVSTAG}:remotes/origin/${CVSTAG} || { | |
789 | echo >&2 "Error: branch $CVSTAG does not exist" | |
790 | exit 3 | |
791 | } | |
703b6deb | 792 | fi |
0c3beb90 | 793 | |
0d494abd | 794 | cvsignore_df .gitignore |
703b6deb | 795 | |
588cb3a9 | 796 | # add default log format to .gitignore if it is relative to package dir |
703b6deb ER |
797 | if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then |
798 | # substitute known "macros" to glob | |
799 | local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\),*,g') | |
800 | if [ "$logfile" ]; then | |
801 | cvsignore_df "$logfile" | |
daeab113 | 802 | fi |
9c909460 | 803 | fi |
703b6deb ER |
804 | |
805 | # create symlinks for tools | |
806 | if [ "$SYMLINK_TOOLS" != "no" ]; then | |
807 | for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do | |
808 | [ -f $a ] || continue | |
809 | ln -sf ../$a $ASSUMED_NAME | |
810 | cvsignore_df $a | |
811 | done | |
812 | fi | |
cd445739 | 813 | fi |
049ab214 | 814 | |
b0121b45 | 815 | if [ -n "$CVSTAG" ]; then |
6cfb5e59 | 816 | git checkout "$CVSTAG" -- 2>/dev/null || git checkout -t "origin/$CVSTAG" > /dev/null || exit |
52f3ced3 KK |
817 | git symbolic-ref -q HEAD > /dev/null && |
818 | git merge '@{u}' | |
52020f4c | 819 | if [ -n "$CVSDATE" ]; then |
c4c0f339 KK |
820 | git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1 |
821 | fi | |
b0121b45 KK |
822 | fi |
823 | ||
9c909460 | 824 | if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then |
518ff1fb | 825 | Exit_error err_no_spec_in_repo |
cd445739 AM |
826 | fi |
827 | ||
828 | if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then | |
9c909460 | 829 | chmod $CHMOD_MODE $ASSUMED_NAME/$SPECFILE |
cd445739 AM |
830 | fi |
831 | unset OPTIONS | |
9c909460 | 832 | [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $ASSUMED_NAME/$SPECFILE |
7e40520f | 833 | |
ce40491a | 834 | set_spec_target |
cd445739 AM |
835 | } |
836 | ||
f6711e2a | 837 | find_mirror() { |
9c909460 | 838 | cd "$REPO_DIR" |
782518da | 839 | local url="$1" |
3526abd9 KK |
840 | if [ ! -f "mirrors" ] ; then |
841 | ln -s rpm-build-toos/mirrors . | |
cd445739 AM |
842 | fi |
843 | ||
844 | IFS="|" | |
782518da ER |
845 | local origin mirror name rest ol prefix |
846 | while read origin mirror name rest; do | |
847 | # skip comments and empty lines | |
2faa4c32 | 848 | if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then |
782518da ER |
849 | continue |
850 | fi | |
a8c9a155 ER |
851 | ol=$(echo -n "$origin" | wc -c) |
852 | prefix=$(echo -n "$url" | head -c $ol) | |
cd445739 | 853 | if [ "$prefix" = "$origin" ] ; then |
a8c9a155 | 854 | suffix=$(echo "$url" | cut -b $((ol+1))-) |
cd445739 AM |
855 | echo -n "$mirror$suffix" |
856 | return 0 | |
857 | fi | |
858 | done < mirrors | |
859 | echo "$url" | |
860 | } | |
861 | ||
e7e0d4ec | 862 | # Warning: unpredictable results if same URL used twice |
f6711e2a | 863 | src_no() { |
9c909460 | 864 | cd $PACKAGE_DIR |
cd445739 AM |
865 | rpm_dump | \ |
866 | grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \ | |
867 | sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \ | |
868 | head -n 1 | xargs | |
1471f6d6 | 869 | } |
870 | ||
f6711e2a | 871 | src_md5() { |
e7e0d4ec | 872 | [ "$NO5" = "yes" ] && return |
cd445739 AM |
873 | no=$(src_no "$1") |
874 | [ -z "$no" ] && return | |
9c909460 | 875 | cd $PACKAGE_DIR |
e7e0d4ec ER |
876 | local md5 |
877 | ||
878 | if [ -f additional-md5sums ]; then | |
e7e0d4ec | 879 | md5=$(grep -s -v '^#' additional-md5sums | \ |
9413a514 | 880 | grep -E "[ ]$(basename "$1")([ ,]|\$)" | \ |
e7e0d4ec ER |
881 | sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \ |
882 | grep -E '^[0-9a-f]{32}$') | |
883 | ||
884 | if [ "$md5" ]; then | |
885 | if [ $(echo "$md5" | wc -l) != 1 ] ; then | |
886 | echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2 | |
887 | fi | |
888 | echo "$md5" | tail -n 1 | |
889 | return | |
890 | fi | |
cd445739 | 891 | fi |
e7e0d4ec | 892 | |
657d488b | 893 | source_md5=`grep -i "^#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` |
e7e0d4ec ER |
894 | if [ -n "$source_md5" ]; then |
895 | echo $source_md5 | |
cd445739 | 896 | else |
7805dcb4 PZ |
897 | source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'` |
898 | if [ -n "$source_md5" ]; then | |
899 | echo $source_md5 | |
900 | else | |
901 | # we have empty SourceX-md5, but it is still possible | |
902 | # that we have NoSourceX-md5 AND NoSource: X | |
657d488b | 903 | nosource_md5=`grep -i "^#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` |
7805dcb4 PZ |
904 | if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then |
905 | echo $nosource_md5 | |
906 | fi | |
cd445739 | 907 | fi |
cd445739 AM |
908 | fi |
909 | } | |
910 | ||
f6711e2a | 911 | distfiles_path() { |
06541433 JR |
912 | echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")" |
913 | } | |
914 | ||
f6711e2a | 915 | distfiles_url() { |
06541433 | 916 | echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")" |
cd445739 AM |
917 | } |
918 | ||
f6711e2a | 919 | distfiles_attic_url() { |
06541433 | 920 | echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")" |
cd445739 AM |
921 | } |
922 | ||
f6711e2a | 923 | good_md5() { |
cd445739 AM |
924 | md5=$(src_md5 "$1") |
925 | [ "$md5" = "" ] || \ | |
926 | [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ] | |
8ba5cdda PG |
927 | } |
928 | ||
f6711e2a | 929 | good_size() { |
a8c9a155 | 930 | size=$(find $(nourl "$1") -printf "%s" 2>/dev/null) |
ce40491a | 931 | [ -n "$size" -a "$size" -gt 0 ] |
a4b50627 AF |
932 | } |
933 | ||
f6711e2a | 934 | cvsignore_df() { |
947025e5 | 935 | if [ "$CVSIGNORE_DF" != "yes" ]; then |
936 | return | |
937 | fi | |
0d494abd | 938 | cvsignore=${PACKAGE_DIR}/.gitignore |
7dc8d095 ER |
939 | |
940 | # add only if not yet there | |
aa189b05 | 941 | if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then |
947025e5 | 942 | echo "$1" >> $cvsignore |
943 | fi | |
944 | } | |
945 | ||
71f8e908 | 946 | # returns true if "$1" is ftp, http or https protocol url |
f6711e2a | 947 | is_url() { |
71f8e908 ER |
948 | case "$1" in |
949 | ftp://*|http://*|https://*) | |
950 | return 0 | |
951 | ;; | |
952 | esac | |
953 | return 1 | |
954 | } | |
955 | ||
f6711e2a | 956 | update_md5() { |
ecba6ad5 ER |
957 | if [ $# -eq 0 ]; then |
958 | return | |
959 | fi | |
960 | ||
961 | update_shell_title "update md5" | |
962 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
963 | set -x |
964 | set -v | |
ecba6ad5 ER |
965 | fi |
966 | ||
9c909460 | 967 | cd "$PACKAGE_DIR" |
ecba6ad5 ER |
968 | |
969 | # pass 1: check files to be fetched | |
970 | local todo | |
971 | local need_files | |
972 | for i in "$@"; do | |
973 | local fp=$(nourl "$i") | |
974 | local srcno=$(src_no "$i") | |
6392b5fd ER |
975 | if [ -n "$ADD5" ]; then |
976 | [ "$fp" = "$i" ] && continue # FIXME what is this check doing? | |
9c909460 AM |
977 | grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue |
978 | grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue | |
6392b5fd | 979 | else |
9c909460 | 980 | grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue |
ecba6ad5 ER |
981 | fi |
982 | if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then | |
983 | need_files="$need_files $i" | |
984 | fi | |
985 | done | |
986 | ||
987 | # pass 1a: get needed files | |
988 | if [ "$need_files" ]; then | |
989 | get_files $need_files | |
990 | fi | |
991 | ||
992 | # pass 2: proceed with md5 adding or updating | |
993 | for i in "$@"; do | |
994 | local fp=$(nourl "$i") | |
995 | local srcno=$(src_no "$i") | |
9c909460 | 996 | local md5=$(grep -iE '^#[ ]*(No)?Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE ) |
e19ad799 | 997 | if [ -z "$md5" ]; then |
9c909460 | 998 | md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE ) |
6c1b2e7d | 999 | fi |
71f8e908 | 1000 | if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then |
6c1b2e7d | 1001 | local tag="# Source$srcno-md5:\t" |
71f8e908 | 1002 | if [[ "$md5" == *NoSource* ]]; then |
6c1b2e7d PZ |
1003 | tag="# NoSource$srcno-md5:\t" |
1004 | elif [ -n "$USEDIGEST" ]; then | |
1005 | tag="BuildRequires:\tdigest(%SOURCE$srcno) = " | |
71f8e908 | 1006 | fi |
ecba6ad5 | 1007 | md5=$(md5sum "$fp" | cut -f1 -d' ') |
15bf3e99 | 1008 | echo "Updating Source$srcno ($md5: $fp)." |
ecba6ad5 | 1009 | perl -i -ne ' |
6c1b2e7d PZ |
1010 | print unless (/^\s*#\s*(No)?Source'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i); |
1011 | print "'"$tag$md5"'\n" if /^Source'$srcno'\s*:\s+/; | |
ecba6ad5 | 1012 | ' \ |
9c909460 | 1013 | $PACKAGE_DIR/$SPECFILE |
ecba6ad5 ER |
1014 | fi |
1015 | done | |
1016 | } | |
1017 | ||
f6711e2a | 1018 | check_md5() { |
60499e54 | 1019 | local bad |
3fbff8b8 ER |
1020 | [ "$NO5" = "yes" ] && return |
1021 | ||
ecba6ad5 ER |
1022 | update_shell_title "check md5" |
1023 | ||
1024 | for i in "$@"; do | |
60499e54 AM |
1025 | bad=0 |
1026 | if ! good_md5 "$i"; then | |
1027 | echo -n "MD5 sum mismatch." | |
1028 | bad=1 | |
1029 | fi | |
1030 | if ! good_size "$i"; then | |
1031 | echo -n "0 sized file." | |
1032 | bad=1 | |
ecba6ad5 ER |
1033 | fi |
1034 | ||
60499e54 AM |
1035 | if [ $bad -eq 1 ]; then |
1036 | echo " Use -U to refetch sources," | |
1037 | echo "or -5 to update md5 sums, if you're sure files are correct." | |
1038 | Exit_error err_no_source_in_repo $i | |
1039 | fi | |
ecba6ad5 ER |
1040 | done |
1041 | } | |
1042 | ||
f6711e2a | 1043 | get_files() { |
7cb24972 | 1044 | update_shell_title "get_files" |
cd445739 AM |
1045 | |
1046 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
1047 | set -x |
1048 | set -v | |
cd445739 AM |
1049 | fi |
1050 | ||
f09c0772 | 1051 | if [ $# -gt 0 ]; then |
9c909460 | 1052 | cd "$PACKAGE_DIR" |
cd445739 | 1053 | |
f2e42a41 | 1054 | local nc=0 |
e7fa3b9f | 1055 | local get_files_cvs="" |
3815b69a | 1056 | for i in "$@"; do |
f2e42a41 | 1057 | nc=$((nc + 1)) |
dcebdffb | 1058 | local cvsup=0 |
3815b69a | 1059 | SHELL_TITLE_PREFIX="get_files[$nc/$#]" |
f2e42a41 | 1060 | update_shell_title "$i" |
f09c0772 | 1061 | local fp=`nourl "$i"` |
ecba6ad5 | 1062 | if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then |
ce40491a | 1063 | continue |
18e5347d | 1064 | fi |
ecba6ad5 | 1065 | |
cd445739 | 1066 | FROM_DISTFILES=0 |
e7e0d4ec | 1067 | local srcmd5=$(src_md5 "$i") |
ecba6ad5 ER |
1068 | |
1069 | # we know if source/patch is present in cvs/distfiles | |
1070 | # - has md5 (in distfiles) | |
1071 | # - in cvs... ideas? | |
1072 | ||
1073 | # CHECK: local file didn't exist or always cvs up (first) requested. | |
f09c0772 | 1074 | if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then |
cd445739 AM |
1075 | if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then |
1076 | echo "Warning: no URL given for $i" | |
1077 | fi | |
08908161 | 1078 | target="$fp" |
cd445739 | 1079 | |
e7e0d4ec | 1080 | if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then |
a4b50627 | 1081 | if good_md5 "$i" && good_size "$i"; then |
e7e0d4ec | 1082 | echo "$fp having proper md5sum already exists" |
cd445739 AM |
1083 | continue |
1084 | fi | |
28b34560 | 1085 | |
bc10f694 | 1086 | # optionally prefer mirror over distfiles if there's mirror |
28b34560 | 1087 | # TODO: build url list and then try each url from the list |
bc10f694 | 1088 | if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then |
28b34560 ER |
1089 | url="$im" |
1090 | else | |
1091 | url=$(distfiles_url "$i") | |
1092 | fi | |
1093 | ||
cd445739 AM |
1094 | url_attic=$(distfiles_attic_url "$i") |
1095 | FROM_DISTFILES=1 | |
ecba6ad5 ER |
1096 | # is $url local file? |
1097 | if [[ "$url" = [./]* ]]; then | |
18a52930 | 1098 | update_shell_title "${GETLOCAL%% *}: $url" |
cd445739 AM |
1099 | ${GETLOCAL} $url $target |
1100 | else | |
1101 | if [ -z "$NOMIRRORS" ]; then | |
9e9f8920 | 1102 | url=$(find_mirror "$url") |
cd445739 | 1103 | fi |
9e9f8920 ER |
1104 | |
1105 | local uri=${url} | |
1106 | # make shorter message for distfiles urls | |
1107 | if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then | |
1108 | uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/} | |
1109 | uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/} | |
1110 | uri="df: $uri" | |
1111 | fi | |
1112 | update_shell_title "${GETURI%% *}: $uri" | |
ca2e6c31 | 1113 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
33da77c4 | 1114 | if [ "`echo $url | grep -E 'ftp://'`" ]; then |
18a52930 | 1115 | update_shell_title "${GETURI2%% *}: $url" |
ca2e6c31 | 1116 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
cd445739 AM |
1117 | fi |
1118 | fi | |
ecba6ad5 ER |
1119 | |
1120 | # is it empty file? | |
1121 | if [ ! -s "$target" ]; then | |
cd445739 AM |
1122 | rm -f "$target" |
1123 | if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then | |
18a52930 | 1124 | update_shell_title "${GETLOCAL%% *}: $url_attic" |
cd445739 AM |
1125 | ${GETLOCAL} $url_attic $target |
1126 | else | |
1127 | if [ -z "$NOMIRRORS" ]; then | |
a8c9a155 | 1128 | url_attic=$(find_mirror "$url_attic") |
cd445739 | 1129 | fi |
18a52930 | 1130 | update_shell_title "${GETURI%% *}: $url_attic" |
ca2e6c31 | 1131 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
33da77c4 | 1132 | if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then |
ce40491a | 1133 | update_shell_title "${GETURI2%% *}: $url_attic" |
ca2e6c31 | 1134 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
cd445739 | 1135 | fi |
1cd7fc57 | 1136 | test -s "$target" || rm -f "$target" |
cd445739 AM |
1137 | fi |
1138 | fi | |
ecba6ad5 ER |
1139 | |
1140 | if [ -s "$target" ]; then | |
947025e5 | 1141 | cvsignore_df $target |
1142 | else | |
cd445739 AM |
1143 | rm -f "$target" |
1144 | FROM_DISTFILES=0 | |
1145 | fi | |
cd445739 AM |
1146 | fi |
1147 | ||
f09c0772 | 1148 | if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then |
cd445739 | 1149 | if [ -z "$NOMIRRORS" ]; then |
a8c9a155 | 1150 | im=$(find_mirror "$i") |
cd445739 AM |
1151 | else |
1152 | im="$i" | |
1153 | fi | |
ce40491a | 1154 | update_shell_title "${GETURI%% *}: $im" |
08908161 | 1155 | ${GETURI} "$im" ${OUTFILEOPT} "$target" || \ |
33da77c4 | 1156 | if [ "`echo $im | grep -E 'ftp://'`" ]; then |
ce40491a | 1157 | update_shell_title "${GETURI2%% *}: $im" |
08908161 | 1158 | ${GETURI2} "$im" ${OUTFILEOPT} "$target" |
7e365483 | 1159 | fi |
1cd7fc57 | 1160 | test -s "$target" || rm -f "$target" |
cd445739 AM |
1161 | fi |
1162 | ||
dcebdffb ER |
1163 | if [ "$cvsup" = 1 ]; then |
1164 | continue | |
1165 | fi | |
1166 | ||
cd445739 | 1167 | fi |
ecba6ad5 ER |
1168 | |
1169 | # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong. | |
f09c0772 | 1170 | if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then |
b3b584c5 | 1171 | Exit_error err_no_source_in_repo $i |
cd445739 | 1172 | fi |
2a5f078d | 1173 | |
ecba6ad5 | 1174 | # we check md5 here just only to refetch immediately |
a4b50627 | 1175 | if good_md5 "$i" && good_size "$i"; then |
cd445739 AM |
1176 | : |
1177 | elif [ "$FROM_DISTFILES" = 1 ]; then | |
deccc50e | 1178 | # wrong md5 from distfiles: remove the file and try again |
cd445739 | 1179 | # but only once ... |
deccc50e | 1180 | echo "MD5 sum mismatch. Trying full fetch." |
cd445739 AM |
1181 | FROM_DISTFILES=2 |
1182 | rm -f $target | |
18a52930 | 1183 | update_shell_title "${GETURI%% *}: $url" |
ca2e6c31 | 1184 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
33da77c4 | 1185 | if [ "`echo $url | grep -E 'ftp://'`" ]; then |
ce40491a | 1186 | update_shell_title "${GETURI2%% *}: $url" |
ca2e6c31 | 1187 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
cd445739 | 1188 | fi |
ecba6ad5 | 1189 | if [ ! -s "$target" ]; then |
cd445739 | 1190 | rm -f "$target" |
18a52930 | 1191 | update_shell_title "${GETURI%% *}: $url_attic" |
ca2e6c31 | 1192 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
33da77c4 | 1193 | if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then |
ce40491a | 1194 | update_shell_title "${GETURI2%% *}: $url_attic" |
ca2e6c31 | 1195 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
cd445739 AM |
1196 | fi |
1197 | fi | |
1198 | test -s "$target" || rm -f "$target" | |
1199 | fi | |
cd445739 | 1200 | done |
e7fa3b9f ER |
1201 | SHELL_TITLE_PREFIX="" |
1202 | ||
cd445739 AM |
1203 | |
1204 | if [ "$CHMOD" = "yes" ]; then | |
a8c9a155 | 1205 | CHMOD_FILES=$(nourl "$@") |
cd445739 AM |
1206 | if [ -n "$CHMOD_FILES" ]; then |
1207 | chmod $CHMOD_MODE $CHMOD_FILES | |
1208 | fi | |
1209 | fi | |
cd445739 AM |
1210 | fi |
1211 | } | |
1212 | ||
1213 | make_tagver() { | |
ce40491a | 1214 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
1215 | set -x |
1216 | set -v | |
ce40491a | 1217 | fi |
78eab2a1 | 1218 | |
ce40491a ER |
1219 | # Check whether first character of PACKAGE_NAME is legal for tag name |
1220 | if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then | |
1221 | TAG_PREFIX=tag_ | |
1222 | fi | |
d712cc12 ER |
1223 | |
1224 | # NOTE: CVS tags may must not contain the characters `$,.:;@' | |
392187d9 | 1225 | TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE | tr '[.@]' '[_#]') |
d712cc12 | 1226 | |
ce40491a ER |
1227 | # Remove #kernel.version_release from TAGVER because tagging sources |
1228 | # could occur with different kernel-headers than kernel-headers used at build time. | |
d712cc12 ER |
1229 | # besides, %{_kernel_ver_str} is not expanded. |
1230 | ||
1231 | # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1#%{_kernel_ver_str} | |
1232 | # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1 | |
1233 | ||
1234 | TAGVER=${TAGVER%#*} | |
ce40491a | 1235 | echo -n "$TAGVER" |
cd445739 AM |
1236 | } |
1237 | ||
f6711e2a | 1238 | tag_files() { |
cd445739 AM |
1239 | TAG_FILES="$@" |
1240 | ||
1241 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
1242 | set -x |
1243 | set -v | |
cd445739 AM |
1244 | fi |
1245 | ||
73ef63d8 ER |
1246 | echo "Version: $PACKAGE_VERSION" |
1247 | echo "Release: $PACKAGE_RELEASE" | |
cd445739 | 1248 | |
a18a9761 | 1249 | local TAGVER |
73ef63d8 | 1250 | if [ "$TAG_VERSION" = "yes" ]; then |
a18a9761 | 1251 | TAGVER=`make_tagver` |
48ab9915 | 1252 | echo "tag: $TAGVER" |
73ef63d8 ER |
1253 | fi |
1254 | if [ -n "$TAG" ]; then | |
48ab9915 | 1255 | echo "tag: $TAG" |
73ef63d8 | 1256 | fi |
cd445739 | 1257 | |
39dcc7de | 1258 | local OPTIONS="tag $CVS_FORCE" |
cd445739 | 1259 | |
c713aac3 AG |
1260 | local _tag=$TAG |
1261 | if [ "$TAG_VERSION" = "yes" ]; then | |
1262 | _tag=$TAGVER | |
1263 | fi; | |
c713aac3 | 1264 | |
9c909460 | 1265 | cd "$PACKAGE_DIR" |
03db3356 | 1266 | |
73ef63d8 | 1267 | if [ "$TAG_VERSION" = "yes" ]; then |
48ab9915 KK |
1268 | update_shell_title "tag sources: $TAGVER" |
1269 | git $OPTIONS $TAGVER || exit | |
73ef63d8 ER |
1270 | fi |
1271 | if [ -n "$TAG" ]; then | |
48ab9915 KK |
1272 | update_shell_title "tag sources: $TAG" |
1273 | git $OPTIONS $TAG $chunk || exit | |
73ef63d8 | 1274 | fi |
cd445739 AM |
1275 | } |
1276 | ||
f6711e2a | 1277 | branch_files() { |
cd445739 | 1278 | TAG=$1 |
f663f264 | 1279 | echo "Git branch: $TAG" |
518ff1fb | 1280 | shift |
cd445739 | 1281 | |
cd445739 | 1282 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
1283 | set -x |
1284 | set -v | |
cd445739 AM |
1285 | fi |
1286 | ||
f663f264 | 1287 | local OPTIONS="branch $CVS_FORCE" |
c10fa4fa | 1288 | |
9c909460 | 1289 | cd "$PACKAGE_DIR" |
f663f264 | 1290 | git $OPTIONS $TAG || exit |
cd445739 AM |
1291 | } |
1292 | ||
1293 | ||
3009b80d ER |
1294 | # this function should exit early if package can't be built for this arch |
1295 | # this avoids unneccessary BR filling. | |
1296 | check_buildarch() { | |
1297 | local out ret | |
13c3c336 | 1298 | out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1) |
3009b80d ER |
1299 | ret=$? |
1300 | if [ $ret -ne 0 ]; then | |
1301 | echo >&2 "$out" | |
1302 | exit $ret | |
1303 | fi | |
1304 | } | |
1305 | ||
9d99a240 ER |
1306 | # from relup.sh |
1307 | set_release() { | |
1308 | local specfile="$1" | |
1309 | local rel="$2" | |
1310 | local newrel="$3" | |
1311 | sed -i -e " | |
1312 | s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/ | |
1313 | s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/ | |
1314 | " $specfile | |
1315 | } | |
1316 | ||
1317 | set_version() { | |
1318 | local specfile="$1" | |
bc8502e6 ER |
1319 | local ver="$2" subver=$ver |
1320 | local newver="$3" newsubver=$newver | |
1321 | ||
1322 | # try handling subver, everything that's not numeric-dotted in version | |
1323 | if grep -Eq '%define\s+subver' $specfile; then | |
1324 | subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,') | |
1325 | ver=${ver%$subver} | |
1326 | newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,') | |
1327 | newver=${newver%$newsubver} | |
1328 | fi | |
9d99a240 ER |
1329 | sed -i -e " |
1330 | s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/ | |
bc8502e6 | 1331 | s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/ |
9d99a240 ER |
1332 | s/^\(Version:[ \t]\+\)$ver\$/\1$newver/ |
1333 | " $specfile | |
1334 | } | |
1335 | ||
cacef28c | 1336 | try_upgrade() { |
cd445739 | 1337 | if [ -n "$TRY_UPGRADE" ]; then |
9d99a240 | 1338 | local TNOTIFY TNEWVER TOLDVER |
ce40491a | 1339 | update_shell_title "build_package: try_upgrade" |
9d99a240 | 1340 | |
cacef28c | 1341 | cd "$PACKAGE_DIR" |
1342 | ||
0907f1eb ER |
1343 | if [ "$UPGRADE_VERSION" ]; then |
1344 | TNEWVER=$UPGRADE_VERSION | |
cd445739 | 1345 | else |
0907f1eb ER |
1346 | if [ -n "$FLOAT_VERSION" ]; then |
1347 | TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1 | |
1348 | else | |
1349 | TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1 | |
1350 | fi | |
cd445739 | 1351 | |
b9bef5ce ER |
1352 | # pldnotify.awk does not set exit codes, but it has match for ERROR |
1353 | # in output which means so. | |
1354 | if [[ "$TNOTIFY" = *ERROR* ]]; then | |
1355 | echo >&2 "$TNOTIFY" | |
1356 | exit 1 | |
1357 | fi | |
1358 | ||
0907f1eb ER |
1359 | TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }') |
1360 | fi | |
cd445739 AM |
1361 | |
1362 | if [ -n "$TNEWVER" ]; then | |
1363 | TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'` | |
9d99a240 | 1364 | echo "New version found, updating spec file from $TOLDVER to version $TNEWVER" |
257af81b ER |
1365 | if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then |
1366 | cp -f $SPECFILE $SPECFILE.bak | |
1367 | fi | |
cd445739 | 1368 | chmod +w $SPECFILE |
cacef28c | 1369 | set_release $SPECFILE $PACKAGE_RELEASE 1 |
9d99a240 | 1370 | set_version $SPECFILE $PACKAGE_VERSION $TNEWVER |
518ff1fb | 1371 | parse_spec |
6decb793 ER |
1372 | if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then |
1373 | echo >&2 "Upgrading version failed, you need to update spec yourself" | |
1374 | exit 1 | |
1375 | fi | |
cacef28c | 1376 | return 1 |
cd445739 AM |
1377 | fi |
1378 | fi | |
cacef28c | 1379 | return 0 |
1380 | } | |
1381 | ||
1382 | build_package() { | |
1383 | update_shell_title "build_package" | |
1384 | if [ -n "$DEBUG" ]; then | |
1385 | set -x | |
1386 | set -v | |
1387 | fi | |
1388 | ||
9c909460 | 1389 | cd "$PACKAGE_DIR" |
2a5f078d | 1390 | |
cd445739 AM |
1391 | case "$COMMAND" in |
1392 | build ) | |
1393 | BUILD_SWITCH="-ba" ;; | |
1394 | build-binary ) | |
1395 | BUILD_SWITCH="-bb" ;; | |
1396 | build-source ) | |
1397 | BUILD_SWITCH="-bs --nodeps" ;; | |
1398 | build-prep ) | |
1399 | BUILD_SWITCH="-bp --nodeps" ;; | |
6594293d AG |
1400 | build-build ) |
1401 | BUILD_SWITCH="-bc" ;; | |
1402 | build-install ) | |
1403 | BUILD_SWITCH="-bi" ;; | |
1404 | build-list ) | |
1405 | BUILD_SWITCH="-bl" ;; | |
1406 | ||
cd445739 | 1407 | esac |
c890b916 | 1408 | |
2e5be021 | 1409 | update_shell_title "build_package: $COMMAND" |
cd445739 AM |
1410 | if [ -n "$LOGFILE" ]; then |
1411 | LOG=`eval echo $LOGFILE` | |
1412 | if [ -d "$LOG" ]; then | |
1413 | echo "Log file $LOG is a directory." | |
1414 | echo "Parse error in the spec?" | |
518ff1fb | 1415 | Exit_error err_build_fail |
cd445739 AM |
1416 | fi |
1417 | if [ -n "$LASTLOG_FILE" ]; then | |
1418 | echo "LASTLOG=$LOG" > $LASTLOG_FILE | |
1419 | fi | |
390d081d | 1420 | RES_FILE=$(tempfile) |
8cc8f5c0 | 1421 | local specfile=$(insert_gitlog $SPECFILE) |
525bf240 | 1422 | |
8cc8f5c0 | 1423 | (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 | 1424 | RETVAL=`cat $RES_FILE` |
8cc8f5c0 | 1425 | rm $RES_FILE $specfile |
cd445739 AM |
1426 | if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then |
1427 | if [ "$RETVAL" -eq "0" ]; then | |
1428 | mv $LOG $LOGDIROK | |
1429 | else | |
1430 | mv $LOG $LOGDIRFAIL | |
1431 | fi | |
1432 | fi | |
8ba5cdda | 1433 | else |
9c909460 | 1434 | eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE |
cd445739 | 1435 | RETVAL=$? |
8ba5cdda | 1436 | fi |
cd445739 AM |
1437 | if [ "$RETVAL" -ne "0" ]; then |
1438 | if [ -n "$TRY_UPGRADE" ]; then | |
cacef28c | 1439 | echo "\nUpgrade package to new version failed." |
257af81b | 1440 | if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then |
cacef28c | 1441 | echo "Restoring old spec file." |
257af81b ER |
1442 | mv -f $SPECFILE.bak $SPECFILE |
1443 | fi | |
cacef28c | 1444 | echo "" |
cd445739 | 1445 | fi |
518ff1fb | 1446 | Exit_error err_build_fail |
cd445739 AM |
1447 | fi |
1448 | unset BUILD_SWITCH | |
1449 | } | |
1450 | ||
f6711e2a | 1451 | nourl() { |
cd445739 AM |
1452 | echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g' |
1453 | } | |
1454 | ||
f6711e2a | 1455 | install_required_packages() { |
cd445739 AM |
1456 | run_poldek -vi $1 |
1457 | return $? | |
1458 | } | |
1459 | ||
f6711e2a | 1460 | find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond |
fa4bf1df | 1461 | local SPEC="$1" |
fa4bf1df ER |
1462 | awk -F"\n" ' |
1463 | /^%changelog/ { exit } | |
fa4bf1df ER |
1464 | /^%bcond_with/{ |
1465 | match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/); | |
8ff97f39 ER |
1466 | bcond = substr($0, RSTART + 6, RLENGTH - 6); |
1467 | gsub(/[ \t]+/, "_", bcond); | |
fa4bf1df ER |
1468 | print bcond |
1469 | }' $SPEC | LC_ALL=C sort -u | |
1470 | } | |
1471 | ||
117d9861 | 1472 | process_bcondrc() { |
301cbfd4 ER |
1473 | # expand bconds from ~/.bcondrc |
1474 | # The file structure is like gentoo's package.use: | |
1475 | # --- | |
1476 | # * -selinux | |
1477 | # samba -mysql -pgsql | |
47a8df12 | 1478 | # w32codec-installer license_agreement |
301cbfd4 ER |
1479 | # php +mysqli |
1480 | # --- | |
fa4bf1df | 1481 | if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then |
117d9861 ER |
1482 | : |
1483 | else | |
1484 | return | |
1485 | fi | |
301cbfd4 | 1486 | |
117d9861 | 1487 | SN=${SPECFILE%%\.spec} |
c8a3e2ac | 1488 | |
117d9861 ER |
1489 | local bcondrc=$HOME/.bcondrc |
1490 | [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc | |
301cbfd4 | 1491 | |
117d9861 | 1492 | local bcond_avail=$(find_spec_bcond $SPECFILE) |
301cbfd4 | 1493 | |
117d9861 ER |
1494 | while read pkg flags; do |
1495 | # ignore comments | |
1496 | [[ "$pkg" == \#* ]] && continue | |
1497 | ||
1498 | # any package or current package? | |
1499 | if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then | |
1500 | for flag in $flags; do | |
1501 | local opt=${flag#[+-]} | |
1502 | ||
1503 | # use only flags which are in this package. | |
1504 | if [[ $bcond_avail = *${opt}* ]]; then | |
1505 | if [[ $flag = -* ]]; then | |
1506 | if [[ $BCOND != *--with?${opt}* ]]; then | |
1507 | BCOND="$BCOND --without $opt" | |
1508 | fi | |
1509 | else | |
1510 | if [[ $BCOND != *--without?${opt}* ]]; then | |
1511 | BCOND="$BCOND --with $opt" | |
301cbfd4 ER |
1512 | fi |
1513 | fi | |
117d9861 ER |
1514 | fi |
1515 | done | |
1516 | fi | |
1517 | done < $bcondrc | |
1518 | update_shell_title "parse ~/.bcondrc: DONE!" | |
1519 | } | |
1520 | ||
8ff97f39 | 1521 | set_bconds_values() { |
117d9861 ER |
1522 | update_shell_title "set bcond values" |
1523 | ||
1524 | AVAIL_BCONDS_WITHOUT="" | |
1525 | AVAIL_BCONDS_WITH="" | |
8ff97f39 | 1526 | |
5a28189c | 1527 | if grep -Eq '^# *_with' ${SPECFILE}; then |
8ff97f39 ER |
1528 | echo >&2 "ERROR: This spec has old style bconds." |
1529 | exit 1 | |
1530 | fi | |
1531 | ||
1532 | if ! grep -q '^%bcond' ${SPECFILE}; then | |
117d9861 | 1533 | return |
301cbfd4 ER |
1534 | fi |
1535 | ||
117d9861 ER |
1536 | local bcond_avail=$(find_spec_bcond $SPECFILE) |
1537 | process_bcondrc "$SPECFILE" | |
1538 | ||
fa4bf1df | 1539 | update_shell_title "parse bconds" |
2a5f078d | 1540 | |
8ff97f39 ER |
1541 | local opt bcond |
1542 | for opt in $bcond_avail; do | |
1543 | case "$opt" in | |
1544 | without_*) | |
1545 | bcond=${opt#without_} | |
10d92f71 ER |
1546 | case "$BCOND" in |
1547 | *--without?${bcond}*) | |
8ff97f39 | 1548 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>" |
10d92f71 ER |
1549 | ;; |
1550 | *) | |
8ff97f39 | 1551 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond" |
10d92f71 ER |
1552 | ;; |
1553 | esac | |
cd445739 | 1554 | ;; |
8ff97f39 ER |
1555 | with_*) |
1556 | bcond=${opt#with_} | |
10d92f71 ER |
1557 | case "$BCOND" in |
1558 | *--with?${bcond}*) | |
8ff97f39 | 1559 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>" |
10d92f71 ER |
1560 | ;; |
1561 | *) | |
8ff97f39 | 1562 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond" |
10d92f71 ER |
1563 | ;; |
1564 | esac | |
cd445739 | 1565 | ;; |
8ff97f39 ER |
1566 | *) |
1567 | echo >&2 "ERROR: unexpected '$opt' in set_bconds_values" | |
1568 | exit 1 | |
1569 | ;; | |
1570 | esac | |
1571 | done | |
cd445739 AM |
1572 | } |
1573 | ||
f6711e2a | 1574 | run_sub_builder() { |
cd445739 | 1575 | package_name="${1}" |
af6b168f | 1576 | update_shell_title "run_sub_builder $package_name" |
cd445739 AM |
1577 | # |
1578 |