Adding binary image type to config call on l-b-cgi frontend.
[debian-live-build.git] / frontends / cgi / live-build-cgi.cron
blobb72673fe274cb40f15f5c69e20eb9f21ac96fe9b
1 #!/bin/sh
3 ## live-build(7) - System Build Scripts
4 ## Copyright (C) 2006-2013 Daniel Baumann <daniel@debian.org>
5 ##
6 ## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7 ## This is free software, and you are welcome to redistribute it
8 ## under certain conditions; see COPYING for details.
10 # Including common functions
11 . /usr/lib/live/build.sh
13 # Reading defaults
14 if [ -r /etc/default/live-build-cgi ]
15 then
16 . /etc/default/live-build-cgi
17 else
18 echo "E: /etc/default/live-build-cgi missing"
19 exit 1
22 # Exit if disabled
23 if [ "${_WEBBUILD}" != "true" ]
24 then
25 exit 0
28 _HOSTNAME="$(hostname -f)"
30 # Turn on debug if true
31 if [ "${_DEBUG}" = "true" ]
32 then
33 set -x
36 # Checking lock file
37 if [ -f /var/lock/live-build-cgi.lock ]
38 then
39 echo "E: live-build-cgi already/still running."
40 exit 1
43 # Creating lock trap
44 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
46 # Creating lock file
47 touch /var/lock/live-build-cgi.lock
49 # Cleanup old builds: cron should be run at least once per hour to take effect
50 if ls "${_DESTDIR}"/`date -d yesterday +%Y%m%d.%H`* > /dev/null 2>&1
51 then
52 rm -rf "${_DESTDIR}"/`date -d yesterday +%Y%m%d.%H`*
54 echo "`date +%b\ %d\ %H:%M:%S` ${_HOSTNAME} live-build-cgi: remove web build (`date -d yesterday +%Y%m%d.%H`*)." >> /var/log/live
57 # Ok from here spin through the live-build-cgi files we have waiting to build
58 #if ls "${_TEMPDIR}"/*.build > /dev/null 2>&1
59 if Find_files ${_TEMPDIR}/*.build
60 then
61 for _FILE in "${_TEMPDIR}"/*.build
63 # Pull in variables from the build file.
64 . "${_FILE}"
66 # Clone the git config to target build directory
67 git clone ${_LB_GIT} "${_TEMPDIR}"/"${_BUILD}" >> /var/log/live
68 _ERRORGIT="${?}"
70 # Sanity check to default to something since we are going to build from git clone.
71 if [ -z "${_LB_CONFIG}" ]
72 then
73 _LB_CONFIG="standard"
76 # Now set a variable for the correct build path
77 _BUILD_PATH="${_TEMPDIR}/${_BUILD}/images/${_LB_CONFIG}"
79 # Drop out some build data for information if something goes wrong.
80 echo "`date +%b\ %d\ %H:%M:%S` ${_HOSTNAME} live-build-cgi: begin web build (${_BUILD})." >> /var/log/live
82 # Creating directory for the config/package-lists
83 mkdir -p "${_BUILD_PATH}"/config/package-lists
85 # Add cgipackages.list.chroot
86 if [ -n "${_LB_CGIPACKAGES}" ]
87 then
88 echo "${_LB_CGIPACKAGES}" > "${_BUILD_PATH}"/config/package-lists/cgipackages.list.chroot
91 _DATE_START="`date -R`"
92 echo "Begin: ${_DATE_START}" > "${_BUILD_PATH}"/log
94 # Generating config here
95 if [ "${_ERRORGIT}" -eq "0" ]
96 then
97 cd "${_BUILD_PATH}"
98 # Do config with git and stack on config file params to build
99 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}"
100 _ERRORCONFIG="${?}"
101 else
102 echo "Config stage skipped. The git clone produced an error: ${_ERRORGIT}" > "${_BUILD_PATH}"/log
105 # Run build if config went ok
106 if [ "${_ERRORCONFIG}" -eq "0" ]
107 then
108 lb build >> "${_BUILD_PATH}"/log 2>&1
109 _ERRORBUILD="${?}"
110 else
111 echo "Build stage skipped. Config produced an error: ${_ERRORCONFIG}" > "${_BUILD_PATH}"/log
114 _DATE_END="`date -R`"
115 echo "End: ${_DATE_END}" >> "${_BUILD_PATH}"/log
117 # Creating image directory
118 mkdir -p "${_DESTDIR}"/"${_BUILD}"
120 # Creating mail and logging.
121 if [ "${_ERRORGIT}" -eq "0" ] && [ "${_ERRORCONFIG}" -eq "0" ] && [ "${_ERRORBUILD}" -eq "0" ]
122 then
123 _STATUS="maybe-successful"
124 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
125 else
126 _STATUS="maybe-failed"
127 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
130 sed -e "s/BUILD/${_BUILD}/g" \
131 -e "s/EMAIL/${_EMAIL}/" \
132 -e "s/VERSION/${VERSION}/" \
133 -e "s/DATE_START/${_DATE_START}/" \
134 -e "s/DATE_END/${_DATE_END}/" \
135 -e "s/STATUS/${_STATUS}/" \
136 -e "s#SERVER#${_SERVER}#" \
137 "${_TEMPLATES}"/mail.txt > "${_DESTDIR}"/"${_BUILD}"/mail
139 cat >> "${_DESTDIR}"/"${_BUILD}"/mail << EOF
143 Here's a list of all build-options that were used to build your image:
147 cat "${_TEMPDIR}"/"${_BUILD}".build >> "${_DESTDIR}"/"${_BUILD}"/mail
149 # Moving binary image
150 #if ls "${_TEMPDIR}"/"${_BUILD}"/binary*.* > /dev/null 2>&1
151 if Find_files ${_BUILD_PATH}/binary*.*
152 then
153 mv "${_BUILD_PATH}"/binary*.* "${_DESTDIR}"/"${_BUILD}"
156 # Moving source image
157 #if ls "${_TEMPDIR}"/"${_BUILD}"/source.* > /dev/null 2>&1
158 if Find_files ${_BUILD_PATH}/source.*
159 then
160 mv "${_BUILD_PATH}"/source.* "${_DESTDIR}"/"${_BUILD}"
163 # Moving build
164 mv "${_TEMPDIR}"/"${_BUILD}".build "${_DESTDIR}"/"${_BUILD}"/build
166 # Moving log
167 mv "${_BUILD_PATH}"/log "${_DESTDIR}"/"${_BUILD}"
169 # Generating md5sum
170 cd "${_DESTDIR}"/"${_BUILD}"
171 md5sum * > md5sum
172 cd "${OLDPWD}"
174 # Sending mail
175 cat "${_DESTDIR}"/"${_BUILD}"/mail | /usr/sbin/sendmail -t
177 # Unmounting devpts-live
178 #if ls "${_TEMPDIR}"/"${_BUILD}"/chroot/dev/pts/* > /dev/null 2>&1
179 if Find_files ${_BUILD_PATH}/chroot/dev/pts/*
180 then
181 umount "${_BUILD_PATH}"/chroot/dev/pts
184 # Unmounting proc
185 if [ -f "${_BUILD_PATH}"/chroot/proc/version ]
186 then
187 umount "${_BUILD_PATH}"/chroot/proc
190 # Unmounting sysfs
191 if [ -d "${_BUILD_PATH}"/chroot/sys/kernel ]
192 then
193 umount "${_BUILD_PATH}"/chroot/sys
196 # Removing build directory
197 rm -rf "${_TEMPDIR}"/"${_BUILD}"
199 echo "`date +%b\ %d\ %H:%M:%S` ${_HOSTNAME} live-build-cgi: end web build (${_BUILD}: ${_STATUS})." >> /var/log/live
200 done