summaryrefslogtreecommitdiff
blob: 95d5cd94918b1c9cb68491b12ddd452c29ee90ce (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
#
# build-stages - Build vserver stages
# Copyright (C) 2005 Christian Heim <phreak@gentoo.org>
#                    Benedikt Boehm <hollow@gentoo.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
#
# v0.1 - initial release

trap "exit 1" INT

if [ -r /sbin/functions.sh ]; then
	source /sbin/functions.sh
else
	echo "/sbin/functions.sh missing. Are you running Gentoo?"
fi

die() {
	eerror ${1:-<no error message>}
	exit ${2:-1}
}

usage() {
	echo "Usage: build-stages <spec>"
	echo
	echo "<spec>  Stages spec file"
}

# checking command line
if [ $# -ne 1 ]; then
	usage
	exit
fi

# check root privs
[ "$(id -u)" != "0" ] && die "Need root privileges"

# read spec file
[ ! -r $1 ] && die "No read-access to $1"
source $1

# set default values
: ${type:=default}
: ${version:=$(date +%Y%m%d)}
: ${sync_snapshots:=1}
: ${sync_source:=ftp.join.uni-muenster.de::gentoo/snapshots/}
: ${snapshot:=latest}
: ${stage1:=1}
: ${stage2:=1}
: ${stage3:=1}

# set subsources
stage_name=${arch}-${version}
: ${stage1_seed:=seed}
: ${stage2_subsource:=${type}/stage1-${stage_name}}
: ${stage3_subsource:=${type}/stage2-${stage_name}}

# setup all the path variables
cdir=$(source /etc/catalyst/catalyst.conf; echo ${storedir:-/var/tmp/catalyst})
tmpdir=${cdir}/tmp
snapdir=${cdir}/snapshots
builddir=${cdir}/builds
stagedir=${builddir}/${type}

mkdir -p ${stagedir}

# check config
[ -z "${arch}" ] && die "arch not set. please fix your config file"
[ -z "${profile}" ] && die "profile not set. please fix your config file"

# display some common info
einfo "Building stages for:"
einfo
einfo "   arch:     ${arch}"
einfo "   type:     ${type}"
einfo "   version:  ${version}"
einfo "   snapshot: ${snapshot}"
einfo "   profile:  ${profile}"
einfo
echo

build_stage() {
	[ $# -ne 2 ] && return 1
	
	local target=$1
	local subsource=$2
	
	local stagefile=${stagedir}/${target}-${arch}-${version}.tar.bz2
	
	if [ -f ${stagefile} ]; then
		einfo "${target} is cached at ${stagefile}"
		return
	fi
	
	einfo "Building ${target} ..."
	
	# we need a seed stage
	[ ! -f ${builddir}/${subsource}.tar.bz2 ] && die "subsource ${builddir}/${subsource}.tar.bz2 does not exist"
	
	# Now run catalyst and gather stats about the build
	/usr/bin/time -v \
		--output=${stagefile}.stats \
	catalyst -C \
		subarch=${arch} \
		version_stamp=${version} \
		rel_type=${type} \
		profile=${profile} \
		snapshot=${snapshot} \
		target=${target} \
		source_subpath=${subsource} \
		|| die "catalyst failed to build ${target}"
	
	# Generate digest
	cd ${stagedir}
	md5sum $(basename ${stagefile}) > $(basename ${stagefile}).md5
	
	# Generate file listings of the tarball
	tar -tjf ${stagefile} > ${stagefile}.CONTENTS
}

if [ ${sync_snapshots} -eq 1 ]; then
	einfo "Syncing snapshots"
	rsync -av ${sync_source}/ ${snapdir}/
fi

[ $stage1 -eq 1 ] && build_stage stage1 ${stage1_seed}
[ $stage2 -eq 1 ] && build_stage stage2 ${stage2_subsource}
[ $stage3 -eq 1 ] && build_stage stage3 ${stage3_subsource}

einfo "All stages built successfully"