]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
- typos
[packages/rpm-build-tools.git] / builder.sh
1 #!/bin/sh
2 # -----------
3 # $Id$
4 # Exit codes:
5 #         0 - succesful
6 #         1 - help displayed
7 #         2 - no spec file name in cmdl parameters
8 #         3 - spec file not stored in repo
9 #         4 - some source, patch or icon files not stored in repo
10 #         5 - package build failed
11 #         6 - spec file with errors
12 #         7 - wrong source in /etc/poldek.conf
13 #         8 - Failed installing buildrequirements and subrequirements
14 #         9 - Requested tag already exist
15 #        10 - Refused to build fractional release
16 #       100 - Unknown error (should not happen)
17
18 # Notes (todo):
19 #       - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
20 #       - when Icon: field is present, -5 and -a5 doesn't work
21 #       - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
22
23 VERSION="\
24 Build package utility from PLD Linux CVS repository
25 v0.16 (C) 1999-2006 Free Penguins".
26 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
27
28 COMMAND="build"
29 TARGET=""
30
31 SPECFILE=""
32 BE_VERBOSE=""
33 QUIET=""
34 CLEAN=""
35 DEBUG=""
36 NOURLS=""
37 NOCVS=""
38 NOCVSSPEC=""
39 NODIST=""
40 NOINIT=""
41 UPDATE=""
42 UPDATE5=""
43 ADD5=""
44 NO5=""
45 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
46 CVSROOT=""
47
48 # It can be used i.e. in log file naming.
49 # See LOGFILE example.
50 DATE=`date +%Y-%m-%d_%H-%M-%S`
51
52 # Example: LOGFILE='../log.$PACKAGE_NAME'
53 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
54 # Yes, you can use variable name! Note _single_ quotes!
55 LOGFILE=''
56
57 LOGDIR=""
58 LOGDIROK=""
59 LOGDIRFAIL=""
60 LASTLOG_FILE=""
61
62 CHMOD="no"
63 CHMOD_MODE="0444"
64 RPMOPTS=""
65 RPMBUILDOPTS=""
66 BCOND=""
67 GROUP_BCONDS="no"
68 CVSIGNORE_DF="no"
69
70 PATCHES=""
71 SOURCES=""
72 ICONS=""
73 PACKAGE_RELEASE=""
74 PACKAGE_VERSION=""
75 PACKAGE_NAME=""
76 PROTOCOL="ftp"
77 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
78 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
79
80 CVSTAG=""
81 RES_FILE=""
82 CVS_FORCE=""
83
84 CVS_SERVER="cvs.pld-linux.org"
85 DISTFILES_SERVER="://distfiles.pld-linux.org"
86 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
87
88 DEF_NICE_LEVEL=19
89 SCHEDTOOL="auto"
90
91 FAIL_IF_NO_SOURCES="yes"
92
93 # let get_files skip over files which are present to get those damn files fetched
94 SKIP_EXISTING_FILES="no"
95
96 TRY_UPGRADE=""
97 # should the specfile be restored if upgrade failed?
98 REVERT_BROKEN_UPGRADE="yes"
99
100 if [ -x /usr/bin/rpm-getdeps ]; then
101         FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
102 else
103         FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
104 fi
105
106 # Here we load saved user environment used to
107 # predefine options set above, or passed to builder
108 # in command line.
109 # This one reads global system environment settings:
110 if [ -f ~/etc/builderrc ]; then
111         . ~/etc/builderrc
112 fi
113 # And this one cascades settings using user personal
114 # builder settings.
115 # Example of ~/.builderrc:
116 #
117 #UPDATE_POLDEK_INDEXES="yes"
118 #FETCH_BUILD_REQUIRES="yes"
119 #REMOVE_BUILD_REQUIRES="force"
120 #GROUP_BCONDS="yes"
121 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
122 #TITLECHANGE=no
123 #
124 SU_SUDO=""
125 if [ -n "$HOME_ETC" ]; then
126         USER_CFG="$HOME_ETC/.builderrc"
127 else
128         USER_CFG=~/.builderrc
129 fi
130
131 [ -f "$USER_CFG" ] && . "$USER_CFG"
132
133 if [ "$SCHEDTOOL" = "auto" ]; then
134         if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
135                 SCHEDTOOL="schedtool -B -e"
136         else
137                 SCHEDTOOL="no"
138         fi
139 fi
140
141 if [ -n "$USE_PROZILLA" ]; then
142         GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
143         GETURI2="$GETURI"
144         OUTFILEOPT="-O"
145 elif [ -n "$USE_AXEL" ]; then
146         GETURI="axel -a $AXEL_OPTS"
147         GETURI2="$GETURI"
148         OUTFILEOPT="-o"
149 else
150         wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
151         wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
152         wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
153
154         GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
155         GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
156         OUTFILEOPT="-O"
157 fi
158
159 GETLOCAL="cp -a"
160
161 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
162         RPM="rpm"
163         RPMBUILD="rpm"
164 else
165         RPM="rpm"
166         RPMBUILD="rpmbuild"
167 fi
168
169 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
170 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
171
172 run_poldek()
173 {
174         RES_FILE=~/tmp/poldek-exit-status.$RANDOM
175         if [ -n "$LOGFILE" ]; then
176                 LOG=`eval echo $LOGFILE`
177                 if [ -n "$LASTLOG_FILE" ]; then
178                         echo "LASTLOG=$LOG" > $LASTLOG_FILE
179                 fi
180                 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
181                 return $exit_pldk
182         else
183                 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
184                 return `cat ${RES_FILE}`
185                 rm -rf ${RES_FILE}
186         fi
187 }
188
189 #---------------------------------------------
190 # functions
191
192 usage()
193 {
194         if [ -n "$DEBUG" ]; then set -xv; fi
195         echo "\
196 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
197 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
198 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] 
199 [-g|--get] [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
200 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
201 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
202 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
203 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds]
204 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec][:cvstag]
205
206 -5, --update-md5    - update md5 comments in spec, implies -nd -ncs
207 -a5, --add-md5      - add md5 comments to URL sources, implies -nc -nd -ncs
208 -n5, --no-md5       - ignore md5 comments in spec
209 -D, --debug         - enable builder script debugging mode,
210 -debug              - produce rpm debug package (same as --opts -debug)
211 -V, --version       - output builder version
212 -a, --as_anon       - get files via pserver as cvs@$CVS_SERVER,
213 -b, -ba, --build    - get all files from CVS repo or HTTP/FTP and build package
214                       from <package>.spec,
215 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
216                       only package from <package>.spec,
217 -bp, --build-prep   - execute the %prep phase of <package>.spec,
218 -bc                 - reserved (not implemented)
219 -bi                   reserved (not implemented)
220 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
221                       them into src.rpm,
222 --short-circuit     - reserved (not implemented)
223 -B, --branch        - add branch
224 -c, --clean         - clean all temporarily created files (in BUILD, SOURCES,
225                       SPECS and \$RPM_BUILD_ROOT),
226 -cf, --cvs-force        - use -F when tagging (useful when moving branches)
227 -d <cvsroot>, --cvsroot <cvsroot>
228                     - setup \$CVSROOT,
229 --define <macro> <value>
230                     - define a macro <macro> with value <value>,
231 --nodeps            - rpm won't check any dependences
232 -g, --get           - get <package>.spec and all related files from CVS repo
233                       or HTTP/FTP,
234 -h, --help          - this message,
235 --http              - use http instead of ftp,
236 -l <logfile>, --logtofile <logfile>
237                     - log all to file,
238 -m, --mr-proper     - only remove all files related to spec file and all work
239                       resources,
240 -nc, --no-cvs       - don't download sources from CVS, if source URL is given,
241 -ncs, --no-cvs-specs
242                     - don't check specs in CVS
243 -nd, --no-distfiles - don't download from distfiles
244 -nm, --no-mirrors   - don't download from mirror, if source URL is given,
245 -nu, --no-urls      - don't try to download from FTP/HTTP location,
246 -ns, --no-srcs      - don't download Sources
247 -ns0, --no-source0  - don't download Source0
248 -nn, --no-net       - don't download anything from the net
249 --no-init           - don't initialize builder paths (SPECS and SOURCES)
250 -ske,
251 --skip-existing-files - skip existing files in get_files
252 --opts <rpm opts>   - additional options for rpm
253 -q, --quiet         - be quiet,
254 --date yyyy-mm-dd   - build package using resources from specified CVS date,
255 -r <cvstag>, --cvstag <cvstag>
256                     - build package using resources from specified CVS tag,
257 -R, --fetch-build-requires
258                     - fetch what is BuildRequired,
259 -RB, --remove-build-requires
260                     - remove all you fetched with -R or --fetch-build-requires
261                       remember, this option requires confirmation,
262 -FRB, --force-remove-build-requires
263                     - remove all you fetched with -R or --fetch-build-requires
264                       remember, this option works without confirmation,
265 -sd, --source-distfiles - list sources available from distfiles (intended for offline
266                       operations; does not work when Icon field is present
267                       but icon file is absent),
268 -sdp, --source-distfiles-paths - list sources available from distfiles -
269                       paths relative to distfiles directory (intended for offline
270                       operations; does not work when Icon field is present
271                       but icon file is absent),
272 -sf, --source-files - list sources - bare filenames (intended for offline
273                       operations; does not work when Icon field is present
274                       but icon file is absent),
275 -sp, --source-paths - list sources - filenames with full local paths (intended for
276                       offline operations; does not work when Icon field is present
277                       but icon file is absent),
278 -su, --source-urls  - list urls - urls to sources and patches
279                       intended for copying urls with spec with lots of macros in urls
280 -T <cvstag> , --tag <cvstag>
281                     - add cvs tag <cvstag> for files,
282 -Tvs, --tag-version-stable
283                     - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
284 -Ts, --tag-stable
285                     - add cvs tag STABLE for files,
286 -Tv, --tag-version
287                     - add cvs tag NAME-VERSION-RELEASE for files,
288 -Tp, --tag-prefix <prefix>
289                     - add <prefix> to NAME-VERSION-RELEASE tags,
290 -tt, --test-tag <prefix>
291                     - fail if tag is already present,
292 -ir, --integer-release-only
293                     - allow only integer and snapshot releases
294 -v, --verbose       - be verbose,
295 -u, --try-upgrade   - check version, and try to upgrade package
296 -un, --try-upgrade-with-float-version
297                     - as above, but allow float version
298 -U, --update        - refetch sources, don't use distfiles, and update md5 comments
299 -Upi, --update-poldek-indexes
300                     - refresh or make poldek package index files.
301 -np, --nopatch <patchnumber>
302                     - don't apply <patchnumber>
303 --show-bconds       - show available conditional builds, which can be used
304                     - with --with and/or --without switches.
305 --with/--without <feature>
306                     - conditional build package depending on %_with_<feature>/
307                       %_without_<feature> macro switch.  You may now use
308                       --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
309                       constructions. Set GROUP_BCONDS to yes to make use of it.
310 --target <platform>, --target=<platform>
311                      - build for platform <platform>.
312 --init-rpm-dir       - initialize ~/rpm directory structure
313 "
314 }
315
316 update_shell_title() {
317         [ -t 1 ] || return
318         local len=${COLUMNS:-80}
319         local msg=$(echo "$*" | cut -c-$len)
320
321         if [ -n "$BE_VERBOSE" ]; then
322                 echo >&2 "$(date +%s.%N) $*"
323         fi
324
325         if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then
326                 local pkg
327                 if [ -n "$PACKAGE_NAME" ]; then
328                         pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
329                 else
330                         pkg=${SPECFILE}
331                 fi
332
333                 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
334                 msg="$(echo $msg | tr -d '\n\r')"
335                 case "$TERM" in
336                         cygwin|xterm*)
337                         echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
338                 ;;
339                         screen*)
340                         echo >&2 -ne "\033]0;$msg\007"
341                 ;;
342                 esac
343         fi
344 }
345
346 # set TARGET from BuildArch: from SPECFILE
347 set_spec_target() {
348         if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
349                 tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
350                 if [ "$tmp" ]; then
351                                 TARGET="$tmp"
352                                 case "$RPMBUILD" in
353                                 "rpmbuild")
354                                         TARGET_SWITCH="--target $TARGET" ;;
355                                 "rpm")
356                                         TARGET_SWITCH="--target=$TARGET" ;;
357                                 esac
358                 fi
359         fi
360 }
361
362 cache_rpm_dump () {
363         if [ -n "$DEBUG" ]; then
364                 set -x;
365                 set -v;
366         fi
367
368         update_shell_title "cache_rpm_dump"
369         local rpm_dump
370         rpm_dump=`
371
372         # we reset macros not to contain macros.build as all the %() macros are
373         # executed here, while none of them are actually needed.
374         # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
375         # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
376         macrofiles="/usr/lib/rpm/macros:$SPECS_DIR/.builder-rpmmacros:~/etc/.rpmmacros:~/.rpmmacros"
377         dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
378         # FIXME: better ideas than .rpmrc?
379         printf 'include:/usr/lib/rpm/rpmrc\nmacrofiles:%s\n' $macrofiles > .builder-rpmrc
380 # TODO: move these to /usr/lib/rpm/macros
381         cat > .builder-rpmmacros <<'EOF'
382 %requires_releq_kernel_up %{nil}
383 %requires_releq_kernel_smp %{nil}
384 %requires_releq() %{nil}
385 %pyrequires_eq() %{nil}
386 %requires_eq() %{nil}
387 %requires_eq_to() %{nil}
388 %releq_kernel_up ERROR
389 %releq_kernel_smp ERROR
390 %kgcc_package ERROR
391 %_fontsdir ERROR
392 %ruby_version ERROR
393 %ruby_ver_requires_eq() %{nil}
394 %ruby_mod_ver_requires_eq() %{nil}
395 %__php_api_requires() %{nil}
396 %php_major_version ERROR
397 %php_api_version ERROR
398 %py_ver ERROR
399 EOF
400         case "$RPMBUILD" in
401         rpm)
402                 ARGS='-bp'
403                 ;;
404         rpmbuild)
405                 ARGS='--nodigest --nosignature --nobuild'
406                 ;;
407         esac
408         if [ "$NOINIT" = "yes" ] ; then
409                 cat >> .builder-rpmmacros <<'EOF'
410 %_specdir ./
411 %_sourcedir ./
412 EOF
413         fi
414         $RPMBUILD --rcfile .builder-rpmrc $ARGS $ARGDIRS --nodeps --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1
415         `
416         if [ $? -gt 0 ]; then
417                 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
418                 echo "$error" >&2
419                 Exit_error err_build_fail;
420         fi
421
422         # make small dump cache
423         rpm_dump_cache=`echo "$rpm_dump" | awk '
424                 $2 ~ /^SOURCEURL/ {print}
425                 $2 ~ /^PATCHURL/  {print}
426                 $2 ~ /^nosource/ {print}
427                 $2 ~ /^PACKAGE_/ {print}
428         '`
429
430         update_shell_title "cache_rpm_dump: OK!"
431 }
432
433 rpm_dump () {
434         if [ -z "$rpm_dump_cache" ] ; then
435                 echo "internal error: cache_rpm_dump not called! (missing %prep?)" 1>&2
436         fi
437         echo "$rpm_dump_cache"
438 }
439
440 get_icons()
441 {
442         update_shell_title "get icons"
443         ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
444         if [ -z "$ICONS" ]; then
445                 return
446         fi
447
448         rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
449 }
450
451 parse_spec()
452 {
453         update_shell_title "parsing specfile"
454         if [ -n "$DEBUG" ]; then
455                 set -x;
456                 set -v;
457         fi
458
459         # icons are needed for successful spec parse
460         get_icons;
461
462         cd $SPECS_DIR
463         cache_rpm_dump
464
465         if [ "$NOSRCS" != "yes" ]; then
466                 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
467         fi
468
469         if (rpm_dump | grep -qEi ":.*nosource.*1"); then
470                 FAIL_IF_NO_SOURCES="no"
471         fi
472
473         PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
474         ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
475         PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3}')
476         PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3}')
477         PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3}')
478
479         if [ -n "$BE_VERBOSE" ]; then
480                 echo "- Sources :  `nourl $SOURCES`"
481                 if [ -n "$PATCHES" ]; then
482                         echo "- Patches :  `nourl $PATCHES`"
483                 else
484                         echo "- Patches :  *no patches needed*"
485                 fi
486                 if [ -n "$ICONS" ]; then
487                         echo "- Icon    :  `nourl $ICONS`"
488                 else
489                         echo "- Icon    :  *no package icon*"
490                 fi
491                 echo "- Name    : $PACKAGE_NAME"
492                 echo "- Version : $PACKAGE_VERSION"
493                 echo "- Release : $PACKAGE_RELEASE"
494         fi
495
496         update_shell_title "parse_spec: OK!"
497 }
498
499 Exit_error()
500 {
501         if [ -n "$DEBUG" ]; then
502                 set -x;
503                 set -v;
504         fi
505
506         cd "$__PWD"
507
508         case "$1" in
509                 "err_no_spec_in_cmdl" )
510                         remove_build_requires
511                         echo "ERROR: spec file name not specified.";
512                         exit 2 ;;
513                 "err_no_spec_in_repo" )
514                         remove_build_requires
515                         echo "Error: spec file not stored in CVS repo.";
516                         exit 3 ;;
517                 "err_no_source_in_repo" )
518                         remove_build_requires
519                         echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
520                         exit 4 ;;
521                 "err_build_fail" )
522                         remove_build_requires
523                         echo "Error: package build failed. (${2:-no more info})";
524                         exit 5 ;;
525                 "err_no_package_data" )
526                         remove_build_requires
527                         echo "Error: couldn't get out package name/version/release from spec file."
528                         exit 6 ;;
529                 "err_tag_exists" )
530                         remove_build_requires
531                         echo "Tag ${2} already exists (spec release: ${3}).";
532                         exit 9 ;;
533                 "err_fract_rel" )
534                         remove_build_requires
535                         echo "Release ${2} not integer and not a snapshot.";
536                         exit 10 ;;
537                 "err_branch_exists" )
538                         remove_build_requires
539                         echo "Tree branch already exists (${2}).";
540                         exit 11 ;;
541
542         esac
543         echo "Unknown error."
544         exit 100
545 }
546
547 init_builder()
548 {
549         if [ -n "$DEBUG" ]; then
550                 set -x;
551                 set -v;
552         fi
553
554         if [ "$NOINIT" != "yes" ] ; then
555                 SOURCE_DIR="`eval $RPM $RPMOPTS --eval '%{_sourcedir}'`"
556                 SPECS_DIR="`eval $RPM $RPMOPTS --eval '%{_specdir}'`"
557         else
558                 SOURCE_DIR="."
559                 SPECS_DIR="."
560         fi
561
562         __PWD="`pwd`"
563 }
564
565 get_spec()
566 {
567
568         update_shell_title "get_spec"
569
570         if [ -n "$DEBUG" ]; then
571                 set -x;
572                 set -v;
573         fi
574
575         cd "$SPECS_DIR"
576         if [ ! -f "$SPECFILE" ]; then
577                 SPECFILE="`basename $SPECFILE .spec`.spec";
578         fi
579         if [ "$NOCVSSPEC" != "yes" ]; then
580
581                 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
582                         echo "Warning: No CVS access defined - using local .spec file"
583                         NOCVSSPEC="yes"
584                 fi
585
586                 cvsup "$SPECFILE" || Exit_error err_no_spec_in_repo
587         fi
588
589         if [ ! -f "$SPECFILE" ]; then
590                 Exit_error err_no_spec_in_repo;
591         fi
592
593         if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
594                 chmod $CHMOD_MODE $SPECFILE
595         fi
596         unset OPTIONS
597         [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
598
599         set_spec_target
600 }
601
602 find_mirror()
603 {
604         cd "$SPECS_DIR"
605         local url="$1"
606         if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
607                 cvs update mirrors >&2
608         fi
609
610         IFS="|"
611         local origin mirror name rest ol prefix
612         while read origin mirror name rest; do
613                 # skip comments and empty lines
614                 if [ -z "$origin" ] || [[ $origin == \#* ]]; then
615                         continue
616                 fi
617                 ol=`echo -n "$origin"|wc -c`
618                 prefix="`echo -n "$url" | head -c $ol`"
619                 if [ "$prefix" = "$origin" ] ; then
620                         suffix="`echo "$url"|cut -b $((ol+1))-`"
621                         echo -n "$mirror$suffix"
622                         return 0
623                 fi
624         done < mirrors
625         echo "$url"
626 }
627
628 # Warning: unpredictable results if same URL used twice
629 src_no ()
630 {
631         cd $SPECS_DIR
632         rpm_dump | \
633         grep "SOURCEURL[0-9]*[  ]*$1""[         ]*$" | \
634         sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
635         head -n 1 | xargs
636 }
637
638 src_md5()
639 {
640         [ "$NO5" = "yes" ] && return
641         no=$(src_no "$1")
642         [ -z "$no" ] && return
643         cd $SPECS_DIR
644         local md5
645
646         if [ -f additional-md5sums ]; then
647                 local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
648                 if [ -z "$spec_rev" ]; then
649                         spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
650                 fi
651                 local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
652                 md5=$(grep -s -v '^#' additional-md5sums | \
653                 grep -E "[      ]$(basename "$1")[      ]+${spec}([     ,]|\$)" | \
654                 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
655                 grep -E '^[0-9a-f]{32}$')
656
657                 if [ "$md5" ]; then
658                         if [ $(echo "$md5" | wc -l) != 1 ] ; then
659                                 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
660                         fi
661                         echo "$md5" | tail -n 1
662                         return
663                 fi
664         fi
665
666         source_md5=`grep -i "#[         ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://'`
667         if [ -n "$source_md5" ]; then
668                 echo $source_md5
669         else
670                 # we have empty SourceX-md5, but it is still possible
671                 # that we have NoSourceX-md5 AND NoSource: X
672                 nosource_md5=`grep -i "#[        ]*NoSource$no-md5[      ]*:" $SPECFILE | sed -e 's/.*://'`
673                 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[     ]*$no$" $SPECFILE`" ] ; then
674                         echo $nosource_md5
675                 fi
676         fi
677 }
678
679 distfiles_path ()
680 {
681         echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
682 }
683
684 distfiles_url ()
685 {
686         echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
687 }
688
689 distfiles_attic_url ()
690 {
691         echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
692 }
693
694 good_md5 ()
695 {
696         md5=$(src_md5 "$1")
697         [ "$md5" = "" ] || \
698         [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
699 }
700
701 good_size ()
702 {
703         size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)"
704         [ -n "$size" -a "$size" -gt 0 ]
705 }
706
707 cvsignore_df ()
708 {
709         if [ "$CVSIGNORE_DF" != "yes" ]; then
710                 return
711         fi
712         cvsignore=${SOURCE_DIR}/.cvsignore
713         if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
714                 echo "$1" >> $cvsignore
715         fi
716 }
717
718 cvsup()
719 {
720         update_shell_title "cvsup"
721         local OPTIONS="up "
722         if [ -n "$CVSROOT" ]; then
723                 OPTIONS="-d $CVSROOT $OPTIONS"
724         fi
725
726         if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
727                 OPTIONS="$OPTIONS -A"
728         else
729                 if [ -n "$CVSDATE" ]; then
730                         OPTIONS="$OPTIONS -D $CVSDATE"
731                 fi
732                 if [ -n "$CVSTAG" ]; then
733                         OPTIONS="$OPTIONS -r $CVSTAG"
734                 fi
735         fi
736
737         local result=1
738         local retries_counter=0
739         if [ $# = 1 ]; then
740                 update_shell_title "cvsup: $*"
741         else
742                 update_shell_title "cvsup: $# files"
743         fi
744         while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
745                 retries_counter=$(( $retries_counter + 1 ))
746                 output=$(LC_ALL=C cvs $OPTIONS "$@" 2>&1)
747                 result=$?
748                 [ -n "$output" ] && echo "$output"
749                 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
750                         echo "Trying again [$*]... ($retries_counter)"
751                         update_shell_title "cvsup: retry #$retries_counter"
752                         sleep 2
753                         continue
754                 else
755                         break
756                 fi
757         done
758         update_shell_title "cvsup: done!"
759         return $result
760 }
761
762 update_md5()
763 {
764         if [ $# -eq 0 ]; then
765                 return
766         fi
767
768         update_shell_title "update md5"
769         if [ -n "$DEBUG" ]; then
770                 set -x;
771                 set -v;
772         fi
773
774         cd "$SOURCE_DIR"
775
776         # pass 1: check files to be fetched
777         local todo
778         local need_files
779         for i in "$@"; do
780                 local fp=$(nourl "$i")
781                 local srcno=$(src_no "$i")
782                 if [ -n "$UPDATE5" ]; then
783                         if [ -n "$ADD5" ]; then
784                                 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
785                                 grep -qiE '^#[  ]*Source'$srcno'-md5[   ]*:' $SPECS_DIR/$SPECFILE && continue
786                         else
787                                 grep -qiE '^#[  ]*Source'$srcno'-md5[   ]*:' $SPECS_DIR/$SPECFILE || continue
788                         fi
789                 fi
790                 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
791                         need_files="$need_files $i"
792                 fi
793         done
794
795         # pass 1a: get needed files
796         if [ "$need_files" ]; then
797                 get_files $need_files
798         fi
799
800         # pass 2: proceed with md5 adding or updating
801         for i in "$@"; do
802                 local fp=$(nourl "$i")
803                 local srcno=$(src_no "$i")
804                 if [ -n "$UPDATE5" ] && \
805                         ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
806                         [ -z "$(grep -E -i '^NoSource[  ]*:[    ]*'$i'([        ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
807                         grep -q -i -E '^#[      ]*source'$srcno'-md5[   ]*:' $SPECS_DIR/$SPECFILE )
808                 then
809                         echo "Updating source-$srcno md5."
810                         md5=$(md5sum "$fp" | cut -f1 -d' ')
811                         perl -i -ne '
812                         print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
813                         print "# Source'$srcno'-md5:\t'$md5'\n"
814                         if /^Source'$srcno'\s*:\s+/;
815                         ' \
816                         $SPECS_DIR/$SPECFILE
817                 fi
818         done
819 }
820
821 check_md5()
822 {
823         update_shell_title "check md5"
824
825         for i in "$@"; do
826                 if good_md5 "$i" && good_size "$i"; then
827                         continue
828                 fi
829
830                 echo "MD5 sum mismatch or 0 size.  Use -U to refetch sources,"
831                 echo "or -5 to update md5 sums, if you're sure files are correct."
832                 Exit_error err_no_source_in_repo $i
833         done
834 }
835
836 get_files()
837 {
838         update_shell_title "get_files"
839
840         if [ -n "$DEBUG" ]; then
841                 set -x;
842                 set -v;
843         fi
844
845         if [ $# -gt 0 ]; then
846                 cd "$SOURCE_DIR"
847
848                 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
849                         echo "Warning: No CVS access defined for SOURCES"
850                         NOCVS="yes"
851                 fi
852
853                 local nc=0
854                 local get_files_cvs=""
855                 for i in "$@"; do
856                         nc=$((nc + 1))
857                         local cvsup=0
858                         SHELL_TITLE_PREFIX="get_files[$nc/$#]"
859                         update_shell_title "$i"
860                         local fp=`nourl "$i"`
861                         if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
862                                 continue
863                         fi
864
865                         FROM_DISTFILES=0
866                         local srcmd5=$(src_md5 "$i")
867
868                         # we know if source/patch is present in cvs/distfiles
869                         # - has md5 (in distfiles)
870                         # - in cvs... ideas?
871
872                         # CHECK: local file didn't exist or always cvs up (first) requested.
873                         if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
874                                 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
875                                         echo "Warning: no URL given for $i"
876                                 fi
877
878                                 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
879                                         if good_md5 "$i" && good_size "$i"; then
880                                                 echo "$fp having proper md5sum already exists"
881                                                 continue
882                                         fi
883                                         target="$fp"
884                                         url=$(distfiles_url "$i")
885                                         url_attic=$(distfiles_attic_url "$i")
886                                         FROM_DISTFILES=1
887                                         # is $url local file?
888                                         if [[ "$url" = [./]* ]]; then
889                                                 update_shell_title "${GETLOCAL%% *}: $url"
890                                                 ${GETLOCAL} $url $target
891                                         else
892                                                 if [ -z "$NOMIRRORS" ]; then
893                                                         url="`find_mirror "$url"`"
894                                                 fi
895                                                 update_shell_title "${GETURI%% *}: $url"
896                                                 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
897                                                 if [ "`echo $url | grep -E 'ftp://'`" ]; then
898                                                         update_shell_title "${GETURI2%% *}: $url"
899                                                         ${GETURI2} ${OUTFILEOPT} "$target" "$url"
900                                                 fi
901                                         fi
902
903                                         # is it empty file?
904                                         if [ ! -s "$target" ]; then
905                                                 rm -f "$target"
906                                                 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
907                                                         update_shell_title "${GETLOCAL%% *}: $url_attic"
908                                                         ${GETLOCAL} $url_attic $target
909                                                 else
910                                                         if [ -z "$NOMIRRORS" ]; then
911                                                                 url_attic="`find_mirror "$url_attic"`"
912                                                         fi
913                                                         update_shell_title "${GETURI%% *}: $url_attic"
914                                                         ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
915                                                         if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
916                                                                 update_shell_title "${GETURI2%% *}: $url_attic"
917                                                                 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
918                                                         fi
919                                                 fi
920                                         fi
921
922                                         if [ -s "$target" ]; then
923                                                 cvsignore_df $target
924                                         else
925                                                 rm -f "$target"
926                                                 FROM_DISTFILES=0
927                                         fi
928                                 elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
929                                         if [ $# -gt 1 ]; then
930                                                 get_files_cvs="$get_files_cvs $fp"
931                                                 update_shell_title "$fp (will cvs up later)"
932                                                 cvsup=1
933                                         else
934                                                 cvsup $fp
935                                         fi
936                                 fi
937
938                                 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
939                                         if [ -z "$NOMIRRORS" ]; then
940                                                 im="`find_mirror "$i"`"
941                                         else
942                                                 im="$i"
943                                         fi
944                                         update_shell_title "${GETURI%% *}: $im"
945                                         ${GETURI} "$im" || \
946                                         if [ "`echo $im | grep -E 'ftp://'`" ]; then
947                                                 update_shell_title "${GETURI2%% *}: $im"
948                                                 ${GETURI2} "$im"
949                                         fi
950                                 fi
951
952                                 if [ "$cvsup" = 1 ]; then
953                                         continue
954                                 fi
955
956                         fi
957
958                         # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
959                         if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
960                                 Exit_error err_no_source_in_repo $i;
961                         fi
962
963                         # we check md5 here just only to refetch immediately
964                         if good_md5 "$i" && good_size "$i"; then
965                                 :
966                         elif [ "$FROM_DISTFILES" = 1 ]; then
967                                 # wrong md5 from distfiles: remove the file and try again
968                                 # but only once ...
969                                 echo "MD5 sum mismatch. Trying full fetch."
970                                 FROM_DISTFILES=2
971                                 rm -f $target
972                                 update_shell_title "${GETURI%% *}: $url"
973                                 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
974                                 if [ "`echo $url | grep -E 'ftp://'`" ]; then
975                                         update_shell_title "${GETURI2%% *}: $url"
976                                         ${GETURI2} ${OUTFILEOPT} "$target" "$url"
977                                 fi
978                                 if [ ! -s "$target" ]; then
979                                         rm -f "$target"
980                                         update_shell_title "${GETURI%% *}: $url_attic"
981                                         ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
982                                         if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
983                                                 update_shell_title "${GETURI2%% *}: $url_attic"
984                                                 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
985                                         fi
986                                 fi
987                                 test -s "$target" || rm -f "$target"
988                         fi
989                 done
990                 SHELL_TITLE_PREFIX=""
991
992                 if [ "$get_files_cvs" ]; then
993                         cvsup $get_files_cvs
994                 fi
995
996                 if [ "$CHMOD" = "yes" ]; then
997                         CHMOD_FILES="`nourl "$@"`"
998                         if [ -n "$CHMOD_FILES" ]; then
999                                 chmod $CHMOD_MODE $CHMOD_FILES
1000                         fi
1001                 fi
1002         fi
1003 }
1004
1005 make_tagver() {
1006         if [ -n "$DEBUG" ]; then
1007                 set -x;
1008                 set -v;
1009         fi
1010
1011         # Check whether first character of PACKAGE_NAME is legal for tag name
1012         if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1013                 TAG_PREFIX=tag_
1014         fi
1015         TAGVER=$TAG_PREFIX$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
1016         # Remove #kernel.version_release from TAGVER because tagging sources
1017         # could occur with different kernel-headers than kernel-headers used at build time.
1018         TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
1019         echo -n "$TAGVER"
1020 }
1021
1022 tag_files()
1023 {
1024         TAG_FILES="$@"
1025
1026         if [ -n "$DEBUG" ]; then
1027                 set -x;
1028                 set -v;
1029         fi
1030
1031         echo "Version: $PACKAGE_VERSION"
1032         echo "Release: $PACKAGE_RELEASE"
1033
1034         TAGVER=`make_tagver`
1035
1036         if [ "$TAG_VERSION" = "yes" ]; then
1037                 echo "CVS tag: $TAGVER"
1038         fi
1039         if [ -n "$TAG" ]; then
1040                 echo "CVS tag: $TAG"
1041         fi
1042
1043         local OPTIONS="tag $CVS_FORCE"
1044         if [ -n "$CVSROOT" ]; then
1045                 OPTIONS="-d $CVSROOT $OPTIONS"
1046         fi
1047
1048         cd "$SOURCE_DIR"
1049         local tag_files
1050         for i in $TAG_FILES; do
1051                 # don't tag files stored on distfiles
1052                 [ -n "`src_md5 $i`" ] && continue
1053                 local fp=`nourl "$i"`
1054                 if [ -f "$fp" ]; then
1055                         tag_files="$tag_files $fp"
1056                 else
1057                         Exit_error err_no_source_in_repo $i
1058                 fi
1059         done
1060
1061         if [ "$tag_files" ]; then
1062                 if [ "$TAG_VERSION" = "yes" ]; then
1063                         update_shell_title "tag sources: $TAGVER"
1064                         cvs $OPTIONS $TAGVER $tag_files
1065                 fi
1066                 if [ -n "$TAG" ]; then
1067                         update_shell_title "tag sources: $TAG"
1068                         cvs $OPTIONS $TAG $tag_files
1069                 fi
1070         fi
1071
1072         cd "$SPECS_DIR"
1073         if [ "$TAG_VERSION" = "yes" ]; then
1074                 update_shell_title "tag spec: $TAGVER"
1075                 cvs $OPTIONS $TAGVER $SPECFILE
1076         fi
1077         if [ -n "$TAG" ]; then
1078                 update_shell_title "tag spec: $TAG"
1079                 cvs $OPTIONS $TAG $SPECFILE
1080         fi
1081 }
1082
1083 branch_files()
1084 {
1085         TAG=$1
1086         echo "CVS branch tag: $TAG"
1087         shift;
1088
1089         TAG_FILES="$@"
1090
1091         if [ -n "$DEBUG" ]; then
1092                 set -x;
1093                 set -v;
1094         fi
1095
1096         local OPTIONS="tag $CVS_FORCE -b"
1097         if [ -n "$CVSROOT" ]; then
1098                 OPTIONS="-d $CVSROOT $OPTIONS"
1099         fi
1100         cd "$SOURCE_DIR"
1101         local tag_files
1102         for i in $TAG_FILES; do
1103                 local fp=`nourl "$i"`
1104                 if [ -f "$fp" ]; then
1105                         tag_files="$tag_files $fp"
1106                 else
1107                         Exit_error err_no_source_in_repo $i
1108                 fi
1109         done
1110         if [ "$tag_files" ]; then
1111                 cvs $OPTIONS $TAG $tag_files
1112         fi
1113
1114         cd "$SPECS_DIR"
1115         cvs $OPTIONS $TAG $SPECFILE
1116 }
1117
1118
1119
1120 build_package()
1121 {
1122         update_shell_title "build_package"
1123         if [ -n "$DEBUG" ]; then
1124                 set -x;
1125                 set -v;
1126         fi
1127
1128         cd "$SPECS_DIR"
1129
1130         if [ -n "$TRY_UPGRADE" ]; then
1131                 update_shell_title "build_package: try_upgrade"
1132                 if [ -n "$FLOAT_VERSION" ]; then
1133                         TNOTIFY=`./pldnotify.awk $SPECFILE -n` || exit 1
1134                 else
1135                         TNOTIFY=`./pldnotify.awk $SPECFILE` || exit 1
1136                 fi
1137
1138                 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
1139
1140                 if [ -n "$TNEWVER" ]; then
1141                         TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1142                         echo "New version found, updating spec file to version " $TNEWVER
1143                         if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1144                                 cp -f $SPECFILE $SPECFILE.bak
1145                         fi
1146                         chmod +w $SPECFILE
1147                         eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
1148                         eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE"
1149                         parse_spec;
1150                         NODIST="yes" get_files $SOURCES $PATCHES;
1151                         UPDATE5="yes" update_md5 $SOURCES
1152
1153                         unset TOLDVER TNEWVER TNOTIFY
1154                 fi
1155         fi
1156         cd "$SPECS_DIR"
1157
1158         case "$COMMAND" in
1159                 build )
1160                         BUILD_SWITCH="-ba" ;;
1161                 build-binary )
1162                         BUILD_SWITCH="-bb" ;;
1163                 build-source )
1164                         BUILD_SWITCH="-bs --nodeps" ;;
1165                 build-prep )
1166                         BUILD_SWITCH="-bp --nodeps" ;;
1167         esac
1168
1169         update_shell_title "build_package: $COMMAND"
1170         if [ -n "$LOGFILE" ]; then
1171                 LOG=`eval echo $LOGFILE`
1172                 if [ -d "$LOG" ]; then
1173                         echo "Log file $LOG is a directory."
1174                         echo "Parse error in the spec?"
1175                         Exit_error err_build_fail;
1176                 fi
1177                 if [ -n "$LASTLOG_FILE" ]; then
1178                         echo "LASTLOG=$LOG" > $LASTLOG_FILE
1179                 fi
1180                 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
1181                 (time eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
1182                 RETVAL=`cat $RES_FILE`
1183                 rm $RES_FILE
1184                 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1185                         if [ "$RETVAL" -eq "0" ]; then
1186                                 mv $LOG $LOGDIROK
1187                         else
1188                                 mv $LOG $LOGDIRFAIL
1189                         fi
1190                 fi
1191         else
1192                 eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE
1193                 RETVAL=$?
1194         fi
1195         if [ "$RETVAL" -ne "0" ]; then
1196                 if [ -n "$TRY_UPGRADE" ]; then
1197                         echo "\n!!! Package with new version cannot be built automagically\n"
1198                         if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1199                                 mv -f $SPECFILE.bak $SPECFILE
1200                         fi
1201                 fi
1202                 Exit_error err_build_fail;
1203         fi
1204         unset BUILD_SWITCH
1205 }
1206
1207 nourl()
1208 {
1209         echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1210 }
1211
1212 install_required_packages()
1213 {
1214         run_poldek -vi $1
1215         return $?
1216 }
1217
1218 find_spec_bcond() {
1219         # taken from find-spec-bcond, but with just getting the list
1220         local SPEC="$1"
1221         # quick revert hint: '$RPMBUILD --bcond $SPEC'
1222         awk -F"\n" '
1223         /^%changelog/ { exit }
1224         /_with(out)?_[_a-zA-Z0-9]+/{
1225                 match($0, /_with(out)?_[_a-zA-Z0-9]+/);
1226                 print substr($0, RSTART, RLENGTH);
1227         }
1228         /^%bcond_with/{
1229                 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1230                 bcond = substr($0, RSTART +5 , RLENGTH -5);
1231                 gsub(/[ \t]+/,"_",bcond);
1232                 print bcond
1233         }' $SPEC | LC_ALL=C sort -u
1234 }
1235
1236 set_bconds_values()
1237 {
1238         update_shell_title "set bcond values"
1239
1240         AVAIL_BCONDS_WITHOUT=""
1241         AVAIL_BCONDS_WITH=""
1242         if `grep -q ^%bcond ${SPECFILE}`; then
1243                 BCOND_VERSION="NEW"
1244         elif `egrep -q ^#\ *_with ${SPECFILE}`; then
1245                 BCOND_VERSION="OLD"
1246         else
1247                 return
1248         fi
1249
1250         local bcond_avail=$(find_spec_bcond $SPECFILE)
1251
1252         # expand bconds from ~/.bcondrc
1253         # The file structure is like gentoo's package.use:
1254         # ---
1255         # * -selinux
1256         # samba -mysql -pgsql
1257         # w32codec-installer license_agreement
1258         # php +mysqli
1259         # ---
1260         if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then
1261                 SN=${SPECFILE%%\.spec}
1262
1263                 local bcondrc=$HOME/.bcondrc
1264                 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1265
1266                 while read pkg flags; do
1267                         # ignore comments
1268                         [[ "$pkg" == \#* ]] && continue
1269
1270                         # any package or current package?
1271                         if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1272                                 for flag in $flags; do
1273                                         local opt=${flag#[+-]}
1274
1275                                         # use only flags which are in this package.
1276                                         if [[ $bcond_avail = *${opt}* ]]; then
1277                                                 if [[ $flag = -* ]]; then
1278                                                         if [[ $BCOND != *--with?${opt}* ]]; then
1279                                                                 BCOND="$BCOND --without $opt"
1280                                                         fi
1281                                                 else
1282                                                         if [[ $BCOND != *--without?${opt}* ]]; then
1283                                                                 BCOND="$BCOND --with $opt"
1284                                                         fi
1285                                                 fi
1286                                         fi
1287                                 done
1288                         fi
1289                 done < $bcondrc
1290                 update_shell_title "parse ~/.bcondrc: DONE!"
1291         fi
1292
1293         update_shell_title "parse bconds"
1294         case "${BCOND_VERSION}" in
1295                 NONE)
1296                         :
1297                         ;;
1298                 OLD)
1299                         echo "Warning: This spec has old style bconds. Fix it || die."
1300                         for opt in `echo "$bcond_avail" | grep ^_without_`
1301                         do
1302                                 AVAIL_BCOND_WITHOUT=${opt#_without_}
1303                                 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
1304                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1305                                 else
1306                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1307                                 fi
1308                         done
1309
1310                         for opt in `echo "$bcond_avail" | grep ^_with_`
1311                         do
1312                                 AVAIL_BCOND_WITH=${opt#_with_}
1313                                 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
1314                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1315                                 else
1316                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1317                                 fi
1318                         done
1319                         ;;
1320                 NEW)
1321                         local cond_type="" # with || without
1322                         for opt in $bcond_avail; do
1323                                 case "$opt" in
1324                                         _without)
1325                                                 cond_type="without"
1326                                                 ;;
1327                                         _with)
1328                                                 cond_type="with"
1329                                                 ;;
1330                                         _without_*)
1331                                                 AVAIL_BCOND_WITHOUT=${opt#_without_}
1332                                                 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
1333                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1334                                                 else
1335                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1336                                                 fi
1337                                                 ;;
1338                                         _with_*)
1339                                                 AVAIL_BCOND_WITH=${opt#_with_}
1340                                                 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
1341                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1342                                                 else
1343                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1344                                                 fi
1345                                                 ;;
1346                                         *)
1347                                                 case "$cond_type" in
1348                                                         with)
1349                                                                 cond_type=''
1350                                                                 AVAIL_BCOND_WITH="$opt"
1351                                                                 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
1352                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1353                                                                 else
1354                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1355                                                                 fi
1356                                                                 ;;
1357                                                         without)
1358                                                                 cond_type=''
1359                                                                 AVAIL_BCOND_WITHOUT="$opt"
1360                                                                 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
1361                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1362                                                                 else
1363                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1364                                                                 fi
1365                                                                 ;;
1366                                                 esac
1367                                                 ;;
1368                                 esac
1369                         done
1370                         ;;
1371         esac
1372 }
1373
1374 run_sub_builder()
1375 {
1376         package_name="${1}"
1377         update_shell_title "run_sub_builder $package_name"
1378         #
1379         # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1380         # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1381         # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1382         # jakby nie bylo tego kawalka kodu.
1383         #
1384         # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1385         #         Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1386         #
1387         #
1388         # y0shi.
1389
1390         parent_spec_name=''
1391
1392         # Istnieje taki spec? ${package}.spec
1393         if [ -f "${SPECS_DIR}/${package}.spec" ]; then
1394                 parent_spec_name=${package}.spec
1395         elif [ -f "${SPECS_DIR}/`echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
1396                 parent_spec_name="`echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g`.spec"
1397         else
1398                 for provides_line in `grep ^Provides:.*$package  ${SPECS_DIR} -R`
1399                 do
1400                         echo $provides_line
1401                 done
1402         fi
1403
1404         if [ "${parent_spec_name}" != "" ]; then
1405                 spawn_sub_builder $parent_spec_name
1406         fi
1407         NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1408 }
1409
1410 spawn_sub_builder()
1411 {
1412         package_name="${1}"
1413         update_shell_title "spawn_sub_builder $package_name"
1414
1415         sub_builder_opts=''
1416         if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
1417                 sub_builder_opts="${sub_builder_opts} -R"
1418         fi
1419         if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
1420                 sub_builder_opts="${sub_builder_opts} -RB"
1421         elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
1422                 sub_builder_opts="${sub_builder_opts} -FRB"
1423         fi
1424         if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
1425                 sub_builder_opts="${sub_builder_opts} -Upi"
1426         fi
1427
1428         cd "${SPECS_DIR}"
1429         ./builder ${sub_builder_opts} "$@"
1430 }
1431
1432 remove_build_requires()
1433 {
1434         if [ "$INSTALLED_PACKAGES" != "" ]; then
1435                 case "$REMOVE_BUILD_REQUIRES" in
1436                         "force")
1437                                 run_poldek --noask -ve $INSTALLED_PACKAGES
1438                                 ;;
1439                         "nice")
1440                                 run_poldek --ask -ve $INSTALLED_PACKAGES
1441                                 ;;
1442                         *)
1443                                 echo You may want to manually remove following BuildRequires fetched:
1444                                 echo $INSTALLED_PACKAGES
1445                                 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
1446                                 ;;
1447                 esac
1448         fi
1449 }
1450
1451 display_bconds()
1452 {
1453         if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
1454                 if [ "$BCOND" != "" ]; then
1455                         echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
1456                         echo -ne "$BCOND"
1457                 else
1458                         echo -ne "\nNo conditional flags passed"
1459                 fi
1460                 echo -ne "\n\nfrom available:\n"
1461                 echo -ne "--with   :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1462         fi
1463 }
1464
1465 display_branches()
1466 {
1467         if [ "$NOCVSSPEC" != "yes" ]; then
1468                 echo -ne "Available branches: "
1469                 cvs status -v "${SPECFILE}" | awk '!/Sticky Tag:/ && /\(branch:/ { print $1 } ' | xargs
1470         fi
1471 }
1472
1473 # checks a given list of packages/files/provides agains current rpmdb.
1474 # outputs all dependencies whcih current rpmdb doesn't satisfy.
1475 # input can be either STDIN or parameters
1476 _rpm_prov_check()
1477 {
1478         local DEPS
1479
1480         if [ "$#" -gt 0 ]; then
1481                 DEPS="$@"
1482         else
1483                 DEPS=$(cat)
1484         fi
1485
1486         DEPS=$(rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1487
1488         # packages
1489         echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1490
1491         # other deps (files)
1492         echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1493 }
1494
1495 # checks if given package/files/provides exists in rpmdb.
1496 # inout can be either stdin or parameters
1497 # returns packages wchi hare present in the rpmdb
1498 _rpm_cnfl_check()
1499 {
1500         local DEPS
1501
1502         if [ "$#" -gt 0 ]; then
1503                 DEPS="$@"
1504         else
1505                 DEPS=$(cat)
1506         fi
1507
1508         rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1509 }
1510
1511 fetch_build_requires()
1512 {
1513         if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1514                 update_shell_title "fetch build requires"
1515                 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1516                         local CONF=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1517                         local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1518
1519                         update_shell_title "poldek: update indexes"
1520                         if [ -n "$CONF" ] || [ -n "$DEPS" ]; then
1521                                 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1522                         fi
1523                         if [ -n "$CONF" ]; then
1524                                 update_shell_title "uninstall conflicting packages: $CONF"
1525                                 echo "Trying to uninstall conflicting packages ($CONF):"
1526                                 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CONF
1527                         fi
1528
1529                 while [ "$DEPS" ]; do
1530                                 update_shell_title "install deps: $DEPS"
1531                                 echo "Trying to install dependencies ($DEPS):"
1532                                 local log=.${SPECFILE}_poldek.log
1533                                 $SU_SUDO /usr/bin/poldek --caplookup -uGq $DEPS | tee $log
1534                                 failed=$(awk -F: '/^error:/{print $2}' $log)
1535                                 rm -f $log
1536                                 local ok
1537                                 if [ -n "$failed" ]; then
1538                                         for package in $failed; do
1539                                                 # FIXME: sanitise, deps could be not .spec files
1540                                                 spawn_sub_builder -bb $package && ok="$ok $package"
1541                                         done
1542                                         DEPS="$ok"
1543                                 else
1544                                         DEPS=""
1545                                 fi
1546                 done
1547                         return
1548                 fi
1549
1550                 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1551                 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1552                 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1553                 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1554                 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1555                 for package_item in `cat $SPECFILE|grep -B100000 ^%changelog|grep -v ^#|grep BuildRequires|grep -v ^-|sed -e "s/^.*BuildRequires://g"|awk '{print $1}'|sed -e s,perl\(,perl-,g -e s,::,-,g -e s,\(.*\),,g -e s,%{,,g -e s,},,g|grep -v OpenGL-devel|sed -e s,sh-utils,coreutils,g -e s,fileutils,coreutils,g -e s,textutils,coreutils,g -e s,kgcc_package,gcc,g -e s,\),,g`
1556                 do
1557                         package_item="`echo $package_item|sed -e s,rpmbuild,rpm-build,g |sed -e s,__perl,perl,g |sed -e s,gasp,binutils-gasp,g -e s,binutils-binutils,binutils,g -e s,apxs,apache,g|sed -e s,apache\(EAPI\)-devel,apache-devel,g -e s,kernel-headers\(netfilter\),kernel-headers,g -e s,awk,mawk,g -e s,mmawk,mawk,g -e s,motif,openmotif,g -e s,openopenmotif,openmotif,g`"
1558                         GO="yes"
1559                         package=`basename "$package_item"|sed -e "s/}$//g"`
1560                         COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1561                         mach=`uname -m`
1562
1563                         COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1564                         if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1565                                 if [ "$COND_ARCH_TST" != "" ] && [ "`echo $COND_ARCH_TST|sed -e "s/i.86/ix86/g"`" != "`echo $mach|sed -e "s/i.86/ix86/g"`" ]; then
1566                                         GO="yes"
1567                                 fi
1568                         # bcond:
1569                         else
1570                                 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1571                                 GO=""
1572                                 # %{without}
1573                                 if `echo $COND_TST|grep -q 'without_'`; then
1574                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
1575                                         if `echo $COND_TST|grep -q !`; then
1576                                                 COND_STATE="with"
1577                                         else
1578                                                 COND_STATE="wout"
1579                                         fi
1580                                         COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1581                                         COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1582                                         if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
1583                                                 COND_ARGV="wout"
1584                                         else
1585                                                 COND_ARGV="with"
1586                                         fi
1587                                 # %{with}
1588                                 elif `echo $COND_TST|grep -q 'with_'`; then
1589                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
1590                                         if `echo $COND_TST|grep -q !`; then
1591                                                 COND_STATE="wout"
1592                                         else
1593                                                 COND_STATE="with"
1594                                         fi
1595                                         COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1596                                         COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1597                                         if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
1598                                                 COND_ARGV="with"
1599                                         else
1600                                                 COND_ARGV="wout"
1601                                         fi
1602                                 fi
1603                                 RESULT="${COND_STATE}-${COND_ARGV}"
1604                                 case "$RESULT" in
1605                                         "with-wout" | "wout-with" )
1606                                                 GO=""
1607                                                 ;;
1608                                         "wout-wout" | "with-with" )
1609                                                 GO="yes"
1610                                                 ;;
1611                                         * )
1612                                                 echo "Action '$RESULT' was not defined for package '$package_item'"
1613                                                 GO="yes"
1614                                                 ;;
1615                                 esac
1616                         fi
1617
1618                         if [ "$GO" = "yes" ]; then
1619                                 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1620                                         echo "Testing if $package has subrequirements..."
1621                                         run_poldek -t -i $package --dumpn=".$package-req.txt"
1622                                         if [ -f ".$package-req.txt" ]; then
1623                                                 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1624                                                 do
1625                                                         if [ "$package_name" = "$package" ]; then
1626                                                                 echo -ne "Installing BuildRequired package:\t$package_name\n"
1627                                                                 update_shell_title "Installing BuildRequired package: ${package_name}"
1628                                                                 install_required_packages $package;
1629                                                         else
1630                                                                 echo -ne "Installing (sub)Required package:\t$package_name\n"
1631                                                                 update_shell_title "Installing (sub)Required package: ${package_name}"
1632                                                                 install_required_packages $package_name;
1633                                                         fi
1634                                                         case $? in
1635                                                                 0)
1636                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1637                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1638                                                                         ;;
1639                                                                 *)
1640                                                                         echo "Attempting to run spawn sub - builder..."
1641                                                                         echo -ne "Package installation failed:\t$package_name\n"
1642                                                                         run_sub_builder $package_name
1643                                                                         if [ $? -eq 0 ]; then
1644                                                                                 install_required_packages $package_name;
1645                                                                                 case $? in
1646                                                                                         0)
1647                                                                                                 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1648                                                                                                 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1649                                                                                                 ;;
1650                                                                                         *)
1651                                                                                                 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1652                                                                                                 ;;
1653                                                                                 esac
1654                                                                         fi
1655                                                                         ;;
1656                                                         esac
1657                                                 done
1658                                                 rm -f ".$package-req.txt"
1659                                         else
1660                                                 echo "Attempting to run spawn sub - builder..."
1661                                                 echo -ne "Package installation failed:\t$package\n"
1662                                                 run_sub_builder $package
1663                                                 if [ $? -eq 0 ]; then
1664                                                         install_required_packages $package;
1665                                                         case $? in
1666                                                                 0)
1667                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1668                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1669                                                                         ;;
1670                                                                 *)
1671                                                                         NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1672                                                                         ;;
1673                                                         esac
1674                                                 fi
1675                                         fi
1676                                 else
1677                                         echo "Package $package is already installed. BuildRequirement satisfied."
1678                                 fi
1679                         fi
1680                 done
1681                 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1682                         echo "Unable to install following packages and their dependencies:"
1683                         for pkg in "$NOT_INSTALLED_PACKAGES"
1684                         do
1685                                 echo $pkg
1686                         done
1687                         remove_build_requires
1688                         exit 8
1689                 fi
1690         fi
1691 }
1692
1693 init_rpm_dir() {
1694
1695         TOP_DIR="`eval $RPM $RPMOPTS --eval '%{_topdir}'`"
1696         CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
1697
1698         mkdir -p $TOP_DIR/{RPMS,BUILD,SRPMS}
1699         cd $TOP_DIR
1700         cvs -d $CVSROOT co SOURCES/.cvsignore SPECS/{mirrors,adapter{,.awk},fetchsrc_request,builder,repackage.sh}
1701
1702         init_builder
1703
1704         echo "To checkout *all* .spec files:"
1705         echo "- remove $SPECS_DIR/CVS/Entries.Static"
1706         echo "- run cvs up in $SPECS_DIR dir"
1707
1708         echo ""
1709         echo "To commit with your developer account:"
1710         echo "- edit $SPECS_DIR/CVS/Root"
1711         echo "- edit $SOURCE_DIR/CVS/Root"
1712 }
1713
1714 #---------------------------------------------
1715 # main()
1716
1717 if [ "$#" = 0 ]; then
1718         usage;
1719         exit 1
1720 fi
1721
1722 while test $# -gt 0
1723 do
1724         case "${1}" in
1725                 -5 | --update-md5 )
1726                         COMMAND="update_md5";
1727                         NODIST="yes"
1728                         NOCVSSPEC="yes"
1729                         UPDATE5="yes"
1730                         shift ;;
1731                 -a5 | --add-md5 )
1732                         COMMAND="update_md5";
1733                         NODIST="yes"
1734                         NOCVS="yes"
1735                         NOCVSSPEC="yes"
1736                         UPDATE5="yes"
1737                         ADD5="yes"
1738                         shift ;;
1739                 -n5 | --no-md5 )
1740                         NO5="yes"
1741                         shift ;;
1742                 -D | --debug )
1743                         DEBUG="yes"; shift ;;
1744                 -V | --version )
1745                         COMMAND="version"; shift ;;
1746                 -a | --as_anon )
1747                         CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1748                 -b | -ba | --build )
1749                         COMMAND="build"; shift ;;
1750                 -bb | --build-binary )
1751                         COMMAND="build-binary"; shift ;;
1752                 -bs | --build-source )
1753                         COMMAND="build-source"; shift ;;
1754                 -bp | --build-prep )
1755                         COMMAND="build-prep"; shift ;;
1756                 -B | --branch )
1757                         COMMAND="branch"; shift; TAG="${1}"; shift;;
1758                 -c | --clean )
1759                         CLEAN="--clean --rmspec --rmsource"; shift ;;
1760                 -cf | --cvs-force )
1761                         CVS_FORCE="-F"; shift;;
1762                 -d | --cvsroot )
1763                         shift; CVSROOT="${1}"; shift ;;
1764                 -g | --get )
1765                         COMMAND="get"; shift ;;
1766                 -h | --help )
1767                         COMMAND="usage"; shift ;;
1768                 --http )
1769                         PROTOCOL="http"; shift ;;
1770                 -l | --logtofile )
1771                         shift; LOGFILE="${1}"; shift ;;
1772                 -ni| --nice )
1773                         shift; DEF_NICE_LEVEL=${1}; shift ;;
1774                 -ske | --skip-existing-files)
1775                         SKIP_EXISTING_FILES="yes"; shift ;;
1776                 -m | --mr-proper )
1777                         COMMAND="mr-proper"; shift ;;
1778                 -nc | --no-cvs )
1779                         NOCVS="yes"; shift ;;
1780                 -ncs | --no-cvs-specs )
1781                         NOCVSSPEC="yes"; shift ;;
1782                 -nd | --no-distfiles )
1783                         NODIST="yes"; shift ;;
1784                 -nm | --no-mirrors )
1785                         NOMIRRORS="yes"; shift ;;
1786                 -nu | --no-urls )
1787                         NOURLS="yes"; shift ;;
1788                 -ns | --no-srcs )
1789                         NOSRCS="yes"; shift ;;
1790                 -ns0 | --no-source0 )
1791                         NOSOURCE0="yes"; shift ;;
1792                 -nn | --no-net )
1793                         NOCVS="yes"
1794                         NOCVSSPEC="yes"
1795                         NODIST="yes"
1796                         NOMIRRORS="yes"
1797                         NOURLS="yes"
1798                         NOSRCS="yes"
1799                         ALWAYS_CVSUP="no"
1800                         shift;;
1801                 --no-init )
1802                         NOINIT="yes"
1803                         shift;;
1804                 --opts )
1805                         shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
1806                 --nopatch | -np )
1807                         shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
1808                 --with | --without )
1809                         case $GROUP_BCONDS in
1810                                 "yes")
1811                                         COND=${1}
1812                                         shift
1813                                         while ! `echo ${1}|grep -qE '(^-|spec)'`
1814                                         do
1815                                                 BCOND="$BCOND $COND $1"
1816                                                 shift
1817                                         done;;
1818                                 "no")
1819                                         if [[ "$2" = *,* ]]; then
1820                                                 for a in $(echo "$2" | tr , ' '); do
1821                                                         BCOND="$BCOND $1 $a"
1822                                                 done
1823                                         else
1824                                                 BCOND="$BCOND $1 $2"
1825                                         fi
1826                                         shift 2 ;;
1827                         esac
1828                         ;;
1829                 --target )
1830                         shift; TARGET="${1}"; shift ;;
1831                 --target=* )
1832                         TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
1833                 -q | --quiet )
1834                         QUIET="--quiet"; shift ;;
1835                 --date )
1836                         CVSDATE="${2}"; shift 2 ;;
1837                 -r | --cvstag )
1838                         shift; CVSTAG="${1}"; shift ;;
1839                 -R | --fetch-build-requires)
1840                         FETCH_BUILD_REQUIRES="yes"
1841                         NOT_INSTALLED_PACKAGES=
1842                         shift ;;
1843                 -RB | --remove-build-requires)
1844                         REMOVE_BUILD_REQUIRES="nice"
1845                         shift ;;
1846                 -FRB | --force-remove-build-requires)
1847                         REMOVE_BUILD_REQUIRES="force"
1848                         shift ;;
1849                 -sd | --sources-distfiles)
1850                         COMMAND="list-sources-distfiles"
1851                         shift ;;
1852                 -sdp | --sources-distfiles-paths)
1853                         COMMAND="list-sources-distfiles-paths"
1854                         shift ;;
1855                 -sf | --sources-files)
1856                         COMMAND="list-sources-files"
1857                         shift ;;
1858                 -sp | --sources-paths)
1859                         COMMAND="list-sources-local-paths"
1860                         shift ;;
1861                 -su | --sources-urls)
1862                         COMMAND="list-sources-urls"
1863                         shift ;;
1864                 -Tvs | --tag-version-stable )
1865                         COMMAND="tag";
1866                         TAG="STABLE"
1867                         TAG_VERSION="yes"
1868                         shift;;
1869                 -Ts | --tag-stable )
1870                         COMMAND="tag";
1871                         TAG="STABLE"
1872                         TAG_VERSION="no"
1873                         shift;;
1874                 -Tv | --tag-version )
1875                         COMMAND="tag";
1876                         TAG=""
1877                         TAG_VERSION="yes"
1878                         shift;;
1879                 -Tp | --tag-prefix )
1880                         TAG_PREFIX="$2"
1881                         shift 2;;
1882                 -tt | --test-tag )
1883                         TEST_TAG="yes"
1884                         shift;;
1885                 -T | --tag )
1886                         COMMAND="tag";
1887                         shift
1888                         TAG="$1"
1889                         TAG_VERSION="no"
1890                         shift;;
1891                 -ir | --integer-release-only )
1892                         INTEGER_RELEASE="yes"
1893                         shift;;
1894                 -U | --update )
1895                         COMMAND="update_md5"
1896                         UPDATE="yes"
1897                         NOCVSSPEC="yes"
1898                         NODIST="yes"
1899                         UPDATE5="yes"
1900                         shift ;;
1901                 -Upi | --update-poldek-indexes )
1902                         UPDATE_POLDEK_INDEXES="yes"
1903                         shift ;;
1904                 --init-rpm-dir)
1905                         COMMAND="init_rpm_dir";
1906                         shift ;;
1907                 -u | --try-upgrade )
1908                         TRY_UPGRADE="1"; shift ;;
1909                 -un | --try-upgrade-with-float-version )
1910                         TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1911                 -v | --verbose )
1912                         BE_VERBOSE="1"; shift ;;
1913                 --define)
1914                         shift
1915                         MACRO="${1}"
1916                         shift
1917                         if echo "${MACRO}" | grep -q '\W'; then
1918                                 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
1919                         else
1920                                 VALUE="${1}"
1921                                 shift
1922                                 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1923                         fi
1924                         ;;
1925                 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
1926                         SHOW_BCONDS="yes"
1927                         shift
1928                         ;;
1929                 --nodeps)
1930                         shift
1931                         RPMOPTS="${RPMOPTS} --nodeps"
1932                         ;;
1933                 -debug)
1934                         RPMBUILDOPTS="${RPMBUILDOPTS} --debug"; shift ;;
1935                 * )
1936                         SPECFILE="${1}"
1937                         # check if specname was passed as specname:cvstag
1938                         if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
1939                                 CVSTAG="${SPECFILE##*:}";
1940                                 SPECFILE="${SPECFILE%%:*}";
1941                         fi
1942                         shift
1943         esac
1944 done
1945
1946 if [ -z "$CVSTAG" ]; then
1947         CVSTAG=$(awk -vSPECFILE="${SPECFILE%.spec}.spec" -F/ '$2 == SPECFILE && $6 ~ /^T/{print substr($6, 2)}' CVS/Entries)
1948         if [ "$CVSTAG" ]; then
1949                 echo "builder: Stick tag $CVSTAG active. Use -r TAGNAME to override."
1950         fi
1951 elif [ "$CVSTAG" = "HEAD" ]; then
1952         # assume -r HEAD is same as -A
1953         CVSTAG=""
1954 fi
1955
1956 if [ -n "$DEBUG" ]; then
1957         set -x;
1958         set -v;
1959 fi
1960
1961 if [ -n "$TARGET" ]; then
1962         case "$RPMBUILD" in
1963                 "rpmbuild")
1964                         TARGET_SWITCH="--target $TARGET" ;;
1965                 "rpm")
1966                         TARGET_SWITCH="--target=$TARGET" ;;
1967         esac
1968 fi
1969
1970 if [ "$SCHEDTOOL" != "no" ]; then
1971         NICE_COMMAND="$SCHEDTOOL"
1972 else
1973         NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
1974 fi
1975
1976 update_shell_title "$COMMAND"
1977 case "$COMMAND" in
1978         "build" | "build-binary" | "build-source" | "build-prep" )
1979                 init_builder;
1980                 if [ -n "$SPECFILE" ]; then
1981                         get_spec;
1982                         parse_spec;
1983                         set_bconds_values;
1984                         display_bconds;
1985                         display_branches;
1986                         [ X"$SHOW_BCONDS" = X"yes" ] && exit 0
1987                         fetch_build_requires;
1988                         if [ "$INTEGER_RELEASE" = "yes" ]; then
1989                                 echo "Checking release $PACKAGE_RELEASE..."
1990                                 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
1991                                         Exit_error err_fract_rel "$PACKAGE_RELEASE"
1992                                 fi
1993                         fi
1994
1995                         if [ -n "$TEST_TAG" ]; then
1996                                 TAGVER=`make_tagver`
1997                                 echo "Searching for tag $TAGVER..."
1998                                 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1999                                 if [ -n "$TAGREL" ]; then
2000                                         Exit_error err_tag_exists "$TAGVER" "$TAGREL"
2001                                 fi
2002
2003                                 # - do not allow to build from HEAD when XX-branch exists
2004                                 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto-\([a-zA-Z]\+\)-.*#\1#g')
2005                                 if [ "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2006                                         TAG_BRANCH="${TREE_PREFIX}-branch"
2007                                         TAG_STATUS=$(cvs status -v $SPECFILE | grep -Ei "${TAG_BRANCH}.+(branch: [0-9.]+)")
2008                                         if [ -n "$TAG_STATUS" -a "$CVSTAG" = "HEAD" ]; then
2009                                                 Exit_error err_branch_exists "$TAG_STATUS"
2010                                         fi
2011                                 fi
2012                         fi
2013
2014                         if [ -n "$NOSOURCE0" ] ; then
2015                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2016                         fi
2017                         get_files $SOURCES $PATCHES
2018                         check_md5 $SOURCES
2019                         build_package;
2020                         if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
2021                                 run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
2022                         fi
2023                         remove_build_requires;
2024                 else
2025                         Exit_error err_no_spec_in_cmdl;
2026                 fi
2027                 ;;
2028         "branch" )
2029                 init_builder;
2030                 if [ -n "$SPECFILE" ]; then
2031                         get_spec;
2032                         parse_spec;
2033                         # don't fetch sources from remote locations
2034                         new_SOURCES=""
2035                         for file in $SOURCES; do
2036                                 [ -n "`src_md5 $file`" ] && continue
2037                                 new_SOURCES="$new_SOURCES $file"
2038                         done
2039                         SOURCES="$new_SOURCES"
2040                         get_files $SOURCES $PATCHES
2041                         check_md5 $SOURCES
2042                         branch_files $TAG $SOURCES $PATCHES $ICONS
2043                 else
2044                         Exit_error err_no_spec_in_cmdl;
2045                 fi
2046                 ;;
2047         "get" )
2048                 init_builder;
2049                 if [ -n "$SPECFILE" ]; then
2050                         get_spec;
2051                         parse_spec
2052
2053                         if [ -n "$NOSOURCE0" ] ; then
2054                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2055                         fi
2056                         get_files $SOURCES $PATCHES
2057                         check_md5 $SOURCES
2058                 else
2059                         Exit_error err_no_spec_in_cmdl;
2060                 fi
2061                 ;;
2062         "update_md5" )
2063                 init_builder;
2064                 if [ -n "$SPECFILE" ]; then
2065                         get_spec;
2066                         parse_spec
2067
2068                         if [ -n "$NOSOURCE0" ] ; then
2069                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2070                         fi
2071                         update_md5 $SOURCES
2072                 else
2073                         Exit_error err_no_spec_in_cmdl;
2074                 fi
2075                 ;;
2076         "tag" )
2077                 NOURLS=1
2078                 NODIST="yes"
2079                 init_builder;
2080                 if [ -n "$SPECFILE" ]; then
2081                         get_spec;
2082                         parse_spec;
2083
2084                         # don't fetch sources from remote locations
2085                         new_SOURCES=""
2086                         for file in $SOURCES; do
2087                                 [ -n "`src_md5 $file`" ] && continue
2088                                 new_SOURCES="$new_SOURCES $file"
2089                         done
2090                         SOURCES="$new_SOURCES"
2091                         get_files $SOURCES $PATCHES
2092                         check_md5 $SOURCES
2093                         tag_files $SOURCES $PATCHES $ICONS
2094                 else
2095                         Exit_error err_no_spec_in_cmdl;
2096                 fi
2097                 ;;
2098         "mr-proper" )
2099                 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
2100                 ;;
2101         "list-sources-files" )
2102                 init_builder
2103                 NOCVSSPEC="yes"
2104                 DONT_PRINT_REVISION="yes"
2105                 get_spec
2106                 parse_spec
2107                 for SAP in $SOURCES $PATCHES; do
2108                         echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2109                 done
2110                 ;;
2111         "list-sources-urls" )
2112                 init_builder
2113                 NOCVSSPEC="yes"
2114                 DONT_PRINT_REVISION="yes"
2115                 get_spec
2116                 parse_spec
2117                 SAPS="$SOURCES $PATCHES"
2118                 for SAP in $SAPS ; do
2119                         echo $SAP
2120                 done
2121                 ;;
2122         "list-sources-local-paths" )
2123                 init_builder
2124                 NOCVSSPEC="yes"
2125                 DONT_PRINT_REVISION="yes"
2126                 get_spec
2127                 parse_spec
2128                 for SAP in $SOURCES $PATCHES; do
2129                         echo $SOURCE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2130                 done
2131                 ;;
2132         "list-sources-distfiles-paths" )
2133                 init_builder
2134                 NOCVSSPEC="yes"
2135                 DONT_PRINT_REVISION="yes"
2136                 get_spec
2137                 parse_spec
2138                 for SAP in $SOURCES $PATCHES; do
2139                         if [ -n "$(src_md5 "$SAP")" ]; then
2140                                 distfiles_path "$SAP"
2141                         fi
2142                 done
2143                 ;;
2144         "list-sources-distfiles" )
2145                 init_builder
2146                 NOCVSSPEC="yes"
2147                 DONT_PRINT_REVISION="yes"
2148                 get_spec
2149                 parse_spec
2150                 for SAP in $SOURCES $PATCHES; do
2151                         if [ -n "$(src_md5 "$SAP")" ]; then
2152                                 distfiles_url "$SAP"
2153                         fi
2154                 done
2155                 ;;
2156         "init_rpm_dir")
2157                 init_rpm_dir
2158                 ;;
2159         "usage" )
2160                 usage;;
2161         "version" )
2162                 echo "$VERSION";;
2163 esac
2164 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2165         rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2166 fi
2167 cd "$__PWD"
2168
2169 # vi:syntax=sh:ts=4:sw=4:noet
This page took 0.185512 seconds and 4 git commands to generate.