~ubuntu-on-ec2/vmbuilder/automated-ec2-builds-fginther

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
#!/bin/sh

# this does nothing more than set environment variables and exec a command
# the advantage of setting here versus in cron, is that anyone can
# easily look at a crontab line and copy and paste it
# 

HOME=/home/vmbuilder
umask 022

EC2_DAILY=${HOME}/ec2-daily.next
CDIMAGE_BIN="${HOME}/cdimage/bin"
AUTO_BUILDS=${EC2_DAILY}/automated-ec2-builds
PUBLISH_SCRIPTS=${HOME}/ec2-publishing-scripts
XC2_PATH="${EC2_DAILY}/xc2"
S3CMD_PATH="${EC2_DAILY}/s3cmd-0.9.9.91"
MISC_PATH="${EC2_DAILY}/misc"
VMBUILDER_PATH="${EC2_DAILY}/vmbuilder"
export LIVE_BUILD_PATH="${EC2_DAILY}/live-build"
MYPATH=${VMBUILDER_PATH}:${XC2_PATH}:${S3CMD_PATH}:${PUBLISH_SCRIPTS}:${AUTO_BUILDS}:${VMBUILDER_PATH}:$HOME/bin:${CDIMAGE_BIN}
export PYTHONPATH="${EC2_DAILY}/boto-1.9b"
LOGDIR="${EC2_DAILY}/logs"

export PATH=${MYPATH}:/usr/bin:/usr/sbin:/usr/bin:/sbin:/bin
export JAVA_HOME=/usr
export START_D=${EC2_DAILY}
export PUBLISH_BASE=/srv/ec2-images
export XC2_RETRY_ON="Server.InternalError Read.timeout Server.Unavailable Unable.to.connect"

unset LANG

summary_file() {
	local file=${1} head=${2:-20} tail=${2:-40}
    local lines="" remain=""
	lines=$(wc -l < "${file}")
	if [ $lines -le $(($head+$tail)) ]; then
		cat "${file}"
	else
		head -n "${head}" "${file}"
		echo "lines=${lines} head=${head} tail=${tail}"
		echo "... <<<< $((${lines}-${head}-${tail})) lines >>>>..."
		tail -n "${tail}" "${file}"
	fi
}

if [ "${1%=*}" = "--logname" -o "$1" = "--log" ]; then
   if [ "$1" = "--log" ]; then
      lbname="${2}-%s"
   else
      lbname="${1#*=}"
   fi
   shift
   logname=$(printf "${lbname}" "$(date +%Y%m%d)")
   [ -d "${LOGDIR}" ] || mkdir -p "${LOGDIR}" ||
      { echo "failed to create ${LOGDIR}" 1>&2; exit 1; }
   lfile="${LOGDIR}/${logname}"
   i=0;
   while lfile="${LOGDIR}/${logname}.${i}.log" && [ -e "${lfile}" ]; do
      i=$((${i}+1))
   done
   "$@" > "${lfile}" 2>&1
   [ $? -eq 0 ] && exit 0
	echo "command failed: ${*}"
	echo "==== [stdout/stderr] ${lfile} ====";
   summary_file "${lfile}"
else
   exec "$@"
fi