]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
- s/^Utilities/Applications
[packages/rpm-build-tools.git] / builder.sh
index 263ba6e459b7b589cd28f0571770219faada2341..f2c514f31b47530376c8c030f5f06237714cca68 100644 (file)
 
 VERSION="\
 Build package utility from PLD CVS repository
-V 0.6 (C) 1999 Tomasz K³oczko".
+V 0.8 (C) 1999 Tomasz K³oczko".
 
 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
-
 COMMAND="build"
 
 SPECFILE=""
@@ -21,8 +21,13 @@ BE_VERBOSE=""
 QUIET=""
 CLEAN=""
 DEBUG=""
+NOURLS=""
+NOCVS=""
+ALLWAYS_CVSUP="yes"
 CVSROOT=${CVSROOT:-""}
 LOGFILE=""
+CHMOD="yes"
+RPMOPTS=""
 
 PATCHES=""
 SOURCES=""
@@ -31,6 +36,14 @@ PACKAGE_RELEASE=""
 PACKAGE_VERSION=""
 PACKAGE_NAME=""
 
+DEF_NICE_LEVEL=0
+
+if [ -f ~/etc/builderrc ]; then
+  . ~/etc/builderrc
+elif [ -f ~/.builderrc ]; then
+  . ~/.builderrc
+fi
+
 #---------------------------------------------
 # functions
 
@@ -38,23 +51,38 @@ 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>] <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,
+       --opts          - additional options for rpm
        -q, --quiet     - be quiet,
        -r, --cvstag    - build package using resources from specified CVS
                          tag,
@@ -65,13 +93,16 @@ 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
 
-    sed -e "s#%prep#%dump#I" $SPECFILE | grep -v -i Icon > $SPECFILE.__
+    sed -e "s#%prep#%dump#I" $SPECFILE | grep -v -i "^Icon\:" > $SPECFILE.__
 
-    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'`"
+    SOURCES="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ SOURCEURL[0-9]+/ {print $3}'`"
+    PATCHES="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ PATCHURL[0-9]+/ {print $3}'`"
+    ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
     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}'`"
@@ -79,10 +110,14 @@ parse_spec()
     rm -f $SPECFILE.__
 
     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,7 +129,10 @@ parse_spec()
 
 Exit_error()
 {
-    if [ -n "$DEBUG" ]; then set -xv; fi
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
 
     cd $__PWD
 
@@ -106,7 +144,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.";
        exit 4 ;;
     "err_build_fail" )
        echo "Error: package build failed.";
@@ -116,33 +154,23 @@ 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
 
@@ -161,14 +189,22 @@ get_spec()
     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" ]; then
+        chmod 444 $SPECFILE
+    fi
     unset OPTIONS
 }
 
 get_all_files()
 {
-    if [ -n "$DEBUG" ]; then set -xv; fi
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
 
     if [ -n "$SOURCES$PATCHES$ICONS" ]; then
        cd $SOURCE_DIR
@@ -182,34 +218,73 @@ get_all_files()
        else
            OPTIONS="$OPTIONS -A"
        fi
-
-       cvs $OPTIONS $SOURCES $PATCHES $ICONS
-       if [ "$?" -ne "0" ]; then
-           Exit_error err_no_source_in_repo;
+       for i in $SOURCES $PATCHES $ICONS; 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
+                       wget -c -nd -t0 "$i"
+               fi
+
+               if [ ! -f "`nourl $i`" ]; then
+                       Exit_error err_no_source_in_repo;
+               fi
+           fi
+       done
+       
+       if [ "$CHMOD" = "yes" ]; then
+           chmod 444 `nourl $SOURCES $PATCHES $ICONS`
        fi
-
-       chmod 444 $SOURCES $PATCHES $ICONS
        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 $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 +296,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,6 +313,16 @@ 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 ;;
+       --opts )
+           shift; RPMOPTS="${1}"; shift ;;
        -q | --quiet )
            QUIET="--quiet"; shift ;;
        -r | --cvstag )
@@ -245,10 +334,13 @@ 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;
@@ -269,6 +361,9 @@ case "$COMMAND" in
            Exit_error err_no_spec_in_cmdl;
        fi
        ;;
+    "mr-proper" )
+       rpm --clean --rmsource --rmspec --force --nodeps $SPECFILE
+       ;;
     "usage" )
        usage;;
     "version" )
This page took 0.046274 seconds and 4 git commands to generate.