2008-09-04 01:18:17 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
PID=$$
|
|
|
|
|
2008-09-04 01:19:35 +00:00
|
|
|
config_file=
|
|
|
|
verbose=0
|
|
|
|
|
2008-09-04 01:18:17 +00:00
|
|
|
usage() {
|
|
|
|
msg=$1
|
|
|
|
|
|
|
|
if [ -n "${msg}" ]; then
|
|
|
|
echo -e "${msg}\n";
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<EOH
|
|
|
|
Usage:
|
|
|
|
stage_build [-c|--config <config>] [--verbose] [-h|--help]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-c|--config Specifies the config file to use (required)
|
|
|
|
--verbose Send output of commands to console as well as log
|
|
|
|
-h|--help Show this message and quit
|
|
|
|
|
|
|
|
EOH
|
|
|
|
}
|
|
|
|
|
|
|
|
send_email() {
|
|
|
|
subject="${EMAIL_SUBJECT_PREPEND} $1"
|
|
|
|
body=$2
|
|
|
|
|
|
|
|
echo -e "From: ${EMAIL_FROM}\r\nTo: ${EMAIL_TO}\r\nSubject: ${subject}\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
|
2008-09-04 01:54:15 +00:00
|
|
|
echo "*** Running command: ${cmd}"
|
2008-09-04 02:25:34 +00:00
|
|
|
${cmd} 2>&1 | tee ${logfile}
|
2008-09-04 01:18:17 +00:00
|
|
|
else
|
2008-09-04 02:25:34 +00:00
|
|
|
${cmd} &> ${logfile}
|
2008-09-04 01:18:17 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Parse args
|
|
|
|
params=${#}
|
|
|
|
while [ ${#} -gt 0 ]
|
|
|
|
do
|
|
|
|
a=${1}
|
|
|
|
shift
|
|
|
|
case "${a}" in
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-c|--config)
|
|
|
|
config_file=$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 "${config_file}" -o ! -e "${config_file}" ]; then
|
|
|
|
usage "You must specify a valid config file to use"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
source ${config_file}
|
|
|
|
|
|
|
|
TMPDIR=/tmp/catalyst-auto.${PID}
|
2008-09-04 02:11:48 +00:00
|
|
|
DATESTAMP=$(date +%Y%m%d)
|
|
|
|
|
|
|
|
if [ ${verbose} = 1 ]; then
|
|
|
|
echo "TMPDIR = ${TMPDIR}"
|
|
|
|
echo "DATESTAMP = ${DATESTAMP}"
|
|
|
|
fi
|
2008-09-04 01:18:17 +00:00
|
|
|
|
|
|
|
# Check if tmp directory exists and remove it
|
|
|
|
if [ -d "${TMPDIR}" ]; then
|
|
|
|
if ! rm -rf "${TMPDIR}"; then
|
|
|
|
echo "Couldn't remove stale tmpdir ${TMPDIR}!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2008-09-04 12:44:33 +00:00
|
|
|
for i in ${TMPDIR} ${TMPDIR}/specs ${TMPDIR}/kconfig ${TMPDIR}/log; do
|
|
|
|
if ! mkdir -p "${i}"; then
|
|
|
|
echo "Couldn't create dir ${i}!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2008-09-04 01:18:17 +00:00
|
|
|
|
|
|
|
cd ${SPECS_DIR}
|
|
|
|
|
2008-09-04 02:17:27 +00:00
|
|
|
for i in ${SPECS}; do
|
2008-09-04 01:18:17 +00:00
|
|
|
cp --parents ${i} ${TMPDIR}/specs/
|
|
|
|
done
|
|
|
|
|
2008-09-04 12:44:33 +00:00
|
|
|
cd ${KCONFIG_DIR}
|
|
|
|
find -type f -exec cp {} ${TMPDIR}/kconfig \;
|
|
|
|
|
2008-09-04 01:18:17 +00:00
|
|
|
cd ${TMPDIR}/specs
|
|
|
|
|
2008-09-04 01:54:15 +00:00
|
|
|
# Fix up specs with datestamp
|
|
|
|
for i in $(find -name '*.spec'); do
|
|
|
|
# Grab current version_stamp and source_subpath
|
|
|
|
old_version_stamp=$(grep version_stamp ${i} | sed -e 's|^version_stamp: *||')
|
|
|
|
old_source_subpath=$(grep source_subpath ${i} | sed -e 's|^source_subpath: .\+-||')
|
|
|
|
|
|
|
|
sed -i 's|^version_stamp:.*$|version_stamp: '${DATESTAMP}'|' ${i}
|
|
|
|
sed -i 's|^snapshot:.*$|snapshot: '${DATESTAMP}'|' ${i}
|
|
|
|
if [ "${old_version_stamp}" = "${old_source_subpath}" ]; then
|
2008-09-04 02:07:52 +00:00
|
|
|
sed -i 's|^source_subpath: \(.\+-\).\+$|source_subpath: \1'${DATESTAMP}'|' ${i}
|
2008-09-04 01:54:15 +00:00
|
|
|
fi
|
2008-09-04 12:44:33 +00:00
|
|
|
|
|
|
|
kconfig_line=$(grep '^boot/kernel/[^/]\+/config:' ${i})
|
|
|
|
if [ -n "${kconfig_line}" ]; then
|
|
|
|
key=$(echo "${kconfig_line}" | cut -d: -f1)
|
|
|
|
filename=$(basename $(echo "${kconfig_line}" | cut -d: -f2))
|
|
|
|
sed -i "s|^${key}:.*\$|${key}: ${TMPDIR}/kconfig/${filename}|" ${i}
|
|
|
|
fi
|
2008-09-04 01:54:15 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Create snapshot
|
2008-09-04 02:07:52 +00:00
|
|
|
if ! run_cmd "catalyst -c ${CATALYST_CONFIG} -s ${DATESTAMP}" "${TMPDIR}/log/snapshot-${DATESTAMP}.log"; then
|
2008-09-04 01:54:15 +00:00
|
|
|
send_email "Catalyst build error - snapshot" "$(tail -n 200 ${TMPDIR}/log/snapshot-${DATESTAMP}.log)"
|
2008-09-04 02:33:23 +00:00
|
|
|
exit 1
|
2008-09-04 01:54:15 +00:00
|
|
|
fi
|
|
|
|
|
2008-09-04 02:17:27 +00:00
|
|
|
for i in ${SPECS}; do
|
2008-09-04 01:18:17 +00:00
|
|
|
LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::').log"
|
|
|
|
run_cmd "catalyst -a -p -c ${CATALYST_CONFIG} -f ${i}" ${LOGFILE}
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
send_email "Catalyst build error - ${i}" "$(tail -n 200 ${LOGFILE})\r\n\r\nFull build log at ${LOGFILE}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
send_email "Catalyst build success" "Everything finished successfully."
|
2008-09-04 02:07:52 +00:00
|
|
|
|
|
|
|
if ! rm -rf "${TMPDIR}"; then
|
|
|
|
echo "Could not remove tmpdir ${TMPDIR}!"
|
|
|
|
exit 1
|
|
|
|
fi
|