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
12 # TODO: "NoSource: N" should disallow adding "SourceN-md5:" tag
15 Build package utility from PLD CVS repository
16 V 0.11 (C) 1999-2003 Free Penguins".
17 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
33 ALLWAYS_CVSUP=${ALLWAYS_CVSUP:-"yes"}
34 if [ -s CVS/Root ]; then
35 CVSROOT=$(cat CVS/Root)
37 CVSROOT=${CVSROOT:-""}
39 # Example: LOGFILE='../log.$PACKAGE_NAME'
40 # Yes, you can use variable name! Note _single_ quotes!
59 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
60 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
65 CVS_SERVER="cvs.pld-linux.org"
66 DISTFILES_SERVER="ftp://distfiles.pld-linux.org"
70 FAIL_IF_NO_SOURCES="yes"
72 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
73 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
75 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
83 if [ -f ~/etc/builderrc ]; then
85 elif [ -f ~/.builderrc ]; then
89 #---------------------------------------------
94 if [ -n "$DEBUG" ]; then set -xv; fi
96 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
98 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
99 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
100 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
101 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
102 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
103 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
104 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
105 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
108 - update md5 comments in spec, implies -nd
109 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd
110 -D, --debug - enable script debugging mode,
111 -V, --version - output builder version
112 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
114 --build - get all files from CVS repo or HTTP/FTP and build
115 package from <package>.spec,
117 - get all files from CVS repo or HTTP/FTP and build
118 binary only package from <package>.spec,
120 --build-source - get all files from CVS repo or HTTP/FTP and only
121 pack them into src.rpm,
122 -B, --branch - add branch
123 -c, --clean - clean all temporarily created files (in BUILD,
124 SOURCES, SPECS and \$RPM_BUILD_ROOT),
125 -d <cvsroot>, --cvsroot <cvsroot>
127 --define <macro> <value>
128 - define a macro <macro> with value <value>,
129 -g, --get - get <package>.spec and all related files from
130 CVS repo or HTTP/FTP,
131 -h, --help - this message,
132 -l <logfile>, --logtofile <logfile>
134 -m, --mr-proper - only remove all files related to spec file and
136 -nc, --no-cvs - don't download sources from CVS, if source URL is
139 - don't check specs in CVS
141 - don't download from distfiles
142 -nm, --no-mirrors - don't download from mirror, if source URL is given,
143 -nu, --no-urls - don't try to download from FTP/HTTP location,
144 -ns, --no-srcs - don't download Sources
146 - don't download Source0
148 - additional options for rpm
149 -q, --quiet - be quiet,
151 - build package using resources from specified CVS
153 -r <cvstag>, --cvstag <cvstag>
154 - build package using resources from specified CVS
156 -T <cvstag> , --tag <cvstag>
157 - add cvs tag <cvstag> for files,
158 -Tvs, --tag-version-stable
159 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
160 -Tvn, --tag-version-nest
161 - add cvs tags NEST and NAME-VERSION-RELESE for files,
163 - add cvs tag STABLE for files,
165 - add cvs tag NEST for files,
167 - add cvs tag NAME-VERSION-RELESE for files,
168 -v, --verbose - be verbose,
170 - check version, and try to upgrade package
171 -un, --try-upgrade-with-float-version
172 - as above, but allow float version
174 - refetch sources, don't use distfiles, and update md5
176 --with/--without <feature>
177 - conditional build package depending on
178 %_with_<feature>/%_without_<feature> macro
185 if [ -n "$DEBUG" ]; then
191 if [ "$NOSRCS" != "yes" ]; then
192 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
194 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
195 FAIL_IF_NO_SOURCES="no"
198 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
199 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
200 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
201 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
202 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
204 if [ -n "$BE_VERBOSE" ]; then
205 echo "- Sources : `nourl $SOURCES`"
206 if [ -n "$PATCHES" ]; then
207 echo "- Patches : `nourl $PATCHES`"
209 echo "- Patches : *no patches needed*"
211 if [ -n "$ICONS" ]; then
212 echo "- Icon : `nourl $ICONS`"
214 echo "- Icon : *no package icon*"
216 echo "- Name : $PACKAGE_NAME"
217 echo "- Version : $PACKAGE_VERSION"
218 echo "- Release : $PACKAGE_RELEASE"
224 if [ -n "$DEBUG" ]; then
232 "err_no_spec_in_cmdl" )
233 echo "ERROR: spec file name not specified.";
235 "err_no_spec_in_repo" )
236 echo "Error: spec file not stored in CVS repo.";
238 "err_no_source_in_repo" )
239 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
242 echo "Error: package build failed. (${2:-no more info})";
249 if [ -n "$DEBUG" ]; then
254 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
255 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
262 if [ -n "$DEBUG" ]; then
267 if [ "$NOCVSSPEC" != "yes" ]; then
272 if [ -n "$CVSROOT" ]; then
273 OPTIONS="-d $CVSROOT $OPTIONS"
275 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
276 echo "warning: No cvs access defined - using local .spec file"
281 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
282 OPTIONS="$OPTIONS -A"
284 if [ -n "$CVSDATE" ]; then
285 OPTIONS="$OPTIONS -D $CVSDATE"
287 if [ -n "$CVSTAG" ]; then
288 OPTIONS="$OPTIONS -r $CVSTAG"
294 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
295 retries_counter=$(( $retries_counter + 1 ))
296 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
298 [ -n "$output" ] && echo "$output"
299 if [ "$result" -ne "0" ]; then
300 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
301 echo "Trying again [$SPECFILE]... ($retries_counter)"
305 Exit_error err_no_spec_in_repo;
309 if [ ! -f "$SPECFILE" ]; then
310 Exit_error err_no_spec_in_repo;
313 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
314 chmod $CHMOD_MODE $SPECFILE
317 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
324 if [ ! -f "mirrors" ] ; then
325 cvs update mirrors >&2
329 while read origin mirror name rest; do
330 ol=`echo -n "$origin"|wc -c`
331 prefix="`echo -n "$url" | head -c $ol`"
332 if [ "$prefix" = "$origin" ] ; then
333 suffix="`echo "$url"|cut -b $ol-`"
334 echo -n "$mirror$suffix"
344 $RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | \
345 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
346 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
353 [ -z "$no" ] && return
355 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
360 echo "$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
367 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
374 if [ -n "$DEBUG" ]; then
379 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
383 if [ -n "$CVSROOT" ]; then
384 OPTIONS="-d $CVSROOT $OPTIONS"
386 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
387 echo "warning: No cvs access defined for SOURCES"
391 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
392 OPTIONS="$OPTIONS -A"
394 if [ -n "$CVSDATE" ]; then
395 OPTIONS="$OPTIONS -D $CVSDATE"
397 if [ -n "$CVSTAG" ]; then
398 OPTIONS="$OPTIONS -r $CVSTAG"
401 for i in $GET_FILES; do
402 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
403 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
404 echo "Warning: no URL given for $i"
407 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
408 if good_md5 "$i"; then
409 echo "$(nourl "$i") having proper md5sum already exists"
413 url=$(distfiles_url "$i")
414 if [ -z "$NOMIRRORS" ] ; then
415 url="`find_mirror "$url"`"
417 ${GETURI} -O "$target" "$url" || \
418 if [ `echo $url | grep -E 'ftp://'` ]; then
419 ${GETURI2} -O "$target" "$url"
421 test -s "$target" || rm -f "$target"
422 elif [ -z "$(src_md5 "$i")" ] && \
423 ( [ -z "$NOCVS" ] || echo $i | grep -qvE '(ftp|http|https)://' ); then
426 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
427 retries_counter=$(( $retries_counter + 1 ))
428 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
430 [ -n "$output" ] && echo "$output"
431 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
432 echo "Trying again [`nourl $i`]... ($retries_counter)"
441 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
442 if [ -z "$NOMIRRORS" ] ; then
443 i="`find_mirror "$i"`"
446 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
450 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
451 Exit_error err_no_source_in_repo $i;
452 elif [ -n "$UPDATE5" ] && \
453 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' ) || \
454 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
457 echo "Updating source-$srcno md5."
458 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
459 perl -i -ne 'print "# Source'$srcno'-md5:\t'$md5'\n"
460 if /^Source'$srcno'\s*:\s+/;
461 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i' \
465 if good_md5 "$i"; then
468 echo "MD5 sum mismatch. Use -U to refetch sources,"
469 echo "or -5 to update md5 sums, if you're sure files are correct."
470 Exit_error err_no_source_in_repo $i
475 if [ "$CHMOD" = "yes" ]; then
476 CHMOD_FILES="`nourl $GET_FILES`"
477 if [ -n "$CHMOD_FILES" ]; then
478 chmod $CHMOD_MODE $CHMOD_FILES
489 if [ -n "$DEBUG" ]; then
494 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
495 echo $PACKAGE_VERSION
496 echo $PACKAGE_RELEASE
497 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
498 if [ "$TAG_VERSION" = "yes" ]; then
499 echo "CVS tag: $TAGVER"
501 if [ -n "$TAG" ]; then
506 if [ -n "$CVSROOT" ]; then
507 OPTIONS="-d $CVSROOT $OPTIONS"
511 for i in $TAG_FILES; do
512 if [ -f `nourl $i` ]; then
513 if [ "$TAG_VERSION" = "yes" ]; then
514 cvs $OPTIONS $TAGVER `nourl $i`
516 if [ -n "$TAG" ]; then
517 cvs $OPTIONS $TAG `nourl $i`
520 Exit_error err_no_source_in_repo $i
525 if [ "$TAG_VERSION" = "yes" ]; then
526 cvs $OPTIONS $TAGVER $SPECFILE
528 if [ -n "$TAG" ]; then
529 cvs $OPTIONS $TAG $SPECFILE
539 echo "CVS branch tag: $TAG"
544 if [ -n "$DEBUG" ]; then
549 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
552 if [ -n "$CVSROOT" ]; then
553 OPTIONS="-d $CVSROOT $OPTIONS"
556 for i in $TAG_FILES; do
557 if [ -f `nourl $i` ]; then
558 cvs $OPTIONS $TAG `nourl $i`
560 Exit_error err_no_source_in_repo $i
564 cvs $OPTIONS $TAG $SPECFILE
574 if [ -n "$DEBUG" ]; then
581 if [ -n "$TRY_UPGRADE" ]; then
583 if [ -n "FLOAT_VERSION" ]; then
584 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
586 TNOTIFY=`./pldnotify.awk $SPECFILE`
589 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
591 if [ -n "$TNEWVER" ]; then
593 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
595 echo "New version found, updating spec file to version " $TNEWVER
597 cp -f $SPECFILE $SPECFILE.bak
601 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
602 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
606 get_files "$SOURCES $PATCHES";
608 unset TOLDVER TNEWVER TNOTIFY
618 BUILD_SWITCH="-ba" ;;
620 BUILD_SWITCH="-bb" ;;
622 BUILD_SWITCH="-bs --nodeps" ;;
624 if [ -n "$LOGFILE" ]; then
625 if [ -n "$CVSTAG" ]; then
626 LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
630 LOG=`eval echo $LOGFILE`
631 if [ -n "$LASTLOG_FILE" ]; then
632 echo "LASTLOG=$LOG" > $LASTLOG_FILE
634 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
635 (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
636 RETVAL=`cat $RES_FILE`
638 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
639 if [ "$RETVAL" -eq "0" ]; then
646 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
650 if [ "$RETVAL" -ne "0" ]; then
652 if [ -n "$TRY_UPGRADE" ]; then
653 echo "\n!!! Package with new version cannot be build automagically\n"
654 mv -f $SPECFILE.bak $SPECFILE
657 Exit_error err_build_fail;
665 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
667 #---------------------------------------------
670 if [ "$#" = 0 ]; then
675 while test $# -gt 0 ; do
690 DEBUG="yes"; shift ;;
692 COMMAND="version"; shift ;;
694 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
696 COMMAND="build"; shift ;;
697 -bb | --build-binary )
698 COMMAND="build-binary"; shift ;;
699 -bs | --build-source )
700 COMMAND="build-source"; shift ;;
702 COMMAND="branch"; shift; TAG="${1}"; shift;;
704 CLEAN="--clean --rmspec --rmsource"; shift ;;
706 shift; CVSROOT="${1}"; shift ;;
708 COMMAND="get"; shift ;;
710 COMMAND="usage"; shift ;;
712 shift; LOGFILE="${1}"; shift ;;
714 shift; DEF_NICE_LEVEL=${1}; shift ;;
716 COMMAND="mr-proper"; shift ;;
718 NOCVS="yes"; shift ;;
719 -ncs | --no-cvs-specs )
720 NOCVSSPEC="yes"; shift ;;
721 -nd | --no-distfiles )
722 NODIST="yes"; shift ;;
724 NOMIRRORS="yes"; shift ;;
726 NOURLS="yes"; shift ;;
728 NOSRCS="yes"; shift ;;
729 -ns0 | --no-source0 )
730 NOSOURCE0="yes"; shift ;;
732 shift; RPMOPTS="${1}"; shift ;;
734 BCOND="$BCOND $1 $2" ; shift 2 ;;
736 QUIET="--quiet"; shift ;;
738 CVSDATE="${2}"; shift 2 ;;
740 shift; CVSTAG="${1}"; shift ;;
741 -Tvs | --tag-version-stable )
746 -Tvn | --tag-version-nest )
761 -Tv | --tag-version )
779 TRY_UPGRADE="1"; shift ;;
780 -un | --try-upgrade-with-float-version )
781 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
783 BE_VERBOSE="1"; shift ;;
789 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
792 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
796 if [ -n "$DEBUG" ]; then
802 "build" | "build-binary" | "build-source" )
804 if [ -n "$SPECFILE" ]; then
808 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
809 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
810 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
811 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
813 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
814 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
818 if [ -n "$ICONS" ]; then
822 if [ -n "$NOSOURCE0" ] ; then
823 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
825 get_files "$SOURCES $PATCHES";
828 Exit_error err_no_spec_in_cmdl;
833 if [ -n "$SPECFILE" ]; then
836 if [ -n "$ICONS" ]; then
840 get_files $SOURCES $PATCHES;
841 branch_files $TAG "$SOURCES $PATCHES $ICONS";
843 Exit_error err_no_spec_in_cmdl;
848 if [ -n "$SPECFILE" ]; then
851 if [ -n "$ICONS" ]; then
855 if [ -n "$NOSOURCE0" ] ; then
856 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
858 get_files $SOURCES $PATCHES
860 Exit_error err_no_spec_in_cmdl;
865 if [ -n "$SPECFILE" ]; then
868 if [ -n "$ICONS" ]; then
872 get_files $SOURCES $PATCHES;
873 tag_files "$SOURCES $PATCHES $ICONS";
875 Exit_error err_no_spec_in_cmdl;
879 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE