live-build/frontends/cgi/live-build-cgi.cron

196 lines
6.1 KiB
Plaintext
Raw Normal View History

2010-03-07 09:49:29 -01:00
#!/bin/sh
## live-build(7) - System Build Scripts
2013-05-06 12:48:46 +00:00
## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.
2010-03-07 09:49:29 -01:00
# Including common functions
. /usr/lib/live/build.sh
2010-03-07 09:49:29 -01:00
# Reading defaults
if [ -r /etc/default/live-build-cgi ]
2010-03-07 09:49:29 -01:00
then
. /etc/default/live-build-cgi
2010-03-07 09:49:29 -01:00
else
echo "E: /etc/default/live-build-cgi missing"
2010-03-07 09:49:29 -01:00
exit 1
fi
# Exit if disabled
2013-05-06 12:48:46 +00:00
if [ "${_WEBBUILD}" != "enabled" ]
2010-03-07 09:49:29 -01:00
then
exit 0
fi
_HOSTNAME="$(hostname -f)"
2013-05-06 12:48:46 +00:00
# Turn on debug if enabled
if [ "${_DEBUG}" = "enabled" ]
2010-03-14 16:05:33 -01:00
then
set -x
fi
2010-03-07 09:49:29 -01:00
# Checking lock file
if [ -f /var/lock/live-build-cgi.lock ]
2010-03-07 09:49:29 -01:00
then
echo "E: live-build-cgi already/still running."
2010-03-07 09:49:29 -01:00
exit 1
fi
# Creating lock trap
trap "test -f /var/lock/live-build-cgi.lock && rm -f /var/lock/live-build-cgi.lock; exit 0" 0 1 2 3 9 15
2010-03-07 09:49:29 -01:00
# Creating lock file
touch /var/lock/live-build-cgi.lock
2010-03-07 09:49:29 -01:00
# Cleanup old builds: cron should be run at least once per hour to take effect
if ls "${_DESTDIR}"/`date -d yesterday +%Y%m%d.%H`* > /dev/null 2>&1
then
rm -rf "${_DESTDIR}"/`date -d yesterday +%Y%m%d.%H`*
echo "`date +%b\ %d\ %H:%M:%S` ${_HOSTNAME} live-build-cgi: remove web build (`date -d yesterday +%Y%m%d.%H`*)." >> /var/log/live
2010-03-07 09:49:29 -01:00
fi
# Ok from here spin through the live-build-cgi files we have waiting to build
2010-03-07 09:49:29 -01:00
#if ls "${_TEMPDIR}"/*.build > /dev/null 2>&1
if Find_files ${_TEMPDIR}/*.build
2010-03-07 09:49:29 -01:00
then
for _FILE in "${_TEMPDIR}"/*.build
do
# Pull in variables from the build file.
. "${_FILE}"
2010-03-07 09:49:29 -01:00
# Clone the git config to target build directory
git clone ${_LB_GIT} "${_TEMPDIR}"/"${_BUILD}" >> /var/log/live
_ERRORGIT="${?}"
# Now set a variable for the correct build path
_BUILD_PATH="${_TEMPDIR}/${_BUILD}/images/${_LB_CONFIG}"
2013-05-06 12:48:46 +00:00
# Drop out some build data for information if something goes wrong.
echo "`date +%b\ %d\ %H:%M:%S` ${_HOSTNAME} live-build-cgi: begin web build (${_BUILD})." >> /var/log/live
# Creating directory for the config/package-lists
mkdir -p "${_BUILD_PATH}"/config/package-lists
# Add cgipackages.list.chroot
if [ -n "${_LB_CGIPACKAGES}" ]
then
echo "${_LB_CGIPACKAGES}" > "${_BUILD_PATH}"/config/package-lists/cgipackages.list.chroot
fi
2013-05-06 12:48:46 +00:00
_DATE_START="`date -R`"
echo "Begin: ${_DATE_START}" > "${_BUILD_PATH}"/log
2013-05-06 12:48:46 +00:00
# Generating config here
if [ "${_ERRORGIT}" -eq "0" ]
then
cd "${_BUILD_PATH}"
# Do config with git and stack on config file params to build
2013-05-06 12:48:46 +00:00
lb config --distribution "${LB_DISTRIBUTION}" --architectures "${LB_ARCHITECTURES}" --archive-areas "${LB_ARCHIVE_AREAS}" --chroot-filesystem "${LB_CHROOT_FILESYSTEM}" --linux-flavours "${LB_LINUX_FLAVOURS}" --security "${LB_SECURITY}" --apt-indices "${LB_APT_INDICES}" --bootappend-install "${LB_BOOTAPPEND_INSTALL}" --bootappend-live "${LB_BOOTAPPEND_LIVE}" --bootloader "${LB_BOOTLOADER}" --debian-installer "${LB_DEBIAN_INSTALLER}" --iso-application "${LB_ISO_APPLICATION}" --iso-preparer "${LB_ISO_PREPARER}" --iso-publisher "${LB_ISO_PUBLISHER}" --iso-volume "${LB_ISO_VOLUME}" --memtest "${LB_MEMTEST}" --net-root-path "${LB_NET_ROOT_PATH}" --net-root-server "${LB_NET_ROOT_SERVER}" --source-images "${LB_SOURCE_IMAGES}" --source "${LB_SOURCE}"
_ERRORCONFIG="${?}"
else
echo "Config stage skipped. The git clone produced an error: ${_ERRORGIT}" > "${_BUILD_PATH}"/log
fi
# Run build if config went ok
if [ "${_ERRORCONFIG}" -eq "0" ]
then
lb build >> "${_BUILD_PATH}"/log 2>&1
_ERRORBUILD="${?}"
else
echo "Build stage skipped. Config produced an error: ${_ERRORCONFIG}" > "${_BUILD_PATH}"/log
fi
2010-03-07 09:49:29 -01:00
_DATE_END="`date -R`"
echo "End: ${_DATE_END}" >> "${_BUILD_PATH}"/log
2010-03-07 09:49:29 -01:00
# Creating image directory
mkdir -p "${_DESTDIR}"/"${_BUILD}"
# Creating mail and logging.
if [ "${_ERRORGIT}" -eq "0" ] && [ "${_ERRORCONFIG}" -eq "0" ] && [ "${_ERRORBUILD}" -eq "0" ]
2010-03-07 09:49:29 -01:00
then
_STATUS="maybe-successful"
echo "${REMOTE_ADDR} - - `date +[%d/%b/%Y:%H:%m:%S\ %z]` \"${_BUILD} ${LB_ARCHITECTURES}/${LB_DISTRIBUTION}/${_LB_CGIPACKAGES}\" 200 - \"-\" \"\"">>/var/log/live-cgi.builds
2010-03-07 09:49:29 -01:00
else
_STATUS="maybe-failed"
echo "${REMOTE_ADDR} - - `date +[%d/%b/%Y:%H:%m:%S\ %z]` \"${_BUILD} ${LB_ARCHITECTURES}/${LB_DISTRIBUTION}/${_LB_CGIPACKAGES}\" 404 - \"-\" \"\"">>/var/log/live-cgi.builds
2010-03-07 09:49:29 -01:00
fi
sed -e "s/BUILD/${_BUILD}/g" \
-e "s/EMAIL/${_EMAIL}/" \
-e "s/VERSION/${VERSION}/" \
-e "s/DATE_START/${_DATE_START}/" \
-e "s/DATE_END/${_DATE_END}/" \
-e "s/STATUS/${_STATUS}/" \
-e "s#SERVER#${_SERVER}#" \
"${_TEMPLATES}"/mail.txt > "${_DESTDIR}"/"${_BUILD}"/mail
cat >> "${_DESTDIR}"/"${_BUILD}"/mail << EOF
---
Here's a list of all build-options that were used to build your image:
EOF
cat "${_TEMPDIR}"/"${_BUILD}".build >> "${_DESTDIR}"/"${_BUILD}"/mail
2010-03-07 09:49:29 -01:00
# Moving binary image
#if ls "${_TEMPDIR}"/"${_BUILD}"/binary*.* > /dev/null 2>&1
if Find_files ${_BUILD_PATH}/binary*.*
2010-03-07 09:49:29 -01:00
then
mv "${_BUILD_PATH}"/binary*.* "${_DESTDIR}"/"${_BUILD}"
2010-03-07 09:49:29 -01:00
fi
# Moving source image
#if ls "${_TEMPDIR}"/"${_BUILD}"/source.* > /dev/null 2>&1
if Find_files ${_BUILD_PATH}/source.*
2010-03-07 09:49:29 -01:00
then
mv "${_BUILD_PATH}"/source.* "${_DESTDIR}"/"${_BUILD}"
2010-03-07 09:49:29 -01:00
fi
# Moving build
mv "${_TEMPDIR}"/"${_BUILD}".build "${_DESTDIR}"/"${_BUILD}"/build
# Moving log
mv "${_BUILD_PATH}"/log "${_DESTDIR}"/"${_BUILD}"
2010-03-07 09:49:29 -01:00
# Generating md5sum
cd "${_DESTDIR}"/"${_BUILD}"
md5sum * > md5sum
cd "${OLDPWD}"
# Sending mail
cat "${_DESTDIR}"/"${_BUILD}"/mail | /usr/sbin/sendmail -t
# Unmounting devpts-live
#if ls "${_TEMPDIR}"/"${_BUILD}"/chroot/dev/pts/* > /dev/null 2>&1
if Find_files ${_BUILD_PATH}/chroot/dev/pts/*
2010-03-07 09:49:29 -01:00
then
umount "${_BUILD_PATH}"/chroot/dev/pts
2010-03-07 09:49:29 -01:00
fi
# Unmounting proc
if [ -f "${_BUILD_PATH}"/chroot/proc/version ]
2010-03-07 09:49:29 -01:00
then
umount "${_BUILD_PATH}"/chroot/proc
2010-03-07 09:49:29 -01:00
fi
# Unmounting sysfs
if [ -d "${_BUILD_PATH}"/chroot/sys/kernel ]
2010-03-07 09:49:29 -01:00
then
umount "${_BUILD_PATH}"/chroot/sys
2010-03-07 09:49:29 -01:00
fi
# Removing build directory
rm -rf "${_TEMPDIR}"/"${_BUILD}"
echo "`date +%b\ %d\ %H:%M:%S` ${_HOSTNAME} live-build-cgi: end web build (${_BUILD}: ${_STATUS})." >> /var/log/live
2010-03-07 09:49:29 -01:00
done
fi