]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
- make builder's chmod configurable
[packages/rpm-build-tools.git] / builder.sh
index ba19b08217d3da67e6ef3cbe1c36467e6525b4d3..108327ff54d58ee588b295e19cb59963f6ce3f90 100644 (file)
@@ -1,5 +1,6 @@
 #!/bin/sh
 # -----------
+# $Id$
 # Exit codes:
 #      0 - succesful
 #      1 - help dispayed
 
 VERSION="\
 Build package utility from PLD CVS repository
-V 0.6 (C) 1999 Tomasz K³oczko".
+V 0.9 (C) 1999-2001 Tomasz K³oczko".
 
 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
-
 COMMAND="build"
 
 SPECFILE=""
@@ -21,8 +22,19 @@ BE_VERBOSE=""
 QUIET=""
 CLEAN=""
 DEBUG=""
-CVSROOT=${CVSROOT:-""}
+NOURLS=""
+NOCVS=""
+ALLWAYS_CVSUP="yes"
+if [ -s CVS/Root ]; then
+    CVSROOT=$(cat CVS/Root)
+else
+    CVSROOT=${CVSROOT:-""}
+fi
 LOGFILE=""
+CHMOD=${CHMOD:-"yes"}
+CHMOD_MODE=${CHMOD_MODE:-444}
+RPMOPTS=""
+BCOND=""
 
 PATCHES=""
 SOURCES=""
@@ -30,6 +42,19 @@ ICONS=""
 PACKAGE_RELEASE=""
 PACKAGE_VERSION=""
 PACKAGE_NAME=""
+WGET_RETRIES=${MAX_WGET_RETRIES:-0}
+
+DEF_NICE_LEVEL=0
+
+FAIL_IF_NO_SOURCES="yes"
+
+GETURI="wget -c -nd -t$WGET_RETRIES"
+
+if [ -f ~/etc/builderrc ]; then
+  . ~/etc/builderrc
+elif [ -f ~/.builderrc ]; then
+  . ~/.builderrc
+fi
 
 #---------------------------------------------
 # functions
@@ -38,26 +63,43 @@ usage()
 {
     if [ -n "$DEBUG" ]; then set -xv; fi
     echo "\
-Usage: builder [-D] [--debug] [-V] [--version] [-a] [--as_anon] [-b]
-       [--build] [-d <cvsroot>] [--cvsroot <cvsroot>] [-g] [--get] [-h]
-       [--help] [-l <logfile>] [--logtofile <logfile>] [-q] [--quiet] [-r
-       <cvstag>] [--cvstag <cvstag>] [-v] [--verbose] <package>.spec
-
-       -D, --debug     - enable scrip debuging mode,
+Usage: builder [-D] [--debug] [-V] [--version] [-a] [--as_anon] [-b] [-ba]
+       [--build] [-bb] [--build-binary] [-bs] [--build-source]
+       [-d <cvsroot>] [--cvsroot <cvsroot>] [-g] [--get] [-h] [--help]
+       [-l <logfile>] [-m] [--mr-proper] [--logtofile <logfile>] [-q] [--quiet]
+       [-r <cvstag>] [--cvstag <cvstag>] [-u] [--no-urls] [-v] [--verbose]
+       [--opts <rpm opts>] [--with/--without pkg] <package>.spec
+
+       -D, --debug     - enable script debugging mode,
        -V, --version   - output builder version
-       -a, --as_anon   - get files via pserver as cvs@cvs.pld.org.pl,
-       -b, --build     - get all files from CVS repo and build
+       -a, --as_anon   - get files via pserver as cvs@anoncvs.pld.org.pl,
+       -b, -ba,
+       --build         - get all files from CVS repo or HTTP/FTP and build
                          package from <package>.spec,
-       -c, --clean     - clean all temporary maked files (in BUILD,
-                         SOURCES, SPECS and $RPM_BUILD_ROOT),
+       -bb,
+       --build-binary  - get all files from CVS repo or HTTP/FTP and build
+                         binary only package from <package>.spec,
+       -bs,
+       --build-source  - get all files from CVS repo or HTTP/FTP and only
+                         pack them into src.rpm,
+       -c, --clean     - clean all temporarily created files (in BUILD,
+                         SOURCES, SPECS and \$RPM_BUILD_ROOT),
+                         SOURCES, SPECS and \$RPM_BUILD_ROOT),
        -d, --cvsroot   - setup \$CVSROOT,
-       -g, --get       - get <package>.spec and all relayted files from
-                         CVS repo,
+       -g, --get       - get <package>.spec and all related files from
+                         CVS repo or HTTP/FTP,
        -h, --help      - this message,
        -l, --logtofile - log all to file,
+       -m, --mr-proper - only remove all files related to spec file and
+                         all work resources,
+       -nc, --no-cvs   - don't download from CVS, if source URL is given,
+       -nu, --no-urls  - don't try to download from FTP/HTTP location,
+       -ns, --no-srcs  - don't downland Sources
+       --opts          - additional options for rpm
        -q, --quiet     - be quiet,
        -r, --cvstag    - build package using resources from specified CVS
                          tag,
+       -T, --tag       - add cvs tags for files,
        -v, --verbose   - be verbose,
 
 "
@@ -65,24 +107,36 @@ Usage: builder [-D] [--debug] [-V] [--version] [-a] [--as_anon] [-b]
 
 parse_spec()
 {
-    if [ -n "$DEBUG" ]; then set -xv; fi
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v;
+    fi
+
+    cd $SPECS_DIR
 
-    sed -e "s#%prep#%dump#I" $SPECFILE | grep -v -i Icon > $SPECFILE.__
+    if [ "$NOSRCS" != "yes" ]; then
+        SOURCES="`rpm -bp --nobuild --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
+    fi
+    if (rpm -bp --nobuild --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
+       FAIL_IF_NO_SOURCES="no"
+    fi
 
-    SOURCES="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ SOURCE[0-9]+/ {print $3}'|sed -e 's#.*/##g'`"
-    PATCHES="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ PATCH[0-9]+/ {print $3}'|sed -e 's#.*/##g'`"
-    ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE} |sed -e 's#.*/##g'`"
-    PACKAGE_NAME="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ name/ {print $3}'`"
-    PACKAGE_VERSION="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ PACKAGE_VERSION/ {print $3}'`"
-    PACKAGE_RELEASE="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ PACKAGE_RELEASE/ {print $3}'`"
 
-    rm -f $SPECFILE.__
+    PATCHES="`rpm -bp --nobuild --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
+    ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
+    PACKAGE_NAME="`rpm -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
+    PACKAGE_VERSION="`rpm -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
+    PACKAGE_RELEASE="`rpm -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
 
     if [ -n "$BE_VERBOSE" ]; then
-       echo "- Sources :  $SOURCES"
-       echo "- Patches :  $PATCHES"
+       echo "- Sources :  `nourl $SOURCES`" 
+       if [ -n "$PATCHES" ]; then
+               echo "- Patches :  `nourl $PATCHES`"
+       else
+               echo "- Patches :  *no patches needed*"
+       fi
        if [ -n "$ICONS" ]; then
-           echo "- Icon    :  $ICONS"
+           echo "- Icon    :  `nourl $ICONS`"
        else
            echo "- Icon    :  *no package icon*"
        fi
@@ -94,11 +148,14 @@ parse_spec()
 
 Exit_error()
 {
-    if [ -n "$DEBUG" ]; then set -xv; fi
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
 
     cd $__PWD
 
-    case "$@" in
+    case "$1" in
     "err_no_spec_in_cmdl" )
        echo "ERROR: spec file name not specified.";
        exit 2 ;;
@@ -106,7 +163,7 @@ Exit_error()
        echo "Error: spec file not stored in CVS repo.";
        exit 3 ;;
     "err_no_source_in_repo" )
-       echo "Error: some source, apatch or icon files not stored in CVS repo.";
+       echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
        exit 4 ;;
     "err_build_fail" )
        echo "Error: package build failed.";
@@ -116,100 +173,180 @@ Exit_error()
 
 init_builder()
 {
-    if [ -n "$DEBUG" ]; then set -xv; fi
-
-    DUMB_SPEC_FILE=`mktemp -q /tmp/bilder.XXXXXX`
-    echo "\
-Summary:       -
-Name:          dumb
-Version:       dumb
-Release:       dumb
-Copyright:     dumb
-Group:         -
-%description
-
-%prep
-echo SOURCE_DIR=%{_sourcedir}
-echo SPECS_DIR=%{_specdir}" > $DUMB_SPEC_FILE
-
-    SOURCE_DIR=`rpm -bp $DUMB_SPEC_FILE 2>&1 | grep "^SOURCE_DIR" | sed "s/SOURCE_DIR\=//"`
-    SPECS_DIR=`rpm -bp $DUMB_SPEC_FILE 2>&1 | grep "^SPECS_DIR" |sed "s/SPECS_DIR\=//"`
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
 
-    rm -f $DUMB_SPEC_FILE
+    SOURCE_DIR="`rpm --eval '%{_sourcedir}'`"
+    SPECS_DIR="`rpm --eval '%{_specdir}'`"
 
     __PWD=`pwd`
 }
 
 get_spec()
 {
-    if [ -n "$DEBUG" ]; then set -xv; fi
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
 
     cd $SPECS_DIR
 
     OPTIONS="up "
 
     if [ -n "$CVSROOT" ]; then
-       OPTIONS="-d $CVSROOT"
+       OPTIONS="-d $CVSROOT $OPTIONS"
     fi
     if [ -n "$CVSTAG" ]; then
        OPTIONS="$OPTIONS -r $CVSTAG"
     else
-       OPTIONS="$OPTIONS -P"
+       OPTIONS="$OPTIONS -A"
     fi
 
     cvs $OPTIONS $SPECFILE
     if [ "$?" -ne "0" ]; then
        Exit_error err_no_spec_in_repo;
     fi
-
-    chmod 444 $SPECFILE
+       if [ ! -f "$SPECFILE" ]; then
+       Exit_error err_no_spec_in_repo;
+       fi
+    
+    if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
+        chmod $CHMOD_MODE $SPECFILE
+    fi
     unset OPTIONS
 }
 
-get_all_files()
+get_files()
 {
-    if [ -n "$DEBUG" ]; then set -xv; fi
+    GET_FILES="$@"
 
-    if [ -n "$SOURCES$PATCHES$ICONS" ]; then
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
+
+    if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
        cd $SOURCE_DIR
 
        OPTIONS="up "
        if [ -n "$CVSROOT" ]; then
-           OPTIONS="-d $CVSROOT"
+           OPTIONS="-d $CVSROOT $OPTIONS"
        fi
        if [ -n "$CVSTAG" ]; then
            OPTIONS="$OPTIONS -r $CVSTAG"
        else
-           OPTIONS="$OPTIONS -P"
+           OPTIONS="$OPTIONS -A"
        fi
+       for i in $GET_FILES; do
+           if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ] 
+             then
+               if 
+                       echo $i | grep -vE '(http|ftp|https|cvs)://' |\
+                       grep -qE '\.(gz|bz2)$'
+               then
+                       echo "Warning: no URL given for $i"
+               fi
+               
+               if      [ -z "$NOCVS" ]||\
+                       [ `echo $i | grep -vE '(ftp|http|https)://'` ]
+               then
+                       cvs $OPTIONS `nourl $i`
+               fi
+               
+               if      [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ]&&\
+                       [ `echo $i | grep -E 'ftp://|http://|https://'` ]
+               then
+                       ${GETURI} "$i"
+               fi
+
+               if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
+                       Exit_error err_no_source_in_repo $i;
+               fi
+           fi
+       done
+       
+       if [ "$CHMOD" = "yes" ]; then
+           CHMOD_FILES="`nourl $GET_FILES`"
+           if [ -n "$CHMOD_FILES" ]; then
+                   chmod $CHMOD_MODE $CHMOD_FILES
+           fi
+       fi
+       unset OPTIONS
+    fi
+}
+
+tag_files()
+{
+    TAG_FILES="$@"
 
-       cvs $OPTIONS $SOURCES $PATCHES $ICONS
-       if [ "$?" -ne "0" ]; then
-           Exit_error err_no_source_in_repo;
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
+
+    if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
+       echo $PACKAGE_VERSION
+       echo $PACKAGE_RELEASE
+       TAG=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g"`
+       echo "CVS tag: $TAG"
+
+       OPTIONS="tag -F"
+       if [ -n "$CVSROOT" ]; then
+           OPTIONS="-d $CVSROOT $OPTIONS"
        fi
 
-       chmod 444 $SOURCES $PATCHES $ICONS
+       cd $SOURCE_DIR
+       for i in $TAG_FILES; do
+           if [ -f `nourl $i` ]; then
+               cvs $OPTIONS $TAG `nourl $i`
+               cvs $OPTIONS STABLE `nourl $i`
+           else
+               Exit_error err_no_source_in_repo $i
+           fi
+       done
+
+       cd $SPECS_DIR
+       cvs $OPTIONS $TAG $SPECFILE
+       cvs $OPTIONS STABLE $SPECFILE
+
        unset OPTIONS
     fi
 }
 
 build_package()
 {
-    if [ -n "$DEBUG" ]; then set -xv; fi
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
 
     cd $SPECS_DIR
-    rpm -ba -v $QUIET $CLEAN $SPECFILE
+    case "$COMMAND" in
+       build )
+            BUILD_SWITCH="-ba" ;;
+       build-binary )
+           BUILD_SWITCH="-bb" ;;
+       build-source )
+           BUILD_SWITCH="-bs --nodeps" ;;
+    esac
+    nice -n ${DEF_NICE_LEVEL} rpm $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 
 
     if [ "$?" -ne "0" ]; then
        Exit_error err_build_fail;
     fi
+    unset BUILD_SWITCH
 }
 
-
+nourl()
+{
+       echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\)://.*/##g'
+}
 #---------------------------------------------
 # main()
 
-if [ "$#" == 0 ]; then
+if [ "$#" = 0 ]; then
     usage;
     exit 1
 fi
@@ -221,9 +358,13 @@ while test $# -gt 0 ; do
        -V | --version )
            COMMAND="version"; shift ;;
        -a | --as_anon )
-           CVSROOT=":pserver:cvs@cvs.pld.org.pl:/cvsroot"; shift ;;
-       -b | --build )
+           CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
+       -b | -ba | --build )
            COMMAND="build"; shift ;;
+       -bb | --build-binary )
+           COMMAND="build-binary"; shift ;;
+       -bs | --build-source )
+           COMMAND="build-source"; shift ;;
        -c | --clean )
            CLEAN="--clean --rmspec --rmsource"; shift ;;
        -d | --cvsroot )
@@ -234,10 +375,26 @@ while test $# -gt 0 ; do
            COMMAND="usage"; shift ;;
        -l | --logtofile )
            shift; LOGFILE="${1}"; shift ;;
+       -ni| --nice )
+           shift; DEF_NICE_LEVEL=${1}; shift ;;
+       -m | --mr-proper )
+           COMMAND="mr-proper"; shift ;;
+       -nc | --no-cvs )
+           NOCVS="yes"; shift ;;
+       -nu | --no-urls )
+           NOURLS="yes"; shift ;;
+       -ns | --no-srcs )
+           NOSRCS="yes"; shift ;;
+       --opts )
+           shift; RPMOPTS="${1}"; shift ;;
+       --with | --without )
+           BCOND="$BCOND $1 $2" ; shift 2 ;;
        -q | --quiet )
            QUIET="--quiet"; shift ;;
        -r | --cvstag )
            shift; CVSTAG="${1}"; shift ;;
+       -T | --tag )
+           COMMAND="tag"; shift;;
        -v | --verbose )
            BE_VERBOSE="1"; shift ;;
        * )
@@ -245,15 +402,22 @@ while test $# -gt 0 ; do
     esac
 done
 
-if [ -n "$DEBUG" ]; then set -xv; fi
+if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+fi
 
 case "$COMMAND" in
-    "build" )
+    "build" | "build-binary" | "build-source" )
        init_builder;
        if [ -n "$SPECFILE" ]; then
            get_spec;
            parse_spec;
-           get_all_files;
+           if [ -n "$ICONS" ]; then
+               get_files $ICONS;
+               parse_spec;
+           fi
+           get_files "$SOURCES $PATCHES";
            build_package;
        else
            Exit_error err_no_spec_in_cmdl;
@@ -264,11 +428,33 @@ case "$COMMAND" in
        if [ -n "$SPECFILE" ]; then
            get_spec;
            parse_spec;
-           get_all_files;
+           if [ -n "$ICONS" ]; then
+                   get_files $ICONS
+                   parse_spec;
+           fi
+           get_files $SOURCES $PATCHES
        else
            Exit_error err_no_spec_in_cmdl;
        fi
        ;;
+    "tag" )
+       init_builder;
+       if [ -n "$SPECFILE" ]; then
+           get_spec;
+           parse_spec;
+           if [ -n "$ICONS" ]; then
+                   get_files $ICONS
+                   parse_spec;
+           fi
+           get_files $SOURCES $PATCHES;
+           tag_files "$SOURCES $PATCHES $ICONS";
+       else
+           Exit_error err_no_spec_in_cmdl;
+       fi
+       ;;
+    "mr-proper" )
+       rpm --clean --rmsource --rmspec --force --nodeps $SPECFILE
+       ;;
     "usage" )
        usage;;
     "version" )
@@ -276,3 +462,52 @@ case "$COMMAND" in
 esac
 
 cd $__PWD
+
+# $Log$
+# Revision 1.83  2001/10/10 08:41:32  misiek
+# - allow more bconds than one
+#
+# Revision 1.82  2001/09/18 10:55:37  ankry
+# - added support for limitting number of wget retries when fetching a file
+#   from ftp/http server via environment variable MAX_WGET_RETRIES.
+#   Defaults to infinite (0).
+#
+# Revision 1.81  2001/07/06 16:52:30  misiek
+# - by default use CVSroot from CVS/Root and if it doesn't exist use from CVSROOT variable
+#
+# Revision 1.80  2001/06/22 18:52:39  misiek
+# - added support for --with/--without options
+#
+# Revision 1.79  2001/05/28 14:44:16  baggins
+# - if file is not in repo TELL which fucking file it is!
+#
+# Revision 1.78  2001/05/13 19:04:44  misiek
+# fixes for ksh93
+#
+# Revision 1.77  2001/05/13 10:51:30  misiek
+# don't fail if no sources found (hack to allow build nosrc packages)
+#
+# Revision 1.76  2001/04/19 23:24:06  misiek
+# fix chmod again
+#
+# Revision 1.75  2001/04/19 23:14:25  misiek
+# redirect errors from query to /dev/null
+#
+# Revision 1.74  2001/04/02 15:39:29  misiek
+# fix problems with get_files when no files passed
+#
+# Revision 1.73  2001/03/30 14:06:10  wiget
+# massive typo by kloczek
+#
+# Revision 1.72  2001/03/26 22:16:22  kloczek
+# - fixed grabbing name, version and release in parse_spec(),
+# - added -T option (tag) (temporary it tags also additional STABLE tag - must
+#   be added -Ts for separate tagging as STABLE).
+#
+# Revision 1.71  2001/03/05 14:12:27  misiek
+# fix chmod
+#
+# Revision 1.70  2001/03/03 19:55:42  misiek
+# workaround for problems with rpm when icons isn't cvs up'ed
+#
+#
This page took 0.091786 seconds and 4 git commands to generate.