]>
Commit | Line | Data |
---|---|---|
15679d9f MT |
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 | ;; | |
7ab7a9b4 | 109 | build_stage_start) |
15679d9f | 110 | MESSAGE=$2 |
7ab7a9b4 | 111 | STAGE_TIME_START=`date +%s` |
15679d9f MT |
112 | echo -ne "${BOLD}*** ${MESSAGE}${SET_VER_COL} version${SET_OPT_COL} options" |
113 | echo -ne "${SET_TIME_COL} time (sec)${SET_RESULT_COL} status${NORMAL}\n" | |
114 | ;; | |
7ab7a9b4 MT |
115 | build_stage_end) |
116 | STAGE_TIME_END=`date +%s` | |
117 | echo -ne "${BOLD}***This stage took:\t\t $[ $STAGE_TIME_END - $STAGE_TIME_START ] (secs)${NORMAL}\n" | |
118 | ;; | |
119 | build_start) | |
120 | BUILD_TIME_START=`date +%s` | |
121 | ;; | |
122 | build_end) | |
123 | BUILD_TIME_END=`date +%s` | |
124 | echo -ne "${BOLD}***Build is finished now!\nThis took:\t\t\t $[ $BUILD_TIME_END - $BUILD_TIME_START ] (secs)${NORMAL}\n" | |
125 | ;; | |
15679d9f MT |
126 | make_pkg) |
127 | echo "$2" | while read PKG_VER PROGRAM OPTIONS | |
128 | do | |
129 | SET_VER_COL_REAL=`position_cursor $OPT_COL $PKG_VER -3` | |
130 | ||
131 | if [ "$OPTIONS" == "" ]; then | |
132 | echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}" | |
133 | echo -ne "${NORMAL} ]${SET_RESULT_COL}" | |
134 | else | |
135 | echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}" | |
136 | echo -ne "${NORMAL} ]${SET_OPT_COL}[ ${BOLD}${OPTIONS}" | |
137 | echo -ne "${NORMAL} ]${SET_RESULT_COL}" | |
138 | fi | |
139 | done | |
140 | ;; | |
141 | result) | |
142 | RESULT=$2 | |
143 | ||
144 | if [ ! $3 ]; then | |
145 | PKG_TIME=0 | |
146 | else | |
147 | PKG_TIME=$3 | |
148 | fi | |
149 | ||
150 | SET_TIME_COL_REAL=`position_cursor $RESULT_COL $PKG_TIME -3` | |
151 | case "$RESULT" in | |
152 | DONE) | |
153 | echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]" | |
154 | echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n" | |
155 | ;; | |
156 | FAIL) | |
157 | echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]" | |
158 | echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n" | |
159 | ;; | |
160 | SKIP) | |
161 | echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]" | |
162 | echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n" | |
163 | ;; | |
164 | esac | |
165 | ;; | |
166 | esac | |
167 | } # End of beautify() | |
168 | ||
169 | ||
170 | get_pkg_ver() | |
171 | { | |
172 | PKG_VER=`grep ^VER $1 | awk '{print $3}'` | |
173 | ||
174 | if [ -z $PKG_VER ]; then | |
175 | PKG_VER=`grep "Exp " $1 | awk '{print $4}'` | |
176 | fi | |
177 | ||
178 | if [ ${#PKG_VER} -gt $VER_WIDTH ]; then | |
179 | # If a package version number is greater than $VER_WIDTH, we keep the first 4 characters | |
180 | # and replace enough characters to fit the resulting string on the screen. We'll replace | |
181 | # the extra character with .. (two dots). That's why the "+ 2" in the formula below. | |
182 | # Example: if we have a 21-long version number that we want to fit into a 10-long space, | |
183 | # we have to remove 11 characters. But if we replace 11 characters with 2 characters, we'll | |
184 | # end up with a 12-character long string. That's why we replace 12 characters with .. | |
185 | REMOVE=`expr substr "$PKG_VER" 4 $[ ${#PKG_VER} - $VER_WIDTH + 2 ]` | |
186 | PKG_VER=`echo ${PKG_VER/$REMOVE/..}` | |
187 | fi | |
188 | ||
189 | echo "$PKG_VER" | |
190 | } # End of get_pkg_ver() | |
191 | ||
192 | if [ 'x86_64' = $MACHINE -o 'i686' = $MACHINE -o 'i586' = $MACHINE ]; then | |
193 | echo "`date -u '+%b %e %T'`: Machine is iX86 (or equivalent)" >> $LOGFILE | |
194 | MACHINE=i586 | |
195 | BUILDTARGET=i586-pc-linux-gnu | |
9b0ff0a0 | 196 | CFLAGS="-O2 -march=i586 -pipe -fomit-frame-pointer" |
b4b6bcdb | 197 | CXXFLAGS="-O2 -march=i586 -pipe -fomit-frame-pointer" |
15679d9f MT |
198 | C2FLAGS="-O2 -march=i586 -mtune=i586 -pipe -fomit-frame-pointer" |
199 | CXX2FLAGS="-O2 -march=i586 -mtune=i586 -pipe -fomit-frame-pointer" | |
200 | else | |
201 | echo "`date -u '+%b %e %T'`: Can't determine your architecture - $MACHINE" >> $LOGFILE | |
202 | exit 1 | |
203 | fi | |
204 | ||
205 | # Define immediately | |
206 | stdumount() { | |
b4b6bcdb MT |
207 | umount $BASEDIR/build/sys 2>/dev/null; |
208 | umount $BASEDIR/build/dev/shm 2>/dev/null; | |
15679d9f | 209 | umount $BASEDIR/build/dev/pts 2>/dev/null; |
b4b6bcdb | 210 | umount $BASEDIR/build/dev 2>/dev/null; |
15679d9f MT |
211 | umount $BASEDIR/build/proc 2>/dev/null; |
212 | umount $BASEDIR/build/install/mnt 2>/dev/null; | |
213 | umount $BASEDIR/build/usr/src/cache 2>/dev/null; | |
214 | umount $BASEDIR/build/usr/src/ccache 2>/dev/null; | |
215 | umount $BASEDIR/build/usr/src/config 2>/dev/null; | |
216 | umount $BASEDIR/build/usr/src/doc 2>/dev/null; | |
217 | umount $BASEDIR/build/usr/src/html 2>/dev/null; | |
218 | umount $BASEDIR/build/usr/src/langs 2>/dev/null; | |
219 | umount $BASEDIR/build/usr/src/lfs 2>/dev/null; | |
220 | umount $BASEDIR/build/usr/src/log 2>/dev/null; | |
221 | umount $BASEDIR/build/usr/src/src 2>/dev/null; | |
222 | } | |
223 | ||
224 | exiterror() { | |
225 | stdumount | |
226 | for i in `seq 0 7`; do | |
227 | if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then | |
228 | losetup -d /dev/loop${i} 2>/dev/null | |
229 | fi; | |
230 | done | |
231 | echo -e "\nERROR: $*" | |
232 | echo " Check $LOGFILE for errors if applicable" | |
233 | exit 1 | |
234 | } | |
235 | ||
236 | entershell() { | |
237 | if [ ! -e $BASEDIR/build/usr/src/lfs/ ]; then | |
238 | exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/" | |
239 | fi | |
240 | echo "Entering to a shell inside LFS chroot, go out with exit" | |
241 | chroot $LFS /tools/bin/env -i HOME=/root TERM=$TERM PS1='\u:\w\$ ' \ | |
242 | PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \ | |
243 | VERSION=$VERSION CONFIG_ROOT=$CONFIG_ROOT \ | |
244 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
245 | CFLAGS="$CF2LAGS" CXXFLAGS="$CXX2FLAGS" \ | |
246 | CCACHE_DIR=/usr/src/ccache \ | |
247 | CCACHE_HASHDIR=1 \ | |
248 | KVER=$KVER \ | |
249 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ | |
250 | KGCC="ccache /usr/bin/gcc" \ | |
251 | /tools/bin/bash | |
252 | if [ $? -ne 0 ]; then | |
253 | beautify message FAIL | |
254 | exiterror "chroot error" | |
255 | else | |
256 | stdumount | |
257 | fi | |
258 | } | |
259 | ||
260 | ############################################################################ | |
261 | # # | |
262 | # Necessary shell functions # | |
263 | # # | |
264 | ############################################################################ | |
265 | # | |
266 | # Common checking before entering the chroot and compilling | |
267 | # | |
268 | # Return:0 caller can continue | |
269 | # :1 skip (nothing to do) | |
270 | # or fail if no script file found | |
271 | # | |
272 | lfsmakecommoncheck() | |
273 | { | |
274 | ||
275 | # Script present? | |
276 | if [ ! -f $BASEDIR/lfs/$1 ]; then | |
277 | exiterror "No such file or directory: $BASEDIR/$1" | |
278 | fi | |
279 | ||
280 | local PKG_VER=`get_pkg_ver $BASEDIR/lfs/$1` | |
281 | beautify make_pkg "$PKG_VER $*" | |
282 | ||
283 | # Script slipped? | |
284 | local i | |
285 | for i in $SKIP_PACKAGE_LIST | |
286 | do | |
287 | if [ "$i" == "$1" ]; then | |
288 | beautify result SKIP | |
289 | return 1; | |
290 | fi | |
291 | done | |
292 | ||
293 | echo -ne "`date -u '+%b %e %T'`: Building $* " >> $LOGFILE | |
294 | ||
295 | cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download >> $LOGFILE 2>&1 | |
296 | if [ $? -ne 0 ]; then | |
297 | exiterror "Download error in $1" | |
298 | fi | |
299 | ||
300 | cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t md5sum" md5 >> $LOGFILE 2>&1 | |
301 | if [ $? -ne 0 ]; then | |
302 | exiterror "md5sum error in $1, check file in cache or signature" | |
303 | fi | |
304 | ||
305 | return 0 # pass all! | |
306 | } # End of lfsmakecommoncheck() | |
307 | ||
308 | lfsmake1() { | |
309 | lfsmakecommoncheck $* | |
310 | [ $? == 1 ] && return 0 | |
311 | ||
312 | local PKG_TIME_START=`date +%s` | |
313 | ||
314 | cd $BASEDIR/lfs && make -f $* BUILDTARGET=$BUILDTARGET \ | |
315 | MACHINE=$MACHINE \ | |
316 | LFS_BASEDIR=$BASEDIR \ | |
317 | ROOT=$LFS \ | |
318 | KVER=$KVER \ | |
319 | MAKETUNING=$MAKETUNING \ | |
320 | install >> $LOGFILE 2>&1 | |
321 | local COMPILE_SUCCESS=$? | |
322 | local PKG_TIME_END=`date +%s` | |
323 | ||
324 | if [ $COMPILE_SUCCESS -ne 0 ]; then | |
325 | beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] | |
326 | exiterror "Building $*"; | |
327 | else | |
328 | beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] | |
329 | fi | |
330 | ||
331 | return 0 | |
332 | } | |
333 | ||
334 | lfsmake2() { | |
335 | lfsmakecommoncheck $* | |
336 | [ $? == 1 ] && return 0 | |
337 | ||
338 | local PKG_TIME_START=`date +%s` | |
339 | chroot $LFS /tools/bin/env -i HOME=/root \ | |
340 | TERM=$TERM PS1='\u:\w\$ ' \ | |
341 | PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \ | |
342 | VERSION=$VERSION \ | |
343 | CONFIG_ROOT=$CONFIG_ROOT \ | |
344 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
345 | CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \ | |
346 | CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \ | |
347 | KVER=$KVER MAKETUNING=$MAKETUNING \ | |
348 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ | |
c8ead4a5 | 349 | IPFVER="$IPFVER" \ |
15679d9f MT |
350 | /tools/bin/bash -x -c "cd /usr/src/lfs && \ |
351 | make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1 | |
352 | local COMPILE_SUCCESS=$? | |
353 | local PKG_TIME_END=`date +%s` | |
354 | ||
355 | if [ $COMPILE_SUCCESS -ne 0 ]; then | |
356 | beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] | |
357 | exiterror "Building $*"; | |
358 | else | |
359 | beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] | |
360 | fi | |
361 | ||
362 | return 0 | |
363 | } | |
364 | ||
365 | ipfiremake() { | |
366 | lfsmakecommoncheck $* | |
367 | [ $? == 1 ] && return 0 | |
368 | ||
369 | local PKG_TIME_START=`date +%s` | |
370 | chroot $LFS /tools/bin/env -i HOME=/root \ | |
371 | TERM=$TERM PS1='\u:\w\$ ' \ | |
372 | PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \ | |
373 | VERSION=$VERSION \ | |
374 | CONFIG_ROOT=$CONFIG_ROOT \ | |
375 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
376 | CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \ | |
377 | CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \ | |
378 | KVER=$KVER MAKETUNING=$MAKETUNING \ | |
379 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ | |
c8ead4a5 | 380 | IPFVER="$IPFVER" \ |
15679d9f MT |
381 | /bin/bash -x -c "cd /usr/src/lfs && \ |
382 | make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1 | |
383 | ||
384 | local COMPILE_SUCCESS=$? | |
385 | local PKG_TIME_END=`date +%s` | |
386 | ||
387 | if [ $COMPILE_SUCCESS -ne 0 ]; then | |
388 | beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] | |
389 | exiterror "Building $*"; | |
390 | else | |
391 | beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] | |
392 | fi | |
393 | return 0 | |
394 | } | |
395 | ||
396 | ipfiredist() { | |
397 | if [ -f $BASEDIR/build/usr/src/lfs/$1 ]; then | |
398 | echo "`date -u '+%b %e %T'`: Packaging $1" | tee -a $LOGFILE | |
399 | chroot $LFS /tools/bin/env -i HOME=/root \ | |
400 | TERM=$TERM PS1='\u:\w\$ ' \ | |
401 | PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \ | |
402 | VERSION=$VERSION \ | |
403 | CONFIG_ROOT=$CONFIG_ROOT \ | |
404 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
405 | CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \ | |
406 | CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \ | |
c8ead4a5 | 407 | KVER=$KVER IPFVER="$IPFVER" \ |
15679d9f MT |
408 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ |
409 | /bin/bash -x -c "cd /usr/src/lfs && \ | |
410 | make -f $1 LFS_BASEDIR=/usr/src dist" >>$LOGFILE 2>&1 | |
411 | if [ $? -ne 0 ]; then | |
412 | exiterror "Packaging $1" | |
413 | fi | |
414 | else | |
415 | exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/$1" | |
416 | fi | |
417 | return 0 | |
418 | } | |
419 | ||
420 | installmake() { | |
41921bd9 MT |
421 | lfsmakecommoncheck $* |
422 | [ $? == 1 ] && return 0 | |
423 | ||
424 | local PKG_TIME_START=`date +%s` | |
15679d9f MT |
425 | chroot $LFS /tools/bin/env -i HOME=/root \ |
426 | TERM=$TERM PS1='\u:\w\$ ' \ | |
4da401bc | 427 | PATH=/opt/i586-uClibc/i586-linux-uclibc/bin:/opt/i586-uClibc/bin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \ |
15679d9f MT |
428 | VERSION=$VERSION \ |
429 | CONFIG_ROOT=$CONFIG_ROOT \ | |
430 | LFS_PASS="install" \ | |
431 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
432 | CFLAGS="-Os" CXXFLAGS="-Os" \ | |
433 | CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \ | |
c8ead4a5 | 434 | KVER=$KVER IPFVER="$IPFVER" \ |
15679d9f MT |
435 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ |
436 | /bin/bash -x -c "cd /usr/src/lfs && \ | |
437 | make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1 | |
41921bd9 MT |
438 | |
439 | local COMPILE_SUCCESS=$? | |
440 | local PKG_TIME_END=`date +%s` | |
441 | ||
442 | if [ $COMPILE_SUCCESS -ne 0 ]; then | |
443 | beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] | |
444 | exiterror "Building $*"; | |
15679d9f | 445 | else |
41921bd9 | 446 | beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] |
15679d9f MT |
447 | fi |
448 | return 0 | |
449 | } | |
450 | ||
451 | update_logs() { | |
452 | tar cfz log/ipfire-logs-`date +'%Y-%m-%d-%H:%M'`.tgz log/_build.* | |
453 | rm -f log/_build.* | |
454 | } | |
455 | ||
456 | batch_script() { | |
457 | echo -ne "### UPDATE LOGS" | |
458 | update_logs | |
459 | evaluate 1 | |
460 | ||
461 | if [ "$IPFIRE_REBUILD" -eq "0" ]; then | |
462 | echo -ne "### SAVING TIME" | |
463 | export IPFIRE_START_TIME=`date` | |
464 | evaluate 1 | |
465 | ||
466 | echo "### RUNNING SVN-UPDATE" | |
467 | $0 svn update | |
468 | evaluate 1 mail SVNUPDATE | |
469 | ||
470 | echo "### EXPORT SOURCES" | |
471 | $0 svn dist | |
472 | evaluate 1 mail SVNDIST | |
473 | ||
474 | echo "### RUNNING PREFETCH" | |
475 | $0 prefetch | grep -q "md5 difference" | |
476 | evaluate 1 mail PREFETCH | |
477 | fi | |
478 | ||
479 | echo "### RUNNING BUILD" | |
480 | $0 build | |
481 | evaluate 1 mail ERROR | |
482 | ||
483 | echo "### UPLOADING ISO" | |
484 | $0 upload iso | |
485 | evaluate 1 mail ISO | |
486 | ||
487 | echo -ne "### UPLOADING PAKS" | |
488 | $0 upload paks | |
489 | evaluate 1 mail PAKS | |
490 | ||
491 | echo -n "${BOLD}***SUCCESS!${NORMAL}" | |
492 | evaluate 0 mail SUCCESS | |
493 | exit 0 | |
494 | } | |
495 | ||
496 | watch_screen() { | |
497 | echo -e "${BOLD}Exit with Ctrl+A, Ctrl+D.${NORMAL}" | |
498 | sleep 0.5 | |
499 | screen -x ipfire | |
500 | } | |
501 | ||
502 | mail() { | |
503 | chmod 755 tools/sendEmail | |
504 | ATTACHMENT=/tmp/ipfire-build-logs-R$SVN_REVISION.tar.gz | |
505 | case "$1" in | |
506 | success) | |
507 | SUBJECT="SUCCESS: IPFIRE-BUILD R$SVN_REVISION on `hostname`" | |
508 | cat <<END > /tmp/ipfire_mail_body | |
509 | Building IPFire on `hostname` in Revision $SVN_REVISION was successfull! | |
510 | You can find the ISO on your ftp server. | |
511 | ||
512 | Statistics: | |
513 | ----------- | |
514 | Started: $IPFIRE_START_TIME | |
515 | Finished: `date` | |
516 | ||
517 | Best Regards | |
518 | Your IPFire-Build-Script | |
519 | ||
520 | END | |
521 | echo -ne "${BOLD}***Sending success message${NORMAL}" | |
522 | ;; | |
523 | *) | |
524 | SUBJECT="ERROR $1: IPFIRE-BUILD R$SVN_REVISION on `hostname`" | |
525 | cat <<END > /tmp/ipfire_mail_body | |
526 | When I was building IPFire on `hostname`, I have found an ERROR with name $1! | |
527 | Here you can see the logs and detect the reason for this error. | |
528 | ||
529 | Best Regards | |
530 | Your IPFire-Build-Script | |
531 | ||
532 | ||
533 | Here is a summary... The full logs are in the attachment. | |
534 | --------------------------------------------------------- | |
535 | ||
536 | `tail log/_*` | |
537 | END | |
538 | echo -ne "${BOLD}***Sending error message${NORMAL}" | |
539 | ;; | |
540 | esac | |
541 | tar cfz $ATTACHMENT log/_build* | |
542 | cat /tmp/ipfire_mail_body | tools/sendEmail -q \ | |
543 | -f $IPFIRE_MAIL_FROM \ | |
544 | -t $IPFIRE_MAIL_REPORT \ | |
545 | -u $SUBJECT \ | |
546 | -s $IPFIRE_MAIL_SERVER:25 \ | |
547 | -xu $IPFIRE_MAIL_USER \ | |
548 | -xp $IPFIRE_MAIL_PASS \ | |
549 | -l log/_build.mail.log \ | |
550 | -a $ATTACHMENT # -v | |
551 | if [ "$?" -eq "0" ]; then | |
552 | beautify message DONE | |
553 | else | |
554 | beautify message FAIL | |
555 | fi | |
556 | rm -f /tmp/ipfire_mail_body $ATTACHMENT | |
557 | } | |
558 | ||
559 | make_config() { | |
560 | echo -e "This is for creating your configuration..." | |
561 | echo -e "We will need some input:" | |
562 | echo -e "" | |
563 | echo -n "FTP-DOMAIN FOR THE ISO: " | |
564 | read IPFIRE_FTP_URL_EXT | |
565 | echo -n "PATH FOR $IPFIRE_FTP_URL_EXT: " | |
566 | read IPFIRE_FTP_PATH_EXT | |
567 | echo -n "USERNAME FOR $IPFIRE_FTP_URL_EXT: " | |
568 | read IPFIRE_FTP_USER_EXT | |
569 | echo -n "PASSWORD FOR $IPFIRE_FTP_URL_EXT: " | |
570 | read -s IPFIRE_FTP_PASS_EXT | |
571 | echo "" | |
572 | echo "(You can leave this empty if the cache-server is the same as your iso-server.)" | |
573 | echo -n "FTP-DOMAIN FOR THE CACHE: " | |
574 | read IPFIRE_FTP_URL_INT | |
575 | echo -n "PATH FOR $IPFIRE_FTP_URL_INT: " | |
576 | read IPFIRE_FTP_PATH_INT | |
577 | if [ $IPFIRE_FTP_URL_INT ]; then | |
578 | echo -n "USERNAME FOR $IPFIRE_FTP_URL_INT: " | |
579 | read IPFIRE_FTP_USER_INT | |
580 | echo -n "PASSWORD FOR $IPFIRE_FTP_URL_INT: " | |
581 | read -s IPFIRE_FTP_PASS_INT | |
582 | else | |
583 | IPFIRE_FTP_URL_INT=$IPFIRE_FTP_URL_EXT | |
584 | IPFIRE_FTP_USER_INT=$IPFIRE_FTP_USER_EXT | |
585 | IPFIRE_FTP_PASS_INT=$IPFIRE_FTP_PASS_EXT | |
586 | echo "USERNAME FOR $IPFIRE_FTP_URL_INT: $IPFIRE_FTP_USER_INT" | |
587 | echo "PASSWORD FOR $IPFIRE_FTP_URL_INT: !HIDDEN!" | |
588 | fi | |
589 | echo "" | |
590 | echo "(You can leave this empty if the pak-server is the same as your iso-server.)" | |
591 | echo -n "FTP-DOMAIN FOR THE PAKS: " | |
592 | read IPFIRE_FTP_URL_PAK | |
593 | echo -n "PATH FOR $IPFIRE_FTP_URL_PAK: " | |
594 | read IPFIRE_FTP_PATH_PAK | |
595 | if [ $IPFIRE_FTP_URL_PAK ]; then | |
596 | echo -n "USERNAME FOR $IPFIRE_FTP_URL_PAK: " | |
597 | read IPFIRE_FTP_USER_PAK | |
598 | echo -n "PASSWORD FOR $IPFIRE_FTP_URL_PAK: " | |
599 | read -s IPFIRE_FTP_PASS_PAK | |
600 | else | |
601 | IPFIRE_FTP_URL_PAK=$IPFIRE_FTP_URL_EXT | |
602 | IPFIRE_FTP_USER_PAK=$IPFIRE_FTP_USER_EXT | |
603 | IPFIRE_FTP_PASS_PAK=$IPFIRE_FTP_PASS_EXT | |
604 | echo "USERNAME FOR $IPFIRE_FTP_URL_PAK: $IPFIRE_FTP_USER_PAK" | |
605 | echo "PASSWORD FOR $IPFIRE_FTP_URL_PAK: !HIDDEN!" | |
606 | fi | |
607 | echo "" | |
608 | echo -e "ONE OR MORE EMAIL ADDRESS(ES) TO WHICH THE REPORTS WILL BE SENT" | |
609 | echo -e "(seperated by comma)" | |
610 | read IPFIRE_MAIL_REPORT | |
611 | echo -n "EMAIL FROM: " | |
612 | read IPFIRE_MAIL_FROM | |
613 | echo -n "EMAIL SERVER: " | |
614 | read IPFIRE_MAIL_SERVER | |
615 | echo -n "LOGIN TO MAIL SERVER: " | |
616 | read IPFIRE_MAIL_USER | |
617 | echo -n "MAIL PASSWORD: " | |
618 | read -s IPFIRE_MAIL_PASS | |
619 | echo -n "Saving..." | |
620 | cat <<END > .config | |
621 | ### ISO server | |
622 | IPFIRE_FTP_URL_EXT=$IPFIRE_FTP_URL_EXT | |
623 | IPFIRE_FTP_PATH_EXT=$IPFIRE_FTP_PATH_EXT | |
624 | IPFIRE_FTP_USER_EXT=$IPFIRE_FTP_USER_EXT | |
625 | IPFIRE_FTP_PASS_EXT=$IPFIRE_FTP_PASS_EXT | |
626 | ### cache server | |
627 | IPFIRE_FTP_URL_INT=$IPFIRE_FTP_URL_INT | |
628 | IPFIRE_FTP_PATH_INT=$IPFIRE_FTP_PATH_INT | |
629 | IPFIRE_FTP_USER_INT=$IPFIRE_FTP_USER_INT | |
630 | IPFIRE_FTP_PASS_INT=$IPFIRE_FTP_PASS_INT | |
631 | ### paks server | |
632 | IPFIRE_FTP_URL_PAK=$IPFIRE_FTP_URL_PAK | |
633 | IPFIRE_FTP_PATH_PAK=$IPFIRE_FTP_PATH_PAK | |
634 | IPFIRE_FTP_USER_PAK=$IPFIRE_FTP_USER_PAK | |
635 | IPFIRE_FTP_PASS_PAK=$IPFIRE_FTP_PASS_PAK | |
636 | ### mail reports | |
637 | IPFIRE_MAIL_REPORT=$IPFIRE_MAIL_REPORT | |
638 | IPFIRE_MAIL_FROM=$IPFIRE_MAIL_FROM | |
639 | IPFIRE_MAIL_SERVER=$IPFIRE_MAIL_SERVER | |
640 | IPFIRE_MAIL_USER=$IPFIRE_MAIL_USER | |
641 | IPFIRE_MAIL_PASS=$IPFIRE_MAIL_PASS | |
642 | END | |
643 | beautify message DONE | |
33634aa8 MT |
644 | } |
645 | ||
646 | compile_tftpd() { | |
647 | mkdir $BASEDIR/tmp | |
648 | tar xvfz $BASEDIR/cache/tftp-hpa-0.42.tar.gz -C $BASEDIR/tmp | |
649 | cd $BASEDIR/tmp/tftp-hpa-0.42 | |
650 | ./configure --prefix=/ipfire/trunk/tools/ \ | |
651 | --sbindir=/ipfire/trunk/tools/ --disable-nls | |
652 | make | |
653 | install -c tftpd/tftpd $BASEDIR/tools/in.tftpd | |
654 | cd - | |
655 | rm -rf $BASEDIR/tmp/tftp-hpa-0.42 | |
656 | } | |
657 | ||
658 | start_tftpd() { | |
659 | if [ ! -e $BASEDIR/tools/in.tftpd ]; then | |
660 | compile_tftpd | |
661 | fi | |
662 | reload_tftpd | |
663 | if [ "$?" == "0" ]; then | |
664 | $BASEDIR/tools/in.tftpd -l -s $BASEDIR/tftpboot | |
665 | beautify message DONE | |
666 | else | |
667 | echo -en "You don not have a pxe boot image in your base directory.\nPlease compile first." | |
668 | beautify message FAIL | |
669 | exit 1 | |
670 | fi | |
671 | } | |
672 | ||
673 | stop_tftpd() { | |
674 | echo -n "Stopping TFTPD..." | |
675 | killall in.tftpd >/dev/null 2>&1 | |
676 | sleep 3 | |
677 | killall -9 in.tftp >/dev/null 2>&1 | |
678 | beautify message DONE | |
679 | } | |
680 | ||
681 | reload_tftpd() { | |
682 | if [ -e $BASEDIR/ipfire-$VERSION-pxe-$MACHINE.tgz ]; then | |
683 | mkdir -p $BASEDIR/tftpboot | |
d733119b | 684 | tar xfz $BASEDIR/ipfire-$VERSION-pxe-$MACHINE.tgz -C $BASEDIR/tftpboot |
33634aa8 MT |
685 | return 0 |
686 | fi | |
687 | return 1 | |
688 | } |