]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/bash | |
2 | ############################################################################ | |
3 | # | |
4 | # Beautifying variables & presentation & input output interface | |
5 | # | |
6 | ############################################################################ | |
7 | ||
8 | ## Screen Dimentions | |
9 | # Find current screen size | |
10 | if [ -z "${COLUMNS}" ]; then | |
11 | COLUMNS=$(stty size) | |
12 | COLUMNS=${COLUMNS##* } | |
13 | fi | |
14 | ||
15 | # When using remote connections, such as a serial port, stty size returns 0 | |
16 | if [ "${COLUMNS}" = "0" ]; then | |
17 | COLUMNS=80 | |
18 | fi | |
19 | ||
20 | ## Measurements for positioning result messages | |
21 | RESULT_WIDTH=4 | |
22 | TIME_WIDTH=8 | |
23 | OPT_WIDTH=6 | |
24 | VER_WIDTH=10 | |
25 | RESULT_COL=$((${COLUMNS} - $RESULT_WIDTH - 4)) | |
26 | TIME_COL=$((${RESULT_COL} - $TIME_WIDTH - 5)) | |
27 | OPT_COL=$((${TIME_COL} - $OPT_WIDTH - 5)) | |
28 | VER_COL=$((${OPT_COL} - $VER_WIDTH - 5)) | |
29 | ||
30 | ## Set Cursur Position Commands, used via echo -e | |
31 | SET_RESULT_COL="\\033[${RESULT_COL}G" | |
32 | SET_TIME_COL="\\033[${TIME_COL}G" | |
33 | SET_OPT_COL="\\033[${OPT_COL}G" | |
34 | SET_VER_COL="\\033[${VER_COL}G" | |
35 | ||
36 | # Define color for messages | |
37 | BOLD="\\033[1;39m" | |
38 | DONE="\\033[1;32m" | |
39 | SKIP="\\033[1;34m" | |
40 | WARN="\\033[1;35m" | |
41 | FAIL="\\033[1;31m" | |
42 | NORMAL="\\033[0;39m" | |
43 | ||
44 | evaluate() { | |
45 | if [ "$?" -eq "0" ]; then | |
46 | beautify message DONE | |
47 | else | |
48 | EXITCODE=$1 | |
49 | shift 1 | |
50 | beautify message FAIL | |
51 | $* | |
52 | if [ $EXITCODE -ne "0" ]; then | |
53 | exit $EXITCODE | |
54 | fi | |
55 | fi | |
56 | } | |
57 | ||
58 | position_cursor() | |
59 | { | |
60 | # ARG1=starting position on screen | |
61 | # ARG2=string to be printed | |
62 | # ARG3=offset, negative for left movement, positive for right movement, relative to ARG1 | |
63 | # For example if your starting position is column 50 and you want to print Hello three columns to the right | |
64 | # of your starting position, your call will look like this: | |
65 | # position_cursor 50 "Hello" 3 (you'll get the string Hello at position 53 (= 50 + 3) | |
66 | # If on the other hand you want your string "Hello" to end three columns to the left of position 50, | |
67 | # your call will look like this: | |
68 | # position_cursor 50 "Hello" -3 (you'll get the string Hello at position 42 (= 50 - 5 -3) | |
69 | # If you want to start printing at the exact starting location, use offset 0 | |
70 | ||
71 | START=$1 | |
72 | STRING=$2 | |
73 | OFFSET=$3 | |
74 | ||
75 | STRING_LENGTH=${#STRING} | |
76 | ||
77 | if [ ${OFFSET} -lt 0 ]; then | |
78 | COL=$((${START} + ${OFFSET} - ${STRING_LENGTH})) | |
79 | else | |
80 | COL=$((${START} + ${OFFSET})) | |
81 | fi | |
82 | ||
83 | SET_COL="\\033[${COL}G" | |
84 | ||
85 | echo $SET_COL | |
86 | } # End of position_cursor() | |
87 | ||
88 | ||
89 | beautify() | |
90 | { | |
91 | # Commands: build_stage, make_pkg, message, result | |
92 | case "$1" in | |
93 | message) | |
94 | case "$2" in | |
95 | DONE) | |
96 | echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n" | |
97 | ;; | |
98 | WARN) | |
99 | echo -ne "${WARN}${3}${NORMAL}${SET_RESULT_COL}[${WARN} WARN ${NORMAL}]\n" | |
100 | ;; | |
101 | FAIL) | |
102 | echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n" | |
103 | ;; | |
104 | SKIP) | |
105 | echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n" | |
106 | ;; | |
107 | esac | |
108 | ;; | |
109 | build_stage) | |
110 | MESSAGE=$2 | |
111 | echo -ne "${BOLD}*** ${MESSAGE}${SET_VER_COL} version${SET_OPT_COL} options" | |
112 | echo -ne "${SET_TIME_COL} time (sec)${SET_RESULT_COL} status${NORMAL}\n" | |
113 | ;; | |
114 | make_pkg) | |
115 | echo "$2" | while read PKG_VER PROGRAM OPTIONS | |
116 | do | |
117 | SET_VER_COL_REAL=`position_cursor $OPT_COL $PKG_VER -3` | |
118 | ||
119 | if [ "$OPTIONS" == "" ]; then | |
120 | echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}" | |
121 | echo -ne "${NORMAL} ]${SET_RESULT_COL}" | |
122 | else | |
123 | echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}" | |
124 | echo -ne "${NORMAL} ]${SET_OPT_COL}[ ${BOLD}${OPTIONS}" | |
125 | echo -ne "${NORMAL} ]${SET_RESULT_COL}" | |
126 | fi | |
127 | done | |
128 | ;; | |
129 | result) | |
130 | RESULT=$2 | |
131 | ||
132 | if [ ! $3 ]; then | |
133 | PKG_TIME=0 | |
134 | else | |
135 | PKG_TIME=$3 | |
136 | fi | |
137 | ||
138 | SET_TIME_COL_REAL=`position_cursor $RESULT_COL $PKG_TIME -3` | |
139 | case "$RESULT" in | |
140 | DONE) | |
141 | echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]" | |
142 | echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n" | |
143 | ;; | |
144 | FAIL) | |
145 | echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]" | |
146 | echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n" | |
147 | ;; | |
148 | SKIP) | |
149 | echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]" | |
150 | echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n" | |
151 | ;; | |
152 | esac | |
153 | ;; | |
154 | esac | |
155 | } # End of beautify() | |
156 | ||
157 | ||
158 | get_pkg_ver() | |
159 | { | |
160 | PKG_VER=`grep ^VER $1 | awk '{print $3}'` | |
161 | ||
162 | if [ -z $PKG_VER ]; then | |
163 | PKG_VER=`grep "Exp " $1 | awk '{print $4}'` | |
164 | fi | |
165 | ||
166 | if [ ${#PKG_VER} -gt $VER_WIDTH ]; then | |
167 | # If a package version number is greater than $VER_WIDTH, we keep the first 4 characters | |
168 | # and replace enough characters to fit the resulting string on the screen. We'll replace | |
169 | # the extra character with .. (two dots). That's why the "+ 2" in the formula below. | |
170 | # Example: if we have a 21-long version number that we want to fit into a 10-long space, | |
171 | # we have to remove 11 characters. But if we replace 11 characters with 2 characters, we'll | |
172 | # end up with a 12-character long string. That's why we replace 12 characters with .. | |
173 | REMOVE=`expr substr "$PKG_VER" 4 $[ ${#PKG_VER} - $VER_WIDTH + 2 ]` | |
174 | PKG_VER=`echo ${PKG_VER/$REMOVE/..}` | |
175 | fi | |
176 | ||
177 | echo "$PKG_VER" | |
178 | } # End of get_pkg_ver() | |
179 | ||
180 | if [ 'x86_64' = $MACHINE -o 'i686' = $MACHINE -o 'i586' = $MACHINE ]; then | |
181 | echo "`date -u '+%b %e %T'`: Machine is iX86 (or equivalent)" >> $LOGFILE | |
182 | MACHINE=i586 | |
183 | BUILDTARGET=i586-pc-linux-gnu | |
184 | CFLAGS="-O2 -march=i586 -pipe -fomit-frame-pointer" | |
185 | CXX2FLAGS="-O2 -march=i586 -pipe -fomit-frame-pointer" | |
186 | C2FLAGS="-O2 -march=i586 -mtune=i586 -pipe -fomit-frame-pointer" | |
187 | CXX2FLAGS="-O2 -march=i586 -mtune=i586 -pipe -fomit-frame-pointer" | |
188 | else | |
189 | echo "`date -u '+%b %e %T'`: Can't determine your architecture - $MACHINE" >> $LOGFILE | |
190 | exit 1 | |
191 | fi | |
192 | ||
193 | # Define immediately | |
194 | stdumount() { | |
195 | umount $BASEDIR/build/dev/pts 2>/dev/null; | |
196 | umount $BASEDIR/build/proc 2>/dev/null; | |
197 | umount $BASEDIR/build/install/mnt 2>/dev/null; | |
198 | umount $BASEDIR/build/usr/src/cache 2>/dev/null; | |
199 | umount $BASEDIR/build/usr/src/ccache 2>/dev/null; | |
200 | umount $BASEDIR/build/usr/src/config 2>/dev/null; | |
201 | umount $BASEDIR/build/usr/src/doc 2>/dev/null; | |
202 | umount $BASEDIR/build/usr/src/html 2>/dev/null; | |
203 | umount $BASEDIR/build/usr/src/langs 2>/dev/null; | |
204 | umount $BASEDIR/build/usr/src/lfs 2>/dev/null; | |
205 | umount $BASEDIR/build/usr/src/log 2>/dev/null; | |
206 | umount $BASEDIR/build/usr/src/src 2>/dev/null; | |
207 | } | |
208 | ||
209 | exiterror() { | |
210 | stdumount | |
211 | for i in `seq 0 7`; do | |
212 | if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then | |
213 | losetup -d /dev/loop${i} 2>/dev/null | |
214 | fi; | |
215 | done | |
216 | echo -e "\nERROR: $*" | |
217 | echo " Check $LOGFILE for errors if applicable" | |
218 | exit 1 | |
219 | } | |
220 | ||
221 | entershell() { | |
222 | if [ ! -e $BASEDIR/build/usr/src/lfs/ ]; then | |
223 | exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/" | |
224 | fi | |
225 | echo "Entering to a shell inside LFS chroot, go out with exit" | |
226 | chroot $LFS /tools/bin/env -i HOME=/root TERM=$TERM PS1='\u:\w\$ ' \ | |
227 | PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \ | |
228 | VERSION=$VERSION CONFIG_ROOT=$CONFIG_ROOT \ | |
229 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
230 | CFLAGS="$CF2LAGS" CXXFLAGS="$CXX2FLAGS" \ | |
231 | CCACHE_DIR=/usr/src/ccache \ | |
232 | CCACHE_HASHDIR=1 \ | |
233 | KVER=$KVER \ | |
234 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ | |
235 | KGCC="ccache /usr/bin/gcc" \ | |
236 | /tools/bin/bash | |
237 | if [ $? -ne 0 ]; then | |
238 | beautify message FAIL | |
239 | exiterror "chroot error" | |
240 | else | |
241 | stdumount | |
242 | fi | |
243 | } | |
244 | ||
245 | ############################################################################ | |
246 | # # | |
247 | # Necessary shell functions # | |
248 | # # | |
249 | ############################################################################ | |
250 | # | |
251 | # Common checking before entering the chroot and compilling | |
252 | # | |
253 | # Return:0 caller can continue | |
254 | # :1 skip (nothing to do) | |
255 | # or fail if no script file found | |
256 | # | |
257 | lfsmakecommoncheck() | |
258 | { | |
259 | ||
260 | # Script present? | |
261 | if [ ! -f $BASEDIR/lfs/$1 ]; then | |
262 | exiterror "No such file or directory: $BASEDIR/$1" | |
263 | fi | |
264 | ||
265 | local PKG_VER=`get_pkg_ver $BASEDIR/lfs/$1` | |
266 | beautify make_pkg "$PKG_VER $*" | |
267 | ||
268 | # Script slipped? | |
269 | local i | |
270 | for i in $SKIP_PACKAGE_LIST | |
271 | do | |
272 | if [ "$i" == "$1" ]; then | |
273 | beautify result SKIP | |
274 | return 1; | |
275 | fi | |
276 | done | |
277 | ||
278 | echo -ne "`date -u '+%b %e %T'`: Building $* " >> $LOGFILE | |
279 | ||
280 | cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download >> $LOGFILE 2>&1 | |
281 | if [ $? -ne 0 ]; then | |
282 | exiterror "Download error in $1" | |
283 | fi | |
284 | ||
285 | cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t md5sum" md5 >> $LOGFILE 2>&1 | |
286 | if [ $? -ne 0 ]; then | |
287 | exiterror "md5sum error in $1, check file in cache or signature" | |
288 | fi | |
289 | ||
290 | return 0 # pass all! | |
291 | } # End of lfsmakecommoncheck() | |
292 | ||
293 | lfsmake1() { | |
294 | lfsmakecommoncheck $* | |
295 | [ $? == 1 ] && return 0 | |
296 | ||
297 | local PKG_TIME_START=`date +%s` | |
298 | ||
299 | cd $BASEDIR/lfs && make -f $* BUILDTARGET=$BUILDTARGET \ | |
300 | MACHINE=$MACHINE \ | |
301 | LFS_BASEDIR=$BASEDIR \ | |
302 | ROOT=$LFS \ | |
303 | KVER=$KVER \ | |
304 | MAKETUNING=$MAKETUNING \ | |
305 | install >> $LOGFILE 2>&1 | |
306 | local COMPILE_SUCCESS=$? | |
307 | local PKG_TIME_END=`date +%s` | |
308 | ||
309 | if [ $COMPILE_SUCCESS -ne 0 ]; then | |
310 | beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] | |
311 | exiterror "Building $*"; | |
312 | else | |
313 | beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] | |
314 | fi | |
315 | ||
316 | return 0 | |
317 | } | |
318 | ||
319 | lfsmake2() { | |
320 | lfsmakecommoncheck $* | |
321 | [ $? == 1 ] && return 0 | |
322 | ||
323 | local PKG_TIME_START=`date +%s` | |
324 | chroot $LFS /tools/bin/env -i HOME=/root \ | |
325 | TERM=$TERM PS1='\u:\w\$ ' \ | |
326 | PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \ | |
327 | VERSION=$VERSION \ | |
328 | CONFIG_ROOT=$CONFIG_ROOT \ | |
329 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
330 | CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \ | |
331 | CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \ | |
332 | KVER=$KVER MAKETUNING=$MAKETUNING \ | |
333 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ | |
334 | /tools/bin/bash -x -c "cd /usr/src/lfs && \ | |
335 | make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1 | |
336 | local COMPILE_SUCCESS=$? | |
337 | local PKG_TIME_END=`date +%s` | |
338 | ||
339 | if [ $COMPILE_SUCCESS -ne 0 ]; then | |
340 | beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] | |
341 | exiterror "Building $*"; | |
342 | else | |
343 | beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] | |
344 | fi | |
345 | ||
346 | return 0 | |
347 | } | |
348 | ||
349 | ipfiremake() { | |
350 | lfsmakecommoncheck $* | |
351 | [ $? == 1 ] && return 0 | |
352 | ||
353 | local PKG_TIME_START=`date +%s` | |
354 | chroot $LFS /tools/bin/env -i HOME=/root \ | |
355 | TERM=$TERM PS1='\u:\w\$ ' \ | |
356 | PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \ | |
357 | VERSION=$VERSION \ | |
358 | CONFIG_ROOT=$CONFIG_ROOT \ | |
359 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
360 | CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \ | |
361 | CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \ | |
362 | KVER=$KVER MAKETUNING=$MAKETUNING \ | |
363 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ | |
364 | /bin/bash -x -c "cd /usr/src/lfs && \ | |
365 | make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1 | |
366 | ||
367 | local COMPILE_SUCCESS=$? | |
368 | local PKG_TIME_END=`date +%s` | |
369 | ||
370 | if [ $COMPILE_SUCCESS -ne 0 ]; then | |
371 | beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] | |
372 | exiterror "Building $*"; | |
373 | else | |
374 | beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] | |
375 | fi | |
376 | return 0 | |
377 | } | |
378 | ||
379 | ipfiredist() { | |
380 | if [ -f $BASEDIR/build/usr/src/lfs/$1 ]; then | |
381 | echo "`date -u '+%b %e %T'`: Packaging $1" | tee -a $LOGFILE | |
382 | chroot $LFS /tools/bin/env -i HOME=/root \ | |
383 | TERM=$TERM PS1='\u:\w\$ ' \ | |
384 | PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \ | |
385 | VERSION=$VERSION \ | |
386 | CONFIG_ROOT=$CONFIG_ROOT \ | |
387 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
388 | CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \ | |
389 | CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \ | |
390 | KVER=$KVER \ | |
391 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ | |
392 | /bin/bash -x -c "cd /usr/src/lfs && \ | |
393 | make -f $1 LFS_BASEDIR=/usr/src dist" >>$LOGFILE 2>&1 | |
394 | if [ $? -ne 0 ]; then | |
395 | exiterror "Packaging $1" | |
396 | fi | |
397 | else | |
398 | exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/$1" | |
399 | fi | |
400 | return 0 | |
401 | } | |
402 | ||
403 | installmake() { | |
404 | if [ -f $BASEDIR/build/usr/src/lfs/$1 ]; then | |
405 | echo "`date -u '+%b %e %T'`: Building $*" | tee -a $LOGFILE | |
406 | cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download >> $LOGFILE 2>&1 | |
407 | if [ $? -ne 0 ]; then | |
408 | exiterror "Download error in $1" | |
409 | fi | |
410 | cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t md5sum" md5 >> $LOGFILE 2>&1 | |
411 | if [ $? -ne 0 ]; then | |
412 | exiterror "md5sum error in $1, check file in cache or signature" | |
413 | fi | |
414 | chroot $LFS /tools/bin/env -i HOME=/root \ | |
415 | TERM=$TERM PS1='\u:\w\$ ' \ | |
416 | PATH=/usr/local/bin:/opt/$MACHINE-uClibc/usr/bin:/bin:/usr/bin:/sbin:/usr/sbin \ | |
417 | VERSION=$VERSION \ | |
418 | CONFIG_ROOT=$CONFIG_ROOT \ | |
419 | LFS_PASS="install" \ | |
420 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
421 | CFLAGS="-Os" CXXFLAGS="-Os" \ | |
422 | CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \ | |
423 | KVER=$KVER \ | |
424 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ | |
425 | /bin/bash -x -c "cd /usr/src/lfs && \ | |
426 | make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1 | |
427 | if [ $? -ne 0 ]; then | |
428 | exiterror "Building $*" | |
429 | fi | |
430 | else | |
431 | exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/$1" | |
432 | fi | |
433 | return 0 | |
434 | } | |
435 | ||
436 | update_logs() { | |
437 | tar cfz log/ipfire-logs-`date +'%Y-%m-%d-%H:%M'`.tgz log/_build.* | |
438 | rm -f log/_build.* | |
439 | } | |
440 | ||
441 | batch_script() { | |
442 | echo -ne "### UPDATE LOGS" | |
443 | update_logs | |
444 | evaluate 1 | |
445 | ||
446 | if [ "$IPFIRE_REBUILD" -eq "0" ]; then | |
447 | echo -ne "### SAVING TIME" | |
448 | export IPFIRE_START_TIME=`date` | |
449 | evaluate 1 | |
450 | ||
451 | echo "### RUNNING SVN-UPDATE" | |
452 | $0 svn update | |
453 | evaluate 1 mail SVNUPDATE | |
454 | ||
455 | echo "### EXPORT SOURCES" | |
456 | $0 svn dist | |
457 | evaluate 1 mail SVNDIST | |
458 | ||
459 | echo "### RUNNING PREFETCH" | |
460 | $0 prefetch | grep -q "md5 difference" | |
461 | evaluate 1 mail PREFETCH | |
462 | fi | |
463 | ||
464 | echo "### RUNNING BUILD" | |
465 | $0 build | |
466 | evaluate 1 mail ERROR | |
467 | ||
468 | echo "### UPLOADING ISO" | |
469 | $0 upload iso | |
470 | evaluate 1 mail ISO | |
471 | ||
472 | echo -ne "### UPLOADING PAKS" | |
473 | $0 upload paks | |
474 | evaluate 1 mail PAKS | |
475 | ||
476 | echo -n "${BOLD}***SUCCESS!${NORMAL}" | |
477 | evaluate 0 mail SUCCESS | |
478 | exit 0 | |
479 | } | |
480 | ||
481 | watch_screen() { | |
482 | echo -e "${BOLD}Exit with Ctrl+A, Ctrl+D.${NORMAL}" | |
483 | sleep 0.5 | |
484 | screen -x ipfire | |
485 | } | |
486 | ||
487 | mail() { | |
488 | chmod 755 tools/sendEmail | |
489 | ATTACHMENT=/tmp/ipfire-build-logs-R$SVN_REVISION.tar.gz | |
490 | case "$1" in | |
491 | success) | |
492 | SUBJECT="SUCCESS: IPFIRE-BUILD R$SVN_REVISION on `hostname`" | |
493 | cat <<END > /tmp/ipfire_mail_body | |
494 | Building IPFire on `hostname` in Revision $SVN_REVISION was successfull! | |
495 | You can find the ISO on your ftp server. | |
496 | ||
497 | Statistics: | |
498 | ----------- | |
499 | Started: $IPFIRE_START_TIME | |
500 | Finished: `date` | |
501 | ||
502 | Best Regards | |
503 | Your IPFire-Build-Script | |
504 | ||
505 | END | |
506 | echo -ne "${BOLD}***Sending success message${NORMAL}" | |
507 | ;; | |
508 | *) | |
509 | SUBJECT="ERROR $1: IPFIRE-BUILD R$SVN_REVISION on `hostname`" | |
510 | cat <<END > /tmp/ipfire_mail_body | |
511 | When I was building IPFire on `hostname`, I have found an ERROR with name $1! | |
512 | Here you can see the logs and detect the reason for this error. | |
513 | ||
514 | Best Regards | |
515 | Your IPFire-Build-Script | |
516 | ||
517 | ||
518 | Here is a summary... The full logs are in the attachment. | |
519 | --------------------------------------------------------- | |
520 | ||
521 | `tail log/_*` | |
522 | END | |
523 | echo -ne "${BOLD}***Sending error message${NORMAL}" | |
524 | ;; | |
525 | esac | |
526 | tar cfz $ATTACHMENT log/_build* | |
527 | cat /tmp/ipfire_mail_body | tools/sendEmail -q \ | |
528 | -f $IPFIRE_MAIL_FROM \ | |
529 | -t $IPFIRE_MAIL_REPORT \ | |
530 | -u $SUBJECT \ | |
531 | -s $IPFIRE_MAIL_SERVER:25 \ | |
532 | -xu $IPFIRE_MAIL_USER \ | |
533 | -xp $IPFIRE_MAIL_PASS \ | |
534 | -l log/_build.mail.log \ | |
535 | -a $ATTACHMENT # -v | |
536 | if [ "$?" -eq "0" ]; then | |
537 | beautify message DONE | |
538 | else | |
539 | beautify message FAIL | |
540 | fi | |
541 | rm -f /tmp/ipfire_mail_body $ATTACHMENT | |
542 | } | |
543 | ||
544 | make_config() { | |
545 | echo -e "This is for creating your configuration..." | |
546 | echo -e "We will need some input:" | |
547 | echo -e "" | |
548 | echo -n "FTP-DOMAIN FOR THE ISO: " | |
549 | read IPFIRE_FTP_URL_EXT | |
550 | echo -n "PATH FOR $IPFIRE_FTP_URL_EXT: " | |
551 | read IPFIRE_FTP_PATH_EXT | |
552 | echo -n "USERNAME FOR $IPFIRE_FTP_URL_EXT: " | |
553 | read IPFIRE_FTP_USER_EXT | |
554 | echo -n "PASSWORD FOR $IPFIRE_FTP_URL_EXT: " | |
555 | read -s IPFIRE_FTP_PASS_EXT | |
556 | echo "" | |
557 | echo "(You can leave this empty if the cache-server is the same as your iso-server.)" | |
558 | echo -n "FTP-DOMAIN FOR THE CACHE: " | |
559 | read IPFIRE_FTP_URL_INT | |
560 | echo -n "PATH FOR $IPFIRE_FTP_URL_INT: " | |
561 | read IPFIRE_FTP_PATH_INT | |
562 | if [ $IPFIRE_FTP_URL_INT ]; then | |
563 | echo -n "USERNAME FOR $IPFIRE_FTP_URL_INT: " | |
564 | read IPFIRE_FTP_USER_INT | |
565 | echo -n "PASSWORD FOR $IPFIRE_FTP_URL_INT: " | |
566 | read -s IPFIRE_FTP_PASS_INT | |
567 | else | |
568 | IPFIRE_FTP_URL_INT=$IPFIRE_FTP_URL_EXT | |
569 | IPFIRE_FTP_USER_INT=$IPFIRE_FTP_USER_EXT | |
570 | IPFIRE_FTP_PASS_INT=$IPFIRE_FTP_PASS_EXT | |
571 | echo "USERNAME FOR $IPFIRE_FTP_URL_INT: $IPFIRE_FTP_USER_INT" | |
572 | echo "PASSWORD FOR $IPFIRE_FTP_URL_INT: !HIDDEN!" | |
573 | fi | |
574 | echo "" | |
575 | echo "(You can leave this empty if the pak-server is the same as your iso-server.)" | |
576 | echo -n "FTP-DOMAIN FOR THE PAKS: " | |
577 | read IPFIRE_FTP_URL_PAK | |
578 | echo -n "PATH FOR $IPFIRE_FTP_URL_PAK: " | |
579 | read IPFIRE_FTP_PATH_PAK | |
580 | if [ $IPFIRE_FTP_URL_PAK ]; then | |
581 | echo -n "USERNAME FOR $IPFIRE_FTP_URL_PAK: " | |
582 | read IPFIRE_FTP_USER_PAK | |
583 | echo -n "PASSWORD FOR $IPFIRE_FTP_URL_PAK: " | |
584 | read -s IPFIRE_FTP_PASS_PAK | |
585 | else | |
586 | IPFIRE_FTP_URL_PAK=$IPFIRE_FTP_URL_EXT | |
587 | IPFIRE_FTP_USER_PAK=$IPFIRE_FTP_USER_EXT | |
588 | IPFIRE_FTP_PASS_PAK=$IPFIRE_FTP_PASS_EXT | |
589 | echo "USERNAME FOR $IPFIRE_FTP_URL_PAK: $IPFIRE_FTP_USER_PAK" | |
590 | echo "PASSWORD FOR $IPFIRE_FTP_URL_PAK: !HIDDEN!" | |
591 | fi | |
592 | echo "" | |
593 | echo -e "ONE OR MORE EMAIL ADDRESS(ES) TO WHICH THE REPORTS WILL BE SENT" | |
594 | echo -e "(seperated by comma)" | |
595 | read IPFIRE_MAIL_REPORT | |
596 | echo -n "EMAIL FROM: " | |
597 | read IPFIRE_MAIL_FROM | |
598 | echo -n "EMAIL SERVER: " | |
599 | read IPFIRE_MAIL_SERVER | |
600 | echo -n "LOGIN TO MAIL SERVER: " | |
601 | read IPFIRE_MAIL_USER | |
602 | echo -n "MAIL PASSWORD: " | |
603 | read -s IPFIRE_MAIL_PASS | |
604 | echo -n "Saving..." | |
605 | cat <<END > .config | |
606 | ### ISO server | |
607 | IPFIRE_FTP_URL_EXT=$IPFIRE_FTP_URL_EXT | |
608 | IPFIRE_FTP_PATH_EXT=$IPFIRE_FTP_PATH_EXT | |
609 | IPFIRE_FTP_USER_EXT=$IPFIRE_FTP_USER_EXT | |
610 | IPFIRE_FTP_PASS_EXT=$IPFIRE_FTP_PASS_EXT | |
611 | ### cache server | |
612 | IPFIRE_FTP_URL_INT=$IPFIRE_FTP_URL_INT | |
613 | IPFIRE_FTP_PATH_INT=$IPFIRE_FTP_PATH_INT | |
614 | IPFIRE_FTP_USER_INT=$IPFIRE_FTP_USER_INT | |
615 | IPFIRE_FTP_PASS_INT=$IPFIRE_FTP_PASS_INT | |
616 | ### paks server | |
617 | IPFIRE_FTP_URL_PAK=$IPFIRE_FTP_URL_PAK | |
618 | IPFIRE_FTP_PATH_PAK=$IPFIRE_FTP_PATH_PAK | |
619 | IPFIRE_FTP_USER_PAK=$IPFIRE_FTP_USER_PAK | |
620 | IPFIRE_FTP_PASS_PAK=$IPFIRE_FTP_PASS_PAK | |
621 | ### mail reports | |
622 | IPFIRE_MAIL_REPORT=$IPFIRE_MAIL_REPORT | |
623 | IPFIRE_MAIL_FROM=$IPFIRE_MAIL_FROM | |
624 | IPFIRE_MAIL_SERVER=$IPFIRE_MAIL_SERVER | |
625 | IPFIRE_MAIL_USER=$IPFIRE_MAIL_USER | |
626 | IPFIRE_MAIL_PASS=$IPFIRE_MAIL_PASS | |
627 | END | |
628 | beautify message DONE | |
629 | } |