]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
- Changed host name which needed
[packages/rpm-build-tools.git] / builder.sh
index 3fc3fab6aedaa3b3f03b7b22b8cf03d6e5c6cda4..c8bd0044bdd989b3e0e19b2c225805596d323f4d 100644 (file)
@@ -11,8 +11,7 @@
 
 VERSION="\
 Build package utility from PLD CVS repository
-V 0.10 (C) 1999-2001 Tomasz K³oczko".
-
+V 0.11 (C) 1999-2001 Free Penguins".
 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
 
 COMMAND="build"
@@ -34,6 +33,12 @@ fi
 # Example: LOGFILE='../log.$PACKAGE_NAME'
 # Yes, you can use variable name! Note _single_ quotes!
 LOGFILE=''
+
+LOGDIR=""
+LOGDIROK=""
+LOGDIRFAIL=""
+LASTLOG_FILE=""
+LTAG=""
 CHMOD="yes"
 CHMOD_MODE="0444"
 RPMOPTS=""
@@ -48,6 +53,9 @@ PACKAGE_NAME=""
 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
 
+CVSTAG=""
+RES_FILE=""
+
 DEF_NICE_LEVEL=0
 
 FAIL_IF_NO_SOURCES="yes"
@@ -81,7 +89,7 @@ Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
        [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
        [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
        [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
-       [-q|--quiet] [-r <cvstag>] [{-T--tag <cvstag>]
+       [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
        [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
        [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
        [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
@@ -89,7 +97,7 @@ Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
 
        -D, --debug     - enable script debugging mode,
        -V, --version   - output builder version
-       -a, --as_anon   - get files via pserver as cvs@anoncvs.pld.org.pl,
+       -a, --as_anon   - get files via pserver as cvs@cvs.pld-linux.org,
        -b, -ba,
        --build         - get all files from CVS repo or HTTP/FTP and build
                          package from <package>.spec,
@@ -119,12 +127,15 @@ Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
                        - don't check specs in CVS
        -nm, --no-mirrors - don't download from mirror, if source URL is given,
        -nu, --no-urls  - don't try to download from FTP/HTTP location,
-       -ns, --no-srcs  - don't downland Sources
+       -ns, --no-srcs  - don't download Sources
        -ns0, --no-source0
-                       - don't downland Source0
+                       - don't download Source0
        --opts <rpm opts>
                        - additional options for rpm
        -q, --quiet     - be quiet,
+       --date yyyy-mm-dd
+                       - build package using resources from specified CVS
+                         date,
        -r <cvstag>, --cvstag <cvstag>
                        - build package using resources from specified CVS
                          tag,
@@ -158,7 +169,6 @@ parse_spec()
     fi
 
     cd $SPECS_DIR
-
     if [ "$NOSRCS" != "yes" ]; then
        SOURCES="`$RPMBUILD -bp  $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
     fi
@@ -173,7 +183,7 @@ parse_spec()
     PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
 
     if [ -n "$BE_VERBOSE" ]; then
-       echo "- Sources :  `nourl $SOURCES`" 
+       echo "- Sources :  `nourl $SOURCES`"
        if [ -n "$PATCHES" ]; then
            echo "- Patches :  `nourl $PATCHES`"
        else
@@ -192,9 +202,9 @@ parse_spec()
 
 Exit_error()
 {
-    if [ -n "$DEBUG" ]; then 
+    if [ -n "$DEBUG" ]; then
        set -x;
-       set -v; 
+       set -v;
     fi
 
     cd $__PWD
@@ -217,9 +227,9 @@ Exit_error()
 
 init_builder()
 {
-    if [ -n "$DEBUG" ]; then 
+    if [ -n "$DEBUG" ]; then
        set -x;
-       set -v; 
+       set -v;
     fi
 
     SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
@@ -230,9 +240,9 @@ init_builder()
 
 get_spec()
 {
-    if [ -n "$DEBUG" ]; then 
+    if [ -n "$DEBUG" ]; then
        set -x;
-       set -v; 
+       set -v;
     fi
 
     if [ "$NOCVSSPEC" != "yes" ]; then
@@ -248,10 +258,16 @@ get_spec()
                NOCVSSPEC="yes"
            fi
        fi
-       if [ -n "$CVSTAG" ]; then
-           OPTIONS="$OPTIONS -r $CVSTAG"
-       else
+
+       if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
            OPTIONS="$OPTIONS -A"
+       else
+           if [ -n "$CVSDATE" ]; then
+               OPTIONS="$OPTIONS -D $CVSDATE"
+           fi
+           if [ -n "$CVSTAG" ]; then
+               OPTIONS="$OPTIONS -r $CVSTAG"
+           fi
        fi
 
        result=1
@@ -262,8 +278,9 @@ get_spec()
            result=$?
            [ -n "$output" ] && echo "$output"
            if [ "$result" -ne "0" ]; then
-               if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
-                   echo "Trying again... ($retries_counter)"
+               if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
+                   echo "Trying again [$SPECFILE]... ($retries_counter)"
+                   sleep 2
                    continue
                 fi
                Exit_error err_no_spec_in_repo;
@@ -284,14 +301,14 @@ get_spec()
 find_mirror(){
 
     cd "$SPECS_DIR"
-    url="$1"   
-    if [ ! -f "mirrors" ] ; then 
-       cvs update mirrors >&2 
+    url="$1"
+    if [ ! -f "mirrors" ] ; then
+       cvs update mirrors >&2
     fi
 
     IFS="|"
     while read origin mirror name rest; do
-       ol=`echo -n "$origin"|wc -c`    
+       ol=`echo -n "$origin"|wc -c`
        prefix="`echo -n "$url" | head -c $ol`"
        if [ "$prefix" = "$origin" ] ; then
            suffix="`echo "$url"|cut -b $ol-`"
@@ -302,13 +319,35 @@ find_mirror(){
     echo "$url"
 }
 
+src_no ()
+{
+    cd $SPECS_DIR
+    $RPMBUILD -bp  $BCOND --define 'prep %dump' $SPECFILE 2>&1 | \
+       grep "SOURCEURL[0-9]*[  ]*$1""[         ]*$" | \
+       sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
+       xargs
+}
+
+src_md5 ()
+{
+    no=$(src_no "$1")
+    [ -z "$no" ] && return
+    cd $SPECS_DIR
+    grep -i "#[        ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://' | xargs
+}
+
+distfiles_url ()
+{
+    echo "ftp://distfiles.pld-ppc.org/src/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')"
+}
+
 get_files()
 {
     GET_FILES="$@"
 
-    if [ -n "$DEBUG" ]; then 
+    if [ -n "$DEBUG" ]; then
        set -x;
-       set -v; 
+       set -v;
     fi
 
     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
@@ -323,18 +362,33 @@ get_files()
                NOCVS="yes"
            fi
        fi
-       if [ -n "$CVSTAG" ]; then
-           OPTIONS="$OPTIONS -r $CVSTAG"
-       else
-           OPTIONS="$OPTIONS -A"
-       fi
+       if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
+            OPTIONS="$OPTIONS -A"
+        else
+            if [ -n "$CVSDATE" ]; then
+                OPTIONS="$OPTIONS -D $CVSDATE"
+            fi
+            if [ -n "$CVSTAG" ]; then
+                OPTIONS="$OPTIONS -r $CVSTAG"
+            fi
+        fi
        for i in $GET_FILES; do
            if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
                if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
                    echo "Warning: no URL given for $i"
                fi
 
-               if [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
+               if [ -n "$(src_md5 "$i")" ] ; then
+                   target=$(nourl "$i")
+                   url=$(distfiles_url "$i")
+                   if [ -z "$NOMIRRORS" ] ; then
+                       url="`find_mirror "$url"`"
+                   fi
+                   ${GETURI} -O "$target" "$url" || \
+                       if [ `echo $url | grep -E 'ftp://'` ]; then
+                           ${GETURI2} -O "$target" "$url"
+                       fi
+               elif [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
                    result=1
                    retries_counter=0
                    while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
@@ -342,8 +396,9 @@ get_files()
                        output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
                        result=$?
                        [ -n "$output" ] && echo "$output"
-                       if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
-                               echo "Trying again... ($retries_counter)"
+                       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
+                               echo "Trying again [`nourl $i`]... ($retries_counter)"
+                               sleep 2
                                continue
                        else
                                break
@@ -352,7 +407,7 @@ get_files()
                fi
 
                if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
-                   if [ -z "$NOMIRRORS" ] ; then 
+                   if [ -z "$NOMIRRORS" ] ; then
                        i="`find_mirror "$i"`"
                    fi
                    ${GETURI} "$i" || \
@@ -379,9 +434,9 @@ tag_files()
 {
     TAG_FILES="$@"
 
-    if [ -n "$DEBUG" ]; then 
+    if [ -n "$DEBUG" ]; then
        set -x;
-       set -v; 
+       set -v;
     fi
 
     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
@@ -460,16 +515,18 @@ branch_files()
     fi
 }
 
+
+
 build_package()
 {
-    if [ -n "$DEBUG" ]; then 
+    if [ -n "$DEBUG" ]; then
        set -x;
-       set -v; 
+       set -v;
     fi
 
     cd $SPECS_DIR
 
-    if [ -n "$TRY_UPGRADE" ]; then 
+    if [ -n "$TRY_UPGRADE" ]; then
 
        if [ -n "FLOAT_VERSION" ]; then
            TNOTIFY=`./pldnotify.awk $SPECFILE -n`
@@ -498,7 +555,7 @@ build_package()
 
            unset TOLDVER TNEWVER TNOTIFY
        fi
-       
+
     fi
 
 
@@ -513,15 +570,34 @@ build_package()
            BUILD_SWITCH="-bs --nodeps" ;;
     esac
     if [ -n "$LOGFILE" ]; then
+       if [ -n "$CVSTAG" ]; then
+           LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
+       else
+           LTAG=""
+       fi
        LOG=`eval echo $LOGFILE`
-       eval nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 2>&1 | tee $LOG
+       if [ -n "$LASTLOG_FILE" ]; then
+           echo "LASTLOG=$LOG" > $LASTLOG_FILE
+       fi
+       RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
+       (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
+       RETVAL=`cat $RES_FILE`
+       rm $RES_FILE
+       if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
+           if [ "$RETVAL" -eq "0" ]; then
+               mv $LOG $LOGDIROK
+           else
+               mv $LOG $LOGDIRFAIL
+           fi
+       fi
     else
        eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
+       RETVAL=$?
     fi
 
-    if [ "$?" -ne "0" ]; then
+    if [ "$RETVAL" -ne "0" ]; then
 
-       if [ -n "$TRY_UPGRADE" ]; then 
+       if [ -n "$TRY_UPGRADE" ]; then
            echo "\n!!! Package with new version cannot be build automagically\n"
            mv -f $SPECFILE.bak $SPECFILE
        fi
@@ -551,7 +627,7 @@ while test $# -gt 0 ; do
        -V | --version )
            COMMAND="version"; shift ;;
        -a | --as_anon )
-           CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
+           CVSROOT=":pserver:cvs@cvs.pld-linux.org:/cvsroot"; shift ;;
        -b | -ba | --build )
            COMMAND="build"; shift ;;
        -bb | --build-binary )
@@ -576,7 +652,7 @@ while test $# -gt 0 ; do
            COMMAND="mr-proper"; shift ;;
        -nc | --no-cvs )
            NOCVS="yes"; shift ;;
-       -ncs | --no-cvs-spec )
+       -ncs | --no-cvs-specs )
            NOCVSSPEC="yes"; shift ;;
        -nm | --no-mirrors )
            NOMIRRORS="yes"; shift ;;
@@ -592,6 +668,8 @@ while test $# -gt 0 ; do
            BCOND="$BCOND $1 $2" ; shift 2 ;;
        -q | --quiet )
            QUIET="--quiet"; shift ;;
+       --date )
+           CVSDATE="${2}"; shift 2 ;;
        -r | --cvstag )
            shift; CVSTAG="${1}"; shift ;;
        -Tvs | --tag-version-stable )
@@ -643,9 +721,9 @@ while test $# -gt 0 ; do
     esac
 done
 
-if [ -n "$DEBUG" ]; then 
+if [ -n "$DEBUG" ]; then
     set -x;
-    set -v; 
+    set -v;
 fi
 
 case "$COMMAND" in
This page took 0.05704 seconds and 4 git commands to generate.