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