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