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