]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
- s/^Utilities/Applications
[packages/rpm-build-tools.git] / builder.sh
index 423c4e13c0e1a0ed276551fdb48bcba217abfc50..f2c514f31b47530376c8c030f5f06237714cca68 100644 (file)
@@ -1,59 +1,91 @@
-#!/bin/bash
-# 
+#!/bin/sh
+# -----------
+# Exit codes:
+#      0 - succesful
+#      1 - help dispayed
+#      2 - no spec file name in cmdl parameters
+#      3 - spec file not stored in repo
+#      4 - some source, apatch or icon files not stored in repo
+#      5 - build package no succed
 
 VERSION="\
 Build package utility from PLD CVS repository
-V 0.1 (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=""
-CVSROOT=${$CVSROOT:-""}
+CLEAN=""
+DEBUG=""
+NOURLS=""
+NOCVS=""
+ALLWAYS_CVSUP="yes"
+CVSROOT=${CVSROOT:-""}
 LOGFILE=""
+CHMOD="yes"
+RPMOPTS=""
 
 PATCHES=""
 SOURCES=""
-ICON=""
+ICONS=""
 PACKAGE_RELEASE=""
 PACKAGE_VERSION=""
 PACKAGE_NAME=""
 
-dumb_spec="\
-Summary:       -
-Name:          dumb
-Version:       dumb
-Release:       dumb
-Copyright:     dumb
-Group:         -
-%description
+DEF_NICE_LEVEL=0
 
-%prep
-echo SOURCEDIR=%{_sourcedir}
-echo SPECS=%{_specdir}"
+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,
+       -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,
 
 "
@@ -61,63 +93,218 @@ Usage: builder [-V] [--version] [-a] [--as_anon] [-b] [--build]
 
 parse_spec()
 {
-    sed -e "s/^Summary:*/Summary:\%dump/I" $SPECFILE > $SPECFILE.__
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
 
-    SOURCES="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ SOURCE[0-9]+/ {print $3}'`"
-    PATCHES="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ PATCH[0-9]+/ {print $3}'`"
-    ICON="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/^Icon:/ {print $2}' ${SPEC}`"
+    sed -e "s#%prep#%dump#I" $SPECFILE | grep -v -i "^Icon\:" > $SPECFILE.__
+
+    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}'`"
 
     rm -f $SPECFILE.__
 
-    if [ "$BE_VERBOSE" != "" ]; then
-       echo -e "- Sources :\n  " $SOURCES
-       echo -e "- Patches :\n  " $PATCHES
-       if [ "$ICON" != "" ]; then
-           echo -e "- Icon    :\n  " $ICON
+    if [ -n "$BE_VERBOSE" ]; then
+       echo "- Sources :  `nourl $SOURCES`" 
+       if [ -n "$PATCHES" ]; then
+               echo "- Patches :  `nourl $PATCHES`"
        else
-           echo -e "- Icon    :  *no package icon*"
+               echo "- Patches :  *no patches needed*"
        fi
-       echo -e "- Name    : " $PACKAGE_NAME
-       echo -e "- Version : " $PACKAGE_VERSION
-       echo -e "- Release : " $PACKAGE_RELEASE
+       if [ -n "$ICONS" ]; then
+           echo "- Icon    :  `nourl $ICONS`"
+       else
+           echo "- Icon    :  *no package icon*"
+       fi
+       echo "- Name    : $PACKAGE_NAME"
+       echo "- Version : $PACKAGE_VERSION"
+       echo "- Release : $PACKAGE_RELEASE"
     fi
 }
 
+Exit_error()
+{
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
+
+    cd $__PWD
+
+    case "$@" in
+    "err_no_spec_in_cmdl" )
+       echo "ERROR: spec file name not specified.";
+       exit 2 ;;
+    "err_no_spec_in_repo" )
+       echo "Error: spec file not stored in CVS repo.";
+       exit 3 ;;
+    "err_no_source_in_repo" )
+       echo "Error: some source, patch or icon files not stored in CVS repo.";
+       exit 4 ;;
+    "err_build_fail" )
+       echo "Error: package build failed.";
+       exit 5 ;;
+    esac
+}
+
+init_builder()
+{
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
+
+    SOURCE_DIR="`rpm --eval "%{_sourcedir}"`"
+    SPECS_DIR="`rpm --eval "%{_specdir}"`"
+
+    __PWD=`pwd`
+}
+
 get_spec()
 {
-    echo "get_spec"
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
+
+    cd $SPECS_DIR
+
+    OPTIONS="up "
+
+    if [ -n "$CVSROOT" ]; then
+       OPTIONS="-d $CVSROOT $OPTIONS"
+    fi
+    if [ -n "$CVSTAG" ]; then
+       OPTIONS="$OPTIONS -r $CVSTAG"
+    else
+       OPTIONS="$OPTIONS -A"
+    fi
+
+    cvs $OPTIONS $SPECFILE
+    if [ "$?" -ne "0" ]; then
+       Exit_error err_no_spec_in_repo;
+    fi
+       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()
 {
-    echo "get_all_files"
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
+
+    if [ -n "$SOURCES$PATCHES$ICONS" ]; then
+       cd $SOURCE_DIR
+
+       OPTIONS="up "
+       if [ -n "$CVSROOT" ]; then
+           OPTIONS="-d $CVSROOT $OPTIONS"
+       fi
+       if [ -n "$CVSTAG" ]; then
+           OPTIONS="$OPTIONS -r $CVSTAG"
+       else
+           OPTIONS="$OPTIONS -A"
+       fi
+       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
+       unset OPTIONS
+    fi
 }
 
 build_package()
 {
-    echo "build_package"
-}
+    if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+    fi
+
+    cd $SPECS_DIR
+    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
+    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 )
            shift; CVSROOT="${1}"; shift ;;
        -g | --get )
@@ -126,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="1"; shift ;;
+           QUIET="--quiet"; shift ;;
+       -r | --cvstag )
+           shift; CVSTAG="${1}"; shift ;;
        -v | --verbose )
            BE_VERBOSE="1"; shift ;;
        * )
@@ -135,30 +334,40 @@ while test $# -gt 0 ; do
     esac
 done
 
+if [ -n "$DEBUG" ]; then 
+       set -x;
+       set -v; 
+fi
+
 case "$COMMAND" in
-    "build" )
-       if [ "$SPECFILE" != "" ]; then
+    "build" | "build-binary" | "build-source" )
+       init_builder;
+       if [ -n "$SPECFILE" ]; then
            get_spec;
            parse_spec;
            get_all_files;
            build_package;
        else
-           echo "ERROR: spec file name not specified.";
-           usage;
+           Exit_error err_no_spec_in_cmdl;
        fi
        ;;
     "get" )
-       if [ "$SPECFILE" != "" ]; then
+       init_builder;
+       if [ -n "$SPECFILE" ]; then
            get_spec;
            parse_spec;
            get_all_files;
        else
-           echo "ERROR: spec file name not specified.";
-           usage;
+           Exit_error err_no_spec_in_cmdl;
        fi
        ;;
+    "mr-proper" )
+       rpm --clean --rmsource --rmspec --force --nodeps $SPECFILE
+       ;;
     "usage" )
        usage;;
     "version" )
        echo "$VERSION";;
 esac
+
+cd $__PWD
This page took 0.039544 seconds and 4 git commands to generate.