summaryrefslogtreecommitdiff
path: root/test/common
blob: 73ffec4e8d82f2823fa9e9804bcb96faae9a21b3 (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
103
104
105
106
107
108
109
#!/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 or 3 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 (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
#

set -e
. ${0%/*}/config
if [ -e ${0%/*}/config.local ]; then
	. ${0%/*}/config.local
fi

: ${BUILD_DIR:=/usr/lib/build}

#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"
	build_args+=(--kvm)
	[ -z "$build_vm_img" ] || build_args+=("$build_vm_img")
	[ -z "$build_vm_swap" ] || build_args+=(--swap "$build_vm_swap")
	[ -z "$build_vm_mem" ] || build_args+=(--memory "$build_vm_mem")
}

run_build()
{
	for i in "$@"; do
		if [ "$i" = '--kvm' ]; then
			enable_kvm
		else
			build_args+=("$i")
		fi
	done
        SU_WRAPPER=""
        [ -x /usr/bin/sudo ] && SU_WRAPPER="sudo env"
	set -- $linux32 $SU_WRAPPER \
		$BUILD_DIR/build \
		--root "${build_root}" \
		"${repos[@]}" \
		"${build_args[@]}"
	echo "$@"
	"$@" || fail
	find $build_root/.build.packages/ -type f -name '*.rpm' -print0 | xargs --no-run-if-empty -0 rpm -K || fail
}