X-Git-Url: https://git.pld-linux.org/?a=blobdiff_plain;f=builder.sh;h=f2c514f31b47530376c8c030f5f06237714cca68;hb=5b95e67782c8eb79b3d62cf4d7bb3939e2017c88;hp=fdde6ae278095f38ef90e5a3fed6b0cf62475474;hpb=23c6eee031b5ef4f0f6522d0180eead17edf81c8;p=packages%2Frpm-build-tools.git diff --git a/builder.sh b/builder.sh index fdde6ae..f2c514f 100644 --- a/builder.sh +++ b/builder.sh @@ -1,4 +1,4 @@ -#!/bin/sh -xv +#!/bin/sh # ----------- # Exit codes: # 0 - succesful @@ -10,44 +10,82 @@ VERSION="\ Build package utility from PLD CVS repository -V 0.5 (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="" -ICON="" +ICONS="" 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 ] [-g] [--get] [-h] [--help] - [-l ] [--logtofile ] [-q] [--quiet] - [-v] [--verbose] .spec + [-l ] [-m] [--mr-proper] [--logtofile ] [-q] [--quiet] + [-r ] [--cvstag ] [-u] [--no-urls] [-v] [--verbose] + [--opts ] .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 .spec, + -bb, + --build-binary - get all files from CVS repo or HTTP/FTP and build + binary only package from .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 .spec and all relayted files from - CVS repo, + -g, --get - get .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, " @@ -55,11 +93,16 @@ 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}'`" @@ -67,21 +110,30 @@ parse_spec() rm -f $SPECFILE.__ if [ -n "$BE_VERBOSE" ]; then - echo "- Sources : $SOURCES" - echo "- Patches : $PATCHES" - if [ -n "$ICON" ]; then - echo "- Icon : $ICON" + 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 : `nourl $ICONS`" else echo "- Icon : *no package icon*" fi echo "- Name : $PACKAGE_NAME" echo "- Version : $PACKAGE_VERSION" - echo "- Release : $PACKAGE_RELEASE" + echo "- Release : $PACKAGE_RELEASE" fi } Exit_error() { + if [ -n "$DEBUG" ]; then + set -x; + set -v; + fi + cd $__PWD case "$@" in @@ -92,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."; @@ -102,84 +154,157 @@ 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 + 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() { - cd $SOURCE_DIR - if [ -n "$CVSROOT" ]; then - cvs -d "$CVSROOT" up $SOURCES $PATCHES $ICON - else - cvs up up $SOURCES $PATCHES $ICON + if [ -n "$DEBUG" ]; then + set -x; + set -v; fi - if [ "$?" -ne "0" ]; then - Exit_error err_no_source_in_repo; + 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() { + if [ -n "$DEBUG" ]; then + set -x; + set -v; + fi + cd $SPECS_DIR - rpm -ba -v $QUIET $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 ) shift; CVSROOT="${1}"; shift ;; -g | --get ) @@ -188,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 ;; * ) @@ -197,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; @@ -219,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" )