3
# live-webhelper - web interface to live-helper
4
# Copyright (C) 2007-2010 Daniel Baumann <daniel@debian.org>
6
# live-webhelper 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
LH_BASE="${LH_BASE:-/usr/share/live-helper}"
13
for _FUNCTION in "${LH_BASE}"/functions/*.sh
19
. /usr/share/live-webhelper/common
22
if [ -r /etc/default/live-webhelper ]
24
. /etc/default/live-webhelper
26
echo "E: /etc/default/live-webhelper missing"
31
if [ "${_WEBBUILD}" != "enabled" ]
37
if [ -f /var/lock/live-webhelper.lock ]
39
echo "E: live-webhelper already/still running."
44
trap "test -f /var/lock/live-webhelper.lock && rm -f /var/lock/live-webhelper.lock; exit 0" 0 1 2 3 9 15
47
touch /var/lock/live-webhelper.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-webhelper: remove web build (`date -d yesterday +%Y%m%d.%H`*)." >> /var/log/live
57
# Ok from here spin through the live-webhelper 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 the variables we want from the config file.
64
# Pul in the build number
65
_BUILD=`awk -F\" '/^_BUILD=/{print $2}' ${_FILE}`
66
# Pull in the email address
67
_EMAIL=`awk -F\" '/^_EMAIL=/{print $2}' ${_FILE}`
68
# Pull in the custom bootstrap
69
_CUSTOM_BOOTSTRAP=`awk -F\" '/^_CUSTOM_BOOTSTRAP=/{print $2}' ${_FILE}`
70
# Pull in the custom binary
71
_CUSTOM_BINARY=`awk -F\" '/^_CUSTOM_BINARY=/{print $2}' ${_FILE}`
73
# Drop out some build data for information if something goes wrong.
74
echo "`date +%b\ %d\ %H:%M:%S` ${HOSTNAME} live-webhelper: begin web build (${_BUILD})." >> /var/log/live
76
# Creating build directory which also creates the config/chroot_sources folder
77
mkdir -p "${_TEMPDIR}"/"${_BUILD}"/config/chroot_sources
79
# The next two tests are for unofficial third party repositories
80
if [ -n "${_CUSTOM_BOOTSTRAP}" ]
82
echo "${_CUSTOM_BOOTSTRAP}" > "${_TEMPDIR}"/"${_BUILD}"/config/chroot_sources/custom.bootstrap
85
if [ -n "${_CUSTOM_BINARY}" ]
87
echo "${_CUSTOM_BINARY}" > "${_TEMPDIR}"/"${_BUILD}"/config/chroot_sources/custom.binary
90
_DATE_START="`date -R`"
91
echo "Begin: ${_DATE_START}" > "${_TEMPDIR}"/"${_BUILD}"/log
94
cd "${_TEMPDIR}"/"${_BUILD}"
95
lh_config -c ${_FILE} >> "${_TEMPDIR}"/"${_BUILD}"/log 2>&1
97
lh_build >> "${_TEMPDIR}"/"${_BUILD}"/log 2>&1
100
_DATE_END="`date -R`"
101
echo "End: ${_DATE_END}" >> "${_TEMPDIR}"/"${_BUILD}"/log
103
# Creating image directory
104
mkdir -p "${_DESTDIR}"/"${_BUILD}"
107
if [ "${_ERRORCONFIG}" -eq "0" ] && [ "${_ERRORBUILD}" -eq "0" ]
109
_STATUS="maybe-successful"
111
_STATUS="maybe-failed"
114
sed -e "s/BUILD/${_BUILD}/g" \
115
-e "s/EMAIL/${_EMAIL}/" \
116
-e "s/VERSION/${VERSION}/" \
117
-e "s/DATE_START/${_DATE_START}/" \
118
-e "s/DATE_END/${_DATE_END}/" \
119
-e "s/STATUS/${_STATUS}/" \
120
-e "s#SERVER#${_SERVER}#" \
121
"${_TEMPLATES}"/mail.txt > "${_DESTDIR}"/"${_BUILD}"/mail
123
# Moving binary image
124
#if ls "${_TEMPDIR}"/"${_BUILD}"/binary*.* > /dev/null 2>&1
125
if Find_files ${_TEMPDIR}/${_BUILD}/binary*.*
127
mv "${_TEMPDIR}"/"${_BUILD}"/binary*.* "${_DESTDIR}"/"${_BUILD}"
130
# Moving source image
131
#if ls "${_TEMPDIR}"/"${_BUILD}"/source.* > /dev/null 2>&1
132
if Find_files ${_TEMPDIR}/${_BUILD}/source.*
134
mv "${_TEMPDIR}"/"${_BUILD}"/source.* "${_DESTDIR}"/"${_BUILD}"
138
mv "${_TEMPDIR}"/"${_BUILD}".build "${_DESTDIR}"/"${_BUILD}"/build
141
mv "${_TEMPDIR}"/"${_BUILD}"/log "${_DESTDIR}"/"${_BUILD}"
144
cd "${_DESTDIR}"/"${_BUILD}"
149
cat "${_DESTDIR}"/"${_BUILD}"/mail | /usr/sbin/sendmail -t
151
# Unmounting devpts-live
152
#if ls "${_TEMPDIR}"/"${_BUILD}"/chroot/dev/pts/* > /dev/null 2>&1
153
if Find_files ${_TEMPDIR}/${_BUILD}/chroot/dev/pts/*
155
umount "${_TEMPDIR}"/${_BUILD}/chroot/dev/pts
159
if [ -f "${_TEMPDIR}"/"${_BUILD}"/chroot/proc/version ]
161
umount "${_TEMPDIR}"/"${_BUILD}"/chroot/proc
165
if [ -d "${_TEMPDIR}"/"${_BUILD}"/chroot/sys/kernel ]
167
umount "${_TEMPDIR}"/${_BUILD}/chroot/sys
170
# Removing build directory
171
rm -rf "${_TEMPDIR}"/"${_BUILD}"
173
echo "`date +%b\ %d\ %H:%M:%S` ${HOSTNAME} live-webhelper: end web build (${_BUILD}: ${_STATUS})." >> /var/log/live