blob: 6834c49bbd937415c8c0937527673836eeb1f701 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
#!/bin/bash
PID=$$
config_file=
verbose=0
keep_tmpdir=0
testing=0
usage() {
msg=$1
if [ -n "${msg}" ]; then
echo -e "${msg}\n";
fi
cat <<EOH
Usage:
stage_build [-c|--config <config>] [--verbose] [-h|--help]
Options:
-c|--config Specifies the config file to use (required)
--verbose Send output of commands to console as well as log
-k|--keep-tmpdir Don't remove temp dir when build finishes
-t|--test Stop after mangling specs and copying files
-h|--help Show this message and quit
EOH
}
send_email() {
subject="${EMAIL_SUBJECT_PREPEND} $1"
message=$2
logfile=$3
if [ -n "${logfile}" ]; then
body=$(echo -e "${message}\n\n"; tail -n 200 "${logfile}"; echo -e "\n\n\nFull build log at ${logfile}")
else
body=${message}
fi
echo -e "From: ${EMAIL_FROM}\r\nTo: ${EMAIL_TO}\r\nSubject: ${subject}\r\n\r\n${body}" | /usr/sbin/sendmail -f ${EMAIL_FROM} ${EMAIL_TO}
}
run_cmd() {
cmd=$1
logfile=$2
if [ $verbose = 1 ]; then
echo "*** Running command: ${cmd}"
${cmd} 2>&1 | tee ${logfile}
else
${cmd} &> ${logfile}
fi
}
pre_build() {
# This is a skeleton function that you can override from the config file.
# It will be executed before the build is started. You can use this to
# update a svn checkout of spec files
local foo=bar
}
post_build() {
# This is a skeleton function that you can override from the config file.
# It will be executed after the build is successfully completed. You can
# use this to rsync the builds to another box
local foo=bar
}
# Parse args
params=${#}
while [ ${#} -gt 0 ]
do
a=${1}
shift
case "${a}" in
-h|--help)
usage
exit 0
;;
-c|--config)
config_file=$1
shift
;;
--verbose)
verbose=1
;;
-k|--keep-tmpdir)
keep_tmpdir=1
;;
-t|--test)
testing=1
;;
-*)
echo "You have specified an invalid option: ${a}"
usage
exit 1
;;
esac
done
# Make sure all required values were specified
if [ -z "${config_file}" -o ! -e "${config_file}" ]; then
usage "You must specify a valid config file to use"
exit 1
fi
source ${config_file}
TMPDIR=/tmp/catalyst-auto.${PID}
DATESTAMP=$(date +%Y%m%d)
if [ ${verbose} = 1 ]; then
echo "TMPDIR = ${TMPDIR}"
echo "DATESTAMP = ${DATESTAMP}"
fi
# Check if tmp directory exists and remove it
if [ -d "${TMPDIR}" ]; then
if ! rm -rf "${TMPDIR}"; then
echo "Couldn't remove stale tmpdir ${TMPDIR}!"
exit 1
fi
fi
for i in ${TMPDIR} ${TMPDIR}/specs ${TMPDIR}/kconfig ${TMPDIR}/log; do
if ! mkdir -p "${i}"; then
echo "Couldn't create dir ${i}!"
exit 1
fi
done
if ! run_cmd "pre_build" "${TMPDIR}/log/pre_build.log"; then
send_email "Catalyst build error - pre_build" "Your pre_build function sucks" "${TMPDIR}/log/pre_build.log"
exit 1
fi
cd ${SPECS_DIR}
for i in ${SPECS} ${OPTIONAL_SPECS}; do
cp --parents ${i} ${TMPDIR}/specs/
done
cd ${KCONFIG_DIR}
find -type f -exec cp {} ${TMPDIR}/kconfig \;
cd ${TMPDIR}/specs
# Fix up specs with datestamp
for i in $(find -name '*.spec'); do
# Grab current version_stamp and source_subpath
old_version_stamp=$(grep version_stamp ${i} | sed -e 's|^version_stamp: *||')
old_source_subpath=$(grep source_subpath ${i} | sed -e 's|^source_subpath: *||')
new_version_stamp=$(echo "${old_version_stamp}" | sed -e 's|^\(.*-\)\?.*$|\1'${DATESTAMP}'|')
new_source_subpath=$(echo "${old_source_subpath}" | sed -e 's|'${old_version_stamp}'$|'${new_version_stamp}'|')
sed -i 's|^version_stamp:.*$|version_stamp: '${new_version_stamp}'|' ${i}
sed -i 's|^snapshot:.*$|snapshot: '${DATESTAMP}'|' ${i}
# We don't want to mangle the source_subpath for our stage1 spec
if ! grep -q '^target: *stage1$' ${i}; then
sed -i 's|^source_subpath:.*$|source_subpath: '${new_source_subpath}'|' ${i}
fi
sed -i '/^livecd\/iso/s|'${old_version_stamp}'|'${new_version_stamp}'|' ${i}
kconfig_lines=$(grep '^boot/kernel/[^/]\+/config:' ${i})
if [ -n "${kconfig_lines}" ]; then
echo "${kconfig_lines}" | while read line; do
key=$(echo "${line}" | cut -d: -f1)
filename=$(basename $(echo "${line}" | cut -d: -f2))
sed -i "s|^${key}:.*\$|${key}: ${TMPDIR}/kconfig/${filename}|" ${i}
done
fi
done
if [ "${testing}" -eq 1 ]; then
echo "Exiting due to --test"
exit
fi
# Create snapshot
if ! run_cmd "catalyst -c ${CATALYST_CONFIG} -s ${DATESTAMP}" "${TMPDIR}/log/snapshot.log"; then
send_email "Catalyst build error - snapshot" "" "${TMPDIR}/log/snapshot.log"
exit 1
fi
for i in ${SPECS}; do
LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::').log"
run_cmd "catalyst -a -p -c ${CATALYST_CONFIG} -f ${i}" ${LOGFILE}
if [ $? != 0 ]; then
send_email "Catalyst fatal build error - ${i}" "" "${LOGFILE}"
exit 1
fi
done
for i in ${OPTIONAL_SPECS}; do
LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::').log"
run_cmd "catalyst -a -p -c ${CATALYST_CONFIG} -f ${i}" ${LOGFILE}
if [ $? != 0 ]; then
send_email "Catalyst non-fatal build error - ${i}" "" "${LOGFILE}"
break
fi
done
for i in ${SPECS} ${OPTIONAL_SPECS}; do
LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::')_purge.log"
run_cmd "catalyst -P -c ${CATALYST_CONFIG} -f ${i}" "${LOGFILE}"
done
if ! run_cmd "post_build" "${TMPDIR}/log/post_build.log"; then
send_email "Catalyst build error - post_build" "Your post_build function sucks" "${TMPDIR}/log/post_build.log"
exit 1
fi
send_email "Catalyst build success" "Build process complete."
if [ "${keep_tmpdir}" = 0 ]; then
if ! rm -rf "${TMPDIR}"; then
echo "Could not remove tmpdir ${TMPDIR}!"
exit 1
fi
fi
|