7 # 2 - no spec file name in cmdl parameters
8 # 3 - spec file not stored in repo
9 # 4 - some source, patch or icon files not stored in repo
10 # 5 - package build failed
13 Build package utility from PLD CVS repository
14 V 0.11 (C) 1999-2001 Free Penguins".
15 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
29 ALLWAYS_CVSUP=${ALLWAYS_CVSUP:-"yes"}
30 if [ -s CVS/Root ]; then
31 CVSROOT=$(cat CVS/Root)
33 CVSROOT=${CVSROOT:-""}
35 # Example: LOGFILE='../log.$PACKAGE_NAME'
36 # Yes, you can use variable name! Note _single_ quotes!
55 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
56 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
61 CVS_SERVER="cvs.pld-linux.org"
62 DISTFILES_SERVER="ftp://distfiles.pld-ppc.org"
66 FAIL_IF_NO_SOURCES="yes"
68 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
69 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
71 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
79 if [ -f ~/etc/builderrc ]; then
81 elif [ -f ~/.builderrc ]; then
85 #---------------------------------------------
90 if [ -n "$DEBUG" ]; then set -xv; fi
92 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
94 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
95 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
96 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
97 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
98 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
99 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
100 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
101 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
103 -D, --debug - enable script debugging mode,
104 -V, --version - output builder version
105 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
107 --build - get all files from CVS repo or HTTP/FTP and build
108 package from <package>.spec,
110 - get all files from CVS repo or HTTP/FTP and build
111 binary only package from <package>.spec,
113 --build-source - get all files from CVS repo or HTTP/FTP and only
114 pack them into src.rpm,
115 -B, --branch - add branch
116 -c, --clean - clean all temporarily created files (in BUILD,
117 SOURCES, SPECS and \$RPM_BUILD_ROOT),
118 -d <cvsroot>, --cvsroot <cvsroot>
120 --define <macro> <value>
121 - define a macro <macro> with value <value>,
122 -g, --get - get <package>.spec and all related files from
123 CVS repo or HTTP/FTP,
124 -h, --help - this message,
125 -l <logfile>, --logtofile <logfile>
127 -m, --mr-proper - only remove all files related to spec file and
129 -nc, --no-cvs - don't download sources from CVS, if source URL is
132 - don't check specs in CVS
134 - don't download from distfiles
135 -nm, --no-mirrors - don't download from mirror, if source URL is given,
136 -nu, --no-urls - don't try to download from FTP/HTTP location,
137 -ns, --no-srcs - don't download Sources
139 - don't download Source0
141 - additional options for rpm
142 -q, --quiet - be quiet,
144 - build package using resources from specified CVS
146 -r <cvstag>, --cvstag <cvstag>
147 - build package using resources from specified CVS
149 -T <cvstag> , --tag <cvstag>
150 - add cvs tag <cvstag> for files,
151 -Tvs, --tag-version-stable
152 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
153 -Tvn, --tag-version-nest
154 - add cvs tags NEST and NAME-VERSION-RELESE for files,
156 - add cvs tag STABLE for files,
158 - add cvs tag NEST for files,
160 - add cvs tag NAME-VERSION-RELESE for files,
161 -v, --verbose - be verbose,
163 - check version, and try to upgrade package
164 -un, --try-upgrade-with-float-version
165 - as above, but allow float version
167 - refetch sources (makes sense with -nc -nd)
168 (CVS updates are controlled by ALLWAYS_CVSUP environment
169 variable, distfiles are checked against md5 sum)
170 --with/--without <feature>
171 - conditional build package depending on
172 %_with_<feature>/%_without_<feature> macro
179 if [ -n "$DEBUG" ]; then
185 if [ "$NOSRCS" != "yes" ]; then
186 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
188 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
189 FAIL_IF_NO_SOURCES="no"
192 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
193 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
194 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
195 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
196 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
198 if [ -n "$BE_VERBOSE" ]; then
199 echo "- Sources : `nourl $SOURCES`"
200 if [ -n "$PATCHES" ]; then
201 echo "- Patches : `nourl $PATCHES`"
203 echo "- Patches : *no patches needed*"
205 if [ -n "$ICONS" ]; then
206 echo "- Icon : `nourl $ICONS`"
208 echo "- Icon : *no package icon*"
210 echo "- Name : $PACKAGE_NAME"
211 echo "- Version : $PACKAGE_VERSION"
212 echo "- Release : $PACKAGE_RELEASE"
218 if [ -n "$DEBUG" ]; then
226 "err_no_spec_in_cmdl" )
227 echo "ERROR: spec file name not specified.";
229 "err_no_spec_in_repo" )
230 echo "Error: spec file not stored in CVS repo.";
232 "err_no_source_in_repo" )
233 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
236 echo "Error: package build failed. (${2:-no more info})";
243 if [ -n "$DEBUG" ]; then
248 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
249 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
256 if [ -n "$DEBUG" ]; then
261 if [ "$NOCVSSPEC" != "yes" ]; then
266 if [ -n "$CVSROOT" ]; then
267 OPTIONS="-d $CVSROOT $OPTIONS"
269 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
270 echo "warning: No cvs access defined - using local .spec file"
275 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
276 OPTIONS="$OPTIONS -A"
278 if [ -n "$CVSDATE" ]; then
279 OPTIONS="$OPTIONS -D $CVSDATE"
281 if [ -n "$CVSTAG" ]; then
282 OPTIONS="$OPTIONS -r $CVSTAG"
288 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
289 retries_counter=$(( $retries_counter + 1 ))
290 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
292 [ -n "$output" ] && echo "$output"
293 if [ "$result" -ne "0" ]; then
294 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
295 echo "Trying again [$SPECFILE]... ($retries_counter)"
299 Exit_error err_no_spec_in_repo;
303 if [ ! -f "$SPECFILE" ]; then
304 Exit_error err_no_spec_in_repo;
307 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
308 chmod $CHMOD_MODE $SPECFILE
311 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
318 if [ ! -f "mirrors" ] ; then
319 cvs update mirrors >&2
323 while read origin mirror name rest; do
324 ol=`echo -n "$origin"|wc -c`
325 prefix="`echo -n "$url" | head -c $ol`"
326 if [ "$prefix" = "$origin" ] ; then
327 suffix="`echo "$url"|cut -b $ol-`"
328 echo -n "$mirror$suffix"
338 $RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | \
339 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
340 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
347 [ -z "$no" ] && return
349 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
354 echo "$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')"
361 if [ -n "$DEBUG" ]; then
366 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
370 if [ -n "$CVSROOT" ]; then
371 OPTIONS="-d $CVSROOT $OPTIONS"
373 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
374 echo "warning: No cvs access defined for SOURCES"
378 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
379 OPTIONS="$OPTIONS -A"
381 if [ -n "$CVSDATE" ]; then
382 OPTIONS="$OPTIONS -D $CVSDATE"
384 if [ -n "$CVSTAG" ]; then
385 OPTIONS="$OPTIONS -r $CVSTAG"
388 for i in $GET_FILES; do
389 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
390 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
391 echo "Warning: no URL given for $i"
394 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
395 if [ "$(src_md5 "$i")" = "$(md5sum $(nourl "$i")|sed -e 's/ .*//')" ]; then
396 echo "$(nourl "$i") having proper md5sum already exists"
400 url=$(distfiles_url "$i")
401 if [ -z "$NOMIRRORS" ] ; then
402 url="`find_mirror "$url"`"
404 ${GETURI} -O "$target" "$url" || \
405 if [ `echo $url | grep -E 'ftp://'` ]; then
406 ${GETURI2} -O "$target" "$url"
408 elif [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
411 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
412 retries_counter=$(( $retries_counter + 1 ))
413 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
415 [ -n "$output" ] && echo "$output"
416 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
417 echo "Trying again [`nourl $i`]... ($retries_counter)"
426 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
427 if [ -z "$NOMIRRORS" ] ; then
428 i="`find_mirror "$i"`"
431 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
432 # echo -n "#Source$(src_no $i)-md5: " >> $SPECS_DIR/$SPECFILE.md5
433 # md5sum `echo $i | perl -ne '/.*\/(.*)/; print "$1\n"'` | cut -f1 -d' ' >> $SPECS_DIR/$SPECFILE.md5
436 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
437 Exit_error err_no_source_in_repo $i;
442 if [ "$CHMOD" = "yes" ]; then
443 CHMOD_FILES="`nourl $GET_FILES`"
444 if [ -n "$CHMOD_FILES" ]; then
445 chmod $CHMOD_MODE $CHMOD_FILES
456 if [ -n "$DEBUG" ]; then
461 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
462 echo $PACKAGE_VERSION
463 echo $PACKAGE_RELEASE
464 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
465 if [ "$TAG_VERSION" = "yes" ]; then
466 echo "CVS tag: $TAGVER"
468 if [ -n "$TAG" ]; then
473 if [ -n "$CVSROOT" ]; then
474 OPTIONS="-d $CVSROOT $OPTIONS"
478 for i in $TAG_FILES; do
479 if [ -f `nourl $i` ]; then
480 if [ "$TAG_VERSION" = "yes" ]; then
481 cvs $OPTIONS $TAGVER `nourl $i`
483 if [ -n "$TAG" ]; then
484 cvs $OPTIONS $TAG `nourl $i`
487 Exit_error err_no_source_in_repo $i
492 if [ "$TAG_VERSION" = "yes" ]; then
493 cvs $OPTIONS $TAGVER $SPECFILE
495 if [ -n "$TAG" ]; then
496 cvs $OPTIONS $TAG $SPECFILE
506 echo "CVS branch tag: $TAG"
511 if [ -n "$DEBUG" ]; then
516 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
519 if [ -n "$CVSROOT" ]; then
520 OPTIONS="-d $CVSROOT $OPTIONS"
523 for i in $TAG_FILES; do
524 if [ -f `nourl $i` ]; then
525 cvs $OPTIONS $TAG `nourl $i`
527 Exit_error err_no_source_in_repo $i
531 cvs $OPTIONS $TAG $SPECFILE
541 if [ -n "$DEBUG" ]; then
548 if [ -n "$TRY_UPGRADE" ]; then
550 if [ -n "FLOAT_VERSION" ]; then
551 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
553 TNOTIFY=`./pldnotify.awk $SPECFILE`
556 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
558 if [ -n "$TNEWVER" ]; then
560 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
562 echo "New version found, updating spec file to version " $TNEWVER
564 cp -f $SPECFILE $SPECFILE.bak
568 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
569 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
573 get_files "$SOURCES $PATCHES";
575 unset TOLDVER TNEWVER TNOTIFY
585 BUILD_SWITCH="-ba" ;;
587 BUILD_SWITCH="-bb" ;;
589 BUILD_SWITCH="-bs --nodeps" ;;
591 if [ -n "$LOGFILE" ]; then
592 if [ -n "$CVSTAG" ]; then
593 LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
597 LOG=`eval echo $LOGFILE`
598 if [ -n "$LASTLOG_FILE" ]; then
599 echo "LASTLOG=$LOG" > $LASTLOG_FILE
601 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
602 (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
603 RETVAL=`cat $RES_FILE`
605 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
606 if [ "$RETVAL" -eq "0" ]; then
613 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
617 if [ "$RETVAL" -ne "0" ]; then
619 if [ -n "$TRY_UPGRADE" ]; then
620 echo "\n!!! Package with new version cannot be build automagically\n"
621 mv -f $SPECFILE.bak $SPECFILE
624 Exit_error err_build_fail;
632 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
634 #---------------------------------------------
637 if [ "$#" = 0 ]; then
642 while test $# -gt 0 ; do
645 DEBUG="yes"; shift ;;
647 COMMAND="version"; shift ;;
649 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
651 COMMAND="build"; shift ;;
652 -bb | --build-binary )
653 COMMAND="build-binary"; shift ;;
654 -bs | --build-source )
655 COMMAND="build-source"; shift ;;
657 COMMAND="branch"; shift; TAG="${1}"; shift;;
659 CLEAN="--clean --rmspec --rmsource"; shift ;;
661 shift; CVSROOT="${1}"; shift ;;
663 COMMAND="get"; shift ;;
665 COMMAND="usage"; shift ;;
667 shift; LOGFILE="${1}"; shift ;;
669 shift; DEF_NICE_LEVEL=${1}; shift ;;
671 COMMAND="mr-proper"; shift ;;
673 NOCVS="yes"; shift ;;
674 -ncs | --no-cvs-specs )
675 NOCVSSPEC="yes"; shift ;;
676 -nd | --no-distfiles )
677 NODIST="yes"; shift ;;
679 NOMIRRORS="yes"; shift ;;
681 NOURLS="yes"; shift ;;
683 NOSRCS="yes"; shift ;;
684 -ns0 | --no-source0 )
685 NOSOURCE0="yes"; shift ;;
687 shift; RPMOPTS="${1}"; shift ;;
689 BCOND="$BCOND $1 $2" ; shift 2 ;;
691 QUIET="--quiet"; shift ;;
693 CVSDATE="${2}"; shift 2 ;;
695 shift; CVSTAG="${1}"; shift ;;
696 -Tvs | --tag-version-stable )
701 -Tvn | --tag-version-nest )
716 -Tv | --tag-version )
728 UPDATE="yes"; shift ;;
730 TRY_UPGRADE="1"; shift ;;
731 -un | --try-upgrade-with-float-version )
732 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
734 BE_VERBOSE="1"; shift ;;
740 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
743 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
747 if [ -n "$DEBUG" ]; then
753 "build" | "build-binary" | "build-source" )
755 if [ -n "$SPECFILE" ]; then
759 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
760 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
761 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
762 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
764 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
765 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
769 if [ -n "$ICONS" ]; then
773 if [ -n "$NOSOURCE0" ] ; then
774 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
776 get_files "$SOURCES $PATCHES";
779 Exit_error err_no_spec_in_cmdl;
784 if [ -n "$SPECFILE" ]; then
787 if [ -n "$ICONS" ]; then
791 get_files $SOURCES $PATCHES;
792 branch_files $TAG "$SOURCES $PATCHES $ICONS";
794 Exit_error err_no_spec_in_cmdl;
799 if [ -n "$SPECFILE" ]; then
802 if [ -n "$ICONS" ]; then
806 if [ -n "$NOSOURCE0" ] ; then
807 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
809 get_files $SOURCES $PATCHES
811 Exit_error err_no_spec_in_cmdl;
816 if [ -n "$SPECFILE" ]; then
819 if [ -n "$ICONS" ]; then
823 get_files $SOURCES $PATCHES;
824 tag_files "$SOURCES $PATCHES $ICONS";
826 Exit_error err_no_spec_in_cmdl;
830 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE