From fceb876786e757a358686258b9039a88122adbe1 Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Sun, 20 Nov 2011 20:16:09 -0600 Subject: [PATCH] - Add the --resultdir option to specify different directory in mock rebuild - Update README --- README.md | 11 ++++- mock_all_fedora | 124 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 96 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 970a53b..cd5aee1 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,19 @@ This script does two things. First it uses rpmbuild to create a SRPM, and then it runs a mock rebuild. With the current variables set at the top, it will build RPMs for Fedora 14-16 both i386 and x86_64. The variables may need to be altered. ## Usage ## + +Run the following from your rpmbuild SPEC directory + ``` +# Specifying the directory to output mock logs and final RPMs +mock_all_fedora --resultdir ${HOME}/rpmbuild/RPMS/"%(dist)s"/"%(target_arch)s" package.spec + +# Using default mock results dir mock_all_fedora package.spec ``` ## To-Do ## -* Extend to use arguments to allow for greater flexibility +None planned, but if you have a request please open an issue # create_all_repos # @@ -22,3 +29,5 @@ create_all_repos * Configure to be much more flexible and not require editing of variables to change script's behavior * Better error handling + +Additional features can be requested via the issue tracker diff --git a/mock_all_fedora b/mock_all_fedora index 8c25e9e..da21d63 100755 --- a/mock_all_fedora +++ b/mock_all_fedora @@ -1,13 +1,59 @@ #!/bin/bash +########################################################### +# This script is used to build RPMs for multiple versions of Fedora +# +# Example usage +# +# mock_all_fedora --resultdir ${HOME}/rpmbuild/RPMS/"%(dist)s"/"%(target_arch)s" package.spec +# +########################################################### + +ARGS=`getopt -o hr: -l help,resultdir: -n "$0" -- "$@"` + +usage () { + +cat << EOF +usage: $(basename $0) -r package.spec + +This script runs a mock rebuild using the specified spec file (ie package.spec) +for Fedora 14-16, x86_64 and i386 + +OPTIONS: + -h, --help Show this message + -r, --results-dir Path to mock results directory + Optional, if unspecified uses mock default + +EOF +} + +[ $# -lt 1 ] && { usage; exit 1; } + +eval set -- "${ARGS}" + +while true; do + case "$1" in + -h|--help) + usage + exit 0 + ;; + -r|--resultdir) + case "$2" in + "") RESULTS_DIR=""; shift 2;; + *) RESULTS_DIR="--resultdir $2"; shift 2;; + esac ;; + --) + shift + break;; + *) + break;; + esac +done + +#[ -z ${RESULTS_DIR} ] && { usage; exit 1; } -if [ ${#} -lt 1 ] || [ ${#} -gt 1 ]; then - echo "Error: wrong number of arguments" - echo "Usage: ${0} " - exit 1 -fi +[ $# -lt 1 ] && { echo "Missing spec file argument"; usage; exit 1; } SPEC="${1}" -RESULTS_DIR="${HOME}/rpmbuild/RPMS/%(dist)s/%(target_arch)s" ARCH="x86_64 i386" DISTRO="fedora" DIST_PREFIX="fc" @@ -23,56 +69,58 @@ RPMBUILD_FAIL="" # Determine if mock is installed test -x ${MOCK} &>/dev/null || { echo "ERROR: ${MOCK} not found"; exit 1; } +# Determine if rpmbuild is installed +test -x ${RPMBUILD} &>/dev/null || { echo "ERROR: ${RPMBUILD} not found"; exit 1; } build_srpm() { - echo "--------------------------------------" - echo "Build SRPM for ${DISTRO}-${version}" - rpmbuild_results=$(${RPMBUILD} -bs --define "dist .${DIST_PREFIX}${version}" --define "${DISTRO} ${version}" ${SPEC}) - if [ ${?} -ne 0 ]; then - echo "ERROR: Failed creating SRPM for ${DISTRO}-${version}" - echo "${rpmbuild_results}" - RPMBUILD_FAIL=true - else - SRPM=$(echo $rpmbuild_results | awk -F": " '{print $2}') - echo "Created: ${SRPM}" - RPMBUILD_FAIL=false - fi + echo "--------------------------------------" + echo "Build SRPM for ${DISTRO}-${version}" + rpmbuild_results=$(${RPMBUILD} -bs --define "dist .${DIST_PREFIX}${version}" --define "${DISTRO} ${version}" ${SPEC}) + if [ ${?} -ne 0 ]; then + echo "ERROR: Failed creating SRPM for ${DISTRO}-${version}" + echo "${rpmbuild_results}" + RPMBUILD_FAIL=true + else + SRPM=$(echo $rpmbuild_results | awk -F": " '{print $2}') + echo "Created: ${SRPM}" + RPMBUILD_FAIL=false + fi } run_mock() { - version="$1" - arch="$2" + version="$1" + arch="$2" - echo "--------------------------------------" - echo "Running mock rebuild for ${DISTRO}-${version}-${arch}" + echo "--------------------------------------" + echo "Running mock rebuild for ${DISTRO}-${version}-${arch}" - ${MOCK} -r ${DISTRO}-${version}-${arch} --resultdir ${RESULTS_DIR} --rebuild ${SRPM} 1>/dev/null 2>&1 - if [ ${?} -ne 0 ]; then - echo "ERROR: failed creating RPM for ${DISTRO}-${version}-${arch}" - echo "Continueing to next mock build" - else - echo "Mock complete: ${DISTRO}-${version}-${arch}" - fi + ${MOCK} -r ${DISTRO}-${version}-${arch} ${RESULTS_DIR} --rebuild ${SRPM} 1>/dev/null 2>&1 + if [ ${?} -ne 0 ]; then + echo "ERROR: failed creating RPM for ${DISTRO}-${version}-${arch}" + echo "Continueing to next mock build" + else + echo "Mock complete: ${DISTRO}-${version}-${arch}" + fi } # For each distro version and each architecture, create the repo and optionally , repoview for version in ${DISTRO_VERSIONS}; do - build_srpm ${version} + build_srpm ${version} - for arch in ${ARCH}; do + for arch in ${ARCH}; do - if [ ! ${RPMBUILD_RESULTS} ]; then - run_mock ${version} ${arch} - else - echo "Skipping mock run for ${DISTRO}-${version}-${arch}" - break - fi + if [ ! ${RPMBUILD_RESULTS} ]; then + run_mock ${version} ${arch} + else + echo "Skipping mock run for ${DISTRO}-${version}-${arch}" + break + fi - done + done done exit 0