#!/bin/bash # # build-stages - Build vserver stages # Copyright (C) 2005 Christian Heim # Benedikt Boehm # # 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:-} exit ${2:-1} } usage() { echo "Usage: build-stages " echo echo " 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/catalyst2/catalyst2.conf; echo ${storedir:-/var/tmp/catalyst2}) 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 catalyst2 and gather stats about the build /usr/bin/time -v \ --output=${stagefile}.stats \ catalyst2 -C \ subarch=${arch} \ version_stamp=${version} \ rel_type=${type} \ profile=${profile} \ snapshot=${snapshot} \ target=${target} \ source_subpath=${subsource} \ || die "catalyst2 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"