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"
73 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
81 if [ -f ~/etc/builderrc ]; then
83 elif [ -f ~/.builderrc ]; then
87 #---------------------------------------------
92 if [ -n "$DEBUG" ]; then set -xv; fi
94 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
96 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
97 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
98 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
99 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
100 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
101 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
102 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
103 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
106 - update md5 comments in spec, implies -nd
107 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd
108 -D, --debug - enable script debugging mode,
109 -V, --version - output builder version
110 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
112 --build - get all files from CVS repo or HTTP/FTP and build
113 package from <package>.spec,
115 - get all files from CVS repo or HTTP/FTP and build
116 binary only package from <package>.spec,
118 --build-source - get all files from CVS repo or HTTP/FTP and only
119 pack them into src.rpm,
120 -B, --branch - add branch
121 -c, --clean - clean all temporarily created files (in BUILD,
122 SOURCES, SPECS and \$RPM_BUILD_ROOT),
123 -d <cvsroot>, --cvsroot <cvsroot>
125 --define <macro> <value>
126 - define a macro <macro> with value <value>,
127 -g, --get - get <package>.spec and all related files from
128 CVS repo or HTTP/FTP,
129 -h, --help - this message,
130 -l <logfile>, --logtofile <logfile>
132 -m, --mr-proper - only remove all files related to spec file and
134 -nc, --no-cvs - don't download sources from CVS, if source URL is
137 - don't check specs in CVS
139 - don't download from distfiles
140 -nm, --no-mirrors - don't download from mirror, if source URL is given,
141 -nu, --no-urls - don't try to download from FTP/HTTP location,
142 -ns, --no-srcs - don't download Sources
144 - don't download Source0
146 - additional options for rpm
147 -q, --quiet - be quiet,
149 - build package using resources from specified CVS
151 -r <cvstag>, --cvstag <cvstag>
152 - build package using resources from specified CVS
154 -T <cvstag> , --tag <cvstag>
155 - add cvs tag <cvstag> for files,
156 -Tvs, --tag-version-stable
157 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
158 -Tvn, --tag-version-nest
159 - add cvs tags NEST and NAME-VERSION-RELESE for files,
161 - add cvs tag STABLE for files,
163 - add cvs tag NEST for files,
165 - add cvs tag NAME-VERSION-RELESE for files,
166 -v, --verbose - be verbose,
168 - check version, and try to upgrade package
169 -un, --try-upgrade-with-float-version
170 - as above, but allow float version
172 - refetch sources, don't use distfiles, and update md5
174 --with/--without <feature>
175 - conditional build package depending on
176 %_with_<feature>/%_without_<feature> macro
183 if [ -n "$DEBUG" ]; then
189 if [ "$NOSRCS" != "yes" ]; then
190 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
192 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
193 FAIL_IF_NO_SOURCES="no"
196 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
197 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
198 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
199 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
200 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
202 if [ -n "$BE_VERBOSE" ]; then
203 echo "- Sources : `nourl $SOURCES`"
204 if [ -n "$PATCHES" ]; then
205 echo "- Patches : `nourl $PATCHES`"
207 echo "- Patches : *no patches needed*"
209 if [ -n "$ICONS" ]; then
210 echo "- Icon : `nourl $ICONS`"
212 echo "- Icon : *no package icon*"
214 echo "- Name : $PACKAGE_NAME"
215 echo "- Version : $PACKAGE_VERSION"
216 echo "- Release : $PACKAGE_RELEASE"
222 if [ -n "$DEBUG" ]; then
230 "err_no_spec_in_cmdl" )
231 echo "ERROR: spec file name not specified.";
233 "err_no_spec_in_repo" )
234 echo "Error: spec file not stored in CVS repo.";
236 "err_no_source_in_repo" )
237 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
240 echo "Error: package build failed. (${2:-no more info})";
247 if [ -n "$DEBUG" ]; then
252 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
253 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
260 if [ -n "$DEBUG" ]; then
265 if [ "$NOCVSSPEC" != "yes" ]; then
270 if [ -n "$CVSROOT" ]; then
271 OPTIONS="-d $CVSROOT $OPTIONS"
273 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
274 echo "warning: No cvs access defined - using local .spec file"
279 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
280 OPTIONS="$OPTIONS -A"
282 if [ -n "$CVSDATE" ]; then
283 OPTIONS="$OPTIONS -D $CVSDATE"
285 if [ -n "$CVSTAG" ]; then
286 OPTIONS="$OPTIONS -r $CVSTAG"
292 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
293 retries_counter=$(( $retries_counter + 1 ))
294 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
296 [ -n "$output" ] && echo "$output"
297 if [ "$result" -ne "0" ]; then
298 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
299 echo "Trying again [$SPECFILE]... ($retries_counter)"
303 Exit_error err_no_spec_in_repo;
307 if [ ! -f "$SPECFILE" ]; then
308 Exit_error err_no_spec_in_repo;
311 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
312 chmod $CHMOD_MODE $SPECFILE
315 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
322 if [ ! -f "mirrors" ] ; then
323 cvs update mirrors >&2
327 while read origin mirror name rest; do
328 ol=`echo -n "$origin"|wc -c`
329 prefix="`echo -n "$url" | head -c $ol`"
330 if [ "$prefix" = "$origin" ] ; then
331 suffix="`echo "$url"|cut -b $ol-`"
332 echo -n "$mirror$suffix"
342 $RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | \
343 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
344 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
351 [ -z "$no" ] && return
353 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
358 echo "$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
365 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
372 if [ -n "$DEBUG" ]; then
377 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
381 if [ -n "$CVSROOT" ]; then
382 OPTIONS="-d $CVSROOT $OPTIONS"
384 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
385 echo "warning: No cvs access defined for SOURCES"
389 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
390 OPTIONS="$OPTIONS -A"
392 if [ -n "$CVSDATE" ]; then
393 OPTIONS="$OPTIONS -D $CVSDATE"
395 if [ -n "$CVSTAG" ]; then
396 OPTIONS="$OPTIONS -r $CVSTAG"
399 for i in $GET_FILES; do
400 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
401 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
402 echo "Warning: no URL given for $i"
405 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
406 if good_md5 "$i"; then
407 echo "$(nourl "$i") having proper md5sum already exists"
411 url=$(distfiles_url "$i")
412 if [ -z "$NOMIRRORS" ] ; then
413 url="`find_mirror "$url"`"
415 ${GETURI} -O "$target" "$url" || \
416 if [ `echo $url | grep -E 'ftp://'` ]; then
417 ${GETURI2} -O "$target" "$url"
419 test -s "$target" || rm -f "$target"
420 elif [ -z "$(src_md5 "$i")" ] && \
421 ( [ -z "$NOCVS" ] || echo $i | grep -qvE '(ftp|http|https)://' ); then
424 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
425 retries_counter=$(( $retries_counter + 1 ))
426 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
428 [ -n "$output" ] && echo "$output"
429 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
430 echo "Trying again [`nourl $i`]... ($retries_counter)"
439 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
440 if [ -z "$NOMIRRORS" ] ; then
441 i="`find_mirror "$i"`"
444 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
448 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
449 Exit_error err_no_source_in_repo $i;
450 elif [ -n "$UPDATE5" ] && \
451 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' ) || \
452 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
455 echo "Updating source-$srcno md5."
456 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
457 perl -i -ne 'print "# Source'$srcno'-md5:\t'$md5'\n"
458 if /^Source'$srcno'\s*:\s+/;
459 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i' \
463 if good_md5 "$i"; then
466 echo "MD5 sum mismatch. Use -U to refetch sources,"
467 echo "or -5 to update md5 sums, if you're sure files are correct."
468 Exit_error err_no_source_in_repo $i
473 if [ "$CHMOD" = "yes" ]; then
474 CHMOD_FILES="`nourl $GET_FILES`"
475 if [ -n "$CHMOD_FILES" ]; then
476 chmod $CHMOD_MODE $CHMOD_FILES
487 if [ -n "$DEBUG" ]; then
492 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
493 echo $PACKAGE_VERSION
494 echo $PACKAGE_RELEASE
495 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
496 if [ "$TAG_VERSION" = "yes" ]; then
497 echo "CVS tag: $TAGVER"
499 if [ -n "$TAG" ]; then
504 if [ -n "$CVSROOT" ]; then
505 OPTIONS="-d $CVSROOT $OPTIONS"
509 for i in $TAG_FILES; do
510 if [ -f `nourl $i` ]; then
511 if [ "$TAG_VERSION" = "yes" ]; then
512 cvs $OPTIONS $TAGVER `nourl $i`
514 if [ -n "$TAG" ]; then
515 cvs $OPTIONS $TAG `nourl $i`
518 Exit_error err_no_source_in_repo $i
523 if [ "$TAG_VERSION" = "yes" ]; then
524 cvs $OPTIONS $TAGVER $SPECFILE
526 if [ -n "$TAG" ]; then
527 cvs $OPTIONS $TAG $SPECFILE
537 echo "CVS branch tag: $TAG"
542 if [ -n "$DEBUG" ]; then
547 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
550 if [ -n "$CVSROOT" ]; then
551 OPTIONS="-d $CVSROOT $OPTIONS"
554 for i in $TAG_FILES; do
555 if [ -f `nourl $i` ]; then
556 cvs $OPTIONS $TAG `nourl $i`
558 Exit_error err_no_source_in_repo $i
562 cvs $OPTIONS $TAG $SPECFILE
572 if [ -n "$DEBUG" ]; then
579 if [ -n "$TRY_UPGRADE" ]; then
581 if [ -n "FLOAT_VERSION" ]; then
582 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
584 TNOTIFY=`./pldnotify.awk $SPECFILE`
587 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
589 if [ -n "$TNEWVER" ]; then
591 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
593 echo "New version found, updating spec file to version " $TNEWVER
595 cp -f $SPECFILE $SPECFILE.bak
599 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
600 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
604 get_files "$SOURCES $PATCHES";
606 unset TOLDVER TNEWVER TNOTIFY
616 BUILD_SWITCH="-ba" ;;
618 BUILD_SWITCH="-bb" ;;
620 BUILD_SWITCH="-bs --nodeps" ;;
622 if [ -n "$LOGFILE" ]; then
623 if [ -n "$CVSTAG" ]; then
624 LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
628 LOG=`eval echo $LOGFILE`
629 if [ -n "$LASTLOG_FILE" ]; then
630 echo "LASTLOG=$LOG" > $LASTLOG_FILE
632 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
633 (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
634 RETVAL=`cat $RES_FILE`
636 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
637 if [ "$RETVAL" -eq "0" ]; then
644 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
648 if [ "$RETVAL" -ne "0" ]; then
650 if [ -n "$TRY_UPGRADE" ]; then
651 echo "\n!!! Package with new version cannot be build automagically\n"
652 mv -f $SPECFILE.bak $SPECFILE
655 Exit_error err_build_fail;
663 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
665 #---------------------------------------------
668 if [ "$#" = 0 ]; then
673 while test $# -gt 0 ; do
688 DEBUG="yes"; shift ;;
690 COMMAND="version"; shift ;;
692 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
694 COMMAND="build"; shift ;;
695 -bb | --build-binary )
696 COMMAND="build-binary"; shift ;;
697 -bs | --build-source )
698 COMMAND="build-source"; shift ;;
700 COMMAND="branch"; shift; TAG="${1}"; shift;;
702 CLEAN="--clean --rmspec --rmsource"; shift ;;
704 shift; CVSROOT="${1}"; shift ;;
706 COMMAND="get"; shift ;;
708 COMMAND="usage"; shift ;;
710 shift; LOGFILE="${1}"; shift ;;
712 shift; DEF_NICE_LEVEL=${1}; shift ;;
714 COMMAND="mr-proper"; shift ;;
716 NOCVS="yes"; shift ;;
717 -ncs | --no-cvs-specs )
718 NOCVSSPEC="yes"; shift ;;
719 -nd | --no-distfiles )
720 NODIST="yes"; shift ;;
722 NOMIRRORS="yes"; shift ;;
724 NOURLS="yes"; shift ;;
726 NOSRCS="yes"; shift ;;
727 -ns0 | --no-source0 )
728 NOSOURCE0="yes"; shift ;;
730 shift; RPMOPTS="${1}"; shift ;;
732 BCOND="$BCOND $1 $2" ; shift 2 ;;
734 QUIET="--quiet"; shift ;;
736 CVSDATE="${2}"; shift 2 ;;
738 shift; CVSTAG="${1}"; shift ;;
739 -Tvs | --tag-version-stable )
744 -Tvn | --tag-version-nest )
759 -Tv | --tag-version )
777 TRY_UPGRADE="1"; shift ;;
778 -un | --try-upgrade-with-float-version )
779 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
781 BE_VERBOSE="1"; shift ;;
787 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
790 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
794 if [ -n "$DEBUG" ]; then
800 "build" | "build-binary" | "build-source" )
802 if [ -n "$SPECFILE" ]; then
806 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
807 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
808 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
809 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
811 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
812 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
816 if [ -n "$ICONS" ]; then
820 if [ -n "$NOSOURCE0" ] ; then
821 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
823 get_files "$SOURCES $PATCHES";
826 Exit_error err_no_spec_in_cmdl;
831 if [ -n "$SPECFILE" ]; then
834 if [ -n "$ICONS" ]; then
838 get_files $SOURCES $PATCHES;
839 branch_files $TAG "$SOURCES $PATCHES $ICONS";
841 Exit_error err_no_spec_in_cmdl;
846 if [ -n "$SPECFILE" ]; then
849 if [ -n "$ICONS" ]; then
853 if [ -n "$NOSOURCE0" ] ; then
854 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
856 get_files $SOURCES $PATCHES
858 Exit_error err_no_spec_in_cmdl;
863 if [ -n "$SPECFILE" ]; then
866 if [ -n "$ICONS" ]; then
870 get_files $SOURCES $PATCHES;
871 tag_files "$SOURCES $PATCHES $ICONS";
873 Exit_error err_no_spec_in_cmdl;
877 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE