From 1886bc7f822449a1c332edb497284d03523f0bb3 Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Wed, 3 Sep 2008 03:46:48 +0000 Subject: [PATCH] Create tools directory Initial commit of stage_build.sh script svn path=/trunk/; revision=562 --- ChangeLog | 4 ++ tools/stage_build.sh | 162 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100755 tools/stage_build.sh diff --git a/ChangeLog b/ChangeLog index d8bf3b27..5f7ec67a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ # Copyright 1999-2008 Gentoo Foundation; Distributed under the GPL v2 # $Header: $ + 03 Sep 2008; ChangeLog: + Create tools directory + Initial commit of stage_build.sh script + 25 Aug 2008; Tobias Scherbaum releases/2008.0/kconfig/hppa/installcd-2.6.24-livecd64.config releases/2008.0/kconfig/hppa/installcd-2.6.24-livecd32.config diff --git a/tools/stage_build.sh b/tools/stage_build.sh new file mode 100755 index 00000000..0dd89a9b --- /dev/null +++ b/tools/stage_build.sh @@ -0,0 +1,162 @@ +#!/bin/bash + +PID=$$ + +profile= +version_stamp= +subarch= +stage1_seed= +snapshot= +config=/etc/catalyst/catalyst.conf +email_from="catalyst@localhost" +email_to="root@localhost" +verbose=0 + +usage() { + msg=$1 + + if [ -n "${msg}" ]; then + echo -e "${msg}\n"; + fi + + cat <] [-v|--version-stamp ] + [-a|--arch ] [-s|--stage1-seed ] [--verbose] + [-f|--email-from ] [-t|--email-to ] [-h|--help] + +Options: + -p|--profile Sets the portage profile (required) + -v|--version-stamp Sets the version stamp (required) + -a|--arch Sets the 'subarch' in the spec (required) + -s|--stage1-seed Sets the seed for the stage1 (required) + -S|--snapshot Sets the snapshot name (if not given defaults to today's + date) + -c|--config catalyst config to use, defaults to catalyst default + --verbose Send output of commands to console as well as log + -f|--email-from Sets the 'From' on emails sent from this script (defaults + to catalyst@localhost) + -t|--email-to Sets the 'To' on emails sent from this script (defaults + to root@localhost) + -h|--help Show this message and quit + +Example: + stage_build -p default-linux/x86/2006.1 -v 2007.0_pre -a i686 -s default/stage3-i686-2006.1 +EOH +} + +send_email() { + subject="[${subarch}] $1" + body=$2 + + echo -e "From: ${email_from}\r\nTo: ${email_to}\r\nSubject: ${subject}\r\n\r\nArch: ${subarch}\r\nProfile: ${profile}\r\nVersion stamp: ${version_stamp}\r\nStage1 seed: ${stage1_seed}\r\nSnapshot: ${snapshot}\r\n\r\n${body}\r\n" | /usr/sbin/sendmail -f ${email_from} ${email_to} +} + +run_cmd() { + cmd=$1 + logfile=$2 + + if [ $verbose = 1 ]; then + ${cmd} 2>&1 | tee ${logfile} + else + ${cmd} &> ${logfile} + fi +} + +# Parse args +params=${#} +while [ ${#} -gt 0 ] +do + a=${1} + shift + case "${a}" in + -h|--help) + usage + exit 0 + ;; + -p|--profile) + profile=$1 + shift + ;; + -v|--version-stamp) + version_stamp=$1 + shift + ;; + -a|--arch) + subarch=$1 + shift + ;; + -f|--email-from) + email_from=$1 + shift + ;; + -t|--email-to) + email_to=$1 + shift + ;; + -s|--stage1-seed) + stage1_seed=$1 + shift + ;; + -S|--snapshot) + snapshot=$1 + shift + ;; + -c|--config) + config=$1 + shift + ;; + --verbose) + verbose=1 + ;; + -*) + echo "You have specified an invalid option: ${a}" + usage + exit 1 + ;; + esac +done + +# Make sure all required values were specified +if [ -z "${profile}" ]; then + usage "You must specify a profile." + exit 1 +fi +if [ -z "${version_stamp}" ]; then + usage "You must specify a version stamp." + exit 1 +fi +if [ -z "${subarch}" ]; then + usage "You must specify an arch." + exit 1 +fi +if [ -z "${stage1_seed}" ]; then + usage "You must specify a stage1 seed." + exit 1 +fi +cd /tmp + +if [ -z "${snapshot}" ]; then + snapshot=`date +%Y%m%d` + run_cmd "catalyst -c ${config} -s '${snapshot}'" "/tmp/catalyst_build_snapshot.${PID}.log" + if [ $? != 0 ]; then + send_email "Catalyst build error - snapshot" "$( stage${i}.spec + if [ ${i} = 1 ]; then + echo "source_subpath: ${stage1_seed}" >> stage${i}.spec + else + echo "source_subpath: default/stage$(expr ${i} - 1)-${subarch}-${version_stamp}" >> stage${i}.spec + fi + run_cmd "catalyst -a -p -c ${config} -f stage${i}.spec" "/tmp/catalyst_build_stage${i}.${PID}.log" + if [ $? != 0 ]; then + send_email "Catalyst build error - stage${i}" "$(tail -n 200 /tmp/catalyst_build_stage${i}.${PID}.log)\r\n\r\nFull build log at /tmp/catalyst_build_stage${i}.${PID}.log" + exit 1 + fi +done + +send_email "Catalyst build success" "Everything finished successfully."