]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
- more fedoraish
[packages/rpm-build-tools.git] / builder.sh
index 2e004f8c4fe05895ffb1a16e623dd8c43fde4b15..f1fd2cc30ab754a5600d2dfda4927b6c136797a6 100644 (file)
@@ -231,7 +231,7 @@ POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
 
 run_poldek() {
-       RES_FILE=$(mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM)
+       RES_FILE=$(tempfile)
        if [ -n "$LOGFILE" ]; then
                LOG=`eval echo $LOGFILE`
                if [ -n "$LASTLOG_FILE" ]; then
@@ -263,7 +263,9 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
 <package>[.spec][:cvstag]
 
+-4                  - force ipv4 when transferring files
 -5, --update-md5    - update md5 comments in spec, implies -nd -ncs
+-6                  - force ipv6 when transferring files
 -a5, --add-md5      - add md5 comments to URL sources, implies -nc -nd -ncs
 -n5, --no-md5       - ignore md5 comments in spec
 -D, --debug         - enable builder script debugging mode,
@@ -394,6 +396,11 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 "
 }
 
+# create tempfile. as secure as possible
+tempfile() {
+       mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
+}
+
 # change dependency to specname
 # common changes:
 # - perl(Package::Name) -> perl-Package-Name
@@ -824,11 +831,14 @@ find_mirror() {
 
 # Warning: unpredictable results if same URL used twice
 src_no() {
+       local file="$1"
+       # escape some regexp characters if part of file name
+       file=$(echo "$file" | sed -e 's#\([\+\*\.]\)#\\\1#g')
        cd $PACKAGE_DIR
        rpm_dump | \
-       grep "SOURCEURL[0-9]*[  ]*$1""[         ]*$" | \
-       sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
-       head -n 1 | xargs
+       grep -E "(SOURCE|PATCH)URL[0-9]*[       ]*${file}""[    ]*$" | \
+       sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
+       head -n 1 | tr OURCEATH ourceath | xargs
 }
 
 src_md5() {
@@ -858,7 +868,7 @@ src_md5() {
                fi
        fi
 
-       source_md5=`grep -i "^#[        ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://'`
+       source_md5=`grep -i "^#[        ]*$no-md5[      ]*:" $SPECFILE | sed -e 's/.*://'`
        if [ -n "$source_md5" ]; then
                echo $source_md5
        else
@@ -868,7 +878,7 @@ src_md5() {
                else
                        # we have empty SourceX-md5, but it is still possible
                        # that we have NoSourceX-md5 AND NoSource: X
-                       nosource_md5=`grep -i "^#[       ]*NoSource$no-md5[      ]*:" $SPECFILE | sed -e 's/.*://'`
+                       nosource_md5=`grep -i "^#[       ]*No$no-md5[    ]*:" $SPECFILE | sed -e 's/.*://'`
                        if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[     ]*$no$" $SPECFILE`" ] ; then
                                echo $nosource_md5
                        fi
@@ -1003,10 +1013,10 @@ update_md5() {
                local srcno=$(src_no "$i")
                if [ -n "$ADD5" ]; then
                        [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
-                       grep -qiE '^#[  ]*Source'$srcno'-md5[   ]*:' $PACKAGE_DIR/$SPECFILE && continue
+                       grep -qiE '^#[  ]*'$srcno'-md5[         ]*:' $PACKAGE_DIR/$SPECFILE && continue
                        grep -qiE '^BuildRequires:[     ]*digest[(]%SOURCE'$srcno'[)][  ]*=' $PACKAGE_DIR/$SPECFILE && continue
                else
-                       grep -qiE '^#[  ]*Source'$srcno'-md5[   ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[      ]*digest[(]%SOURCE'$srcno'[)][  ]*=' $PACKAGE_DIR/$SPECFILE || continue
+                       grep -qiE '^#[  ]*'$srcno'-md5[         ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[      ]*digest[(]%SOURCE'$srcno'[)][  ]*=' $PACKAGE_DIR/$SPECFILE || continue
                fi
                if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
                        need_files="$need_files $i"
@@ -1022,22 +1032,22 @@ update_md5() {
        for i in "$@"; do
                local fp=$(nourl "$i")
                local srcno=$(src_no "$i")
-               local md5=$(grep -iE '^#[       ]*(No)?Source'$srcno'-md5[      ]*:' $PACKAGE_DIR/$SPECFILE )
+               local md5=$(grep -iE '^#[       ]*(No)?'$srcno'-md5[    ]*:' $PACKAGE_DIR/$SPECFILE )
                if [ -z "$md5" ]; then
                        md5=$(grep -iE '^[      ]*BuildRequires:[       ]*digest[(]%SOURCE'$srcno'[)][  ]*=' $PACKAGE_DIR/$SPECFILE )
                fi
                if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
-                       local tag="# Source$srcno-md5:\t"
+                       local tag="# $srcno-md5:\t"
                        if [[ "$md5" == *NoSource* ]]; then
                                tag="# NoSource$srcno-md5:\t"
                        elif [ -n "$USEDIGEST" ]; then
                                tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
                        fi
                        md5=$(md5sum "$fp" | cut -f1 -d' ')
-                       echo "Updating Source$srcno ($md5: $fp)."
+                       echo "Updating $srcno ($md5: $fp)."
                        perl -i -ne '
-                               print unless (/^\s*#\s*(No)?Source'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
-                               print "'"$tag$md5"'\n" if /^Source'$srcno'\s*:\s+/;
+                               print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
+                               print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
                        ' \
                        $PACKAGE_DIR/$SPECFILE
                fi
@@ -1555,7 +1565,7 @@ build_package() {
                if [ -n "$LASTLOG_FILE" ]; then
                        echo "LASTLOG=$LOG" > $LASTLOG_FILE
                fi
-               RES_FILE=$(mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM)
+               RES_FILE=$(tempfile)
 
                (time eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
                RETVAL=`cat $RES_FILE`
@@ -2113,7 +2123,7 @@ mr_proper() {
        cvs_entry_remove $PACKAGE_DIR $SPECFILE $SOURCES $PATCHES
 
        # remove spec and sources
-       $RPMBUILD --clean --rmsource --rmspec --nodeps --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE
+       $RPMBUILD --clean --rmsource --rmspec --nodeps --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $SPECFILE
 }
 
 #---------------------------------------------
@@ -2126,6 +2136,12 @@ fi
 
 while [ $# -gt 0 ]; do
        case "${1}" in
+               -4|-6)
+                       # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
+                       # unfortunately $GETURI is already formed
+                       GETURI="$GETURI $1"
+                       shift
+                       ;;
                -5 | --update-md5)
                        COMMAND="update_md5"
                        NODIST="yes"
@@ -2559,7 +2575,7 @@ case "$COMMAND" in
                                ;;
                        *)
                                NODIST="yes" get_files $SOURCES $PATCHES
-                               update_md5 $SOURCES
+                               update_md5 $SOURCES $PATCHES
                                ;;
                esac
                build_package
@@ -2629,7 +2645,7 @@ case "$COMMAND" in
                if [ -n "$NOSOURCE0" ] ; then
                        SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
                fi
-               update_md5 $SOURCES
+               update_md5 $SOURCES $PATCHES
                ;;
        "tag" )
                NOURLS=1
This page took 0.040217 seconds and 4 git commands to generate.