3 ## live-build(7) - System Build Scripts
4 ## Copyright (C) 2006-2013 Daniel Baumann <daniel@debian.org>
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
14 if [ -r /etc
/default
/live-build-cgi
]
16 .
/etc
/default
/live-build-cgi
18 echo "E: /etc/default/live-build-cgi missing"
23 if [ "${_WEBBUILD}" != "true" ]
28 _HOSTNAME
="$(hostname -f)"
30 # Turn on debug if true
31 if [ "${_DEBUG}" = "true" ]
37 if [ -f /var
/lock
/live-build-cgi.lock
]
39 echo "E: live-build-cgi already/still running."
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
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
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
61 for _FILE
in "${_TEMPDIR}"/*.build
63 # Pull in variables from the build file.
66 # Clone the git config to target build directory
67 git clone
${_LB_GIT} "${_TEMPDIR}"/"${_BUILD}" >> /var/log/live
70 # Sanity check to default to something since we are going to build from git clone.
71 if [ -z "${_LB_CONFIG}" ]
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}" ]
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" ]
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}"
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" ]
108 lb build
>> "${_BUILD_PATH}"/log
2>&1
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" ]
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
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
*.
*
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.
*
160 mv "${_BUILD_PATH}"/source.* "${_DESTDIR}"/"${_BUILD}"
164 mv "${_TEMPDIR}"/"${_BUILD}".build "${_DESTDIR}"/"${_BUILD}"/build
167 mv "${_BUILD_PATH}"/log "${_DESTDIR}"/"${_BUILD}"
170 cd "${_DESTDIR}"/"${_BUILD}"
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
/*
181 umount
"${_BUILD_PATH}"/chroot
/dev
/pts
185 if [ -f "${_BUILD_PATH}"/chroot
/proc
/version
]
187 umount
"${_BUILD_PATH}"/chroot
/proc
191 if [ -d "${_BUILD_PATH}"/chroot
/sys
/kernel
]
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