]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
- escape some regexp characters in file name, so grep has a chance to find line with...
[packages/rpm-build-tools.git] / builder.sh
index 3f917fed06070454d8c5ca30abc2322ae0225fdb..f1fd2cc30ab754a5600d2dfda4927b6c136797a6 100644 (file)
@@ -37,8 +37,8 @@ APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
 RCSID='$Id$' r=${RCSID#* * } rev=${r%% *}
 VERSION="v0.35/$rev"
 VERSIONSTRING="\
-Build package utility from PLD Linux CVS repository
-$VERSION (C) 1999-2010 Free Penguins".
+Build package utility from PLD Linux Packages repository
+$VERSION (C) 1999-2011 Free Penguins".
 
 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
 
@@ -105,7 +105,7 @@ PACKAGE_RELEASE=""
 PACKAGE_VERSION=""
 PACKAGE_NAME=""
 ASSUMED_NAME=""
-PROTOCOL="ftp"
+PROTOCOL="http"
 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
 
 CVS_COMMAND=${CVS_COMMAND:-cvs}
@@ -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
@@ -255,7 +255,7 @@ usage() {
 Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--add_cvs] [-b|-ba|--build]
 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
-[-g|--get] [-h|--help] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
+[-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] [--use-greed-sources]
@@ -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,
@@ -300,7 +302,8 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 -g, --get           - get <package>.spec and all related files from CVS repo
                       or HTTP/FTP,
 -h, --help          - this message,
---http              - use http instead of ftp,
+-jN, -j N           - set %_smp_mflags to propagate concurrent jobs
+--ftp, --http       - use ftp or http protocol to access distfiles server
 -l <logfile>, --logtofile <logfile>
                     - log all to file,
 -nc, --no-cvs       - don't download sources from CVS, if source URL is given,
@@ -341,7 +344,7 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 -sf, --source-files - list sources - bare filenames (intended for offline
                       operations; does not work when Icon field is present
                       but icon file is absent),
--sp, --source-paths - list sources - filenames with full local paths (intended for
+-lsp, --source-paths - list sources - filenames with full local paths (intended for
                       offline operations; does not work when Icon field is present
                       but icon file is absent),
 -su, --source-urls  - list urls - urls to sources and patches
@@ -372,8 +375,10 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 -U, --update        - refetch sources, don't use distfiles, and update md5 comments
 -Upi, --update-poldek-indexes
                     - refresh or make poldek package index files.
+-sp, --skip-patch <patchnumber>
+                    - don't apply <patchnumber>. may be repeated.
 -np, --nopatch <patchnumber>
-                    - don't apply <patchnumber>
+                    - abort instead of applying patch <patchnumber>
 --show-bconds       - show available conditional builds, which can be used
                     - with --with and/or --without switches.
 --show-bcond-args   - show active bconds, from ~/.bcondrc. this is used by
@@ -391,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
@@ -739,8 +749,9 @@ get_spec() {
                if [ -d "$ASSUMED_NAME" -a -s "$ASSUMED_NAME/CVS/Root" ]; then
                        cvsup "$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
                elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
-                       if [ ! -d "$ASSUMED_NAME" ]; then
-                               install -d "$ASSUMED_NAME"
+                       if [ ! -r "$ASSUMED_NAME/$SPECFILE" ]; then
+                               echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
+                               exit 101
                        fi
                        if [ ! -s "$ASSUMED_NAME/CVS/Root" ]; then
                                cvsup -a $ASSUMED_NAME || Exit_error err_cvs_add_failed
@@ -820,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() {
@@ -854,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
@@ -864,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
@@ -999,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"
@@ -1018,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
@@ -1551,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`
@@ -2109,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
 }
 
 #---------------------------------------------
@@ -2122,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"
@@ -2174,8 +2194,18 @@ while [ $# -gt 0 ]; do
                        COMMAND="get"; shift ;;
                -h | --help )
                        COMMAND="usage"; shift ;;
+               --ftp )
+                       PROTOCOL="ftp"; shift ;;
                --http )
                        PROTOCOL="http"; shift ;;
+               -j)
+                       RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
+                       shift 2
+                       ;;
+               -j[0-9]*)
+                       RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
+                       shift
+                       ;;
                -l | --logtofile )
                        shift; LOGFILE="${1}"; shift ;;
                -ni| --nice )
@@ -2217,6 +2247,8 @@ while [ $# -gt 0 ]; do
                        shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
                --nopatch | -np )
                        shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
+               --skip-patch | -sp )
+                       shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
                --topdir)
                        RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
                        shift 2
@@ -2272,19 +2304,19 @@ while [ $# -gt 0 ]; do
                -sc | --sources-cvs)
                        COMMAND="list-sources-cvs"
                        shift ;;
-               -sd | --sources-distfiles)
+               -sd | --source-distfiles)
                        COMMAND="list-sources-distfiles"
                        shift ;;
-               -sdp | --sources-distfiles-paths)
+               -sdp | --source-distfiles-paths)
                        COMMAND="list-sources-distfiles-paths"
                        shift ;;
-               -sf | --sources-files)
+               -sf | --source-files)
                        COMMAND="list-sources-files"
                        shift ;;
-               -sp | --sources-paths)
+               -lsp | --source-paths)
                        COMMAND="list-sources-local-paths"
                        shift ;;
-               -su | --sources-urls)
+               -su | --source-urls)
                        COMMAND="list-sources-urls"
                        shift ;;
                -Tvs | --tag-version-stable )
@@ -2436,48 +2468,52 @@ update_shell_title "$COMMAND"
 case "$COMMAND" in
        "show_bconds")
                init_builder
-               if [ -n "$SPECFILE" ]; then
-                       get_spec > /dev/null
-                       parse_spec
-                       set_bconds_values
-                       display_bconds
+               if [ -z "$SPECFILE" ]; then
+                       Exit_error err_no_spec_in_cmdl
                fi
+               get_spec > /dev/null
+               parse_spec
+               set_bconds_values
+               display_bconds
                ;;
        "show_bcond_args")
                init_builder
-               if [ -n "$SPECFILE" ]; then
-                       get_spec > /dev/null
-                       parse_spec
-                       set_bconds_values
-                       echo "$BCOND"
+               if [ -z "$SPECFILE" ]; then
+                       Exit_error err_no_spec_in_cmdl
                fi
+               get_spec > /dev/null
+               parse_spec
+               set_bconds_values
+               echo "$BCOND"
                ;;
        "show_avail_bconds")
                init_builder
-               if [ -n "$SPECFILE" ]; then
-                       get_spec > /dev/null
-                       parse_spec
-                       local bcond_avail=$(find_spec_bcond $SPECFILE)
-                       local opt bcond bconds
-                       for opt in $bcond_avail; do
-                               case "$opt" in
-                               without_*)
-                                       bcond=${opt#without_}
-                                       bconds="$bconds $bcond"
-                                       ;;
-                               with_*)
-                                       bcond=${opt#with_}
-                                       bconds="$bconds $bcond"
-                                       ;;
-                               *)
-                                       echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
-                                       exit 1
-                                       ;;
-                               esac
-                       done
-                       echo $bconds
+               if [ -z "$SPECFILE" ]; then
+                       Exit_error err_no_spec_in_cmdl
                fi
 
+               get_spec > /dev/null
+               parse_spec
+               local bcond_avail=$(find_spec_bcond $SPECFILE)
+               local opt bcond bconds
+               for opt in $bcond_avail; do
+                       case "$opt" in
+                       without_*)
+                               bcond=${opt#without_}
+                               bconds="$bconds $bcond"
+                               ;;
+                       with_*)
+                               bcond=${opt#with_}
+                               bconds="$bconds $bcond"
+                               ;;
+                       *)
+                               echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
+                               exit 1
+                               ;;
+                       esac
+               done
+               echo $bconds
+
                ;;
        "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
                init_builder
@@ -2539,7 +2575,7 @@ case "$COMMAND" in
                                ;;
                        *)
                                NODIST="yes" get_files $SOURCES $PATCHES
-                               update_md5 $SOURCES
+                               update_md5 $SOURCES $PATCHES
                                ;;
                esac
                build_package
@@ -2609,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.065394 seconds and 4 git commands to generate.