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