Skip to content

Commit

Permalink
- Add the --resultdir option to specify different directory in mock r…
Browse files Browse the repository at this point in the history
…ebuild

- Update README
  • Loading branch information
Trey Dockendorf committed Nov 21, 2011
1 parent 7c69013 commit fceb876
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 39 deletions.
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -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 #

Expand All @@ -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
124 changes: 86 additions & 38 deletions 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 <results directory path> 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} <spec file>"
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"
Expand All @@ -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

0 comments on commit fceb876

Please sign in to comment.