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