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-2003 Free Penguins".
15 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
31 ALLWAYS_CVSUP=${ALLWAYS_CVSUP:-"yes"}
32 if [ -s CVS/Root ]; then
33 CVSROOT=$(cat CVS/Root)
35 CVSROOT=${CVSROOT:-""}
37 # Example: LOGFILE='../log.$PACKAGE_NAME'
38 # Yes, you can use variable name! Note _single_ quotes!
57 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
58 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
63 CVS_SERVER="cvs.pld-linux.org"
64 DISTFILES_SERVER="ftp://distfiles.pld-linux.org"
68 FAIL_IF_NO_SOURCES="yes"
70 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
71 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
74 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
82 if [ -f ~/etc/builderrc ]; then
84 elif [ -f ~/.builderrc ]; then
88 #---------------------------------------------
93 if [ -n "$DEBUG" ]; then set -xv; fi
95 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
97 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
98 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
99 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
100 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
101 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
102 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
103 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
104 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
107 - update md5 comments in spec, implies -nd
108 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd
109 -D, --debug - enable script debugging mode,
110 -V, --version - output builder version
111 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
113 --build - get all files from CVS repo or HTTP/FTP and build
114 package from <package>.spec,
116 - get all files from CVS repo or HTTP/FTP and build
117 binary only package from <package>.spec,
119 --build-source - get all files from CVS repo or HTTP/FTP and only
120 pack them into src.rpm,
121 -B, --branch - add branch
122 -c, --clean - clean all temporarily created files (in BUILD,
123 SOURCES, SPECS and \$RPM_BUILD_ROOT),
124 -d <cvsroot>, --cvsroot <cvsroot>
126 --define <macro> <value>
127 - define a macro <macro> with value <value>,
128 -g, --get - get <package>.spec and all related files from
129 CVS repo or HTTP/FTP,
130 -h, --help - this message,
131 -l <logfile>, --logtofile <logfile>
133 -m, --mr-proper - only remove all files related to spec file and
135 -nc, --no-cvs - don't download sources from CVS, if source URL is
138 - don't check specs in CVS
140 - don't download from distfiles
141 -nm, --no-mirrors - don't download from mirror, if source URL is given,
142 -nu, --no-urls - don't try to download from FTP/HTTP location,
143 -ns, --no-srcs - don't download Sources
145 - don't download Source0
147 - additional options for rpm
148 -q, --quiet - be quiet,
150 - build package using resources from specified CVS
152 -r <cvstag>, --cvstag <cvstag>
153 - build package using resources from specified CVS
155 -T <cvstag> , --tag <cvstag>
156 - add cvs tag <cvstag> for files,
157 -Tvs, --tag-version-stable
158 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
159 -Tvn, --tag-version-nest
160 - add cvs tags NEST and NAME-VERSION-RELESE for files,
162 - add cvs tag STABLE for files,
164 - add cvs tag NEST for files,
166 - add cvs tag NAME-VERSION-RELESE for files,
167 -v, --verbose - be verbose,
169 - check version, and try to upgrade package
170 -un, --try-upgrade-with-float-version
171 - as above, but allow float version
173 - refetch sources, don't use distfiles, and update md5
175 --with/--without <feature>
176 - conditional build package depending on
177 %_with_<feature>/%_without_<feature> macro
184 if [ -n "$DEBUG" ]; then
190 if [ "$NOSRCS" != "yes" ]; then
191 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
193 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
194 FAIL_IF_NO_SOURCES="no"
197 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
198 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
199 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
200 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
201 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
203 if [ -n "$BE_VERBOSE" ]; then
204 echo "- Sources : `nourl $SOURCES`"
205 if [ -n "$PATCHES" ]; then
206 echo "- Patches : `nourl $PATCHES`"
208 echo "- Patches : *no patches needed*"
210 if [ -n "$ICONS" ]; then
211 echo "- Icon : `nourl $ICONS`"
213 echo "- Icon : *no package icon*"
215 echo "- Name : $PACKAGE_NAME"
216 echo "- Version : $PACKAGE_VERSION"
217 echo "- Release : $PACKAGE_RELEASE"
223 if [ -n "$DEBUG" ]; then
231 "err_no_spec_in_cmdl" )
232 echo "ERROR: spec file name not specified.";
234 "err_no_spec_in_repo" )
235 echo "Error: spec file not stored in CVS repo.";
237 "err_no_source_in_repo" )
238 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
241 echo "Error: package build failed. (${2:-no more info})";
248 if [ -n "$DEBUG" ]; then
253 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
254 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
261 if [ -n "$DEBUG" ]; then
266 if [ "$NOCVSSPEC" != "yes" ]; then
271 if [ -n "$CVSROOT" ]; then
272 OPTIONS="-d $CVSROOT $OPTIONS"
274 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
275 echo "warning: No cvs access defined - using local .spec file"
280 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
281 OPTIONS="$OPTIONS -A"
283 if [ -n "$CVSDATE" ]; then
284 OPTIONS="$OPTIONS -D $CVSDATE"
286 if [ -n "$CVSTAG" ]; then
287 OPTIONS="$OPTIONS -r $CVSTAG"
293 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
294 retries_counter=$(( $retries_counter + 1 ))
295 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
297 [ -n "$output" ] && echo "$output"
298 if [ "$result" -ne "0" ]; then
299 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
300 echo "Trying again [$SPECFILE]... ($retries_counter)"
304 Exit_error err_no_spec_in_repo;
308 if [ ! -f "$SPECFILE" ]; then
309 Exit_error err_no_spec_in_repo;
312 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
313 chmod $CHMOD_MODE $SPECFILE
316 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
323 if [ ! -f "mirrors" ] ; then
324 cvs update mirrors >&2
328 while read origin mirror name rest; do
329 ol=`echo -n "$origin"|wc -c`
330 prefix="`echo -n "$url" | head -c $ol`"
331 if [ "$prefix" = "$origin" ] ; then
332 suffix="`echo "$url"|cut -b $ol-`"
333 echo -n "$mirror$suffix"
343 $RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | \
344 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
345 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
352 [ -z "$no" ] && return
354 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
359 echo "$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
366 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
373 if [ -n "$DEBUG" ]; then
378 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
382 if [ -n "$CVSROOT" ]; then
383 OPTIONS="-d $CVSROOT $OPTIONS"
385 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
386 echo "warning: No cvs access defined for SOURCES"
390 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
391 OPTIONS="$OPTIONS -A"
393 if [ -n "$CVSDATE" ]; then
394 OPTIONS="$OPTIONS -D $CVSDATE"
396 if [ -n "$CVSTAG" ]; then
397 OPTIONS="$OPTIONS -r $CVSTAG"
400 for i in $GET_FILES; do
401 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
402 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
403 echo "Warning: no URL given for $i"
406 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
407 if good_md5 "$i"; then
408 echo "$(nourl "$i") having proper md5sum already exists"
412 url=$(distfiles_url "$i")
413 if [ `echo $url | grep -E '^(\.|/)'` ] ; then
414 ${GETLOCAL} $url $target
416 if [ -z "$NOMIRRORS" ] ; then
417 url="`find_mirror "$url"`"
419 ${GETURI} -O "$target" "$url" || \
420 if [ `echo $url | grep -E 'ftp://'` ]; then
421 ${GETURI2} -O "$target" "$url"
423 test -s "$target" || rm -f "$target"
425 elif [ -z "$(src_md5 "$i")" ] && \
426 ( [ -z "$NOCVS" ] || echo $i | grep -qvE '(ftp|http|https)://' ); then
429 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
430 retries_counter=$(( $retries_counter + 1 ))
431 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
433 [ -n "$output" ] && echo "$output"
434 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
435 echo "Trying again [`nourl $i`]... ($retries_counter)"
444 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
445 if [ -z "$NOMIRRORS" ] ; then
446 i="`find_mirror "$i"`"
449 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
454 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
455 Exit_error err_no_source_in_repo $i;
456 elif [ -n "$UPDATE5" ] && \
457 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
458 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'[^0-9]' $SPECS_DIR/$SPECFILE)" ] ) || \
459 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
461 echo "Updating source-$srcno md5."
462 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
463 perl -i -ne 'print "# Source'$srcno'-md5:\t'$md5'\n"
464 if /^Source'$srcno'\s*:\s+/;
465 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i' \
469 if good_md5 "$i"; then
472 echo "MD5 sum mismatch. Use -U to refetch sources,"
473 echo "or -5 to update md5 sums, if you're sure files are correct."
474 Exit_error err_no_source_in_repo $i
479 if [ "$CHMOD" = "yes" ]; then
480 CHMOD_FILES="`nourl $GET_FILES`"
481 if [ -n "$CHMOD_FILES" ]; then
482 chmod $CHMOD_MODE $CHMOD_FILES
493 if [ -n "$DEBUG" ]; then
498 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
499 echo $PACKAGE_VERSION
500 echo $PACKAGE_RELEASE
501 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
502 if [ "$TAG_VERSION" = "yes" ]; then
503 echo "CVS tag: $TAGVER"
505 if [ -n "$TAG" ]; then
510 if [ -n "$CVSROOT" ]; then
511 OPTIONS="-d $CVSROOT $OPTIONS"
515 for i in $TAG_FILES; do
516 if [ -f `nourl $i` ]; then
517 if [ "$TAG_VERSION" = "yes" ]; then
518 cvs $OPTIONS $TAGVER `nourl $i`
520 if [ -n "$TAG" ]; then
521 cvs $OPTIONS $TAG `nourl $i`
524 Exit_error err_no_source_in_repo $i
529 if [ "$TAG_VERSION" = "yes" ]; then
530 cvs $OPTIONS $TAGVER $SPECFILE
532 if [ -n "$TAG" ]; then
533 cvs $OPTIONS $TAG $SPECFILE
543 echo "CVS branch tag: $TAG"
548 if [ -n "$DEBUG" ]; then
553 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
556 if [ -n "$CVSROOT" ]; then
557 OPTIONS="-d $CVSROOT $OPTIONS"
560 for i in $TAG_FILES; do
561 if [ -f `nourl $i` ]; then
562 cvs $OPTIONS $TAG `nourl $i`
564 Exit_error err_no_source_in_repo $i
568 cvs $OPTIONS $TAG $SPECFILE
578 if [ -n "$DEBUG" ]; then
585 if [ -n "$TRY_UPGRADE" ]; then
587 if [ -n "FLOAT_VERSION" ]; then
588 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
590 TNOTIFY=`./pldnotify.awk $SPECFILE`
593 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
595 if [ -n "$TNEWVER" ]; then
597 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
599 echo "New version found, updating spec file to version " $TNEWVER
601 cp -f $SPECFILE $SPECFILE.bak
605 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
606 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
610 get_files "$SOURCES $PATCHES";
612 unset TOLDVER TNEWVER TNOTIFY
622 BUILD_SWITCH="-ba" ;;
624 BUILD_SWITCH="-bb" ;;
626 BUILD_SWITCH="-bs --nodeps" ;;
628 if [ -n "$LOGFILE" ]; then
629 if [ -n "$CVSTAG" ]; then
630 LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
634 LOG=`eval echo $LOGFILE`
635 if [ -n "$LASTLOG_FILE" ]; then
636 echo "LASTLOG=$LOG" > $LASTLOG_FILE
638 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
639 (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
640 RETVAL=`cat $RES_FILE`
642 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
643 if [ "$RETVAL" -eq "0" ]; then
650 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
654 if [ "$RETVAL" -ne "0" ]; then
656 if [ -n "$TRY_UPGRADE" ]; then
657 echo "\n!!! Package with new version cannot be build automagically\n"
658 mv -f $SPECFILE.bak $SPECFILE
661 Exit_error err_build_fail;
669 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
671 #---------------------------------------------
674 if [ "$#" = 0 ]; then
679 while test $# -gt 0 ; do
694 DEBUG="yes"; shift ;;
696 COMMAND="version"; shift ;;
698 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
700 COMMAND="build"; shift ;;
701 -bb | --build-binary )
702 COMMAND="build-binary"; shift ;;
703 -bs | --build-source )
704 COMMAND="build-source"; shift ;;
706 COMMAND="branch"; shift; TAG="${1}"; shift;;
708 CLEAN="--clean --rmspec --rmsource"; shift ;;
710 shift; CVSROOT="${1}"; shift ;;
712 COMMAND="get"; shift ;;
714 COMMAND="usage"; shift ;;
716 shift; LOGFILE="${1}"; shift ;;
718 shift; DEF_NICE_LEVEL=${1}; shift ;;
720 COMMAND="mr-proper"; shift ;;
722 NOCVS="yes"; shift ;;
723 -ncs | --no-cvs-specs )
724 NOCVSSPEC="yes"; shift ;;
725 -nd | --no-distfiles )
726 NODIST="yes"; shift ;;
728 NOMIRRORS="yes"; shift ;;
730 NOURLS="yes"; shift ;;
732 NOSRCS="yes"; shift ;;
733 -ns0 | --no-source0 )
734 NOSOURCE0="yes"; shift ;;
736 shift; RPMOPTS="${1}"; shift ;;
738 BCOND="$BCOND $1 $2" ; shift 2 ;;
740 QUIET="--quiet"; shift ;;
742 CVSDATE="${2}"; shift 2 ;;
744 shift; CVSTAG="${1}"; shift ;;
745 -Tvs | --tag-version-stable )
750 -Tvn | --tag-version-nest )
765 -Tv | --tag-version )
783 TRY_UPGRADE="1"; shift ;;
784 -un | --try-upgrade-with-float-version )
785 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
787 BE_VERBOSE="1"; shift ;;
793 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
796 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
800 if [ -n "$DEBUG" ]; then
806 "build" | "build-binary" | "build-source" )
808 if [ -n "$SPECFILE" ]; then
812 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
813 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
814 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
815 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
817 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
818 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
822 if [ -n "$ICONS" ]; then
826 if [ -n "$NOSOURCE0" ] ; then
827 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
829 get_files "$SOURCES $PATCHES";
832 Exit_error err_no_spec_in_cmdl;
837 if [ -n "$SPECFILE" ]; then
840 if [ -n "$ICONS" ]; then
844 get_files $SOURCES $PATCHES;
845 branch_files $TAG "$SOURCES $PATCHES $ICONS";
847 Exit_error err_no_spec_in_cmdl;
852 if [ -n "$SPECFILE" ]; then
855 if [ -n "$ICONS" ]; then
859 if [ -n "$NOSOURCE0" ] ; then
860 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
862 get_files $SOURCES $PATCHES
864 Exit_error err_no_spec_in_cmdl;
869 if [ -n "$SPECFILE" ]; then
872 if [ -n "$ICONS" ]; then
876 get_files $SOURCES $PATCHES;
877 tag_files "$SOURCES $PATCHES $ICONS";
879 Exit_error err_no_spec_in_cmdl;
883 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE