summaryrefslogtreecommitdiff
path: root/bin/git-mock
diff options
context:
space:
mode:
Diffstat (limited to 'bin/git-mock')
-rwxr-xr-xbin/git-mock100
1 files changed, 100 insertions, 0 deletions
diff --git a/bin/git-mock b/bin/git-mock
new file mode 100755
index 0000000..c06cdb6
--- /dev/null
+++ b/bin/git-mock
@@ -0,0 +1,100 @@
+#!/bin/sh
+
+# Assumed directory layout:
+# this script sits in the top-level directory. Under which there's
+# a subdirectory for each package. There is also the special
+# adminitrative subdirectory rpmbuild
+
+set -e
+
+# Make sure we have the necessary tools.
+if [ ! -x /usr/bin/mock ]; then
+ echo "mock not found; you need to install the mock package" >&2
+ exit 1
+fi
+
+#my_dir=`dirname $0`
+#top_dir="$my_dir/.."
+top_dir=".."
+build_dir="$top_dir/rpmbuild"
+specs_dir="$build_dir/SPECS"
+sources_dir="$build_dir/SOURCES"
+srpms_dir="$build_dir/SRPMS"
+rpms_pat="results/%(dist)s/%(target_arch)s/"
+
+releases="cpbx-45-x86_64 cpbx-45-i386"
+
+usage() {
+ me=`basename $0`
+ echo \
+"Usage:
+ $me <export|build|clean>
+ $me import path/to/srpm
+
+ export: export a source RPM package from git tree
+ build: build latest source RPM using mock
+ import: create/update a git repository from source RPM
+ clean: delete all produced RPM packages under $build_dir
+"
+}
+
+# There must be a saner way to do that or a reason why this is not required
+fix_arch() {
+ ARCH=${ARCH:-`uname -m`}
+ case "$ARCH" in
+ amd64) ARCH='x86_64';;
+ esac
+}
+
+while [ $# != 0 ]; do
+ case "$1" in
+ --define) shift ;;
+ *.spec) SPEC="$1"
+ esac
+ shift
+done
+
+create_srpm() {
+ spec=`ls -t $specs_dir/*.spec | head -n1`
+
+ mkdir -p "$srpms_dir"
+ rpmbuild -bs \
+ --define "_sourcedir $sources_dir" \
+ --define "_srcrpmdir $srpms_dir" \
+ "$spec"
+}
+
+# Mock wrapper: used internally
+git_builder() {
+ local spec="$SPEC"
+ local root=${GIT_MOCK_ROOT:-${DIST}-${ARCH}}
+ if [ ! -d "$GIT_MOCK_EXPORT_DIR" ]; then
+ echo >&2 "$0: Missing outputs directory (GIT_MOCK_EXPORT_DIR). Aborting."
+ exit 1
+ fi
+ #local export_dir="$GIT_MOCK_EXPORT_DIR"
+ export_dir="$PWD"
+ spec="$export_dir/SPECS/$spec"
+ sources="$export_dir/SOURCES"
+ srpms="$export_dir/SRPMS"
+ pat="${GIT_MOCK_RESULTS_PAT-results/%(dist)s/%(target_arch)s/}"
+ local resultdir="$export_dir/$pat"
+ local mock="mock -r $root --resultdir=$srpms --spec=$spec --sources=$sources"
+ set -e
+
+ $mock --buildsrpm
+ #rpmbuild -bs --define "_topdir ." "SPECS/$spec"
+ # Assuming that nothing was built in this directory since the previous command:
+ local srpm=`ls -t $PWD/SRPMS/*.src.rpm | head -n1`
+ $mock --no-cleanup-after --resultdir $resultdir --rebuild "$srpm"
+ #for rel in $releases; do
+ # mock -r $rel --resultdir="$PWD/$rpms_pat" \
+ # --no-cleanup-after \
+ # --rebuild "$srpm"
+ #done
+}
+
+
+fix_arch
+
+git_builder