]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
- s/^Utilities/Applications
[packages/rpm-build-tools.git] / builder.sh
index 88015feccc7c03c2e125ec1f35e9b23e98f657d4..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=""
 BE_VERBOSE=""
 QUIET=""
 CLEAN=""
+DEBUG=""
+NOURLS=""
+NOCVS=""
+ALLWAYS_CVSUP="yes"
 CVSROOT=${CVSROOT:-""}
 LOGFILE=""
+CHMOD="yes"
+RPMOPTS=""
 
 PATCHES=""
 SOURCES=""
@@ -30,29 +36,56 @@ PACKAGE_RELEASE=""
 PACKAGE_VERSION=""
 PACKAGE_NAME=""
 
+DEF_NICE_LEVEL=0
+
+if [ -f ~/etc/builderrc ]; then
+  . ~/etc/builderrc
+elif [ -f ~/.builderrc ]; then
+  . ~/.builderrc
+fi
+
 #---------------------------------------------
 # functions
 
 usage()
 {
-echo "\
-Usage: builder [-V] [--version] [-a] [--as_anon] [-b] [--build]
+    if [ -n "$DEBUG" ]; then set -xv; fi
+    echo "\
+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>] [--logtofile <logfile>] [-q] [--quiet] 
-       [-v] [--verbose] <package>.spec
+       [-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,
        -v, --verbose   - be verbose,
 
 "
@@ -60,11 +93,16 @@ Usage: builder [-V] [--version] [-a] [--as_anon] [-b] [--build]
 
 parse_spec()
 {
-    sed -e "s#%prep#%dump#I" $SPECFILE | grep -v -i Icon > $SPECFILE.__
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
+
+    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}'`"
@@ -72,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
@@ -87,6 +129,11 @@ parse_spec()
 
 Exit_error()
 {
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
+
     cd $__PWD
 
     case "$@" in
@@ -97,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.";
@@ -107,92 +154,155 @@ Exit_error()
 
 init_builder()
 {
-    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 -x;
+       set -v; 
+    fi
+
     cd $SPECS_DIR
 
+    OPTIONS="up "
+
     if [ -n "$CVSROOT" ]; then
-       cvs -d "$CVSROOT" up $SPECFILE
+       OPTIONS="-d $CVSROOT $OPTIONS"
+    fi
+    if [ -n "$CVSTAG" ]; then
+       OPTIONS="$OPTIONS -r $CVSTAG"
     else
-       cvs up $SPECFILE
+       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" ]; then
+        chmod 444 $SPECFILE
+    fi
+    unset OPTIONS
 }
 
 get_all_files()
 {
-set -xv
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
+
     if [ -n "$SOURCES$PATCHES$ICONS" ]; then
        cd $SOURCE_DIR
 
+       OPTIONS="up "
        if [ -n "$CVSROOT" ]; then
-           cvs -d "$CVSROOT" up $SOURCES $PATCHES $ICONS
+           OPTIONS="-d $CVSROOT $OPTIONS"
+       fi
+       if [ -n "$CVSTAG" ]; then
+           OPTIONS="$OPTIONS -r $CVSTAG"
        else
-           cvs up $SOURCES $PATCHES $ICONS
+           OPTIONS="$OPTIONS -A"
        fi
-
-       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 -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
 
 while test $# -gt 0 ; do
     case "${1}" in
+       -D | --debug )
+           DEBUG="yes"; shift ;;
        -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 )
@@ -203,8 +313,20 @@ 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 )
+           shift; CVSTAG="${1}"; shift ;;
        -v | --verbose )
            BE_VERBOSE="1"; shift ;;
        * )
@@ -212,8 +334,13 @@ while test $# -gt 0 ; do
     esac
 done
 
+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;
@@ -234,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.040936 seconds and 4 git commands to generate.