]>
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") | |
b1f2a05a | 38 | VERSION="v0.35" |
d43959a2 | 39 | VERSIONSTRING="\ |
b71f5024 | 40 | Build package utility from PLD Linux Packages repository |
be93ada0 | 41 | $VERSION (C) 1999-2016 Free Penguins". |
d43959a2 | 42 | |
670b1ed4 | 43 | CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin" |
b03f053b | 44 | |
b7cc0c94 ER |
45 | # required rpm-build-macros |
46 | RPM_MACROS_VER=1.534 | |
47 | ||
cd445739 | 48 | COMMAND="build" |
64ea5308 | 49 | TARGET="" |
cd445739 | 50 | |
bde1c404 | 51 | SPECFILE="" |
d287305c | 52 | BE_VERBOSE="" |
4003ad8c | 53 | QUIET="" |
cd445739 AM |
54 | CLEAN="" |
55 | DEBUG="" | |
56 | NOURLS="" | |
cd445739 AM |
57 | NOCVSSPEC="" |
58 | NODIST="" | |
47761337 | 59 | NOINIT="" |
bc10f694 | 60 | PREFMIRRORS="" |
cd445739 | 61 | UPDATE="" |
cd445739 AM |
62 | ADD5="" |
63 | NO5="" | |
64 | ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"} | |
cd445739 | 65 | |
6c1b2e7d PZ |
66 | # use rpm 4.4.6+ digest format instead of comments if non-zero |
67 | USEDIGEST= | |
68 | ||
e3aa6f5e ER |
69 | # user agent when fetching files |
70 | USER_AGENT="PLD/Builder($VERSION)" | |
71 | ||
cd445739 AM |
72 | # It can be used i.e. in log file naming. |
73 | # See LOGFILE example. | |
74 | DATE=`date +%Y-%m-%d_%H-%M-%S` | |
75 | ||
7534a77d ER |
76 | # target arch, can also be used for log file naming |
77 | TARGET=$(rpm -E %{_target}) | |
78 | ||
01d8ce69 | 79 | # Note the *single* quotes, this allows using shell variables expanded at build time |
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' |
01d8ce69 | 84 | # Example: LOGFILE='.log.$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE.$TARGET.$DATE' |
cd445739 AM |
85 | LOGFILE='' |
86 | ||
12da9e3d ER |
87 | # use teeboth Perl wrapper |
88 | # temporary option to disable if broken | |
89 | USE_TEEBOTH=yes | |
90 | ||
cd445739 AM |
91 | LOGDIR="" |
92 | LOGDIROK="" | |
93 | LOGDIRFAIL="" | |
94 | LASTLOG_FILE="" | |
95 | ||
96 | CHMOD="no" | |
1da227e8 | 97 | CHMOD_MODE="0644" |
cd445739 | 98 | RPMOPTS="" |
d1c5a9a7 | 99 | RPMBUILDOPTS="" |
cd445739 AM |
100 | BCOND="" |
101 | GROUP_BCONDS="no" | |
ccffa567 ER |
102 | |
103 | # create symlinks for tools in PACKAGE_DIR, see get_spec() | |
2dd0af86 | 104 | SYMLINK_TOOLS="no" |
d287305c | 105 | |
106 | PATCHES="" | |
107 | SOURCES="" | |
cd445739 | 108 | ICONS="" |
d287305c | 109 | PACKAGE_RELEASE="" |
110 | PACKAGE_VERSION="" | |
111 | PACKAGE_NAME="" | |
14bead22 | 112 | ASSUMED_NAME="" |
fd71d65c | 113 | PROTOCOL="http" |
2060f498 AM |
114 | |
115 | # use lftp by default when available | |
f4bac425 | 116 | USE_LFTP= |
2060f498 | 117 | lftp --version > /dev/null 2>&1 && USE_LFTP=yes |
d4c8d3a9 | 118 | PARALLEL_DOWNLOADS=10 |
2060f498 | 119 | |
cd445739 | 120 | WGET_RETRIES=${MAX_WGET_RETRIES:-0} |
cd445739 | 121 | |
939f2c12 | 122 | CVS_FORCE="" |
f123bcb5 | 123 | CVSIGNORE_DF="yes" |
cd445739 | 124 | CVSTAG="" |
7446994b KK |
125 | GIT_SERVER="git://git.pld-linux.org" |
126 | GIT_PUSH="git@git.pld-linux.org" | |
76636346 | 127 | PACKAGES_DIR="packages" |
a8f917c2 | 128 | HEAD_DETACHED="" |
3189511a | 129 | DEPTH="" |
3f79cb18 | 130 | ALL_BRANCHES="" |
608c01a7 | 131 | REMOTE_PLD="origin" |
406b9ecf | 132 | NEW_REPO="" |
939f2c12 | 133 | |
cd445739 AM |
134 | RES_FILE="" |
135 | ||
cd445739 | 136 | DISTFILES_SERVER="://distfiles.pld-linux.org" |
d4730dae | 137 | ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org" |
cd445739 | 138 | |
36d03934 | 139 | DEF_NICE_LEVEL=19 |
86aafdbe | 140 | SCHEDTOOL="auto" |
cd445739 AM |
141 | |
142 | FAIL_IF_NO_SOURCES="yes" | |
143 | ||
18e5347d ER |
144 | # let get_files skip over files which are present to get those damn files fetched |
145 | SKIP_EXISTING_FILES="no" | |
146 | ||
975d7b23 | 147 | TRY_UPGRADE="" |
257af81b ER |
148 | # should the specfile be restored if upgrade failed? |
149 | REVERT_BROKEN_UPGRADE="yes" | |
150 | ||
90baf90b ER |
151 | if rpm --specsrpm 2>/dev/null; then |
152 | FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes" | |
ce40491a | 153 | FETCH_BUILD_REQUIRES_RPMGETDEPS="no" |
90baf90b ER |
154 | else |
155 | FETCH_BUILD_REQUIRES_RPMSPECSRPM="no" | |
156 | if [ -x /usr/bin/rpm-getdeps ]; then | |
157 | FETCH_BUILD_REQUIRES_RPMGETDEPS="yes" | |
158 | else | |
159 | FETCH_BUILD_REQUIRES_RPMGETDEPS="no" | |
160 | fi | |
ab4a2b6e ER |
161 | fi |
162 | ||
8a390970 | 163 | UPDATE_POLDEK_INDEXES_OPTS="" |
90baf90b | 164 | |
cd445739 AM |
165 | # Here we load saved user environment used to |
166 | # predefine options set above, or passed to builder | |
167 | # in command line. | |
168 | # This one reads global system environment settings: | |
169 | if [ -f ~/etc/builderrc ]; then | |
170 | . ~/etc/builderrc | |
171 | fi | |
172 | # And this one cascades settings using user personal | |
173 | # builder settings. | |
174 | # Example of ~/.builderrc: | |
175 | # | |
176 | #UPDATE_POLDEK_INDEXES="yes" | |
8a390970 | 177 | #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff" |
cd445739 AM |
178 | #FETCH_BUILD_REQUIRES="yes" |
179 | #REMOVE_BUILD_REQUIRES="force" | |
180 | #GROUP_BCONDS="yes" | |
181 | #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE' | |
982e358c | 182 | #TITLECHANGE=no |
aa7e48da ER |
183 | |
184 | SU_SUDO="sudo" | |
185 | ||
cd445739 AM |
186 | if [ -n "$HOME_ETC" ]; then |
187 | USER_CFG="$HOME_ETC/.builderrc" | |
20117088 | 188 | BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros" |
cd445739 AM |
189 | else |
190 | USER_CFG=~/.builderrc | |
20117088 | 191 | BUILDER_MACROS=~/.builder-rpmmacros |
cd445739 AM |
192 | fi |
193 | ||
194 | [ -f "$USER_CFG" ] && . "$USER_CFG" | |
195 | ||
86aafdbe ER |
196 | if [ "$SCHEDTOOL" = "auto" ]; then |
197 | if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then | |
198 | SCHEDTOOL="schedtool -B -e" | |
199 | else | |
200 | SCHEDTOOL="no" | |
201 | fi | |
202 | fi | |
203 | ||
ca2e6c31 | 204 | if [ -n "$USE_PROZILLA" ]; then |
7e365483 KK |
205 | GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS" |
206 | GETURI2="$GETURI" | |
207 | OUTFILEOPT="-O" | |
ca2e6c31 | 208 | elif [ -n "$USE_AXEL" ]; then |
cede92b3 | 209 | GETURI="axel -a $AXEL_OPTS" |
7e365483 KK |
210 | GETURI2="$GETURI" |
211 | OUTFILEOPT="-o" | |
9639be96 | 212 | elif [ -n "$USE_LFTP" ]; then |
9639be96 AM |
213 | GETURI=download_lftp |
214 | GETURI2=$GETURI | |
215 | OUTFILEOPT="" | |
ca2e6c31 | 216 | else |
5700ee32 ER |
217 | wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate" |
218 | wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet" | |
219 | wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused" | |
9f37a487 | 220 | wget --help 2>&1 | grep -q -- ' --no-iri ' && WGET_OPTS="$WGET_OPTS --no-iri" |
e3aa6f5e | 221 | WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT" |
6f9a5d76 | 222 | |
7e365483 KK |
223 | GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS" |
224 | GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS" | |
225 | OUTFILEOPT="-O" | |
2bc5451f | 226 | fi |
11468b23 | 227 | |
11468b23 AM |
228 | GETLOCAL="cp -a" |
229 | ||
15e34b63 | 230 | if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then |
11468b23 AM |
231 | RPM="rpm" |
232 | RPMBUILD="rpm" | |
233 | else | |
234 | RPM="rpm" | |
235 | RPMBUILD="rpmbuild" | |
236 | fi | |
237 | ||
c86939e2 | 238 | # |
239 | # sanity checks | |
240 | # | |
241 | if [ -d $HOME/rpm/SOURCES ]; then | |
242 | echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2 | |
243 | echo "ERROR: get rid of your ~/rpm/SOURCES" >&2 | |
244 | exit 1 | |
245 | fi | |
246 | ||
a8c9a155 | 247 | POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/" |
aa7e48da | 248 | POLDEK_CMD="$SU_SUDO /usr/bin/poldek" |
11468b23 | 249 | |
12da9e3d | 250 | # TODO: add teeboth |
aa7e48da | 251 | # TODO: what this function does? |
f6711e2a | 252 | run_poldek() { |
390d081d | 253 | RES_FILE=$(tempfile) |
cd445739 AM |
254 | if [ -n "$LOGFILE" ]; then |
255 | LOG=`eval echo $LOGFILE` | |
256 | if [ -n "$LASTLOG_FILE" ]; then | |
257 | echo "LASTLOG=$LOG" > $LASTLOG_FILE | |
258 | fi | |
aa7e48da | 259 | (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG |
12da9e3d | 260 | # FIXME $exit_pldk undefined |
cd445739 AM |
261 | return $exit_pldk |
262 | else | |
aa7e48da | 263 | (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null |
cd445739 AM |
264 | return `cat ${RES_FILE}` |
265 | rm -rf ${RES_FILE} | |
266 | fi | |
267 | } | |
268 | ||
cd445739 AM |
269 | #--------------------------------------------- |
270 | # functions | |
da946cd6 | 271 | |
f4bac425 | 272 | download_lftp() { |
6928bb29 | 273 | local outfile=$1 url=$2 retval tmpfile |
f4bac425 ER |
274 | # TODO: use mktemp |
275 | tmpfile=$outfile.tmp | |
4d1fc6ce AM |
276 | lftp -c " |
277 | $([ "$DEBUG" = "yes" ] && echo "debug 5;") | |
78ff632e | 278 | set ssl:verify-certificate no; |
4d1fc6ce AM |
279 | set net:max-retries $WGET_RETRIES; |
280 | set http:user-agent \"$USER_AGENT\"; | |
d4c8d3a9 | 281 | pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\" |
4d1fc6ce | 282 | " |
f4bac425 ER |
283 | |
284 | retval=$? | |
285 | if [ $retval -eq 0 ]; then | |
286 | mv -f "$tmpfile" "$outfile" | |
287 | else | |
288 | rm -f "$tmpfile" | |
289 | fi | |
290 | return $retval | |
291 | } | |
292 | ||
f6711e2a | 293 | usage() { |
cd445739 | 294 | if [ -n "$DEBUG" ]; then set -xv; fi |
647fead0 ER |
295 | # NOTE: |
296 | # to make this output parseable by bash-completion _parse_help() | |
297 | # if the line contains short and long option, it will take only the long option | |
298 | # but if you want both being completed, put the short option to separate line | |
cd445739 | 299 | echo "\ |
3f79cb18 | 300 | Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build] |
6594293d | 301 | [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade] |
0c8e5e9d | 302 | [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>] |
fd71d65c | 303 | [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper] |
ccb03bc0 | 304 | [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>] |
a7b2951c | 305 | [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version] |
b3b584c5 | 306 | [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] |
6594293d | 307 | [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit] |
3009b80d | 308 | [--show-bconds] [--with/--without <feature>] [--define <macro> <value>] |
ccb03bc0 | 309 | <package>[.spec][:tag] |
2a5f078d | 310 | |
647fead0 ER |
311 | -4 - force IPv4 when transferring files |
312 | -6 - force IPv6 when transferring files | |
313 | -5, | |
314 | --update-md5 - update md5 comments in spec, implies -nd -ncs | |
315 | -a5, | |
316 | --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs | |
4ca1edbd | 317 | --all-branches - make shallow fetch of all branches; --depth required |
cd445739 | 318 | -n5, --no-md5 - ignore md5 comments in spec |
9243e80b ER |
319 | -D, --debug - enable builder script debugging mode, |
320 | -debug - produce rpm debug package (same as --opts -debug) | |
d43959a2 ER |
321 | -V, --version - output builder version string |
322 | --short-version - output builder short version | |
647fead0 ER |
323 | -a - try add new package to PLD repo. |
324 | -b, | |
325 | -ba | |
326 | - get all files from PLD repo or HTTP/FTP and build package | |
cd445739 | 327 | from <package>.spec, |
647fead0 | 328 | -bb - get all files from PLD repo or HTTP/FTP and build binary |
cd445739 | 329 | only package from <package>.spec, |
647fead0 | 330 | -bp - execute the %prep phase of <package>.spec, |
6594293d AG |
331 | -bc - execute the %build phase of <package>.spec, |
332 | -bi - execute the %install phase of <package>.spec | |
4ca1edbd | 333 | -bl - execute the %files phase of <package>.spec |
647fead0 | 334 | -bs - get all files from PLD repo or HTTP/FTP and only pack |
cd445739 | 335 | them into src.rpm, |
6594293d | 336 | --short-circuit - short-circuit build |
cd445739 | 337 | -B, --branch - add branch |
647fead0 ER |
338 | -c, |
339 | --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands. | |
387eaf99 | 340 | may be used with building process. |
6f10b394 | 341 | -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES, |
4ca1edbd KK |
342 | SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building. |
343 | -cf, --cvs-force - use -f when tagging | |
eccfb714 | 344 | --define '<macro> <value>' |
cd445739 | 345 | - define a macro <macro> with value <value>, |
4ca1edbd | 346 | --depth <number> - make shallow fetch |
44058243 ER |
347 | --alt_kernel <kernel> |
348 | - same as --define 'alt_kernel <kernel>' | |
cd445739 | 349 | --nodeps - rpm won't check any dependences |
647fead0 ER |
350 | -g |
351 | --get - get <package>.spec and all related files from PLD repo | |
cd445739 | 352 | -h, --help - this message, |
647fead0 ER |
353 | -j N - set %_smp_mflags to propagate concurrent jobs |
354 | --ftp - use FTP protocol to access distfiles server | |
355 | --http - use HTTP protocol to access distfiles server | |
356 | -l <logfile>, --logtofile=<logfile> | |
cd445739 | 357 | - log all to file, |
cd445739 | 358 | -ncs, --no-cvs-specs |
ccb03bc0 | 359 | - don't pull from PLD repo |
cd445739 AM |
360 | -nd, --no-distfiles - don't download from distfiles |
361 | -nm, --no-mirrors - don't download from mirror, if source URL is given, | |
362 | -nu, --no-urls - don't try to download from FTP/HTTP location, | |
7cbc2d88 | 363 | -ns, --no-srcs - don't download Sources/Patches |
cd445739 AM |
364 | -ns0, --no-source0 - don't download Source0 |
365 | -nn, --no-net - don't download anything from the net | |
647fead0 | 366 | -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS) |
4ca1edbd KK |
367 | -pm, --prefer-mirrors |
368 | - prefer mirrors (if any) over distfiles for SOURCES | |
b572253e | 369 | --no-init - don't initialize builder paths (SPECS and SOURCES) |
18e5347d | 370 | -ske, |
4ca1edbd KK |
371 | --skip-existing-files |
372 | - skip existing files in get_files | |
cd445739 AM |
373 | --opts <rpm opts> - additional options for rpm |
374 | -q, --quiet - be quiet, | |
ccb03bc0 KK |
375 | --date yyyy-mm-dd - build package using resources from specified date, |
376 | -r <tag>, --cvstag <ref> | |
377 | - build package using resources from specified branch/tag, | |
5053a974 | 378 | -A - build package using master branch as any sticky tags/branch/date being reset. |
cd445739 AM |
379 | -R, --fetch-build-requires |
380 | - fetch what is BuildRequired, | |
381 | -RB, --remove-build-requires | |
382 | - remove all you fetched with -R or --fetch-build-requires | |
383 | remember, this option requires confirmation, | |
384 | -FRB, --force-remove-build-requires | |
385 | - remove all you fetched with -R or --fetch-build-requires | |
386 | remember, this option works without confirmation, | |
4ca1edbd KK |
387 | -sd, --source-distfiles |
388 | - list sources available from distfiles (intended for offline | |
06541433 JR |
389 | operations; does not work when Icon field is present |
390 | but icon file is absent), | |
4ca1edbd KK |
391 | -sc, --source-cvs - list sources available from PLD repo |
392 | -sdp, --source-distfiles-paths | |
393 | - list sources available from distfiles - | |
06541433 JR |
394 | paths relative to distfiles directory (intended for offline |
395 | operations; does not work when Icon field is present | |
396 | but icon file is absent), | |
a7eefc54 | 397 | -sf, --source-files - list sources - bare filenames (intended for offline |
398 | operations; does not work when Icon field is present | |
3621e588 | 399 | but icon file is absent), |
4ca1edbd KK |
400 | -lsp, --source-paths |
401 | - list sources - filenames with full local paths (intended for | |
a7eefc54 | 402 | offline operations; does not work when Icon field is present |
3621e588 | 403 | but icon file is absent), |
2dddf439 ER |
404 | -su, --source-urls - list urls - urls to sources and patches |
405 | intended for copying urls with spec with lots of macros in urls | |
ccb03bc0 KK |
406 | -T <tag> , --tag <tag> |
407 | - add git tag <tag> for files, | |
cd445739 | 408 | -Tvs, --tag-version-stable |
ccb03bc0 | 409 | - add git tags STABLE and NAME-VERSION-RELEASE for files, |
cd445739 | 410 | -Ts, --tag-stable |
ccb03bc0 | 411 | - add git tag STABLE for files, |
647fead0 ER |
412 | -Tv, |
413 | --tag-version - add git tag NAME-VERSION-RELEASE for files, | |
cd445739 AM |
414 | -Tp, --tag-prefix <prefix> |
415 | - add <prefix> to NAME-VERSION-RELEASE tags, | |
416 | -tt, --test-tag <prefix> | |
417 | - fail if tag is already present, | |
50321881 JK |
418 | -ir, --integer-release-only |
419 | - allow only integer and snapshot releases | |
cd445739 AM |
420 | -v, --verbose - be verbose, |
421 | -u, --try-upgrade - check version, and try to upgrade package | |
422 | -un, --try-upgrade-with-float-version | |
423 | - as above, but allow float version | |
4ca1edbd | 424 | php-pear-Services_Digg/ |
0907f1eb | 425 | --upgrade-version - upgrade to specified version in try-upgrade |
deccc50e | 426 | -U, --update - refetch sources, don't use distfiles, and update md5 comments |
cd445739 AM |
427 | -Upi, --update-poldek-indexes |
428 | - refresh or make poldek package index files. | |
647fead0 ER |
429 | -sp <patchnumber>, |
430 | --skip-patch <patchnumber> | |
8bd5e66d | 431 | - don't apply <patchnumber>. may be repeated. |
647fead0 ER |
432 | -np <patchnumber>, |
433 | --nopatch <patchnumber> | |
8bd5e66d | 434 | - abort instead of applying patch <patchnumber> |
fc8edbe5 ER |
435 | --noinit |
436 | - do not initialize SPECS_DIR and SOURCES_DIR (set them to .) | |
dfe2cb9a MK |
437 | --show-bconds - show available conditional builds, which can be used |
438 | - with --with and/or --without switches. | |
b05205af BZ |
439 | --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script. |
440 | In other words, the output is parseable by scripts. | |
24a97174 | 441 | --show-avail-bconds - show available bconds |
647fead0 ER |
442 | --with <feature>, |
443 | --without <feature> | |
cd445739 AM |
444 | - conditional build package depending on %_with_<feature>/ |
445 | %_without_<feature> macro switch. You may now use | |
446 | --with feat1 feat2 feat3 --without feat4 feat5 --with feat6 | |
447 | constructions. Set GROUP_BCONDS to yes to make use of it. | |
6dd19291 | 448 | --target <platform>, --target=<platform> |
a6494cd4 | 449 | - build for platform <platform>. |
5eb1d24b ER |
450 | --init-rpm-dir, --init |
451 | - initialize ~/rpm directory structure | |
5a491465 | 452 | " |
453 | } | |
454 | ||
390d081d ER |
455 | # create tempfile. as secure as possible |
456 | tempfile() { | |
aa7e48da ER |
457 | local prefix=builder.$PACKAGE_NAME${1:+.$1} |
458 | mktemp --tmpdir -t $prefix.XXXXXX || echo ${TMPDIR:-/tmp}/$prefix.$RANDOM.$$ | |
390d081d ER |
459 | } |
460 | ||
397fa865 | 461 | tempdir() { |
aa7e48da ER |
462 | local prefix=builder.$PACKAGE_NAME${1:+.$1} |
463 | mktemp --tmpdir -d $prefix.XXXXXX | |
397fa865 KK |
464 | } |
465 | ||
8cc8f5c0 | 466 | # inserts git log instead of %changelog |
053a88fc | 467 | # @output directory containing modified specfile |
8cc8f5c0 | 468 | insert_gitlog() { |
397fa865 | 469 | local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile) |
8cc8f5c0 ER |
470 | |
471 | # allow this being customized | |
472 | local log_entries=$(rpm -E '%{?_buildchangelogtruncate}') | |
473 | ||
474 | # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997' | |
475 | # otherwise i'd use --date=iso here | |
476 | # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1 | |
b34dcd91 | 477 | # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33 |
8cc8f5c0 ER |
478 | # NOTE: changelog date is always in UTC for rpmbuild |
479 | # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900 | |
9fd1eb80 | 480 | git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do |
f8704064 | 481 | local logfmt='%B%n' |
31f3bc1c ER |
482 | git notes list $sha1 > /dev/null 2>&1 && logfmt='%N' |
483 | git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q' | |
9c0fe78c | 484 | done > $gitlog |
9e269b3c ER |
485 | |
486 | # add link to full git logs | |
e93ee6d9 | 487 | local giturl="http://git.pld-linux.org/?p=packages/${SPECFILE%.spec}.git;a=log" |
9e269b3c ER |
488 | if [ -n "$CVSTAG" ]; then |
489 | giturl="$giturl;h=$CVSTAG" | |
490 | fi | |
491 | local gitauthor="PLD Linux Team <feedback@pld-linux.org>" | |
492 | LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{ | |
493 | printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl); | |
494 | print; | |
495 | exit | |
496 | }' > $speclog | |
497 | ||
498 | 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 |
499 | sed '/^%changelog/,$d' $SPECFILE | sed -e "\${ |
500 | a%changelog | |
501 | r $speclog | |
502 | } | |
397fa865 | 503 | " > $specdir/$SPECFILE |
8cc8f5c0 | 504 | rm -f $gitlog $speclog |
397fa865 | 505 | echo $specdir |
8cc8f5c0 ER |
506 | } |
507 | ||
12da9e3d ER |
508 | # @param string logfile |
509 | # @param varargs... commands to execute | |
510 | teeboth() { | |
511 | local rc | |
512 | # use teeboth from toys/cleanbuild, if available and enabled | |
513 | if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then | |
514 | $APPDIR/teeboth "$@" | |
515 | rc=$? | |
516 | else | |
517 | local efile rc logfile=$1; shift | |
518 | if [ "$logfile" ]; then | |
519 | efile=$(tempfile) | |
806a7b72 | 520 | { "$@" 2>&1; echo $? > $efile; } | tee -a $logfile |
12da9e3d ER |
521 | rc=$(< $efile) |
522 | rm -f $efile | |
523 | else | |
551a62ae | 524 | "$@" |
12da9e3d ER |
525 | rc=$? |
526 | fi | |
527 | fi | |
528 | return $rc | |
529 | } | |
530 | ||
31d2bd0b ER |
531 | # change dependency to specname |
532 | # common changes: | |
533 | # - perl(Package::Name) -> perl-Package-Name | |
534 | depspecname() { | |
aa7e48da ER |
535 | local DEPS |
536 | ||
537 | if [ $# -gt 0 ]; then | |
538 | DEPS="$@" | |
539 | else | |
540 | DEPS=$(cat) | |
541 | fi | |
542 | ||
543 | echo "$DEPS" | tr ' ' '\n' | sed -re ' | |
544 | # perl virtual deps | |
545 | /perl\(.*\)/{ | |
546 | s/perl\((.*)\)/perl-\1/ | |
547 | s/::/-/g | |
548 | } | |
31d2bd0b | 549 | |
aa7e48da ER |
550 | s/apache\(EAPI\)-devel/apache-devel/ |
551 | ||
552 | s/db-devel/db5.3-devel/ | |
553 | s/libjpeg-devel/libjpeg-turbo-devel/ | |
554 | ' | |
31d2bd0b ER |
555 | } |
556 | ||
c890b916 | 557 | update_shell_title() { |
6c40c5a2 | 558 | [ -t 2 ] || return |
0b65d15e | 559 | local len=${COLUMNS:-80} |
5c795f16 | 560 | local msg="$(echo "$*" | cut -c-$len)" |
0b65d15e | 561 | |
e225de91 ER |
562 | if [ -n "$BE_VERBOSE" ]; then |
563 | echo >&2 "$(date +%s.%N) $*" | |
564 | fi | |
565 | ||
5c795f16 | 566 | if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then |
138bbc98 ER |
567 | local pkg |
568 | if [ -n "$PACKAGE_NAME" ]; then | |
569 | pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE} | |
570 | else | |
571 | pkg=${SPECFILE} | |
572 | fi | |
573 | ||
574 | msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg" | |
a8c9a155 | 575 | msg=$(echo $msg | tr -d '\n\r') |
982e358c MP |
576 | case "$TERM" in |
577 | cygwin|xterm*) | |
578 | echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007" | |
579 | ;; | |
580 | screen*) | |
581 | echo >&2 -ne "\033]0;$msg\007" | |
582 | ;; | |
583 | esac | |
584 | fi | |
c890b916 ER |
585 | } |
586 | ||
7e40520f ER |
587 | # set TARGET from BuildArch: from SPECFILE |
588 | set_spec_target() { | |
ce40491a | 589 | if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then |
8c91ee46 | 590 | local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE) |
ce40491a | 591 | if [ "$tmp" ]; then |
8c91ee46 | 592 | local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}') |
7e40520f ER |
593 | TARGET="$tmp" |
594 | case "$RPMBUILD" in | |
595 | "rpmbuild") | |
f9109a96 | 596 | TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;; |
7e40520f | 597 | "rpm") |
ce40491a | 598 | TARGET_SWITCH="--target=$TARGET" ;; |
7e40520f | 599 | esac |
ce40491a ER |
600 | fi |
601 | fi | |
7e40520f ER |
602 | } |
603 | ||
ace3fd80 ER |
604 | # runs rpm with minimal macroset |
605 | minirpm() { | |
202b825e | 606 | safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ') |
ace3fd80 ER |
607 | |
608 | # TODO: move these to /usr/lib/rpm/macros | |
20117088 | 609 | cat > $BUILDER_MACROS <<'EOF' |
5b5e5f7f | 610 | %x8664 x86_64 amd64 ia32e |
f78a0bb7 | 611 | %alt_kernel %{nil} |
612 | %_alt_kernel %{nil} | |
5ff15c97 | 613 | %bootstrap_release() %{1} |
407b204b ER |
614 | %requires_releq_kernel_up(s:n:) %{nil} |
615 | %requires_releq_kernel_smp(s:n:) %{nil} | |
616 | %requires_releq_kernel(s:n:) %{nil} | |
6b8134e3 | 617 | %requires_releq() %{nil} |
bb01dee9 | 618 | %pyrequires_eq() %{nil} |
559d511f | 619 | %requires_eq() %{nil} |
c13be3d1 | 620 | %requires_eq_to() %{nil} |
99c05e13 | 621 | %requires_ge() %{nil} |
500b0eb8 ER |
622 | %requires_ge_to() %{nil} |
623 | %requires_ge() %{nil} | |
407b204b ER |
624 | %releq_kernel_up(n:) ERROR |
625 | %releq_kernel_smp(n:) ERROR | |
626 | %releq_kernel(n:) ERROR | |
e94e25f9 | 627 | %py_postclean(x:) ERROR |
74d9fd14 | 628 | %kgcc_package ERROR |
237bd3f1 | 629 | %_fontsdir ERROR |
7141278d | 630 | %ruby_version ERROR |
631 | %ruby_ver_requires_eq() %{nil} | |
632 | %ruby_mod_ver_requires_eq() %{nil} | |
c13be3d1 | 633 | %__php_api_requires() %{nil} |
7141278d | 634 | %php_major_version ERROR |
635 | %php_api_version ERROR | |
99f819cf AM |
636 | %requires_xorg_xserver_extension %{nil} |
637 | %requires_xorg_xserver_xinput %{nil} | |
638 | %requires_xorg_xserver_font %{nil} | |
639 | %requires_xorg_xserver_videodrv %{nil} | |
7141278d | 640 | %py_ver ERROR |
41035426 ER |
641 | %perl_vendorarch ERROR |
642 | %perl_vendorlib ERROR | |
703ae20b ER |
643 | # damn. need it here! - copied from /usr/lib/rpm/macros.build |
644 | %tmpdir %(echo "${TMPDIR:-/tmp}") | |
1f28fcb7 ER |
645 | %patchset_source(f:b:) %( |
646 | base=%{-b*}%{!-b*:10000}; | |
647 | start=$(expr $base + %1); | |
648 | end=$(expr $base + %{?2}%{!?2:%{1}}); | |
649 | # we need to call seq twice as it doesn't allow two formats | |
650 | seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1; | |
651 | seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2; | |
652 | paste %{tmpdir}/__ps{1,2}; | |
653 | rm -f %{tmpdir}/__ps{1,2}; | |
654 | ) \ | |
655 | %{nil} | |
991f09a5 ER |
656 | %add_etc_shells(p) %{p:<lua>} |
657 | %remove_etc_shells(p) %{p:<lua>} | |
709995c4 ER |
658 | %lua_add_etc_shells() %{nil} |
659 | %lua_remove_etc_shells() %{nil} | |
5adfcd17 | 660 | %required_jdk jdk |
0ca65fa4 | 661 | %buildrequires_jdk %{nil} |
f9063abe | 662 | %pear_package_print_optionalpackages %{nil} |
fb198857 | 663 | EOF |
3d12d055 | 664 | if [ "$NOINIT" = "yes" ] ; then |
20117088 | 665 | cat >> $BUILDER_MACROS <<'EOF' |
3d12d055 JR |
666 | %_specdir ./ |
667 | %_sourcedir ./ | |
668 | EOF | |
c039643c | 669 | fi |
670b1ed4 | 670 | eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1 |
ace3fd80 ER |
671 | } |
672 | ||
673 | cache_rpm_dump() { | |
674 | if [ -n "$DEBUG" ]; then | |
675 | set -x | |
676 | set -v | |
677 | fi | |
678 | ||
d1d24c14 | 679 | if [ -x /usr/bin/rpm-specdump ]; then |
525bf240 | 680 | update_shell_title "cache_rpm_dump using rpm-specdump command" |
646d81cf | 681 | rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE) |
d1d24c14 | 682 | else |
525bf240 | 683 | update_shell_title "cache_rpm_dump using rpmbuild command" |
d1d24c14 ER |
684 | local rpm_dump |
685 | rpm_dump=` | |
686 | # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES. | |
687 | dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump' | |
688 | case "$RPMBUILD" in | |
689 | rpm) | |
690 | ARGS='-bp' | |
691 | ;; | |
692 | rpmbuild) | |
693 | ARGS='--nodigest --nosignature --nobuild' | |
694 | ;; | |
695 | esac | |
696 | minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE | |
697 | ` | |
698 | if [ $? -gt 0 ]; then | |
699 | error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p') | |
700 | echo "$error" >&2 | |
701 | Exit_error err_build_fail | |
702 | fi | |
d05e8080 | 703 | |
d1d24c14 ER |
704 | # make small dump cache |
705 | rpm_dump_cache=`echo "$rpm_dump" | awk ' | |
706 | $2 ~ /^SOURCEURL/ {print} | |
707 | $2 ~ /^PATCHURL/ {print} | |
708 | $2 ~ /^nosource/ {print} | |
709 | $2 ~ /^PACKAGE_/ {print} | |
710 | '` | |
711 | fi | |
d05e8080 | 712 | |
13974367 | 713 | update_shell_title "cache_rpm_dump: OK!" |
cd445739 AM |
714 | } |
715 | ||
ace3fd80 | 716 | rpm_dump() { |
cd445739 | 717 | if [ -z "$rpm_dump_cache" ] ; then |
45e2a818 | 718 | echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)" |
cd445739 AM |
719 | fi |
720 | echo "$rpm_dump_cache" | |
721 | } | |
722 | ||
f6711e2a | 723 | get_icons() { |
d05e8080 | 724 | update_shell_title "get icons" |
9d99a240 | 725 | ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE}) |
d05e8080 ER |
726 | if [ -z "$ICONS" ]; then |
727 | return | |
728 | fi | |
729 | ||
975d7b23 | 730 | rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS |
d05e8080 ER |
731 | } |
732 | ||
f6711e2a | 733 | parse_spec() { |
af4d5315 | 734 | update_shell_title "parsing specfile" |
cd445739 | 735 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
736 | set -x |
737 | set -v | |
cd445739 | 738 | fi |
b2975fc3 | 739 | |
d05e8080 | 740 | # icons are needed for successful spec parse |
518ff1fb | 741 | get_icons |
d05e8080 | 742 | |
9c909460 | 743 | cd $PACKAGE_DIR |
cd445739 | 744 | cache_rpm_dump |
00fcec7e | 745 | |
15e34b63 | 746 | if rpm_dump | grep -qEi ":.*nosource.*1"; then |
cd445739 AM |
747 | FAIL_IF_NO_SOURCES="no" |
748 | fi | |
749 | ||
7cbc2d88 ER |
750 | if [ "$NOSRCS" != "yes" ]; then |
751 | SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}') | |
752 | PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}') | |
753 | ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE}) | |
754 | fi | |
755 | ||
dfe2b2d9 ER |
756 | PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}') |
757 | PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}') | |
758 | PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}') | |
78eab2a1 | 759 | |
0b4119a2 | 760 | if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then |
7854d40c | 761 | echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)" |
0b4119a2 JR |
762 | fi |
763 | ||
cd445739 AM |
764 | if [ -n "$BE_VERBOSE" ]; then |
765 | echo "- Sources : `nourl $SOURCES`" | |
766 | if [ -n "$PATCHES" ]; then | |
767 | echo "- Patches : `nourl $PATCHES`" | |
768 | else | |
769 | echo "- Patches : *no patches needed*" | |
770 | fi | |
771 | if [ -n "$ICONS" ]; then | |
772 | echo "- Icon : `nourl $ICONS`" | |
773 | else | |
774 | echo "- Icon : *no package icon*" | |
775 | fi | |
776 | echo "- Name : $PACKAGE_NAME" | |
777 | echo "- Version : $PACKAGE_VERSION" | |
778 | echo "- Release : $PACKAGE_RELEASE" | |
779 | fi | |
13974367 ER |
780 | |
781 | update_shell_title "parse_spec: OK!" | |
cd445739 AM |
782 | } |
783 | ||
aa7e48da ER |
784 | # aborts program abnormally |
785 | die() { | |
786 | local rc=${2:-1} | |
787 | echo >&2 "$PROGRAM: ERROR: $*" | |
788 | exit $rc | |
789 | } | |
790 | ||
f6711e2a | 791 | Exit_error() { |
cd445739 | 792 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
793 | set -x |
794 | set -v | |
cd445739 AM |
795 | fi |
796 | ||
797 | cd "$__PWD" | |
798 | ||
799 | case "$1" in | |
800 | "err_no_spec_in_cmdl" ) | |
801 | remove_build_requires | |
45e2a818 | 802 | echo >&2 "ERROR: spec file name not specified." |
cd445739 | 803 | exit 2 ;; |
a08d92fc | 804 | "err_invalid_cmdline" ) |
45e2a818 | 805 | echo >&2 "ERROR: invalid command line arg ($2)." |
a08d92fc | 806 | exit 2 ;; |
cd445739 AM |
807 | "err_no_spec_in_repo" ) |
808 | remove_build_requires | |
e55ef62b ER |
809 | echo >&2 "Error: spec file not stored in repository." |
810 | if [ -n "$2" ]; then | |
811 | echo >&2 "Tried: $2" | |
812 | fi | |
813 | ||
cd445739 AM |
814 | exit 3 ;; |
815 | "err_no_source_in_repo" ) | |
816 | remove_build_requires | |
bba21388 | 817 | echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)" |
cd445739 | 818 | exit 4 ;; |
703b6deb | 819 | "err_cvs_add_failed" ) |
bba21388 | 820 | echo >&2 "Error: failed to add package to PLD repo." |
703b6deb | 821 | exit 4 ;; |
cd445739 AM |
822 | "err_build_fail" ) |
823 | remove_build_requires | |
45e2a818 | 824 | echo >&2 "Error: package build failed. (${2:-no more info})" |
cd445739 | 825 | exit 5 ;; |
78eab2a1 AM |
826 | "err_no_package_data" ) |
827 | remove_build_requires | |
45e2a818 | 828 | echo >&2 "Error: couldn't get out package name/version/release from spec file." |
78eab2a1 | 829 | exit 6 ;; |
ce40491a | 830 | "err_tag_exists" ) |
50321881 | 831 | remove_build_requires |
d2842af2 | 832 | echo >&2 "Tag ${2} already exists" |
50321881 | 833 | exit 9 ;; |
ce40491a | 834 | "err_fract_rel" ) |
50321881 | 835 | remove_build_requires |
45e2a818 | 836 | echo >&2 "Release ${2} not integer and not a snapshot." |
50321881 | 837 | exit 10 ;; |
fb96e0b5 AM |
838 | "err_branch_exists" ) |
839 | remove_build_requires | |
45e2a818 | 840 | echo >&2 "Tree branch already exists (${2})." |
fb96e0b5 | 841 | exit 11 ;; |
cfc497c0 ER |
842 | "err_acl_deny" ) |
843 | remove_build_requires | |
45e2a818 | 844 | echo >&2 "Error: conditions reject building this spec (${2})." |
cfc497c0 | 845 | exit 12 ;; |
406b9ecf KK |
846 | "err_remote_problem" ) |
847 | remove_build_requires | |
848 | echo >&2 "Error: problem with remote (${2})" | |
849 | exit 13 ;; | |
6217f407 KK |
850 | "err_no_checkut" ) |
851 | echo >&2 "Error: cannot checkout $2" | |
852 | exit 14 ;; | |
67963237 | 853 | "err_not_implemented" ) |
779fcca4 | 854 | remove_build_requires |
67963237 KK |
855 | echo >&2 "Error: functionality not yet imlemented" |
856 | exit 110 ;; | |
cd445739 | 857 | esac |
45e2a818 | 858 | echo >&2 "Unknown error." |
73848362 | 859 | exit 100 |
cd445739 AM |
860 | } |
861 | ||
f6711e2a | 862 | init_builder() { |
cd445739 | 863 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
864 | set -x |
865 | set -v | |
0dd6320d | 866 | fi |
cd445739 | 867 | |
4aeb9973 | 868 | if [ "$NOINIT" != "yes" ] ; then |
9c909460 | 869 | TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}') |
b7cc0c94 | 870 | |
09bf17c9 | 871 | local macros_ver=$(rpm -E %?rpm_build_macros) |
b7cc0c94 ER |
872 | if [ -z "$macros_ver" ]; then |
873 | REPO_DIR=$TOP_DIR/packages | |
874 | PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME | |
875 | else | |
876 | if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then | |
877 | echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER" | |
878 | exit 1 | |
879 | fi | |
880 | REPO_DIR=$TOP_DIR | |
881 | PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME | |
882 | fi | |
29e90b02 | 883 | else |
d723feca ER |
884 | TOP_DIR=$(pwd) |
885 | PACKAGE_DIR=$TOP_DIR | |
5c41c44d | 886 | REPO_DIR=$PACKAGE_DIR |
d723feca | 887 | RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'" |
29e90b02 | 888 | fi |
52f3ced3 KK |
889 | export GIT_WORK_TREE=$PACKAGE_DIR |
890 | export GIT_DIR=$PACKAGE_DIR/.git | |
cd445739 | 891 | |
acd0d41d | 892 | if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then |
a095de80 KK |
893 | if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then |
894 | CVSTAG=${CVSTAG#refs/heads/} | |
895 | if [ "$CVSTAG" != "master" ]; then | |
896 | echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override" | |
897 | fi | |
898 | else | |
899 | echo >&2 "On detached HEAD. Use -r BRANCHNAME to override" | |
900 | HEAD_DETACHED="yes" | |
901 | fi | |
902 | elif [ "$CVSTAG" = "HEAD" ]; then | |
903 | # assume -r HEAD is same as -A | |
904 | CVSTAG="master" | |
905 | fi | |
906 | ||
a8c9a155 | 907 | __PWD=$(pwd) |
00fcec7e | 908 | } |
909 | ||
406b9ecf KK |
910 | create_git_repo() { |
911 | update_shell_title "add_package" | |
912 | ||
913 | if [ -n "$DEBUG" ]; then | |
914 | set -x | |
915 | set -v | |
916 | fi | |
917 | ||
918 | cd "$REPO_DIR" | |
919 | SPECFILE=$(basename $SPECFILE) | |
920 | if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then | |
921 | echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2 | |
922 | exit 101 | |
923 | fi | |
924 | [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes | |
c6418b06 | 925 | ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed |
d8dbe300 ER |
926 | ( |
927 | set -e | |
406b9ecf | 928 | git init |
d8dbe300 ER |
929 | git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git |
930 | git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} | |
931 | ||
932 | git config --local push.default current | |
933 | git config --local branch.master.remote $REMOTE_PLD | |
934 | git config --local branch.master.merge refs/heads/master | |
935 | ) | |
936 | test $? = 0 || Exit_error err_remote_problem $REMOTE_PLD | |
406b9ecf KK |
937 | } |
938 | ||
f6711e2a | 939 | get_spec() { |
c890b916 | 940 | |
2e5be021 | 941 | update_shell_title "get_spec" |
c890b916 | 942 | |
cd445739 | 943 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
944 | set -x |
945 | set -v | |
cd445739 AM |
946 | fi |
947 | ||
9c909460 | 948 | cd "$REPO_DIR" |
e0ddd96d | 949 | SPECFILE=$(basename $SPECFILE) |
1ef6f5de | 950 | if [ "$NOCVSSPEC" != "yes" ]; then |
3189511a | 951 | if [ -z "$DEPTH" ]; then |
30419e36 | 952 | if [ -d "$PACKAGE_DIR/.git" ]; then |
608c01a7 | 953 | git fetch $REMOTE_PLD || Exit_error err_no_spec_in_repo |
3189511a | 954 | elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then |
30419e36 ER |
955 | if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then |
956 | echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2 | |
3189511a KK |
957 | exit 101 |
958 | fi | |
959 | Exit_error err_not_implemented | |
960 | else | |
961 | ( | |
962 | unset GIT_WORK_TREE | |
eda17ab7 | 963 | git clone -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || { |
588cb3a9 | 964 | # softfail if new package, i.e not yet added to PLD rep |
30419e36 | 965 | [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo |
2b25efd8 | 966 | echo "Warning: package not in GIT - assuming new package" |
3189511a KK |
967 | NOCVSSPEC="yes" |
968 | } | |
71435fd3 ER |
969 | git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*' |
970 | git config --local --add "remote.$REMOTE_PLD.push" 'refs/notes/*:refs/notes/*' | |
971 | git config --local --add "remote.$REMOTE_PLD.push" HEAD | |
972 | git config --local push.default current | |
eda17ab7 | 973 | git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} |
3189511a | 974 | ) |
703b6deb | 975 | fi |
9c909460 | 976 | else |
30419e36 ER |
977 | if [ ! -d "$PACKAGE_DIR/.git" ]; then |
978 | if [ ! -d "$PACKAGE_DIR" ]; then | |
979 | install -d $PACKAGE_DIR | |
3189511a KK |
980 | fi |
981 | git init | |
a153a767 | 982 | git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git |
71435fd3 ER |
983 | git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*' |
984 | git config --local --add "remote.$REMOTE_PLD.push" 'refs/heads/*:refs/remotes/origin/*' | |
985 | git config --local --add "remote.$REMOTE_PLD.push" HEAD | |
986 | git config --local push.default current | |
48184c96 | 987 | git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} |
6a9f8358 | 988 | CVSTAG=${CVSTAG:-"master"} |
3189511a | 989 | fi |
3f79cb18 KK |
990 | local refs='' |
991 | if [ -z "$ALL_BRANCHES" ]; then | |
992 | refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}" | |
993 | fi | |
994 | git fetch $DEPTH $REMOTE_PLD $refs || { | |
3189511a KK |
995 | echo >&2 "Error: branch $CVSTAG does not exist" |
996 | exit 3 | |
997 | } | |
703b6deb | 998 | fi |
f343238b | 999 | git fetch $REMOTE_PLD 'refs/notes/*:refs/notes/*' |
0c3beb90 | 1000 | |
0d494abd | 1001 | cvsignore_df .gitignore |
703b6deb | 1002 | |
588cb3a9 | 1003 | # add default log format to .gitignore if it is relative to package dir |
703b6deb ER |
1004 | if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then |
1005 | # substitute known "macros" to glob | |
3870f979 | 1006 | local logfile=$(echo "$LOGFILE" | sed -r -e 's,\$(PACKAGE_(NAME|VERSION|RELEASE)|DATE|TARGET),*,g') |
703b6deb ER |
1007 | if [ "$logfile" ]; then |
1008 | cvsignore_df "$logfile" | |
daeab113 | 1009 | fi |
9c909460 | 1010 | fi |
703b6deb ER |
1011 | |
1012 | # create symlinks for tools | |
30419e36 | 1013 | if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then |
4ec6d58b | 1014 | for a in dropin md5 builder {relup,compile,repackage,rsync,pearize}.sh; do |
046b715f | 1015 | # skip tools that don't exist in top dir |
703b6deb | 1016 | [ -f $a ] || continue |
046b715f | 1017 | # skip tools that already exist |
30419e36 ER |
1018 | [ -f $PACKAGE_DIR/$a ] && continue |
1019 | ln -s ../$a $PACKAGE_DIR | |
703b6deb ER |
1020 | cvsignore_df $a |
1021 | done | |
1022 | fi | |
cd445739 | 1023 | fi |
049ab214 | 1024 | |
b0121b45 | 1025 | if [ -n "$CVSTAG" ]; then |
6217f407 KK |
1026 | if git rev-parse --verify -q "$CVSTAG"; then |
1027 | git checkout "$CVSTAG" -- | |
1028 | elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then | |
1029 | git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null | |
1030 | fi | |
1031 | if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then | |
1032 | Exit_error "err_no_checkut" "$CVSTAG" | |
1033 | fi | |
ef4c7d3d | 1034 | git merge --ff-only '@{u}' |
2226518e | 1035 | git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] && |
52020f4c | 1036 | if [ -n "$CVSDATE" ]; then |
c4c0f339 KK |
1037 | git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1 |
1038 | fi | |
b0121b45 KK |
1039 | fi |
1040 | ||
30419e36 | 1041 | if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then |
e55ef62b | 1042 | Exit_error err_no_spec_in_repo "$PACKAGE_DIR/$SPECFILE" |
cd445739 AM |
1043 | fi |
1044 | ||
1045 | if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then | |
30419e36 | 1046 | chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE |
cd445739 AM |
1047 | fi |
1048 | unset OPTIONS | |
30419e36 | 1049 | [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE |
7e40520f | 1050 | |
ce40491a | 1051 | set_spec_target |
cd445739 AM |
1052 | } |
1053 | ||
236af16b ER |
1054 | # find mirrors in this order. first match wins: |
1055 | # - package dir (~/rpm/packages/foo) | |
1056 | # - repository dir (~/rpm/packages) | |
1057 | # - tools dir dir (~/rpm/packages/rpm-build-tools) | |
f6711e2a | 1058 | find_mirror() { |
782518da | 1059 | local url="$1" |
cd445739 | 1060 | |
236af16b ER |
1061 | update_shell_title "find_mirror[$url][$REPO_DIR]" |
1062 | ||
1063 | # NOTE: as while loop runs in subshell, | |
1064 | # we use exit 2 to indicate that the match was found | |
1065 | # otherwise we end up outputing mirror url and origin url. | |
1066 | ||
782518da | 1067 | local origin mirror name rest ol prefix |
236af16b ER |
1068 | IFS="|" |
1069 | cat "$PACKAGE_DIR/mirrors" "$REPO_DIR/mirrors" "$REPO_DIR/../rpm-build-tools/mirrors" /dev/null 2>/dev/null | \ | |
782518da ER |
1070 | while read origin mirror name rest; do |
1071 | # skip comments and empty lines | |
2faa4c32 | 1072 | if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then |
782518da ER |
1073 | continue |
1074 | fi | |
a8c9a155 ER |
1075 | ol=$(echo -n "$origin" | wc -c) |
1076 | prefix=$(echo -n "$url" | head -c $ol) | |
cd445739 | 1077 | if [ "$prefix" = "$origin" ] ; then |
a8c9a155 | 1078 | suffix=$(echo "$url" | cut -b $((ol+1))-) |
cd445739 | 1079 | echo -n "$mirror$suffix" |
236af16b | 1080 | exit 2 |
cd445739 | 1081 | fi |
236af16b | 1082 | done && echo "$url" |
cd445739 AM |
1083 | } |
1084 | ||
e7e0d4ec | 1085 | # Warning: unpredictable results if same URL used twice |
f6711e2a | 1086 | src_no() { |
8510980a AM |
1087 | local file="$1" |
1088 | # escape some regexp characters if part of file name | |
298e75e2 | 1089 | file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g') |
9c909460 | 1090 | cd $PACKAGE_DIR |
cd445739 | 1091 | rpm_dump | \ |
8510980a | 1092 | grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \ |
647e3d7f KK |
1093 | sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \ |
1094 | head -n 1 | tr OURCEATH ourceath | xargs | |
1471f6d6 | 1095 | } |
1096 | ||
f6711e2a | 1097 | src_md5() { |
e7e0d4ec | 1098 | [ "$NO5" = "yes" ] && return |
cd445739 AM |
1099 | no=$(src_no "$1") |
1100 | [ -z "$no" ] && return | |
9c909460 | 1101 | cd $PACKAGE_DIR |
e7e0d4ec ER |
1102 | local md5 |
1103 | ||
edcaeac2 ER |
1104 | # use "sources" file from package dir, like vim |
1105 | if [ -f sources ]; then | |
1106 | md5=$(grep -s -v '^#' sources | \ | |
5fe6b5d9 | 1107 | grep -E "[ *]$(basename "$1")([ ,]|\$)" | \ |
e7e0d4ec ER |
1108 | sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \ |
1109 | grep -E '^[0-9a-f]{32}$') | |
1110 | ||
1111 | if [ "$md5" ]; then | |
1112 | if [ $(echo "$md5" | wc -l) != 1 ] ; then | |
edcaeac2 | 1113 | echo "$SPECFILE: more then one entry in sources for $1" 1>&2 |
e7e0d4ec ER |
1114 | fi |
1115 | echo "$md5" | tail -n 1 | |
1116 | return | |
1117 | fi | |
cd445739 | 1118 | fi |
e7e0d4ec | 1119 | |
32131a0e | 1120 | source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://') |
e7e0d4ec ER |
1121 | if [ -n "$source_md5" ]; then |
1122 | echo $source_md5 | |
cd445739 | 1123 | else |
7805dcb4 PZ |
1124 | source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'` |
1125 | if [ -n "$source_md5" ]; then | |
1126 | echo $source_md5 | |
1127 | else | |
1128 | # we have empty SourceX-md5, but it is still possible | |
1129 | # that we have NoSourceX-md5 AND NoSource: X | |
647e3d7f | 1130 | nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` |
7805dcb4 PZ |
1131 | if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then |
1132 | echo $nosource_md5 | |
1133 | fi | |
cd445739 | 1134 | fi |
cd445739 AM |
1135 | fi |
1136 | } | |
1137 | ||
f6711e2a | 1138 | distfiles_path() { |
06541433 JR |
1139 | echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")" |
1140 | } | |
1141 | ||
f6711e2a | 1142 | distfiles_url() { |
06541433 | 1143 | echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")" |
cd445739 AM |
1144 | } |
1145 | ||
f6711e2a | 1146 | distfiles_attic_url() { |
06541433 | 1147 | echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")" |
cd445739 AM |
1148 | } |
1149 | ||
f6711e2a | 1150 | good_md5() { |
cd445739 AM |
1151 | md5=$(src_md5 "$1") |
1152 | [ "$md5" = "" ] || \ | |
1153 | [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ] | |
8ba5cdda PG |
1154 | } |
1155 | ||
f6711e2a | 1156 | good_size() { |
a8c9a155 | 1157 | size=$(find $(nourl "$1") -printf "%s" 2>/dev/null) |
ce40491a | 1158 | [ -n "$size" -a "$size" -gt 0 ] |
a4b50627 AF |
1159 | } |
1160 | ||
f6711e2a | 1161 | cvsignore_df() { |
947025e5 | 1162 | if [ "$CVSIGNORE_DF" != "yes" ]; then |
1163 | return | |
1164 | fi | |
be93ada0 | 1165 | local cvsignore=${PACKAGE_DIR}/.git/info/exclude |
7dc8d095 ER |
1166 | |
1167 | # add only if not yet there | |
aa189b05 | 1168 | if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then |
947025e5 | 1169 | echo "$1" >> $cvsignore |
1170 | fi | |
1171 | } | |
1172 | ||
71f8e908 | 1173 | # returns true if "$1" is ftp, http or https protocol url |
f6711e2a | 1174 | is_url() { |
71f8e908 ER |
1175 | case "$1" in |
1176 | ftp://*|http://*|https://*) | |
1177 | return 0 | |
1178 | ;; | |
1179 | esac | |
1180 | return 1 | |
1181 | } | |
1182 | ||
f6711e2a | 1183 | update_md5() { |
ecba6ad5 ER |
1184 | if [ $# -eq 0 ]; then |
1185 | return | |
1186 | fi | |
1187 | ||
1188 | update_shell_title "update md5" | |
1189 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
1190 | set -x |
1191 | set -v | |
ecba6ad5 ER |
1192 | fi |
1193 | ||
9c909460 | 1194 | cd "$PACKAGE_DIR" |
ecba6ad5 ER |
1195 | |
1196 | # pass 1: check files to be fetched | |
1197 | local todo | |
1198 | local need_files | |
1199 | for i in "$@"; do | |
1200 | local fp=$(nourl "$i") | |
1201 | local srcno=$(src_no "$i") | |
6392b5fd ER |
1202 | if [ -n "$ADD5" ]; then |
1203 | [ "$fp" = "$i" ] && continue # FIXME what is this check doing? | |
647e3d7f | 1204 | grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue |
9c909460 | 1205 | grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue |
6392b5fd | 1206 | else |
647e3d7f | 1207 | grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue |
ecba6ad5 ER |
1208 | fi |
1209 | if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then | |
1210 | need_files="$need_files $i" | |
1211 | fi | |
1212 | done | |
1213 | ||
1214 | # pass 1a: get needed files | |
1215 | if [ "$need_files" ]; then | |
1216 | get_files $need_files | |
1217 | fi | |
1218 | ||
1219 | # pass 2: proceed with md5 adding or updating | |
1220 | for i in "$@"; do | |
1221 | local fp=$(nourl "$i") | |
1222 | local srcno=$(src_no "$i") | |
647e3d7f | 1223 | local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE ) |
e19ad799 | 1224 | if [ -z "$md5" ]; then |
9c909460 | 1225 | md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE ) |
6c1b2e7d | 1226 | fi |
71f8e908 | 1227 | if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then |
647e3d7f | 1228 | local tag="# $srcno-md5:\t" |
71f8e908 | 1229 | if [[ "$md5" == *NoSource* ]]; then |
6663e1f3 | 1230 | tag="# No$srcno-md5:\t" |
6c1b2e7d PZ |
1231 | elif [ -n "$USEDIGEST" ]; then |
1232 | tag="BuildRequires:\tdigest(%SOURCE$srcno) = " | |
71f8e908 | 1233 | fi |
ecba6ad5 | 1234 | md5=$(md5sum "$fp" | cut -f1 -d' ') |
647e3d7f | 1235 | echo "Updating $srcno ($md5: $fp)." |
ecba6ad5 | 1236 | perl -i -ne ' |
647e3d7f KK |
1237 | print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i); |
1238 | print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i; | |
ecba6ad5 | 1239 | ' \ |
9c909460 | 1240 | $PACKAGE_DIR/$SPECFILE |
ecba6ad5 ER |
1241 | fi |
1242 | done | |
1243 | } | |
1244 | ||
f6711e2a | 1245 | check_md5() { |
60499e54 | 1246 | local bad |
3fbff8b8 ER |
1247 | [ "$NO5" = "yes" ] && return |
1248 | ||
ecba6ad5 ER |
1249 | update_shell_title "check md5" |
1250 | ||
1251 | for i in "$@"; do | |
60499e54 AM |
1252 | bad=0 |
1253 | if ! good_md5 "$i"; then | |
1254 | echo -n "MD5 sum mismatch." | |
1255 | bad=1 | |
1256 | fi | |
1257 | if ! good_size "$i"; then | |
1258 | echo -n "0 sized file." | |
1259 | bad=1 | |
ecba6ad5 ER |
1260 | fi |
1261 | ||
60499e54 AM |
1262 | if [ $bad -eq 1 ]; then |
1263 | echo " Use -U to refetch sources," | |
1264 | echo "or -5 to update md5 sums, if you're sure files are correct." | |
1265 | Exit_error err_no_source_in_repo $i | |
1266 | fi | |
ecba6ad5 ER |
1267 | done |
1268 | } | |
1269 | ||
f6711e2a | 1270 | get_files() { |
7cb24972 | 1271 | update_shell_title "get_files" |
cd445739 AM |
1272 | |
1273 | if [ -n "$DEBUG" ]; then | |
518ff1fb ER |
1274 | set -x |
1275 | set -v | |
cd445739 AM |
1276 | fi |
1277 | ||
f09c0772 | 1278 | if [ $# -gt 0 ]; then |
9c909460 | 1279 | cd "$PACKAGE_DIR" |
cd445739 | 1280 | |
f2e42a41 | 1281 | local nc=0 |
e7fa3b9f | 1282 | local get_files_cvs="" |
3815b69a | 1283 | for i in "$@"; do |
f2e42a41 | 1284 | nc=$((nc + 1)) |
dcebdffb | 1285 | local cvsup=0 |
3815b69a | 1286 | SHELL_TITLE_PREFIX="get_files[$nc/$#]" |
f2e42a41 | 1287 | update_shell_title "$i" |
f09c0772 | 1288 | local fp=`nourl "$i"` |
ecba6ad5 | 1289 | if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then |
ce40491a | 1290 | continue |
18e5347d | 1291 | fi |
ecba6ad5 | 1292 | |
cd445739 | 1293 | FROM_DISTFILES=0 |
e7e0d4ec | 1294 | local srcmd5=$(src_md5 "$i") |
ecba6ad5 ER |
1295 | |
1296 | # we know if source/patch is present in cvs/distfiles | |
1297 | # - has md5 (in distfiles) | |
1298 | # - in cvs... ideas? | |
1299 | ||
1300 | # CHECK: local file didn't exist or always cvs up (first) requested. | |
f09c0772 | 1301 | if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then |
cd445739 AM |
1302 | if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then |
1303 | echo "Warning: no URL given for $i" | |
1304 | fi | |
08908161 | 1305 | target="$fp" |
cd445739 | 1306 | |
e7e0d4ec | 1307 | if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then |
a4b50627 | 1308 | if good_md5 "$i" && good_size "$i"; then |
e7e0d4ec | 1309 | echo "$fp having proper md5sum already exists" |
cd445739 AM |
1310 | continue |
1311 | fi | |
28b34560 | 1312 | |
bc10f694 | 1313 | # optionally prefer mirror over distfiles if there's mirror |
28b34560 | 1314 | # TODO: build url list and then try each url from the list |
bc10f694 | 1315 | if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then |
28b34560 ER |
1316 | url="$im" |
1317 | else | |
1318 | url=$(distfiles_url "$i") | |
1319 | fi | |
1320 | ||
cd445739 AM |
1321 | url_attic=$(distfiles_attic_url "$i") |
1322 | FROM_DISTFILES=1 | |
ecba6ad5 ER |
1323 | # is $url local file? |
1324 | if [[ "$url" = [./]* ]]; then | |
18a52930 | 1325 | update_shell_title "${GETLOCAL%% *}: $url" |
cd445739 AM |
1326 | ${GETLOCAL} $url $target |
1327 | else | |
9e9f8920 ER |
1328 | local uri=${url} |
1329 | # make shorter message for distfiles urls | |
1330 | if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then | |
1331 | uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/} | |
1332 | uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/} | |
1333 | uri="df: $uri" | |
1334 | fi | |
1335 | update_shell_title "${GETURI%% *}: $uri" | |
ca2e6c31 | 1336 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
33da77c4 | 1337 | if [ "`echo $url | grep -E 'ftp://'`" ]; then |
18a52930 | 1338 | update_shell_title "${GETURI2%% *}: $url" |
ca2e6c31 | 1339 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
cd445739 AM |
1340 | fi |
1341 | fi | |
ecba6ad5 ER |
1342 | |
1343 | # is it empty file? | |
1344 | if [ ! -s "$target" ]; then | |
cd445739 AM |
1345 | rm -f "$target" |
1346 | if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then | |
18a52930 | 1347 | update_shell_title "${GETLOCAL%% *}: $url_attic" |
cd445739 AM |
1348 | ${GETLOCAL} $url_attic $target |
1349 | else | |
18a52930 | 1350 | update_shell_title "${GETURI%% *}: $url_attic" |
ca2e6c31 | 1351 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
33da77c4 | 1352 | if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then |
ce40491a | 1353 | update_shell_title "${GETURI2%% *}: $url_attic" |
ca2e6c31 | 1354 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
cd445739 | 1355 | fi |
1cd7fc57 | 1356 | test -s "$target" || rm -f "$target" |
cd445739 AM |
1357 | fi |
1358 | fi | |
ecba6ad5 ER |
1359 | |
1360 | if [ -s "$target" ]; then | |
947025e5 | 1361 | cvsignore_df $target |
1362 | else | |
cd445739 AM |
1363 | rm -f "$target" |
1364 | FROM_DISTFILES=0 | |
1365 | fi | |
cd445739 AM |
1366 | fi |
1367 | ||
f09c0772 | 1368 | if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then |
cd445739 | 1369 | if [ -z "$NOMIRRORS" ]; then |
a8c9a155 | 1370 | im=$(find_mirror "$i") |
cd445739 AM |
1371 | else |
1372 | im="$i" | |
1373 | fi | |
ce40491a | 1374 | update_shell_title "${GETURI%% *}: $im" |
99b8f51f | 1375 | ${GETURI} ${OUTFILEOPT} "$target" "$im" || \ |
33da77c4 | 1376 | if [ "`echo $im | grep -E 'ftp://'`" ]; then |
ce40491a | 1377 | update_shell_title "${GETURI2%% *}: $im" |
99b8f51f | 1378 | ${GETURI2} ${OUTFILEOPT} "$target" "$im" |
7e365483 | 1379 | fi |
1cd7fc57 | 1380 | test -s "$target" || rm -f "$target" |
cd445739 AM |
1381 | fi |
1382 | ||
dcebdffb ER |
1383 | if [ "$cvsup" = 1 ]; then |
1384 | continue | |
1385 | fi | |
1386 | ||
cd445739 | 1387 | fi |
ecba6ad5 ER |
1388 | |
1389 | # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong. | |
f09c0772 | 1390 | if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then |
b3b584c5 | 1391 | Exit_error err_no_source_in_repo $i |
cd445739 | 1392 | fi |
2a5f078d | 1393 | |
ecba6ad5 | 1394 | # we check md5 here just only to refetch immediately |
a4b50627 | 1395 | if good_md5 "$i" && good_size "$i"; then |
cd445739 AM |
1396 | : |
1397 | elif [ "$FROM_DISTFILES" = 1 ]; then | |
deccc50e | 1398 | # wrong md5 from distfiles: remove the file and try again |
cd445739 | 1399 | # but only once ... |
deccc50e | 1400 | echo "MD5 sum mismatch. Trying full fetch." |
cd445739 AM |
1401 | FROM_DISTFILES=2 |
1402 | rm -f $target | |
18a52930 | 1403 | update_shell_title "${GETURI%% *}: $url" |
ca2e6c31 | 1404 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
33da77c4 | 1405 | if [ "`echo $url | grep -E 'ftp://'`" ]; then |
ce40491a | 1406 | update_shell_title "${GETURI2%% *}: $url" |
ca2e6c31 | 1407 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
cd445739 | 1408 | fi |
ecba6ad5 | 1409 | if [ ! -s "$target" ]; then |
cd445739 | 1410 | rm -f "$target" |
18a52930 | 1411 | update_shell_title "${GETURI%% *}: $url_attic" |
ca2e6c31 | 1412 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
33da77c4 | 1413 | if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then |
ce40491a | 1414 | update_shell_title "${GETURI2%% *}: $url_attic" |
ca2e6c31 | 1415 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
cd445739 AM |
1416 | fi |
1417 | fi | |
1418 | test -s "$target" || rm -f "$target" | |
1419 | fi | |
cd445739 | 1420 | done |
e7fa3b9f ER |
1421 | SHELL_TITLE_PREFIX="" |
1422 | ||
cd445739 AM |
1423 | |
1424 | if [ "$CHMOD" = "yes" ]; then | |
a8c9a155 | 1425 | CHMOD_FILES=$(nourl "$@") |
cd445739 AM |
1426 | if [ -n "$CHMOD_FILES" ]; then |
1427 | chmod $CHMOD_MODE $CHMOD_FILES | |
1428 | fi | |
1429 | fi | |
cd445739 AM |
1430 | fi |
1431 | } | |
1432 | ||
7605fe95 | 1433 | tag_exist() { |
8b6d1795 KK |
1434 | # If tag exists and points to other commit exit with error |
1435 | # If it existsts and points to HEAD return 1 | |
1436 | # If it doesn't exist return 0 | |
f8bfce7d | 1437 | local _tag="$1" |
8b6d1795 | 1438 | local sha1=$(git rev-parse HEAD) |
7605fe95 KK |
1439 | echo "Searching for tag $_tag..." |
1440 | if [ -n "$DEPTH" ]; then | |
8b6d1795 | 1441 | local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40) |
7605fe95 | 1442 | else |
7baf7b2f | 1443 | local ref=$(git show-ref -s "refs/tags/$_tag") |
7605fe95 | 1444 | fi |
8b6d1795 KK |
1445 | [ -z "$ref" ] && return 0 |
1446 | [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag" | |
1447 | return 1 | |
7605fe95 KK |
1448 | } |
1449 | ||
cd445739 | 1450 | make_tagver() { |
ce40491a | 1451 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
1452 | set -x |
1453 | set -v | |
ce40491a | 1454 | fi |
78eab2a1 | 1455 | |
ce40491a ER |
1456 | # Check whether first character of PACKAGE_NAME is legal for tag name |
1457 | if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then | |
1458 | TAG_PREFIX=tag_ | |
1459 | fi | |
d712cc12 ER |
1460 | |
1461 | # NOTE: CVS tags may must not contain the characters `$,.:;@' | |
8c043136 | 1462 | TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE) |
d712cc12 | 1463 | |
8c043136 | 1464 | # Remove @kernel.version_release from TAGVER because tagging sources |
ce40491a | 1465 | # could occur with different kernel-headers than kernel-headers used at build time. |
d712cc12 ER |
1466 | # besides, %{_kernel_ver_str} is not expanded. |
1467 | ||
8c043136 | 1468 | # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str} |
d712cc12 ER |
1469 | # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1 |
1470 | ||
8c043136 | 1471 | TAGVER=${TAGVER%@*} |
ce40491a | 1472 | echo -n "$TAGVER" |
cd445739 AM |
1473 | } |
1474 | ||
f6711e2a | 1475 | tag_files() { |
cd445739 | 1476 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
1477 | set -x |
1478 | set -v | |
cd445739 AM |
1479 | fi |
1480 | ||
73ef63d8 ER |
1481 | echo "Version: $PACKAGE_VERSION" |
1482 | echo "Release: $PACKAGE_RELEASE" | |
cd445739 | 1483 | |
c9100f10 | 1484 | local _tag |
73ef63d8 | 1485 | if [ "$TAG_VERSION" = "yes" ]; then |
c9100f10 | 1486 | _tag=`make_tagver` |
73ef63d8 ER |
1487 | fi |
1488 | if [ -n "$TAG" ]; then | |
c9100f10 | 1489 | _tag="$TAG" |
73ef63d8 | 1490 | fi |
c9100f10 | 1491 | echo "tag: $_tag" |
cd445739 | 1492 | |
39dcc7de | 1493 | local OPTIONS="tag $CVS_FORCE" |
cd445739 | 1494 | |
9c909460 | 1495 | cd "$PACKAGE_DIR" |
03db3356 | 1496 | |
ace99bc6 KK |
1497 | if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then |
1498 | update_shell_title "tag sources: $_tag" | |
1499 | git $OPTIONS $_tag || exit | |
1500 | git push $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD | |
1501 | else | |
1502 | echo "Tag $_tag already exists and points to the same commit" | |
1503 | fi | |
cd445739 AM |
1504 | } |
1505 | ||
f6711e2a | 1506 | branch_files() { |
cd445739 | 1507 | TAG=$1 |
f663f264 | 1508 | echo "Git branch: $TAG" |
518ff1fb | 1509 | shift |
cd445739 | 1510 | |
cd445739 | 1511 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
1512 | set -x |
1513 | set -v | |
cd445739 AM |
1514 | fi |
1515 | ||
f663f264 | 1516 | local OPTIONS="branch $CVS_FORCE" |
c10fa4fa | 1517 | |
9c909460 | 1518 | cd "$PACKAGE_DIR" |
f663f264 | 1519 | git $OPTIONS $TAG || exit |
cd445739 AM |
1520 | } |
1521 | ||
1522 | ||
3009b80d ER |
1523 | # this function should exit early if package can't be built for this arch |
1524 | # this avoids unneccessary BR filling. | |
1525 | check_buildarch() { | |
1526 | local out ret | |
13c3c336 | 1527 | out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1) |
3009b80d ER |
1528 | ret=$? |
1529 | if [ $ret -ne 0 ]; then | |
1530 | echo >&2 "$out" | |
1531 | exit $ret | |
1532 | fi | |
1533 | } | |
1534 | ||
9d99a240 ER |
1535 | # from relup.sh |
1536 | set_release() { | |
1537 | local specfile="$1" | |
1538 | local rel="$2" | |
1539 | local newrel="$3" | |
1540 | sed -i -e " | |
1541 | s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/ | |
1542 | s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/ | |
1543 | " $specfile | |
1544 | } | |
1545 | ||
1546 | set_version() { | |
1547 | local specfile="$1" | |
bc8502e6 ER |
1548 | local ver="$2" subver=$ver |
1549 | local newver="$3" newsubver=$newver | |
1550 | ||
1551 | # try handling subver, everything that's not numeric-dotted in version | |
1552 | if grep -Eq '%define\s+subver' $specfile; then | |
1553 | subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,') | |
1554 | ver=${ver%$subver} | |
1555 | newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,') | |
1556 | newver=${newver%$newsubver} | |
1557 | fi | |
9d99a240 ER |
1558 | sed -i -e " |
1559 | s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/ | |
bc8502e6 | 1560 | s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/ |
9d99a240 ER |
1561 | s/^\(Version:[ \t]\+\)$ver\$/\1$newver/ |
1562 | " $specfile | |
1563 | } | |
1564 | ||
52a2ef00 ER |
1565 | # try to upgrade .spec to new version |
1566 | # if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version | |
1567 | # | |
1568 | # return 1: if .spec was updated | |
1569 | # return 0: no changes to .spec | |
1570 | # exit 1 in case of error | |
cacef28c | 1571 | try_upgrade() { |
52a2ef00 ER |
1572 | if [ -z "$TRY_UPGRADE" ]; then |
1573 | return 0 | |
1574 | fi | |
9d99a240 | 1575 | |
52a2ef00 ER |
1576 | local TNOTIFY TNEWVER TOLDVER |
1577 | update_shell_title "build_package: try_upgrade" | |
cd445739 | 1578 | |
52a2ef00 | 1579 | cd "$PACKAGE_DIR" |
b9bef5ce | 1580 | |
52a2ef00 ER |
1581 | if [ "$UPGRADE_VERSION" ]; then |
1582 | TNEWVER=$UPGRADE_VERSION | |
1583 | echo "Updating spec file to version $TNEWVER" | |
1584 | else | |
1585 | if [ -n "$FLOAT_VERSION" ]; then | |
d1d44ebd | 1586 | TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1 |
52a2ef00 | 1587 | else |
d1d44ebd | 1588 | TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1 |
0907f1eb | 1589 | fi |
cd445739 | 1590 | |
d1d44ebd | 1591 | # pldnotify does not set exit codes, but it has match for ERROR |
52a2ef00 ER |
1592 | # in output which means so. |
1593 | if [[ "$TNOTIFY" = *ERROR* ]]; then | |
1594 | echo >&2 "$TNOTIFY" | |
1595 | exit 1 | |
cd445739 | 1596 | fi |
52a2ef00 ER |
1597 | |
1598 | TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'` | |
1599 | echo "New version found, updating spec file from $TOLDVER to version $TNEWVER" | |
1600 | ||
1601 | TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }') | |
1602 | fi | |
1603 | ||
1604 | if [ -z "$TNEWVER" ]; then | |
1605 | return 0 | |
1606 | fi | |
1607 | ||
1608 | if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then | |
1609 | cp -f $SPECFILE $SPECFILE.bak | |
1610 | fi | |
1611 | chmod +w $SPECFILE | |
1612 | set_version $SPECFILE $PACKAGE_VERSION $TNEWVER | |
1613 | set_release $SPECFILE $PACKAGE_RELEASE 1 | |
1614 | parse_spec | |
1615 | if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then | |
1616 | echo >&2 "Upgrading version failed, you need to update spec yourself" | |
1617 | exit 1 | |
cd445739 | 1618 | fi |
52a2ef00 | 1619 | return 1 |
cacef28c | 1620 | } |
1621 | ||
1622 | build_package() { | |
1623 | update_shell_title "build_package" | |
1624 | if [ -n "$DEBUG" ]; then | |
1625 | set -x | |
1626 | set -v | |
1627 | fi | |
1628 | ||
9c909460 | 1629 | cd "$PACKAGE_DIR" |
2a5f078d | 1630 | |
cd445739 AM |
1631 | case "$COMMAND" in |
1632 | build ) | |
1633 | BUILD_SWITCH="-ba" ;; | |
1634 | build-binary ) | |
1635 | BUILD_SWITCH="-bb" ;; | |
1636 | build-source ) | |
1637 | BUILD_SWITCH="-bs --nodeps" ;; | |
1638 | build-prep ) | |
1639 | BUILD_SWITCH="-bp --nodeps" ;; | |
6594293d AG |
1640 | build-build ) |
1641 | BUILD_SWITCH="-bc" ;; | |
1642 | build-install ) | |
1643 | BUILD_SWITCH="-bi" ;; | |
1644 | build-list ) | |
1645 | BUILD_SWITCH="-bl" ;; | |
1646 | ||
cd445739 | 1647 | esac |
c890b916 | 1648 | |
2e5be021 | 1649 | update_shell_title "build_package: $COMMAND" |
12da9e3d | 1650 | local logfile retval |
cd445739 | 1651 | if [ -n "$LOGFILE" ]; then |
12da9e3d ER |
1652 | logfile=`eval echo $LOGFILE` |
1653 | if [ -d "$logfile" ]; then | |
1654 | echo "Log file $logfile is a directory." | |
cd445739 | 1655 | echo "Parse error in the spec?" |
518ff1fb | 1656 | Exit_error err_build_fail |
cd445739 AM |
1657 | fi |
1658 | if [ -n "$LASTLOG_FILE" ]; then | |
12da9e3d | 1659 | echo "LASTLOG=$logfile" > $LASTLOG_FILE |
cd445739 | 1660 | fi |
12da9e3d ER |
1661 | fi |
1662 | ||
bfea86a5 ER |
1663 | # unset these, should not be exposed to builder shell! |
1664 | unset GIT_WORK_TREE GIT_DIR | |
c69e0c61 | 1665 | # these are set by jenkins |
bfea86a5 | 1666 | unset GIT_PREVIOUS_COMMIT GIT_URL GIT_PREVIOUS_SUCCESSFUL_COMMIT GIT_BRANCH GIT_COMMIT |
256edc2e ER |
1667 | # this may be set by user |
1668 | unset GIT_SSH | |
4666645f ER |
1669 | # may be set by user |
1670 | unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL | |
bfea86a5 ER |
1671 | # fail if something still set |
1672 | env | grep ^GIT_ && Exit_error err_build_fail | |
1673 | ||
12da9e3d ER |
1674 | local specdir=$(insert_gitlog $SPECFILE) |
1675 | # FIXME: eval here is exactly why? | |
6dd8b9cc | 1676 | PATH=$CLEAN_PATH eval teeboth "'$logfile'" ${TIME_COMMAND} ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE |
12da9e3d ER |
1677 | retval=$? |
1678 | rm -r $specdir | |
1679 | ||
1680 | if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then | |
1681 | if [ "$retval" -eq "0" ]; then | |
1682 | mv $logfile $LOGDIROK | |
1683 | else | |
1684 | mv $logfile $LOGDIRFAIL | |
cd445739 | 1685 | fi |
8ba5cdda | 1686 | fi |
12da9e3d ER |
1687 | |
1688 | if [ "$retval" -ne "0" ]; then | |
cd445739 | 1689 | if [ -n "$TRY_UPGRADE" ]; then |
cacef28c | 1690 | echo "\nUpgrade package to new version failed." |
257af81b | 1691 | if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then |
cacef28c | 1692 | echo "Restoring old spec file." |
257af81b ER |
1693 | mv -f $SPECFILE.bak $SPECFILE |
1694 | fi | |
cacef28c | 1695 | echo "" |
cd445739 | 1696 | fi |
518ff1fb | 1697 | Exit_error err_build_fail |
cd445739 AM |
1698 | fi |
1699 | unset BUILD_SWITCH | |
1700 | } | |
1701 | ||
f6711e2a | 1702 | nourl() { |
cd445739 AM |
1703 | echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g' |
1704 | } | |
1705 | ||
f6711e2a | 1706 | install_required_packages() { |
cd445739 AM |
1707 | run_poldek -vi $1 |
1708 | return $? | |
1709 | } | |
1710 | ||
f6711e2a | 1711 | find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond |
fa4bf1df | 1712 | local SPEC="$1" |
fa4bf1df ER |
1713 | awk -F"\n" ' |
1714 | /^%changelog/ { exit } | |
fa4bf1df ER |
1715 | /^%bcond_with/{ |
1716 | match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/); | |
8ff97f39 ER |
1717 | bcond = substr($0, RSTART + 6, RLENGTH - 6); |
1718 | gsub(/[ \t]+/, "_", bcond); | |
fa4bf1df ER |
1719 | print bcond |
1720 | }' $SPEC | LC_ALL=C sort -u | |
1721 | } | |
1722 | ||
117d9861 | 1723 | process_bcondrc() { |
301cbfd4 ER |
1724 | # expand bconds from ~/.bcondrc |
1725 | # The file structure is like gentoo's package.use: | |
1726 | # --- | |
1727 | # * -selinux | |
1728 | # samba -mysql -pgsql | |
47a8df12 | 1729 | # w32codec-installer license_agreement |
301cbfd4 ER |
1730 | # php +mysqli |
1731 | # --- | |
15e34b63 | 1732 | if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then |
117d9861 ER |
1733 | : |
1734 | else | |
1735 | return | |
1736 | fi | |
301cbfd4 | 1737 | |
117d9861 | 1738 | SN=${SPECFILE%%\.spec} |
c8a3e2ac | 1739 | |
117d9861 ER |
1740 | local bcondrc=$HOME/.bcondrc |
1741 | [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc | |
301cbfd4 | 1742 | |
117d9861 | 1743 | local bcond_avail=$(find_spec_bcond $SPECFILE) |
301cbfd4 | 1744 | |
117d9861 ER |
1745 | while read pkg flags; do |
1746 | # ignore comments | |
1747 | [[ "$pkg" == \#* ]] && continue | |
1748 | ||
1749 | # any package or current package? | |
1750 | if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then | |
1751 | for flag in $flags; do | |
1752 | local opt=${flag#[+-]} | |
1753 | ||
1754 | # use only flags which are in this package. | |
1755 | if [[ $bcond_avail = *${opt}* ]]; then | |
1756 | if [[ $flag = -* ]]; then | |
1757 | if [[ $BCOND != *--with?${opt}* ]]; then | |
1758 | BCOND="$BCOND --without $opt" | |
1759 | fi | |
1760 | else | |
1761 | if [[ $BCOND != *--without?${opt}* ]]; then | |
1762 | BCOND="$BCOND --with $opt" | |
301cbfd4 ER |
1763 | fi |
1764 | fi | |
117d9861 ER |
1765 | fi |
1766 | done | |
1767 | fi | |
1768 | done < $bcondrc | |
1769 | update_shell_title "parse ~/.bcondrc: DONE!" | |
1770 | } | |
1771 | ||
8ff97f39 | 1772 | set_bconds_values() { |
117d9861 ER |
1773 | update_shell_title "set bcond values" |
1774 | ||
1775 | AVAIL_BCONDS_WITHOUT="" | |
1776 | AVAIL_BCONDS_WITH="" | |
8ff97f39 | 1777 | |
5a28189c | 1778 | if grep -Eq '^# *_with' ${SPECFILE}; then |
8ff97f39 ER |
1779 | echo >&2 "ERROR: This spec has old style bconds." |
1780 | exit 1 | |
1781 | fi | |
1782 | ||
1783 | if ! grep -q '^%bcond' ${SPECFILE}; then | |
117d9861 | 1784 | return |
301cbfd4 ER |
1785 | fi |
1786 | ||
117d9861 ER |
1787 | local bcond_avail=$(find_spec_bcond $SPECFILE) |
1788 | process_bcondrc "$SPECFILE" | |
1789 | ||
fa4bf1df | 1790 | update_shell_title "parse bconds" |
2a5f078d | 1791 | |
8ff97f39 ER |
1792 | local opt bcond |
1793 | for opt in $bcond_avail; do | |
1794 | case "$opt" in | |
1795 | without_*) | |
1796 | bcond=${opt#without_} | |
10d92f71 ER |
1797 | case "$BCOND" in |
1798 | *--without?${bcond}*) | |
8ff97f39 | 1799 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>" |
10d92f71 ER |
1800 | ;; |
1801 | *) | |
8ff97f39 | 1802 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond" |
10d92f71 ER |
1803 | ;; |
1804 | esac | |
cd445739 | 1805 | ;; |
8ff97f39 ER |
1806 | with_*) |
1807 | bcond=${opt#with_} | |
10d92f71 ER |
1808 | case "$BCOND" in |
1809 | *--with?${bcond}*) | |
8ff97f39 | 1810 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>" |
10d92f71 ER |
1811 | ;; |
1812 | *) | |
8ff97f39 | 1813 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond" |
10d92f71 ER |
1814 | ;; |
1815 | esac | |
cd445739 | 1816 | ;; |
8ff97f39 ER |
1817 | *) |
1818 | echo >&2 "ERROR: unexpected '$opt' in set_bconds_values" | |
1819 | exit 1 | |
1820 | ;; | |
1821 | esac | |
1822 | done | |
cd445739 AM |
1823 | } |
1824 | ||
f6711e2a | 1825 | run_sub_builder() { |
cd445739 | 1826 | package_name="${1}" |
af6b168f | 1827 | update_shell_title "run_sub_builder $package_name" |
cd445739 | 1828 | # |
8f64e264 ER |
1829 | # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego |
1830 | # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do | |
cd445739 AM |
1831 | # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo |
1832 | # jakby nie bylo tego kawalka kodu. | |
1833 | # | |
8f64e264 ER |
1834 | # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy. |
1835 | # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach. | |
cd445739 AM |
1836 | # |
1837 | # | |
1838 | # y0shi. | |
a8c9a155 | 1839 | # kurwa. translate that ^^^^ |
cd445739 AM |
1840 | |
1841 | parent_spec_name='' | |
1842 | ||
cd445739 | 1843 | # Istnieje taki spec? ${package}.spec |
9c909460 | 1844 | if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then |
cd445739 | 1845 | parent_spec_name=${package}.spec |
9c909460 | 1846 | elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then |
a8c9a155 | 1847 | parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" |
d6a77ddb | 1848 | else |
9c909460 | 1849 | for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do |
cd445739 AM |
1850 | echo $provides_line |
1851 | done | |
1852 | fi | |
1853 | ||
1854 | if [ "${parent_spec_name}" != "" ]; then | |
af6b168f | 1855 | spawn_sub_builder $parent_spec_name |
cd445739 AM |
1856 | fi |
1857 | NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name" | |
1858 | } | |
1859 | ||
aa7e48da ER |
1860 | # install package with poldek |
1861 | # @return exit code from poldek | |
1862 | # | |
1863 | # this requires following sudo rules: | |
dd5f5cd7 | 1864 | # - poldek --noask --caplookup -uG |
aa7e48da | 1865 | poldek_install() { |
d95f0e69 | 1866 | LANG=C $POLDEK_CMD --noask --caplookup --uniq -uG "$@" |
aa7e48da ER |
1867 | } |
1868 | ||
1869 | # install packages | |
dd5f5cd7 ER |
1870 | # |
1871 | # this requires following sudo rules: | |
1872 | # - poldek -q --update --upa | |
aa7e48da ER |
1873 | install_packages() { |
1874 | # sync poldek indexes once per invocation | |
1875 | if [ -z "$package_indexes_updated" ]; then | |
1876 | update_shell_title "poldek: update indexes" | |
1877 | $POLDEK_CMD -q --update --upa | |
1878 | package_indexes_updated=true | |
1879 | fi | |
1880 | ||
1881 | update_shell_title "install packages: $*" | |
1882 | poldek_install "$@" && return | |
1883 | ||
1884 | # retry install, install packages one by one | |
1885 | # this is slower one | |
1886 | local rc=0 package | |
1887 | for package in $*; do | |
1888 | package=$(depspecname $package) | |
1889 | update_shell_title "install package: $package" | |
1890 | poldek_install "$package" || rc=$? | |
1891 | done | |
1892 | return $rc | |
1893 | } | |
1894 | ||
1895 | uninstall_packages() { | |
1896 | update_shell_title "uninstall packages: $*" | |
1897 | $POLDEK_CMD --noask --nofollow -ev "$@" | |
1898 | } | |
1899 | ||
f6711e2a | 1900 | spawn_sub_builder() { |
ce40491a ER |
1901 | package_name="${1}" |
1902 | update_shell_title "spawn_sub_builder $package_name" | |
af6b168f | 1903 | |
ce40491a | 1904 | sub_builder_opts='' |
c2d6312c | 1905 | if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then |
ce40491a ER |
1906 | sub_builder_opts="${sub_builder_opts} -R" |
1907 | fi | |
c2d6312c | 1908 | if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then |
ce40491a | 1909 | sub_builder_opts="${sub_builder_opts} -RB" |
c2d6312c | 1910 | elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then |
ce40491a ER |
1911 | sub_builder_opts="${sub_builder_opts} -FRB" |
1912 | fi | |
c2d6312c | 1913 | if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then |
ce40491a ER |
1914 | sub_builder_opts="${sub_builder_opts} -Upi" |
1915 | fi | |
af6b168f | 1916 | |
9c909460 | 1917 | cd "${PACKAGE_DIR}" |
ce40491a | 1918 | ./builder ${sub_builder_opts} "$@" |
af6b168f ER |
1919 | } |
1920 | ||
f6711e2a | 1921 | remove_build_requires() { |
cd445739 AM |
1922 | if [ "$INSTALLED_PACKAGES" != "" ]; then |
1923 | case "$REMOVE_BUILD_REQUIRES" in | |
1924 | "force") | |
1925 | run_poldek --noask -ve $INSTALLED_PACKAGES | |
1926 | ;; | |
1927 | "nice") | |
1928 | run_poldek --ask -ve $INSTALLED_PACKAGES | |
1929 | ;; | |
1930 | *) | |
1931 | echo You may want to manually remove following BuildRequires fetched: | |
1932 | echo $INSTALLED_PACKAGES | |
90baf90b | 1933 | echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`" |
cd445739 AM |
1934 | ;; |
1935 | esac | |
1936 | fi | |
1937 | } | |
1938 | ||
f6711e2a | 1939 | display_bconds() { |
8ff97f39 ER |
1940 | if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then |
1941 | if [ "$BCOND" ]; then | |
10d92f71 ER |
1942 | echo "" |
1943 | echo "Building $SPECFILE with the following conditional flags:" | |
1944 | echo -n "$BCOND" | |
cd445739 | 1945 | else |
10d92f71 ER |
1946 | echo "" |
1947 | echo "No conditional flags passed" | |
cd445739 | 1948 | fi |
10d92f71 ER |
1949 | echo "" |
1950 | echo "from available:" | |
1951 | echo "--with :\t$AVAIL_BCONDS_WITH" | |
1952 | echo "--without:\t$AVAIL_BCONDS_WITHOUT" | |
1953 | echo "" | |
cd445739 AM |
1954 | fi |
1955 | } | |
1956 | ||
f6711e2a | 1957 | display_branches() { |
a0fc9d5b | 1958 | echo -n "Available branches: " |
9fd1eb80 | 1959 | git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs |
ec4dbe02 AM |
1960 | } |
1961 | ||
aa7e48da | 1962 | # checks a given list of packages/files/provides against current rpmdb. |
ea26d7fc | 1963 | # outputs all dependencies which current rpmdb doesn't satisfy. |
af213c6e | 1964 | # input can be either STDIN or parameters |
f6711e2a | 1965 | _rpm_prov_check() { |
e99e2f34 | 1966 | local deps out |
af213c6e | 1967 | |
ea26d7fc | 1968 | if [ $# -gt 0 ]; then |
e99e2f34 | 1969 | deps="$@" |
ce40491a | 1970 | else |
e99e2f34 | 1971 | deps=$(cat) |
ce40491a | 1972 | fi |
af213c6e | 1973 | |
e99e2f34 | 1974 | out=$(LC_ALL=C rpm -q --whatprovides $deps 2>&1) |
af213c6e | 1975 | |
ce40491a | 1976 | # packages |
e99e2f34 | 1977 | echo "$out" | awk '/^no package provides/ { print $NF }' |
af213c6e | 1978 | |
ce40491a | 1979 | # other deps (files) |
e99e2f34 | 1980 | echo "$out" | sed -rne 's/file (.*): No such file or directory/\1/p' |
af213c6e ER |
1981 | } |
1982 | ||
1983 | # checks if given package/files/provides exists in rpmdb. | |
ea26d7fc ER |
1984 | # input can be either stdin or parameters |
1985 | # returns packages which are present in the rpmdb | |
f6711e2a | 1986 | _rpm_cnfl_check() { |
ce40491a | 1987 | local DEPS |
af213c6e | 1988 | |
ea26d7fc | 1989 | if [ $# -gt 0 ]; then |
ce40491a ER |
1990 | DEPS="$@" |
1991 | else | |
1992 | DEPS=$(cat) | |
1993 | fi | |
af213c6e | 1994 | |
5ce6ccff | 1995 | LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }' |
af213c6e ER |
1996 | } |
1997 | ||
18e0f841 ER |
1998 | # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm' |
1999 | install_build_requires_rpmdeps() { | |
aa7e48da | 2000 | local DEPS CNFL |
18e0f841 ER |
2001 | if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then |
2002 | # TODO: Conflicts list doesn't check versions | |
74ede51d ER |
2003 | CNFL=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs) |
2004 | DEPS=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs) | |
18e0f841 ER |
2005 | fi |
2006 | if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then | |
74ede51d ER |
2007 | CNFL=$(eval rpm -q --specsrpm --conflicts $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs) |
2008 | DEPS=$(eval rpm -q --specsrpm --requires $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs) | |
18e0f841 ER |
2009 | fi |
2010 | ||
18e0f841 | 2011 | if [ -n "$CNFL" ]; then |
e99e2f34 | 2012 | echo "Uninstall conflicting packages: $CNFL" |
aa7e48da ER |
2013 | uninstall_packages $CNFL |
2014 | fi | |
2015 | ||
2016 | if [ -n "$DEPS" ]; then | |
e99e2f34 | 2017 | echo "Install dependencies: $DEPS" |
aa7e48da ER |
2018 | install_packages $DEPS |
2019 | fi | |
18e0f841 | 2020 | } |
af213c6e | 2021 | |
18e0f841 ER |
2022 | fetch_build_requires() |
2023 | { | |
2024 | if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then | |
2025 | return | |
2026 | fi | |
2dddf439 | 2027 | |
18e0f841 ER |
2028 | update_shell_title "fetch build requires" |
2029 | if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then | |
2030 | install_build_requires_rpmdeps | |
2031 | return | |
2032 | fi | |
2a5f078d | 2033 | |
aa7e48da | 2034 | die "need rpm-getdeps tool" |
cd445739 AM |
2035 | } |
2036 | ||
b0600c6a KK |
2037 | init_repository() { |
2038 | local remoterepo=$1 | |
2039 | local localrepo=$2 | |
2040 | ||
2041 | if [ ! -e $localrepo ]; then | |
2042 | git clone -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo | |
2043 | git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo | |
2044 | fi | |
2045 | } | |
2046 | ||
ce5daafb | 2047 | init_rpm_dir() { |
0bf6d4a9 ER |
2048 | local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}') |
2049 | local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}') | |
2050 | local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}') | |
2051 | local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}') | |
ceda6f3c | 2052 | local TEMPLATES=template-specs |
0bf6d4a9 | 2053 | local tmp |
ce5daafb | 2054 | |
0c8e5e9d | 2055 | echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER" |
0bf6d4a9 ER |
2056 | mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir |
2057 | ||
2911d25f | 2058 | cd "$TOP_DIR" |
b0600c6a KK |
2059 | init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools |
2060 | init_repository projects/$TEMPLATES ../$TEMPLATES | |
4ec6d58b | 2061 | for a in builder fetchsrc_request compile repackage; do |
a4161989 | 2062 | ln -sf ../rpm-build-tools/${a}.sh $a |
885f2a00 | 2063 | done |
6e0b69d5 ER |
2064 | for a in md5; do |
2065 | ln -sf ../rpm-build-tools/${a} $a | |
2066 | done | |
a4161989 | 2067 | ln -sf ../rpm-build-tools/mirrors mirrors |
ce5daafb | 2068 | init_builder |
ce5daafb ER |
2069 | } |
2070 | ||
6f10b394 ER |
2071 | mr_proper() { |
2072 | init_builder | |
2073 | NOCVSSPEC="yes" | |
2074 | DONT_PRINT_REVISION="yes" | |
66a79c87 KK |
2075 | |
2076 | # remove spec and sources | |
664084c6 | 2077 | PATH=$CLEAN_PATH $RPMBUILD --clean --rmsource --rmspec --nodeps --define "__urlgetfile() %nil" --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $PACKAGE_DIR/$SPECFILE |
bd71e706 | 2078 | rm -rf $PACKAGE_DIR/{.git,.gitignore} |
d37defc1 | 2079 | rmdir --ignore-fail-on-non-empty $PACKAGE_DIR |
6f10b394 ER |
2080 | } |
2081 | ||
cd445739 AM |
2082 | #--------------------------------------------- |
2083 | # main() | |
2084 | ||
2d5c07df | 2085 | if [ $# = 0 ]; then |
518ff1fb | 2086 | usage |
cd445739 AM |
2087 | exit 1 |
2088 | fi | |
2089 | ||
0b668a05 ER |
2090 | # stuff global $BUILDER_OPTS from env as args |
2091 | if [ "$BUILDER_OPTS" ]; then | |
2092 | set -- "$BUILDER_OPTS" "$@" | |
2093 | fi | |
2094 | ||
2d5c07df | 2095 | while [ $# -gt 0 ]; do |
cd445739 | 2096 | case "${1}" in |
5efcb865 ER |
2097 | -4|-6) |
2098 | # NOTE: we should be fetcher specific, like fille WGET_OPTS, but | |
2099 | # unfortunately $GETURI is already formed | |
2100 | GETURI="$GETURI $1" | |
2101 | shift | |
2102 | ;; | |
2d5c07df | 2103 | -5 | --update-md5) |
518ff1fb | 2104 | COMMAND="update_md5" |
cd445739 AM |
2105 | NODIST="yes" |
2106 | NOCVSSPEC="yes" | |
cd445739 AM |
2107 | shift ;; |
2108 | -a5 | --add-md5 ) | |
518ff1fb | 2109 | COMMAND="update_md5" |
cd445739 | 2110 | NODIST="yes" |
cd445739 | 2111 | NOCVSSPEC="yes" |
cd445739 AM |
2112 | ADD5="yes" |
2113 | shift ;; | |
2114 | -n5 | --no-md5 ) | |
2115 | NO5="yes" | |
2116 | shift ;; | |
2117 | -D | --debug ) | |
2118 | DEBUG="yes"; shift ;; | |
2119 | -V | --version ) | |
2120 | COMMAND="version"; shift ;; | |
d43959a2 ER |
2121 | --short-version ) |
2122 | COMMAND="short-version"; shift ;; | |
db9fdf51 ER |
2123 | -a | --add_cvs) |
2124 | COMMAND="add_cvs"; | |
2125 | shift ;; | |
3f79cb18 KK |
2126 | --all-branches ) |
2127 | ALL_BRANCHES="yes" | |
2128 | shift ;; | |
cd445739 AM |
2129 | -b | -ba | --build ) |
2130 | COMMAND="build"; shift ;; | |
2131 | -bb | --build-binary ) | |
2132 | COMMAND="build-binary"; shift ;; | |
6594293d AG |
2133 | -bc ) |
2134 | COMMAND="build-build"; shift ;; | |
2135 | -bi ) | |
2136 | COMMAND="build-install"; shift ;; | |
2137 | -bl ) | |
2138 | COMMAND="build-list"; shift ;; | |
cd445739 AM |
2139 | -bp | --build-prep ) |
2140 | COMMAND="build-prep"; shift ;; | |
6594293d AG |
2141 | -bs | --build-source ) |
2142 | COMMAND="build-source"; shift ;; | |
cd445739 AM |
2143 | -B | --branch ) |
2144 | COMMAND="branch"; shift; TAG="${1}"; shift;; | |
2145 | -c | --clean ) | |
387eaf99 | 2146 | CLEAN="--clean"; shift ;; |
39dcc7de | 2147 | -cf | --cvs-force ) |
df1306b5 | 2148 | CVS_FORCE="-f"; shift;; |
3189511a KK |
2149 | --depth ) |
2150 | DEPTH="--depth=$2" | |
2151 | shift 2 | |
2152 | ;; | |
cd445739 AM |
2153 | -g | --get ) |
2154 | COMMAND="get"; shift ;; | |
2155 | -h | --help ) | |
2156 | COMMAND="usage"; shift ;; | |
fd71d65c ER |
2157 | --ftp ) |
2158 | PROTOCOL="ftp"; shift ;; | |
cd445739 AM |
2159 | --http ) |
2160 | PROTOCOL="http"; shift ;; | |
6c5362e5 ER |
2161 | -j) |
2162 | RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\"" | |
2163 | shift 2 | |
2164 | ;; | |
2165 | -j[0-9]*) | |
2166 | RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\"" | |
2167 | shift | |
2168 | ;; | |
d4c8d3a9 ER |
2169 | -p) |
2170 | PARALLEL_DOWNLOADS=$2 | |
2171 | shift 2 | |
2172 | ;; | |
2173 | -p[0-9]) | |
2174 | PARALLEL_DOWNLOADS=${1#-p} | |
2175 | shift | |
2176 | ;; | |
cd445739 AM |
2177 | -l | --logtofile ) |
2178 | shift; LOGFILE="${1}"; shift ;; | |
2179 | -ni| --nice ) | |
2180 | shift; DEF_NICE_LEVEL=${1}; shift ;; | |
18e5347d ER |
2181 | -ske | --skip-existing-files) |
2182 | SKIP_EXISTING_FILES="yes"; shift ;; | |
cd445739 AM |
2183 | -m | --mr-proper ) |
2184 | COMMAND="mr-proper"; shift ;; | |
cd445739 AM |
2185 | -ncs | --no-cvs-specs ) |
2186 | NOCVSSPEC="yes"; shift ;; | |
2187 | -nd | --no-distfiles ) | |
2188 | NODIST="yes"; shift ;; | |
2189 | -nm | --no-mirrors ) | |
2190 | NOMIRRORS="yes"; shift ;; | |
2191 | -nu | --no-urls ) | |
2192 | NOURLS="yes"; shift ;; | |
2193 | -ns | --no-srcs ) | |
2194 | NOSRCS="yes"; shift ;; | |
2195 | -ns0 | --no-source0 ) | |
2196 | NOSOURCE0="yes"; shift ;; | |
2197 | -nn | --no-net ) | |
cd445739 AM |
2198 | NOCVSSPEC="yes" |
2199 | NODIST="yes" | |
2200 | NOMIRRORS="yes" | |
2201 | NOURLS="yes" | |
2202 | NOSRCS="yes" | |
f09c0772 | 2203 | ALWAYS_CVSUP="no" |
cd445739 | 2204 | shift;; |
bc10f694 JB |
2205 | -pm | --prefer-mirrors ) |
2206 | PREFMIRRORS="yes" | |
2207 | shift;; | |
89e05bdd | 2208 | --noinit | --no-init ) |
29e90b02 JR |
2209 | NOINIT="yes" |
2210 | shift;; | |
cd445739 | 2211 | --opts ) |
4250a189 | 2212 | shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;; |
469e5fd1 | 2213 | --nopatch | -np ) |
3accf718 | 2214 | shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;; |
8bd5e66d ER |
2215 | --skip-patch | -sp ) |
2216 | shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;; | |
dfa39149 ER |
2217 | --topdir) |
2218 | RPMOPTS="${RPMOPTS} --define \"_topdir $2\"" | |
2219 | shift 2 | |
2220 | ;; | |
cd445739 AM |
2221 | --with | --without ) |
2222 | case $GROUP_BCONDS in | |
2223 | "yes") | |
2224 | COND=${1} | |
2225 | shift | |
c2e1d2a2 | 2226 | # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql |
cd445739 AM |
2227 | while ! `echo ${1}|grep -qE '(^-|spec)'` |
2228 | do | |
2229 | BCOND="$BCOND $COND $1" | |
2230 | shift | |
2231 | done;; | |
2232 | "no") | |
d4d1ec20 | 2233 | if [[ "$2" = *,* ]]; then |
ce40491a ER |
2234 | for a in $(echo "$2" | tr , ' '); do |
2235 | BCOND="$BCOND $1 $a" | |
2236 | done | |
d4d1ec20 | 2237 | else |
ce40491a | 2238 | BCOND="$BCOND $1 $2" |
d4d1ec20 ER |
2239 | fi |
2240 | shift 2 ;; | |
cd445739 AM |
2241 | esac |
2242 | ;; | |
64ea5308 | 2243 | --target ) |
2244 | shift; TARGET="${1}"; shift ;; | |
6dd19291 | 2245 | --target=* ) |
2246 | TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;; | |
cd445739 AM |
2247 | -q | --quiet ) |
2248 | QUIET="--quiet"; shift ;; | |
2249 | --date ) | |
d383b191 KK |
2250 | CVSDATE="${2}"; shift 2 |
2251 | date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; } | |
2252 | ;; | |
cd445739 | 2253 | -r | --cvstag ) |
3ccc5cef ER |
2254 | CVSTAG="$2" |
2255 | shift 2 | |
2256 | ;; | |
5323fffd | 2257 | -A) |
3ccc5cef | 2258 | shift |
aa43ca3e | 2259 | CVSTAG="master" |
3ccc5cef | 2260 | ;; |
cd445739 AM |
2261 | -R | --fetch-build-requires) |
2262 | FETCH_BUILD_REQUIRES="yes" | |
2263 | NOT_INSTALLED_PACKAGES= | |
2264 | shift ;; | |
2265 | -RB | --remove-build-requires) | |
2266 | REMOVE_BUILD_REQUIRES="nice" | |
2267 | shift ;; | |
2268 | -FRB | --force-remove-build-requires) | |
2269 | REMOVE_BUILD_REQUIRES="force" | |
2270 | shift ;; | |
f982c603 | 2271 | -sc | --source-cvs) |
e15852ab JR |
2272 | COMMAND="list-sources-cvs" |
2273 | shift ;; | |
ae58a474 | 2274 | -sd | --source-distfiles) |
06541433 JR |
2275 | COMMAND="list-sources-distfiles" |
2276 | shift ;; | |
ae58a474 | 2277 | -sdp | --source-distfiles-paths) |
06541433 JR |
2278 | COMMAND="list-sources-distfiles-paths" |
2279 | shift ;; | |
ae58a474 | 2280 | -sf | --source-files) |
a7eefc54 | 2281 | COMMAND="list-sources-files" |
95ad5bf0 | 2282 | shift ;; |
ae58a474 | 2283 | -lsp | --source-paths) |
a7eefc54 | 2284 | COMMAND="list-sources-local-paths" |
95ad5bf0 | 2285 | shift ;; |
ae58a474 | 2286 | -su | --source-urls) |
2dddf439 ER |
2287 | COMMAND="list-sources-urls" |
2288 | shift ;; | |
cd445739 | 2289 | -Tvs | --tag-version-stable ) |
518ff1fb | 2290 | COMMAND="tag" |
cd445739 AM |
2291 | TAG="STABLE" |
2292 | TAG_VERSION="yes" | |
2293 | shift;; | |
cd445739 | 2294 | -Ts | --tag-stable ) |
518ff1fb | 2295 | COMMAND="tag" |
cd445739 AM |
2296 | TAG="STABLE" |
2297 | TAG_VERSION="no" | |
2298 | shift;; | |
cd445739 | 2299 | -Tv | --tag-version ) |
518ff1fb | 2300 | COMMAND="tag" |
cd445739 AM |
2301 | TAG="" |
2302 | TAG_VERSION="yes" | |
2303 | shift;; | |
2304 | -Tp | --tag-prefix ) | |
2305 | TAG_PREFIX="$2" | |
2306 | shift 2;; | |
2307 | -tt | --test-tag ) | |
2308 | TEST_TAG="yes" | |
2309 | shift;; | |
2310 | -T | --tag ) | |
518ff1fb | 2311 | COMMAND="tag" |
cd445739 AM |
2312 | shift |
2313 | TAG="$1" | |
2314 | TAG_VERSION="no" | |
2315 | shift;; | |
50321881 JK |
2316 | -ir | --integer-release-only ) |
2317 | INTEGER_RELEASE="yes" | |
2318 | shift;; | |
cd445739 | 2319 | -U | --update ) |
ecba6ad5 | 2320 | COMMAND="update_md5" |
cd445739 AM |
2321 | UPDATE="yes" |
2322 | NOCVSSPEC="yes" | |
2323 | NODIST="yes" | |
cd445739 AM |
2324 | shift ;; |
2325 | -Upi | --update-poldek-indexes ) | |
2326 | UPDATE_POLDEK_INDEXES="yes" | |
2327 | shift ;; | |
5eb1d24b | 2328 | --init-rpm-dir|--init) |
518ff1fb | 2329 | COMMAND="init_rpm_dir" |
ce5daafb | 2330 | shift ;; |
cd445739 AM |
2331 | -u | --try-upgrade ) |
2332 | TRY_UPGRADE="1"; shift ;; | |
0907f1eb ER |
2333 | --upgrade-version ) |
2334 | shift; UPGRADE_VERSION="$1"; shift;; | |
cd445739 AM |
2335 | -un | --try-upgrade-with-float-version ) |
2336 | TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;; | |
2337 | -v | --verbose ) | |
2338 | BE_VERBOSE="1"; shift ;; | |
2339 | --define) | |
2340 | shift | |
2341 | MACRO="${1}" | |
cf264933 | 2342 | shift |
2343 | if echo "${MACRO}" | grep -q '\W'; then | |
2344 | RPMOPTS="${RPMOPTS} --define \"${MACRO}\"" | |
2345 | else | |
2346 | VALUE="${1}" | |
2347 | shift | |
2348 | RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\"" | |
2349 | fi | |
cd445739 | 2350 | ;; |
44058243 ER |
2351 | --alt_kernel) |
2352 | shift | |
5153358c | 2353 | RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\" --define \"build_kernels $1\"" |
44058243 ER |
2354 | shift |
2355 | ;; | |
6594293d AG |
2356 | --short-circuit) |
2357 | RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit" | |
2358 | shift | |
2359 | ;; | |
dfe2cb9a | 2360 | --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds ) |
518ff1fb | 2361 | COMMAND="show_bconds" |
dfe2cb9a MK |
2362 | shift |
2363 | ;; | |
9b78be50 ER |
2364 | --show-bcond-args) |
2365 | COMMAND="show_bcond_args" | |
2366 | shift | |
2367 | ;; | |
24a97174 ER |
2368 | --show-avail-bconds) |
2369 | COMMAND="show_avail_bconds" | |
2370 | shift | |
2371 | ;; | |
cd445739 AM |
2372 | --nodeps) |
2373 | shift | |
2374 | RPMOPTS="${RPMOPTS} --nodeps" | |
2375 | ;; | |
9243e80b | 2376 | -debug) |
a08d92fc ER |
2377 | RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift |
2378 | ;; | |
bb4d488a | 2379 | -*) |
a08d92fc ER |
2380 | Exit_error err_invalid_cmdline "$1" |
2381 | ;; | |
bb4d488a | 2382 | *) |
76997578 | 2383 | SPECFILE=${1%/}; shift |
f19103b5 AG |
2384 | # check if specname was passed as specname:cvstag |
2385 | if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then | |
518ff1fb ER |
2386 | CVSTAG="${SPECFILE##*:}" |
2387 | SPECFILE="${SPECFILE%%:*}" | |
f19103b5 | 2388 | fi |
8f7946e0 ER |
2389 | # always have SPECFILE ending with .spec extension |
2390 | SPECFILE=${SPECFILE%%.spec}.spec | |
a8c9a155 | 2391 | ASSUMED_NAME=$(basename ${SPECFILE%%.spec}) |
cd445739 AM |
2392 | esac |
2393 | done | |
2394 | ||
3ccc5cef ER |
2395 | if [ "$CVSTAG" ]; then |
2396 | # pass $CVSTAG used by builder to rpmbuild too, so specs could use it | |
2397 | RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\"" | |
2398 | fi | |
2399 | ||
3f79cb18 KK |
2400 | if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then |
2401 | echo >&2 "--all branches requires --depth <number>" | |
2402 | Exit_error err_invalid_cmdline | |
2403 | fi | |
2404 | ||
cd445739 | 2405 | if [ -n "$DEBUG" ]; then |
518ff1fb ER |
2406 | set -x |
2407 | set -v | |
cd445739 AM |
2408 | fi |
2409 | ||
2a5f078d | 2410 | if [ -n "$TARGET" ]; then |
2411 | case "$RPMBUILD" in | |
2412 | "rpmbuild") | |
2413 | TARGET_SWITCH="--target $TARGET" ;; | |
2414 | "rpm") | |
2415 | TARGET_SWITCH="--target=$TARGET" ;; | |
2416 | esac | |
2417 | fi | |
2418 | ||
86aafdbe ER |
2419 | if [ "$SCHEDTOOL" != "no" ]; then |
2420 | NICE_COMMAND="$SCHEDTOOL" | |
2421 | else | |
2422 | NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}" | |
2423 | fi | |
2424 | ||
6dd8b9cc ER |
2425 | # see time(1) for output format that could be used |
2426 | TIME_COMMAND="time -p" | |
2427 | ||
c890b916 | 2428 | update_shell_title "$COMMAND" |
cd445739 | 2429 | case "$COMMAND" in |
117d9861 ER |
2430 | "show_bconds") |
2431 | init_builder | |
8b7889f3 ER |
2432 | if [ -z "$SPECFILE" ]; then |
2433 | Exit_error err_no_spec_in_cmdl | |
117d9861 | 2434 | fi |
8b7889f3 ER |
2435 | get_spec > /dev/null |
2436 | parse_spec | |
2437 | set_bconds_values | |
2438 | display_bconds | |
117d9861 | 2439 | ;; |
9b78be50 ER |
2440 | "show_bcond_args") |
2441 | init_builder | |
8b7889f3 ER |
2442 | if [ -z "$SPECFILE" ]; then |
2443 | Exit_error err_no_spec_in_cmdl | |
9b78be50 | 2444 | fi |
8b7889f3 ER |
2445 | get_spec > /dev/null |
2446 | parse_spec | |
2447 | set_bconds_values | |
2448 | echo "$BCOND" | |
24a97174 ER |
2449 | ;; |
2450 | "show_avail_bconds") | |
2451 | init_builder | |
8b7889f3 ER |
2452 | if [ -z "$SPECFILE" ]; then |
2453 | Exit_error err_no_spec_in_cmdl | |
24a97174 ER |
2454 | fi |
2455 | ||
8b7889f3 ER |
2456 | get_spec > /dev/null |
2457 | parse_spec | |
2458 | local bcond_avail=$(find_spec_bcond $SPECFILE) | |
2459 | local opt bcond bconds | |
2460 | for opt in $bcond_avail; do | |
2461 | case "$opt" in | |
2462 | without_*) | |
2463 | bcond=${opt#without_} | |
2464 | bconds="$bconds $bcond" | |
2465 | ;; | |
2466 | with_*) | |
2467 | bcond=${opt#with_} | |
2468 | bconds="$bconds $bcond" | |
2469 | ;; | |
2470 | *) | |
2471 | echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds" | |
2472 | exit 1 | |
2473 | ;; | |
2474 | esac | |
2475 | done | |
2476 | echo $bconds | |
2477 | ||
9b78be50 | 2478 | ;; |
6594293d | 2479 | "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list") |
117d9861 | 2480 | init_builder |
db9fdf51 ER |
2481 | if [ -z "$SPECFILE" ]; then |
2482 | Exit_error err_no_spec_in_cmdl | |
2483 | fi | |
62623fc0 | 2484 | |
db9fdf51 ER |
2485 | # display SMP make flags if set |
2486 | smp_mflags=$(rpm -E %{?_smp_mflags}) | |
2487 | if [ "$smp_mflags" ]; then | |
2488 | echo "builder: SMP make flags are set to $smp_mflags" | |
2489 | fi | |
2490 | ||
2491 | get_spec | |
2492 | parse_spec | |
2493 | set_bconds_values | |
2494 | display_bconds | |
2495 | display_branches | |
2496 | if [ "$COMMAND" != "build-source" ]; then | |
2497 | check_buildarch | |
2498 | fi | |
2499 | fetch_build_requires | |
2500 | if [ "$INTEGER_RELEASE" = "yes" ]; then | |
2501 | echo "Checking release $PACKAGE_RELEASE..." | |
2502 | if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then | |
2503 | Exit_error err_fract_rel "$PACKAGE_RELEASE" | |
cd445739 | 2504 | fi |
db9fdf51 | 2505 | fi |
cd445739 | 2506 | |
db9fdf51 ER |
2507 | # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt |
2508 | if [ -n "$TEST_TAG" ]; then | |
2509 | local TAGVER=`make_tagver` | |
2fc07e25 | 2510 | tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER |
8c043136 | 2511 | # check also tags created in CVS |
2fc07e25 | 2512 | local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]') |
d03404e7 KK |
2513 | local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]') |
2514 | tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \ | |
2515 | || Exit_error err_tag_exists $TAGVER_CVS | |
db9fdf51 | 2516 | # - do not allow to build from HEAD when XX-branch exists |
2200d50e | 2517 | TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g') |
b6c4f6ba | 2518 | if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then |
db9fdf51 | 2519 | TAG_BRANCH="${TREE_PREFIX}-branch" |
f9b0409c KK |
2520 | if [ -n "$DEPTH" ]; then |
2521 | cmd_branches="git ls-remote --heads" | |
2522 | ref_prefix=refs/heads | |
2523 | else | |
2524 | cmd_branches="git show-ref" | |
2525 | ref_prefix=refs/remotes/${REMOTE_PLD} | |
2526 | fi | |
0c6ce8b5 KK |
2527 | TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40') |
2528 | if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then | |
db9fdf51 | 2529 | Exit_error err_branch_exists "$TAG_STATUS" |
074de301 | 2530 | fi |
2a5f078d | 2531 | fi |
2532 | ||
cd445739 | 2533 | fi |
db9fdf51 ER |
2534 | |
2535 | if [ -n "$NOSOURCE0" ] ; then | |
2536 | SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'` | |
2537 | fi | |
2538 | try_upgrade | |
2539 | case $? in | |
2540 | 0) | |
2541 | get_files $SOURCES $PATCHES | |
d3df4e78 | 2542 | check_md5 $SOURCES $PATCHES |
db9fdf51 ER |
2543 | ;; |
2544 | *) | |
2545 | NODIST="yes" get_files $SOURCES $PATCHES | |
647e3d7f | 2546 | update_md5 $SOURCES $PATCHES |
db9fdf51 ER |
2547 | ;; |
2548 | esac | |
2549 | build_package | |
fe7c0a38 | 2550 | if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then |
8a390970 | 2551 | run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz |
db9fdf51 ER |
2552 | fi |
2553 | remove_build_requires | |
2a5f078d | 2554 | ;; |
cd445739 | 2555 | "branch" ) |
518ff1fb | 2556 | init_builder |
db9fdf51 | 2557 | if [ -z "$SPECFILE" ]; then |
518ff1fb | 2558 | Exit_error err_no_spec_in_cmdl |
cd445739 | 2559 | fi |
db9fdf51 ER |
2560 | |
2561 | get_spec | |
2562 | parse_spec | |
f663f264 | 2563 | branch_files $TAG |
cd445739 | 2564 | ;; |
703b6deb ER |
2565 | "add_cvs" ) |
2566 | init_builder | |
2567 | if [ -z "$SPECFILE" ]; then | |
2568 | Exit_error err_no_spec_in_cmdl | |
2569 | fi | |
2570 | ||
406b9ecf KK |
2571 | create_git_repo |
2572 | if [ -n "$NEW_REPO" ]; then | |
2573 | parse_spec | |
2574 | local file | |
2575 | for file in $SOURCES $PATCHES; do | |
2576 | if [ -z $(src_md5 "$file") ]; then | |
2577 | git add $file || Exit_error err_no_source_in_repo $file | |
2578 | else | |
2579 | cvsignore_df `nourl $file` | |
2580 | fi | |
2581 | done | |
2582 | git add $SPECFILE | |
c9933bf8 | 2583 | echo "When you are ready commit your changes and run git push origin master" |
406b9ecf KK |
2584 | else |
2585 | echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}" | |
703b6deb | 2586 | fi |
703b6deb | 2587 | ;; |
cd445739 | 2588 | "get" ) |
518ff1fb | 2589 | init_builder |
db9fdf51 | 2590 | if [ -z "$SPECFILE" ]; then |
518ff1fb | 2591 | Exit_error err_no_spec_in_cmdl |
ecba6ad5 | 2592 | fi |
db9fdf51 ER |
2593 | |
2594 | get_spec | |
2595 | parse_spec | |
2596 | ||
2597 | if [ -n "$NOSOURCE0" ] ; then | |
2598 | SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'` | |
2599 | fi | |
2600 | get_files $SOURCES $PATCHES | |
2601 | check_md5 $SOURCES | |
652dc2d1 | 2602 | fetch_build_requires |
ecba6ad5 ER |
2603 | ;; |
2604 | "update_md5" ) | |
518ff1fb | 2605 | init_builder |
db9fdf51 | 2606 | if [ -z "$SPECFILE" ]; then |
518ff1fb | 2607 | Exit_error err_no_spec_in_cmdl |
cd445739 | 2608 | fi |
db9fdf51 ER |
2609 | |
2610 | get_spec | |
2611 | parse_spec | |
2612 | ||
2613 | if [ -n "$NOSOURCE0" ] ; then | |
2614 | SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'` | |
2615 | fi | |
647e3d7f | 2616 | update_md5 $SOURCES $PATCHES |
cd445739 AM |
2617 | ;; |
2618 | "tag" ) | |
2619 | NOURLS=1 | |
f7b91886 | 2620 | NODIST="yes" |
518ff1fb | 2621 | init_builder |
db9fdf51 | 2622 | if [ -z "$SPECFILE" ]; then |
518ff1fb | 2623 | Exit_error err_no_spec_in_cmdl |
cd445739 | 2624 | fi |
db9fdf51 | 2625 | |
db9fdf51 | 2626 | parse_spec |
cc4edaf4 KK |
2627 | if [ ! -d .git ]; then |
2628 | echo "No git reposiotory" >&2 | |
2629 | exit 101 | |
2630 | fi | |
1fb35df5 | 2631 | tag_files |
cd445739 AM |
2632 | ;; |
2633 | "mr-proper" ) | |
6f10b394 | 2634 | mr_proper |
cd445739 | 2635 | ;; |
a7eefc54 | 2636 | "list-sources-files" ) |
2637 | init_builder | |
2638 | NOCVSSPEC="yes" | |
2639 | DONT_PRINT_REVISION="yes" | |
2640 | get_spec | |
2641 | parse_spec | |
ecba6ad5 | 2642 | for SAP in $SOURCES $PATCHES; do |
ce40491a | 2643 | echo $SAP | awk '{gsub(/.*\//,"") ; print}' |
a7eefc54 | 2644 | done |
2645 | ;; | |
2dddf439 | 2646 | "list-sources-urls" ) |
fe61ecd4 | 2647 | init_builder >&2 |
2dddf439 ER |
2648 | NOCVSSPEC="yes" |
2649 | DONT_PRINT_REVISION="yes" | |
fe61ecd4 ER |
2650 | get_spec >&2 |
2651 | parse_spec >&2 | |
2dddf439 | 2652 | SAPS="$SOURCES $PATCHES" |
fe61ecd4 | 2653 | for SAP in $SAPS; do |
ce40491a | 2654 | echo $SAP |
2dddf439 ER |
2655 | done |
2656 | ;; | |
a7eefc54 | 2657 | "list-sources-local-paths" ) |
2658 | init_builder | |
2659 | NOCVSSPEC="yes" | |
2660 | DONT_PRINT_REVISION="yes" | |
2661 | get_spec | |
2662 | parse_spec | |
ecba6ad5 | 2663 | for SAP in $SOURCES $PATCHES; do |
9c909460 | 2664 | echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }') |
a7eefc54 | 2665 | done |
2666 | ;; | |
06541433 JR |
2667 | "list-sources-distfiles-paths" ) |
2668 | init_builder | |
2669 | NOCVSSPEC="yes" | |
2670 | DONT_PRINT_REVISION="yes" | |
2671 | get_spec | |
2672 | parse_spec | |
ecba6ad5 | 2673 | for SAP in $SOURCES $PATCHES; do |
06541433 JR |
2674 | if [ -n "$(src_md5 "$SAP")" ]; then |
2675 | distfiles_path "$SAP" | |
2676 | fi | |
2677 | done | |
2678 | ;; | |
2679 | "list-sources-distfiles" ) | |
2680 | init_builder | |
2681 | NOCVSSPEC="yes" | |
2682 | DONT_PRINT_REVISION="yes" | |
2683 | get_spec | |
2684 | parse_spec | |
ecba6ad5 | 2685 | for SAP in $SOURCES $PATCHES; do |
06541433 JR |
2686 | if [ -n "$(src_md5 "$SAP")" ]; then |
2687 | distfiles_url "$SAP" | |
2688 | fi | |
2689 | done | |
2690 | ;; | |
e15852ab JR |
2691 | "list-sources-cvs" ) |
2692 | init_builder | |
2693 | # NOCVSSPEC="yes" | |
2694 | DONT_PRINT_REVISION="yes" | |
2695 | get_spec | |
2696 | parse_spec | |
2697 | for SAP in $SOURCES $PATCHES; do | |
2698 | if [ -z "$(src_md5 "$SAP")" ]; then | |
2699 | echo $SAP | awk '{gsub(/.*\//,"") ; print}' | |
2700 | fi | |
2701 | done | |
2702 | ;; | |
ce5daafb ER |
2703 | "init_rpm_dir") |
2704 | init_rpm_dir | |
2705 | ;; | |
cd445739 | 2706 | "usage" ) |
d43959a2 ER |
2707 | usage |
2708 | ;; | |
2709 | "short-version" ) | |
2710 | echo "$VERSION" | |
2711 | ;; | |
cd445739 | 2712 | "version" ) |
d43959a2 ER |
2713 | echo "$VERSIONSTRING" |
2714 | ;; | |
bde1c404 | 2715 | esac |
31898c61 AM |
2716 | if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then |
2717 | rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" | |
03d5c71d | 2718 | fi |
cd445739 AM |
2719 | cd "$__PWD" |
2720 | ||
73848362 | 2721 | # vi:syntax=sh:ts=4:sw=4:noet |