2010-03-07 09:49:29 -01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2010-09-02 11:12:37 +00:00
|
|
|
## live-build(7) - System Build Scripts
|
2012-12-31 22:12:04 -01:00
|
|
|
## Copyright (C) 2006-2013 Daniel Baumann <daniel@debian.org>
|
2010-09-02 11:12:37 +00:00
|
|
|
##
|
2012-07-29 23:59:00 +00:00
|
|
|
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
|
2010-09-02 11:12:37 +00:00
|
|
|
## 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
|
2012-08-21 13:45:07 +00:00
|
|
|
. /usr/lib/live/build.sh
|
2010-03-07 09:49:29 -01:00
|
|
|
|
|
|
|
# Reading defaults
|
2011-08-09 04:39:06 +00:00
|
|
|
if [ -r /etc/default/live-build-cgi ]
|
2010-03-07 09:49:29 -01:00
|
|
|
then
|
2011-08-09 04:39:06 +00:00
|
|
|
. /etc/default/live-build-cgi
|
2010-03-07 09:49:29 -01:00
|
|
|
else
|
2011-08-09 04:39:06 +00:00
|
|
|
echo "E: /etc/default/live-build-cgi missing"
|
2010-03-07 09:49:29 -01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Exit if disabled
|
2012-12-20 03:15:24 -01:00
|
|
|
if [ "${_WEBBUILD}" != "true" ]
|
2010-03-07 09:49:29 -01:00
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2011-08-08 18:36:57 +00:00
|
|
|
_HOSTNAME="$(hostname -f)"
|
|
|
|
|
2012-12-20 03:15:24 -01:00
|
|
|
# Turn on debug if true
|
|
|
|
if [ "${_DEBUG}" = "true" ]
|
2010-03-14 16:05:33 -01:00
|
|
|
then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2010-03-07 09:49:29 -01:00
|
|
|
# Checking lock file
|
2011-08-09 04:39:06 +00:00
|
|
|
if [ -f /var/lock/live-build-cgi.lock ]
|
2010-03-07 09:49:29 -01:00
|
|
|
then
|
2011-08-09 04:39:06 +00:00
|
|
|
echo "E: live-build-cgi already/still running."
|
2010-03-07 09:49:29 -01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Creating lock trap
|
2011-08-09 04:39:06 +00:00
|
|
|
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
|
2011-08-09 04:39:06 +00:00
|
|
|
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`*
|
|
|
|
|
2011-08-09 04:39:06 +00:00
|
|
|
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
|
|
|
|
|
2011-08-09 04:39:06 +00:00
|
|
|
# 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
|
2010-03-14 16:02:27 -01:00
|
|
|
if Find_files ${_TEMPDIR}/*.build
|
2010-03-07 09:49:29 -01:00
|
|
|
then
|
|
|
|
for _FILE in "${_TEMPDIR}"/*.build
|
|
|
|
do
|
2012-08-21 21:09:31 +00:00
|
|
|
# Pull in variables from the build file.
|
|
|
|
. "${_FILE}"
|
2010-03-07 09:49:29 -01:00
|
|
|
|
2013-02-26 23:09:06 -01: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
|
|
|
|
|
2012-08-05 01:00:05 +00:00
|
|
|
# Clone the git config to target build directory
|
2012-12-14 22:40:16 -01:00
|
|
|
git clone ${_LB_GIT} "${_TEMPDIR}"/"${_BUILD}" >> /var/log/live
|
2012-08-05 01:00:05 +00:00
|
|
|
_ERRORGIT="${?}"
|
|
|
|
|
2013-02-23 15:11:02 -01:00
|
|
|
# Sanity check to default to something since we are going to build from git clone.
|
|
|
|
if [ -z "${_LB_CONFIG}" ]
|
|
|
|
then
|
|
|
|
_LB_CONFIG="standard"
|
|
|
|
fi
|
|
|
|
|
2012-12-14 22:40:16 -01:00
|
|
|
# Now set a variable for the correct build path
|
|
|
|
_BUILD_PATH="${_TEMPDIR}/${_BUILD}/images/${_LB_CONFIG}"
|
|
|
|
|
2013-02-26 23:09:06 -01:00
|
|
|
_DATE_START="`date -R`"
|
|
|
|
echo "Begin live-build-cgi: ${_DATE_START}" > "${_BUILD_PATH}"/log
|
|
|
|
echo "Info live-build-cgi: Config tree cloned from ${_LB_GIT} for build ${_BUILD}" >> "${_BUILD_PATH}"/log
|
2012-08-21 21:09:31 +00:00
|
|
|
|
|
|
|
# Creating directory for the config/package-lists
|
2012-12-14 22:40:16 -01:00
|
|
|
mkdir -p "${_BUILD_PATH}"/config/package-lists
|
2011-12-24 00:58:31 -01:00
|
|
|
|
2012-08-21 21:09:31 +00:00
|
|
|
# Add cgipackages.list.chroot
|
2011-12-24 00:58:31 -01:00
|
|
|
if [ -n "${_LB_CGIPACKAGES}" ]
|
|
|
|
then
|
2012-12-14 22:40:16 -01:00
|
|
|
echo "${_LB_CGIPACKAGES}" > "${_BUILD_PATH}"/config/package-lists/cgipackages.list.chroot
|
2011-12-24 00:58:31 -01:00
|
|
|
fi
|
|
|
|
|
2012-08-21 21:09:31 +00:00
|
|
|
# Generating config here
|
|
|
|
if [ "${_ERRORGIT}" -eq "0" ]
|
|
|
|
then
|
2012-12-14 22:40:16 -01:00
|
|
|
cd "${_BUILD_PATH}"
|
2012-08-21 21:09:31 +00:00
|
|
|
# Do config with git and stack on config file params to build
|
2013-02-25 16:07:23 -01:00
|
|
|
lb config ${_CGI_CONFIG_APPEND} --distribution "${LB_DISTRIBUTION}" --binary-images "${LB_BINARY_IMAGES}" --architectures "${LIVE_IMAGE_ARCHITECTURE}" --archive-areas "${LIVE_IMAGE_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}"
|
2012-08-21 21:09:31 +00:00
|
|
|
_ERRORCONFIG="${?}"
|
|
|
|
else
|
2012-12-14 22:40:16 -01:00
|
|
|
echo "Config stage skipped. The git clone produced an error: ${_ERRORGIT}" > "${_BUILD_PATH}"/log
|
2012-08-21 21:09:31 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Run build if config went ok
|
|
|
|
if [ "${_ERRORCONFIG}" -eq "0" ]
|
|
|
|
then
|
2012-12-14 22:40:16 -01:00
|
|
|
lb build >> "${_BUILD_PATH}"/log 2>&1
|
2012-08-21 21:09:31 +00:00
|
|
|
_ERRORBUILD="${?}"
|
|
|
|
else
|
2012-12-14 22:40:16 -01:00
|
|
|
echo "Build stage skipped. Config produced an error: ${_ERRORCONFIG}" > "${_BUILD_PATH}"/log
|
2012-08-21 21:09:31 +00:00
|
|
|
fi
|
2010-03-07 09:49:29 -01:00
|
|
|
|
|
|
|
_DATE_END="`date -R`"
|
2012-12-14 22:40:16 -01:00
|
|
|
echo "End: ${_DATE_END}" >> "${_BUILD_PATH}"/log
|
2010-03-07 09:49:29 -01:00
|
|
|
|
|
|
|
# Creating image directory
|
|
|
|
mkdir -p "${_DESTDIR}"/"${_BUILD}"
|
|
|
|
|
2010-07-04 16:10:55 +00:00
|
|
|
# Creating mail and logging.
|
2012-08-05 01:00:05 +00:00
|
|
|
if [ "${_ERRORGIT}" -eq "0" ] && [ "${_ERRORCONFIG}" -eq "0" ] && [ "${_ERRORBUILD}" -eq "0" ]
|
2010-03-07 09:49:29 -01:00
|
|
|
then
|
|
|
|
_STATUS="maybe-successful"
|
2012-12-19 09:16:57 -01:00
|
|
|
echo "${REMOTE_ADDR} - - `date +[%d/%b/%Y:%H:%m:%S\ %z]` \"${_BUILD} ${LIVE_IMAGE_ARCHITECTURE}/${LB_DISTRIBUTION}/${_LB_CGIPACKAGES}\" 200 - \"-\" \"\"">>/var/log/live-cgi.builds
|
2010-03-07 09:49:29 -01:00
|
|
|
else
|
|
|
|
_STATUS="maybe-failed"
|
2012-12-19 09:16:57 -01:00
|
|
|
echo "${REMOTE_ADDR} - - `date +[%d/%b/%Y:%H:%m:%S\ %z]` \"${_BUILD} ${LIVE_IMAGE_ARCHITECTURE}/${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
|
|
|
|
|
2010-06-21 20:52:10 +00:00
|
|
|
cat >> "${_DESTDIR}"/"${_BUILD}"/mail << EOF
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
Here's a list of all build-options that were used to build your image:
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2010-06-23 16:31:07 +00:00
|
|
|
cat "${_TEMPDIR}"/"${_BUILD}".build >> "${_DESTDIR}"/"${_BUILD}"/mail
|
2010-06-21 20:52:10 +00:00
|
|
|
|
2010-03-07 09:49:29 -01:00
|
|
|
# Moving binary image
|
|
|
|
#if ls "${_TEMPDIR}"/"${_BUILD}"/binary*.* > /dev/null 2>&1
|
2012-12-14 22:40:16 -01:00
|
|
|
if Find_files ${_BUILD_PATH}/binary*.*
|
2010-03-07 09:49:29 -01:00
|
|
|
then
|
2012-12-14 22:40:16 -01:00
|
|
|
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
|
2012-12-14 22:40:16 -01:00
|
|
|
if Find_files ${_BUILD_PATH}/source.*
|
2010-03-07 09:49:29 -01:00
|
|
|
then
|
2012-12-14 22:40:16 -01:00
|
|
|
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
|
2012-12-14 22:40:16 -01:00
|
|
|
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
|
2012-12-14 22:40:16 -01:00
|
|
|
if Find_files ${_BUILD_PATH}/chroot/dev/pts/*
|
2010-03-07 09:49:29 -01:00
|
|
|
then
|
2012-12-14 22:40:16 -01:00
|
|
|
umount "${_BUILD_PATH}"/chroot/dev/pts
|
2010-03-07 09:49:29 -01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Unmounting proc
|
2012-12-14 22:40:16 -01:00
|
|
|
if [ -f "${_BUILD_PATH}"/chroot/proc/version ]
|
2010-03-07 09:49:29 -01:00
|
|
|
then
|
2012-12-14 22:40:16 -01:00
|
|
|
umount "${_BUILD_PATH}"/chroot/proc
|
2010-03-07 09:49:29 -01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Unmounting sysfs
|
2012-12-14 22:40:16 -01:00
|
|
|
if [ -d "${_BUILD_PATH}"/chroot/sys/kernel ]
|
2010-03-07 09:49:29 -01:00
|
|
|
then
|
2012-12-14 22:40:16 -01:00
|
|
|
umount "${_BUILD_PATH}"/chroot/sys
|
2010-03-07 09:49:29 -01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Removing build directory
|
|
|
|
rm -rf "${_TEMPDIR}"/"${_BUILD}"
|
|
|
|
|
2011-08-09 04:39:06 +00:00
|
|
|
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
|