]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
- remove some bashizm
[packages/rpm-build-tools.git] / builder.sh
index c6397a3b86814d09b576975334f58bdf4f46c39d..06d0795ae3ccad744d1bfdf3a1e2ca858b09ce9b 100644 (file)
@@ -57,6 +57,7 @@ CHMOD="no"
 CHMOD_MODE="0444"
 RPMOPTS=""
 BCOND=""
+GROUP_BCONDS="no"
 
 PATCHES=""
 SOURCES=""
@@ -98,9 +99,9 @@ POLDEK_SOURCE="cvs"
 
 # Example grep cvs /etc/poldek.conf:
 # source = cvs /home/users/yoshi/rpm/RPMS/
-if [ "$UPDATE_POLDEK_INDEXES" == "yes" ]; then
+if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
        POLDEK_SOURCE_VALIDITY="`grep ${POLDEK_SOURCE} /etc/poldek.conf|grep -v ^#`"
-       if [ "${POLDEK_SOURCE_VALIDITY}" == "" ]; then 
+       if [ "${POLDEK_SOURCE_VALIDITY}" = "" ]; then 
                echo "Using improper source '${POLDEK_SOURCE}' in /etc/poldek.conf"
                echo "Fix it and try to contiune"
                exit 7
@@ -185,6 +186,12 @@ Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
                          tag,
         -R, --fetch-build-requires
                         - fetch what is BuildRequired,
+       -RB, --remove-build-requires
+                       - remove all you fetched with -R or --fetch-build-requires
+                         remember, this option requires confirmation,
+       -FRB, --force-remove-build-requires
+                       - remove all you fetched with -R or --fetch-build-requires
+                         remember, this option works without confirmation,
        -T <cvstag> , --tag <cvstag>
                        - add cvs tag <cvstag> for files,
        -Tvs, --tag-version-stable
@@ -290,15 +297,19 @@ Exit_error()
 
     case "$1" in
     "err_no_spec_in_cmdl" )
+        remove_build_requires
        echo "ERROR: spec file name not specified.";
        exit 2 ;;
     "err_no_spec_in_repo" )
+        remove_build_requires
        echo "Error: spec file not stored in CVS repo.";
        exit 3 ;;
     "err_no_source_in_repo" )
+        remove_build_requires
        echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
        exit 4 ;;
     "err_build_fail" )
+        remove_build_requires
        echo "Error: package build failed. (${2:-no more info})";
        exit 5 ;;
     esac
@@ -807,10 +818,29 @@ do
 done
 }
 
+remove_build_requires()
+{
+    if [ "$INSTALLED_PACKAGES" != "" ]; then
+           case "$REMOVE_BUILD_REQUIRES" in
+                   "force")
+                       poldek --noask -e $INSTALLED_PACKAGES
+                   ;;
+                   "nice")
+                       poldek --ask -e $INSTALLED_PACKAGES
+                   ;;
+                   *)
+                           echo You may want to manually remove following BuildRequires fetched:
+                           echo $INSTALLED_PACKAGES
+                           echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
+                   ;;
+           esac
+    fi
+}
+
 display_bconds()
 {
 if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
-        echo -ne "We are going to build $SPECFILE with the following confitional flags:\n"
+        echo -ne "We are going to build $SPECFILE with the following conditional flags:\n"
         if [ "$BCOND" != "" ]; then
                 echo -ne "$BCOND"
         else
@@ -823,7 +853,12 @@ fi
 
 fetch_build_requires()
 {
-if [ "$FETCH_BUILD_REQUIRES" == "yes" ]; then
+if [ "$FETCH_BUILD_REQUIRES" = "yes" ]; then
+           echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
+           echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
+           echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
+           echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
+           echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
             for package_item in `cat $SPECFILE|grep -B100000 ^%changelog|grep -v ^#|grep BuildRequires|grep -v ^-|sed -e "s/^.*BuildRequires://g"|awk '{print $1}'|sed -e s,\(.*\),,g -e s,%{,,g`
             do
                package_item=`echo $package_item|sed -e s,rpmbuild,rpm-build,g`
@@ -883,19 +918,35 @@ if [ "$FETCH_BUILD_REQUIRES" == "yes" ]; then
 
                 fi
               
-                if [ "$GO" == "yes" ]; then
+                if [ "$GO" = "yes" ]; then
                         if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
-                                echo "Package $package is not installed. Attempting to install..."
-                                poldek -i $package
-                                case $? in
-                                1)
-                                        echo "Unable to install $package package! Still trying to fetch rest..."
-                                        NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package"
-                                        ;;
-                                0)
-                                       INSTALLED_PACKAGES="$package $INSTALLED_PACKAGES"
-                                        ;;
-                                esac
+                                echo "Testing if $package has subrequirements..."
+                               poldek -t -i $package --dumpn=".$package-req.txt"
+                               for package_name in `cat ".$package-req.txt"|grep -v ^#`
+                               do 
+                                       if [ "$package_name" = "$package" ]; then
+                                               echo -ne "Installing BuildRequired package:\t$package_name\n"
+                                               poldek -i $package_name
+                                       else
+                                               echo -ne "Installing (sub)Required package:\t$package_name\n"
+                                               poldek -i $package_name
+                                       fi
+                                       case $? in
+                                       1)
+                                               echo -ne "Package installation failed:\t$package_name\n"
+                                               #
+                                               # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
+                                               # pakieta zbudowaæ. 
+                                               #
+                                               NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
+                                               ;;
+                                       0)
+                                               INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
+                                               echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
+                                               ;;
+                                       esac
+                               done
+                               rm ".$package-req.txt"
                         else
                                 echo "Package $package is already installed. BuildRequirement satisfied."
                         fi
@@ -907,6 +958,7 @@ if [ "$FETCH_BUILD_REQUIRES" == "yes" ]; then
                     do
                             echo $pkg
                     done
+                   remove_build_requires
                     exit 1
             fi
 fi
@@ -983,13 +1035,19 @@ while test $# -gt 0 ; do
        --opts )
            shift; RPMOPTS="${1}"; shift ;;
        --with | --without )
-            COND=${1}
-            shift
-            while [ "`echo ${1}|grep ^-`" == "" ] && [ "`echo ${1}|grep spec`" == "" ]
-            do
-                BCOND="$BCOND $COND $1"
-                shift
-            done;;
+           case $GROUP_BCONDS in
+               "yes")
+                       COND=${1}
+                       shift
+                       while [ "`echo ${1}|grep ^-`" = "" ] && [ "`echo ${1}|grep spec`" = "" ]
+                       do
+                               BCOND="$BCOND $COND $1"
+                               shift
+                       done;;
+               "no")
+                       BCOND="$BCOND $1 $2" ; shift 2 ;;
+           esac
+           ;;
        -q | --quiet )
            QUIET="--quiet"; shift ;;
        --date )
@@ -1001,6 +1059,12 @@ while test $# -gt 0 ; do
            #UPDATE_POLDEK_INDEXES="yes"
             NOT_INSTALLED_PACKAGES=
             shift ;;
+        -RB | --remove-build-requires)
+            REMOVE_BUILD_REQUIRES="nice"
+           shift ;;
+       -FRB | --force-remove-build-requires)
+           REMOVE_BUILD_REQUIRES="force"
+           shift ;;
        -Tvs | --tag-version-stable )
            COMMAND="tag";
            TAG="STABLE"
@@ -1101,10 +1165,11 @@ case "$COMMAND" in
            fi
            get_files "$SOURCES $PATCHES";
            build_package;
-           if [ $? -eq 0 ] && [ "$UPDATE_POLDEK_INDEXES" == "yes" ]; then
+           if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
                    poldek --sn ${POLDEK_SOURCE} --mkidx="${POLDEK_INDEX_DIR}/packages.dir.gz"
                    poldek --sn ${POLDEK_SOURCE} --up
            fi
+           remove_build_requires;
        else
            Exit_error err_no_spec_in_cmdl;
        fi
@@ -1171,5 +1236,4 @@ case "$COMMAND" in
     "version" )
        echo "$VERSION";;
 esac
-
 cd $__PWD
This page took 0.041744 seconds and 4 git commands to generate.