--- /dev/null
+#!/bin/bash
+# common functions for build script testing
+# Copyright (C) 2009 SUSE LINUX Products GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+set -e
+. ${0%/*}/config
+if [ -e ${0%/*}/config.local ]; then
+ . ${0%/*}/config.local
+fi
+
+if [ ! -e "$build_vm_img" ]; then
+ sudo dd if=/dev/zero of="$build_vm_img" bs=512 count=0 seek=$((build_vm_image_size*2*1024))
+fi
+if [ ! -e "$build_vm_swap" ]; then
+ sudo dd if=/dev/zero of="$build_vm_swap" bs=512 count=0 seek=$((build_vm_swap_size*2*1024))
+fi
+
+die()
+{
+ test -z "$1" || echo "$*" >&2
+ exit 1
+}
+
+fail()
+{
+ echo FAILED
+ test -z "$1" || echo "$*"
+ exit 2
+}
+
+skip()
+{
+ echo skipped
+ test -z "$1" || echo "$*"
+ exit 3
+}
+
+build_args=()
+repos=()
+repo()
+{
+ local dir
+ eval dir="\"\$repo_$1\""
+ [ -n "$dir" ] || die "repo $1 not defined, try adding repo_$1=/path/to/repo to config.local"
+ test -d "$dir" || skip
+ repos[${#repos[@]}]="--repository";
+ repos[${#repos[@]}]="$dir";
+}
+
+linux32=
+arch32bit()
+{
+ local hostarch=`uname -m`
+ case "$hostarch" in
+ x86_64) linux32=linux32 ;;
+ *) skip ;;
+ esac
+}
+
+enable_kvm()
+{
+ test -w /dev/kvm || skip "no kvm support"
+ set -- "${build_args[@]}" \
+ --root "${build_root}" \
+ --kvm "${build_vm_img}" \
+ --swap "${build_vm_swap}" \
+ --memory "$build_vm_mem"
+
+ build_args=("$@")
+}
+
+run_build()
+{
+ for i in "$@"; do
+ if [ "$i" = '--kvm' ]; then
+ enable_kvm
+ else
+ build_args[${#build_args[@]}]="$i";
+ fi
+ done
+ set -- $linux32 sudo env \
+ /usr/bin/build \
+ "${repos[@]}" \
+ "${build_args[@]}"
+ echo "$@"
+ "$@" || fail
+ find $build_root/.build.packages/ -type f -name '*.rpm' -print0 | xargs -0 rpm -K || fail
+}