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