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