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