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