summaryrefslogtreecommitdiff
path: root/test/common
blob: cd41825af9ef9cc9cbb4c1149f1419b839aa5e97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/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
}