~oem-solutions-releng/live-build/lb-sg-2.x-add-support-for-xz-and-bzip2-compression

« back to all changes in this revision

Viewing changes to cgi/cron

  • Committer: Daniel Baumann
  • Date: 2011-03-09 18:17:04 UTC
  • Revision ID: daniel@debian.org-20110309181704-fuq28tc89dn0pggz
Merging live-webhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
# live-webhelper - web interface to live-helper
 
4
# Copyright (C) 2007-2010 Daniel Baumann <daniel@debian.org>
 
5
#
 
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.
 
9
 
 
10
# Including common functions
 
11
LH_BASE="${LH_BASE:-/usr/share/live-helper}"
 
12
 
 
13
for _FUNCTION in "${LH_BASE}"/functions/*.sh
 
14
do
 
15
        . "${_FUNCTION}"
 
16
done
 
17
 
 
18
# Reading common
 
19
. /usr/share/live-webhelper/common
 
20
 
 
21
# Reading defaults
 
22
if [ -r /etc/default/live-webhelper ]
 
23
then
 
24
        . /etc/default/live-webhelper
 
25
else
 
26
        echo "E: /etc/default/live-webhelper missing"
 
27
        exit 1
 
28
fi
 
29
 
 
30
# Exit if disabled
 
31
if [ "${_WEBBUILD}" != "enabled" ]
 
32
then
 
33
        exit 0
 
34
fi
 
35
 
 
36
# Checking lock file
 
37
if [ -f /var/lock/live-webhelper.lock ]
 
38
then
 
39
        echo "E: live-webhelper already/still running."
 
40
        exit 1
 
41
fi
 
42
 
 
43
# Creating lock trap
 
44
trap "test -f /var/lock/live-webhelper.lock && rm -f /var/lock/live-webhelper.lock; exit 0" 0 1 2 3 9 15
 
45
 
 
46
# Creating lock file
 
47
touch /var/lock/live-webhelper.lock
 
48
 
 
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`*
 
53
 
 
54
        echo "`date +%b\ %d\ %H:%M:%S` ${HOSTNAME} live-webhelper: remove web build (`date -d yesterday +%Y%m%d.%H`*)." >> /var/log/live
 
55
fi
 
56
 
 
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 
 
60
then
 
61
        for _FILE in "${_TEMPDIR}"/*.build
 
62
        do
 
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}`
 
72
                
 
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
 
75
 
 
76
                # Creating build directory which also creates the config/chroot_sources folder
 
77
                mkdir -p "${_TEMPDIR}"/"${_BUILD}"/config/chroot_sources
 
78
 
 
79
                # The next two tests are for unofficial third party repositories
 
80
                if [ -n "${_CUSTOM_BOOTSTRAP}" ]
 
81
                then
 
82
                        echo "${_CUSTOM_BOOTSTRAP}" > "${_TEMPDIR}"/"${_BUILD}"/config/chroot_sources/custom.bootstrap
 
83
                fi
 
84
 
 
85
                if [ -n "${_CUSTOM_BINARY}" ]
 
86
                then
 
87
                        echo "${_CUSTOM_BINARY}" > "${_TEMPDIR}"/"${_BUILD}"/config/chroot_sources/custom.binary
 
88
                fi
 
89
 
 
90
                _DATE_START="`date -R`"
 
91
                echo "Begin: ${_DATE_START}" > "${_TEMPDIR}"/"${_BUILD}"/log
 
92
 
 
93
                # Generating image
 
94
                cd "${_TEMPDIR}"/"${_BUILD}"
 
95
                lh_config -c ${_FILE} >> "${_TEMPDIR}"/"${_BUILD}"/log 2>&1
 
96
                _ERRORCONFIG="${?}"
 
97
                lh_build >> "${_TEMPDIR}"/"${_BUILD}"/log 2>&1
 
98
                _ERRORBUILD="${?}"
 
99
 
 
100
                _DATE_END="`date -R`"
 
101
                echo "End: ${_DATE_END}" >> "${_TEMPDIR}"/"${_BUILD}"/log
 
102
 
 
103
                # Creating image directory
 
104
                mkdir -p "${_DESTDIR}"/"${_BUILD}"
 
105
 
 
106
                # Creating mail
 
107
                if [ "${_ERRORCONFIG}" -eq "0" ] && [ "${_ERRORBUILD}" -eq "0" ]
 
108
                then
 
109
                        _STATUS="maybe-successful"
 
110
                else
 
111
                        _STATUS="maybe-failed"
 
112
                fi
 
113
 
 
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
 
122
 
 
123
                # Moving binary image
 
124
                #if ls "${_TEMPDIR}"/"${_BUILD}"/binary*.* > /dev/null 2>&1
 
125
                if Find_files ${_TEMPDIR}/${_BUILD}/binary*.*
 
126
                then
 
127
                        mv "${_TEMPDIR}"/"${_BUILD}"/binary*.* "${_DESTDIR}"/"${_BUILD}"
 
128
                fi
 
129
 
 
130
                # Moving source image
 
131
                #if ls "${_TEMPDIR}"/"${_BUILD}"/source.* > /dev/null 2>&1
 
132
                if Find_files ${_TEMPDIR}/${_BUILD}/source.*
 
133
                then
 
134
                        mv "${_TEMPDIR}"/"${_BUILD}"/source.* "${_DESTDIR}"/"${_BUILD}"
 
135
                fi
 
136
 
 
137
                # Moving build
 
138
                mv "${_TEMPDIR}"/"${_BUILD}".build "${_DESTDIR}"/"${_BUILD}"/build
 
139
 
 
140
                # Moving log
 
141
                mv "${_TEMPDIR}"/"${_BUILD}"/log "${_DESTDIR}"/"${_BUILD}"
 
142
 
 
143
                # Generating md5sum
 
144
                cd "${_DESTDIR}"/"${_BUILD}"
 
145
                md5sum * > md5sum
 
146
                cd "${OLDPWD}"
 
147
 
 
148
                # Sending mail
 
149
                cat "${_DESTDIR}"/"${_BUILD}"/mail | /usr/sbin/sendmail -t
 
150
 
 
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/*
 
154
                then
 
155
                        umount "${_TEMPDIR}"/${_BUILD}/chroot/dev/pts
 
156
                fi
 
157
 
 
158
                # Unmounting proc
 
159
                if [ -f "${_TEMPDIR}"/"${_BUILD}"/chroot/proc/version ]
 
160
                then
 
161
                        umount "${_TEMPDIR}"/"${_BUILD}"/chroot/proc
 
162
                fi
 
163
 
 
164
                # Unmounting sysfs
 
165
                if [ -d "${_TEMPDIR}"/"${_BUILD}"/chroot/sys/kernel ]
 
166
                then
 
167
                        umount "${_TEMPDIR}"/${_BUILD}/chroot/sys
 
168
                fi
 
169
 
 
170
                # Removing build directory
 
171
                rm -rf "${_TEMPDIR}"/"${_BUILD}"
 
172
 
 
173
                echo "`date +%b\ %d\ %H:%M:%S` ${HOSTNAME} live-webhelper: end web build (${_BUILD}: ${_STATUS})." >> /var/log/live
 
174
        done
 
175
fi