]>
Commit | Line | Data |
---|---|---|
15679d9f | 1 | #!/bin/bash |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007 Michael Tremer & Christian Schmidt # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ############################################################################### | |
15679d9f MT |
22 | # |
23 | # Beautifying variables & presentation & input output interface | |
24 | # | |
70df8302 | 25 | ############################################################################### |
15679d9f MT |
26 | |
27 | ## Screen Dimentions | |
28 | # Find current screen size | |
29 | if [ -z "${COLUMNS}" ]; then | |
30 | COLUMNS=$(stty size) | |
31 | COLUMNS=${COLUMNS##* } | |
32 | fi | |
33 | ||
34 | # When using remote connections, such as a serial port, stty size returns 0 | |
35 | if [ "${COLUMNS}" = "0" ]; then | |
36 | COLUMNS=80 | |
37 | fi | |
38 | ||
39 | ## Measurements for positioning result messages | |
40 | RESULT_WIDTH=4 | |
41 | TIME_WIDTH=8 | |
42 | OPT_WIDTH=6 | |
43 | VER_WIDTH=10 | |
44 | RESULT_COL=$((${COLUMNS} - $RESULT_WIDTH - 4)) | |
45 | TIME_COL=$((${RESULT_COL} - $TIME_WIDTH - 5)) | |
46 | OPT_COL=$((${TIME_COL} - $OPT_WIDTH - 5)) | |
47 | VER_COL=$((${OPT_COL} - $VER_WIDTH - 5)) | |
48 | ||
49 | ## Set Cursur Position Commands, used via echo -e | |
50 | SET_RESULT_COL="\\033[${RESULT_COL}G" | |
51 | SET_TIME_COL="\\033[${TIME_COL}G" | |
52 | SET_OPT_COL="\\033[${OPT_COL}G" | |
53 | SET_VER_COL="\\033[${VER_COL}G" | |
54 | ||
55 | # Define color for messages | |
56 | BOLD="\\033[1;39m" | |
57 | DONE="\\033[1;32m" | |
58 | SKIP="\\033[1;34m" | |
59 | WARN="\\033[1;35m" | |
60 | FAIL="\\033[1;31m" | |
61 | NORMAL="\\033[0;39m" | |
62 | ||
63 | evaluate() { | |
64 | if [ "$?" -eq "0" ]; then | |
65 | beautify message DONE | |
66 | else | |
67 | EXITCODE=$1 | |
68 | shift 1 | |
69 | beautify message FAIL | |
70 | $* | |
71 | if [ $EXITCODE -ne "0" ]; then | |
72 | exit $EXITCODE | |
73 | fi | |
74 | fi | |
75 | } | |
76 | ||
77 | position_cursor() | |
78 | { | |
79 | # ARG1=starting position on screen | |
80 | # ARG2=string to be printed | |
81 | # ARG3=offset, negative for left movement, positive for right movement, relative to ARG1 | |
82 | # For example if your starting position is column 50 and you want to print Hello three columns to the right | |
83 | # of your starting position, your call will look like this: | |
84 | # position_cursor 50 "Hello" 3 (you'll get the string Hello at position 53 (= 50 + 3) | |
85 | # If on the other hand you want your string "Hello" to end three columns to the left of position 50, | |
86 | # your call will look like this: | |
87 | # position_cursor 50 "Hello" -3 (you'll get the string Hello at position 42 (= 50 - 5 -3) | |
88 | # If you want to start printing at the exact starting location, use offset 0 | |
89 | ||
90 | START=$1 | |
91 | STRING=$2 | |
92 | OFFSET=$3 | |
93 | ||
94 | STRING_LENGTH=${#STRING} | |
95 | ||
96 | if [ ${OFFSET} -lt 0 ]; then | |
97 | COL=$((${START} + ${OFFSET} - ${STRING_LENGTH})) | |
98 | else | |
99 | COL=$((${START} + ${OFFSET})) | |
100 | fi | |
101 | ||
102 | SET_COL="\\033[${COL}G" | |
103 | ||
104 | echo $SET_COL | |
105 | } # End of position_cursor() | |
106 | ||
107 | ||
108 | beautify() | |
109 | { | |
110 | # Commands: build_stage, make_pkg, message, result | |
111 | case "$1" in | |
112 | message) | |
113 | case "$2" in | |
114 | DONE) | |
115 | echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n" | |
116 | ;; | |
117 | WARN) | |
118 | echo -ne "${WARN}${3}${NORMAL}${SET_RESULT_COL}[${WARN} WARN ${NORMAL}]\n" | |
119 | ;; | |
120 | FAIL) | |
121 | echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n" | |
122 | ;; | |
123 | SKIP) | |
124 | echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n" | |
125 | ;; | |
126 | esac | |
127 | ;; | |
0b59f25c | 128 | build_stage) |
15679d9f | 129 | MESSAGE=$2 |
0b59f25c MT |
130 | if [ "$STAGE_TIME_START" ]; then |
131 | LAST_STAGE_TIME=$[ `date +%s` - $STAGE_TIME_START ] | |
132 | fi | |
7ab7a9b4 | 133 | STAGE_TIME_START=`date +%s` |
0b59f25c MT |
134 | echo -ne "${BOLD}*** ${MESSAGE}${NORMAL}" |
135 | if [ "$LAST_STAGE_TIME" ]; then | |
136 | echo -ne "${DONE} (Last stage took $LAST_STAGE_TIME secs)${NORMAL}" | |
137 | fi | |
138 | echo -ne "${BOLD}${SET_VER_COL} version${SET_OPT_COL} options${SET_TIME_COL} time (sec)${SET_RESULT_COL} status${NORMAL}\n" | |
7ab7a9b4 MT |
139 | ;; |
140 | build_start) | |
141 | BUILD_TIME_START=`date +%s` | |
142 | ;; | |
143 | build_end) | |
144 | BUILD_TIME_END=`date +%s` | |
070fb401 CS |
145 | seconds=$[ $BUILD_TIME_END - $BUILD_TIME_START ] |
146 | hours=$((seconds / 3600)) | |
147 | seconds=$((seconds % 3600)) | |
148 | minutes=$((seconds / 60)) | |
149 | seconds=$((seconds % 60)) | |
150 | ||
151 | echo -ne "${DONE}***Build is finished now and took $hours hour(s) $minutes minute(s) $seconds second(s)!${NORMAL}\n" | |
7ab7a9b4 | 152 | ;; |
15679d9f MT |
153 | make_pkg) |
154 | echo "$2" | while read PKG_VER PROGRAM OPTIONS | |
155 | do | |
156 | SET_VER_COL_REAL=`position_cursor $OPT_COL $PKG_VER -3` | |
157 | ||
158 | if [ "$OPTIONS" == "" ]; then | |
159 | echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}" | |
160 | echo -ne "${NORMAL} ]${SET_RESULT_COL}" | |
161 | else | |
162 | echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}" | |
163 | echo -ne "${NORMAL} ]${SET_OPT_COL}[ ${BOLD}${OPTIONS}" | |
164 | echo -ne "${NORMAL} ]${SET_RESULT_COL}" | |
165 | fi | |
166 | done | |
167 | ;; | |
168 | result) | |
169 | RESULT=$2 | |
170 | ||
171 | if [ ! $3 ]; then | |
172 | PKG_TIME=0 | |
173 | else | |
174 | PKG_TIME=$3 | |
175 | fi | |
176 | ||
177 | SET_TIME_COL_REAL=`position_cursor $RESULT_COL $PKG_TIME -3` | |
178 | case "$RESULT" in | |
179 | DONE) | |
180 | echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]" | |
181 | echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n" | |
182 | ;; | |
183 | FAIL) | |
184 | echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]" | |
185 | echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n" | |
186 | ;; | |
187 | SKIP) | |
188 | echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]" | |
189 | echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n" | |
190 | ;; | |
191 | esac | |
192 | ;; | |
193 | esac | |
194 | } # End of beautify() | |
195 | ||
196 | ||
197 | get_pkg_ver() | |
198 | { | |
199 | PKG_VER=`grep ^VER $1 | awk '{print $3}'` | |
200 | ||
201 | if [ -z $PKG_VER ]; then | |
202 | PKG_VER=`grep "Exp " $1 | awk '{print $4}'` | |
203 | fi | |
204 | ||
205 | if [ ${#PKG_VER} -gt $VER_WIDTH ]; then | |
206 | # If a package version number is greater than $VER_WIDTH, we keep the first 4 characters | |
207 | # and replace enough characters to fit the resulting string on the screen. We'll replace | |
208 | # the extra character with .. (two dots). That's why the "+ 2" in the formula below. | |
209 | # Example: if we have a 21-long version number that we want to fit into a 10-long space, | |
210 | # we have to remove 11 characters. But if we replace 11 characters with 2 characters, we'll | |
211 | # end up with a 12-character long string. That's why we replace 12 characters with .. | |
212 | REMOVE=`expr substr "$PKG_VER" 4 $[ ${#PKG_VER} - $VER_WIDTH + 2 ]` | |
213 | PKG_VER=`echo ${PKG_VER/$REMOVE/..}` | |
214 | fi | |
215 | ||
216 | echo "$PKG_VER" | |
217 | } # End of get_pkg_ver() | |
218 | ||
219 | if [ 'x86_64' = $MACHINE -o 'i686' = $MACHINE -o 'i586' = $MACHINE ]; then | |
220 | echo "`date -u '+%b %e %T'`: Machine is iX86 (or equivalent)" >> $LOGFILE | |
221 | MACHINE=i586 | |
222 | BUILDTARGET=i586-pc-linux-gnu | |
9b0ff0a0 | 223 | CFLAGS="-O2 -march=i586 -pipe -fomit-frame-pointer" |
b4b6bcdb | 224 | CXXFLAGS="-O2 -march=i586 -pipe -fomit-frame-pointer" |
15679d9f MT |
225 | C2FLAGS="-O2 -march=i586 -mtune=i586 -pipe -fomit-frame-pointer" |
226 | CXX2FLAGS="-O2 -march=i586 -mtune=i586 -pipe -fomit-frame-pointer" | |
227 | else | |
228 | echo "`date -u '+%b %e %T'`: Can't determine your architecture - $MACHINE" >> $LOGFILE | |
229 | exit 1 | |
230 | fi | |
231 | ||
232 | # Define immediately | |
233 | stdumount() { | |
b4b6bcdb MT |
234 | umount $BASEDIR/build/sys 2>/dev/null; |
235 | umount $BASEDIR/build/dev/shm 2>/dev/null; | |
15679d9f | 236 | umount $BASEDIR/build/dev/pts 2>/dev/null; |
b4b6bcdb | 237 | umount $BASEDIR/build/dev 2>/dev/null; |
15679d9f MT |
238 | umount $BASEDIR/build/proc 2>/dev/null; |
239 | umount $BASEDIR/build/install/mnt 2>/dev/null; | |
240 | umount $BASEDIR/build/usr/src/cache 2>/dev/null; | |
241 | umount $BASEDIR/build/usr/src/ccache 2>/dev/null; | |
242 | umount $BASEDIR/build/usr/src/config 2>/dev/null; | |
243 | umount $BASEDIR/build/usr/src/doc 2>/dev/null; | |
244 | umount $BASEDIR/build/usr/src/html 2>/dev/null; | |
245 | umount $BASEDIR/build/usr/src/langs 2>/dev/null; | |
246 | umount $BASEDIR/build/usr/src/lfs 2>/dev/null; | |
247 | umount $BASEDIR/build/usr/src/log 2>/dev/null; | |
248 | umount $BASEDIR/build/usr/src/src 2>/dev/null; | |
249 | } | |
250 | ||
251 | exiterror() { | |
252 | stdumount | |
253 | for i in `seq 0 7`; do | |
254 | if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then | |
255 | losetup -d /dev/loop${i} 2>/dev/null | |
256 | fi; | |
257 | done | |
258 | echo -e "\nERROR: $*" | |
259 | echo " Check $LOGFILE for errors if applicable" | |
260 | exit 1 | |
261 | } | |
262 | ||
263 | entershell() { | |
264 | if [ ! -e $BASEDIR/build/usr/src/lfs/ ]; then | |
265 | exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/" | |
266 | fi | |
267 | echo "Entering to a shell inside LFS chroot, go out with exit" | |
268 | chroot $LFS /tools/bin/env -i HOME=/root TERM=$TERM PS1='\u:\w\$ ' \ | |
269 | PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \ | |
270 | VERSION=$VERSION CONFIG_ROOT=$CONFIG_ROOT \ | |
271 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
272 | CFLAGS="$CF2LAGS" CXXFLAGS="$CXX2FLAGS" \ | |
273 | CCACHE_DIR=/usr/src/ccache \ | |
274 | CCACHE_HASHDIR=1 \ | |
275 | KVER=$KVER \ | |
276 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ | |
277 | KGCC="ccache /usr/bin/gcc" \ | |
278 | /tools/bin/bash | |
279 | if [ $? -ne 0 ]; then | |
280 | beautify message FAIL | |
281 | exiterror "chroot error" | |
282 | else | |
283 | stdumount | |
284 | fi | |
285 | } | |
286 | ||
287 | ############################################################################ | |
288 | # # | |
289 | # Necessary shell functions # | |
290 | # # | |
291 | ############################################################################ | |
292 | # | |
293 | # Common checking before entering the chroot and compilling | |
294 | # | |
295 | # Return:0 caller can continue | |
296 | # :1 skip (nothing to do) | |
297 | # or fail if no script file found | |
298 | # | |
299 | lfsmakecommoncheck() | |
300 | { | |
15679d9f MT |
301 | # Script present? |
302 | if [ ! -f $BASEDIR/lfs/$1 ]; then | |
303 | exiterror "No such file or directory: $BASEDIR/$1" | |
304 | fi | |
305 | ||
306 | local PKG_VER=`get_pkg_ver $BASEDIR/lfs/$1` | |
307 | beautify make_pkg "$PKG_VER $*" | |
308 | ||
309 | # Script slipped? | |
310 | local i | |
311 | for i in $SKIP_PACKAGE_LIST | |
312 | do | |
a50d04ab | 313 | if [ "$i" == "$1" ]; then |
15679d9f MT |
314 | beautify result SKIP |
315 | return 1; | |
316 | fi | |
317 | done | |
318 | ||
319 | echo -ne "`date -u '+%b %e %T'`: Building $* " >> $LOGFILE | |
320 | ||
321 | cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download >> $LOGFILE 2>&1 | |
322 | if [ $? -ne 0 ]; then | |
323 | exiterror "Download error in $1" | |
324 | fi | |
325 | ||
326 | cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t md5sum" md5 >> $LOGFILE 2>&1 | |
327 | if [ $? -ne 0 ]; then | |
328 | exiterror "md5sum error in $1, check file in cache or signature" | |
329 | fi | |
330 | ||
331 | return 0 # pass all! | |
332 | } # End of lfsmakecommoncheck() | |
333 | ||
334 | lfsmake1() { | |
335 | lfsmakecommoncheck $* | |
336 | [ $? == 1 ] && return 0 | |
337 | ||
338 | local PKG_TIME_START=`date +%s` | |
339 | ||
340 | cd $BASEDIR/lfs && make -f $* BUILDTARGET=$BUILDTARGET \ | |
341 | MACHINE=$MACHINE \ | |
342 | LFS_BASEDIR=$BASEDIR \ | |
343 | ROOT=$LFS \ | |
344 | KVER=$KVER \ | |
345 | MAKETUNING=$MAKETUNING \ | |
346 | install >> $LOGFILE 2>&1 | |
347 | local COMPILE_SUCCESS=$? | |
348 | local PKG_TIME_END=`date +%s` | |
349 | ||
350 | if [ $COMPILE_SUCCESS -ne 0 ]; then | |
351 | beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] | |
352 | exiterror "Building $*"; | |
353 | else | |
354 | beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] | |
355 | fi | |
356 | ||
357 | return 0 | |
358 | } | |
359 | ||
360 | lfsmake2() { | |
361 | lfsmakecommoncheck $* | |
362 | [ $? == 1 ] && return 0 | |
363 | ||
364 | local PKG_TIME_START=`date +%s` | |
365 | chroot $LFS /tools/bin/env -i HOME=/root \ | |
366 | TERM=$TERM PS1='\u:\w\$ ' \ | |
367 | PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \ | |
368 | VERSION=$VERSION \ | |
369 | CONFIG_ROOT=$CONFIG_ROOT \ | |
370 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
371 | CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \ | |
372 | CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \ | |
373 | KVER=$KVER MAKETUNING=$MAKETUNING \ | |
374 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ | |
c8ead4a5 | 375 | IPFVER="$IPFVER" \ |
15679d9f MT |
376 | /tools/bin/bash -x -c "cd /usr/src/lfs && \ |
377 | make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1 | |
378 | local COMPILE_SUCCESS=$? | |
379 | local PKG_TIME_END=`date +%s` | |
380 | ||
381 | if [ $COMPILE_SUCCESS -ne 0 ]; then | |
382 | beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] | |
383 | exiterror "Building $*"; | |
384 | else | |
385 | beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] | |
386 | fi | |
387 | ||
388 | return 0 | |
389 | } | |
390 | ||
391 | ipfiremake() { | |
392 | lfsmakecommoncheck $* | |
393 | [ $? == 1 ] && return 0 | |
394 | ||
395 | local PKG_TIME_START=`date +%s` | |
396 | chroot $LFS /tools/bin/env -i HOME=/root \ | |
397 | TERM=$TERM PS1='\u:\w\$ ' \ | |
398 | PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \ | |
399 | VERSION=$VERSION \ | |
400 | CONFIG_ROOT=$CONFIG_ROOT \ | |
401 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
402 | CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \ | |
403 | CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \ | |
404 | KVER=$KVER MAKETUNING=$MAKETUNING \ | |
405 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ | |
c8ead4a5 | 406 | IPFVER="$IPFVER" \ |
15679d9f MT |
407 | /bin/bash -x -c "cd /usr/src/lfs && \ |
408 | make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1 | |
409 | ||
410 | local COMPILE_SUCCESS=$? | |
411 | local PKG_TIME_END=`date +%s` | |
412 | ||
413 | if [ $COMPILE_SUCCESS -ne 0 ]; then | |
414 | beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] | |
415 | exiterror "Building $*"; | |
416 | else | |
417 | beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] | |
418 | fi | |
419 | return 0 | |
420 | } | |
421 | ||
422 | ipfiredist() { | |
0d909a4a MT |
423 | lfsmakecommoncheck $* |
424 | [ $? == 1 ] && return 0 | |
425 | ||
426 | local PKG_TIME_START=`date +%s` | |
427 | chroot $LFS /tools/bin/env -i HOME=/root \ | |
428 | TERM=$TERM PS1='\u:\w\$ ' \ | |
429 | PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \ | |
430 | VERSION=$VERSION \ | |
431 | CONFIG_ROOT=$CONFIG_ROOT \ | |
432 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
433 | CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \ | |
434 | CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \ | |
435 | KVER=$KVER IPFVER="$IPFVER" \ | |
436 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ | |
437 | /bin/bash -x -c "cd /usr/src/lfs && \ | |
438 | make -f $1 LFS_BASEDIR=/usr/src dist" >>$LOGFILE 2>&1 | |
439 | ||
440 | local COMPILE_SUCCESS=$? | |
441 | local PKG_TIME_END=`date +%s` | |
442 | ||
443 | if [ $COMPILE_SUCCESS -ne 0 ]; then | |
444 | beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] | |
445 | exiterror "Packaging $*"; | |
15679d9f | 446 | else |
0d909a4a | 447 | beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] |
15679d9f MT |
448 | fi |
449 | return 0 | |
450 | } | |
451 | ||
452 | installmake() { | |
41921bd9 MT |
453 | lfsmakecommoncheck $* |
454 | [ $? == 1 ] && return 0 | |
455 | ||
456 | local PKG_TIME_START=`date +%s` | |
15679d9f MT |
457 | chroot $LFS /tools/bin/env -i HOME=/root \ |
458 | TERM=$TERM PS1='\u:\w\$ ' \ | |
4da401bc | 459 | PATH=/opt/i586-uClibc/i586-linux-uclibc/bin:/opt/i586-uClibc/bin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \ |
15679d9f MT |
460 | VERSION=$VERSION \ |
461 | CONFIG_ROOT=$CONFIG_ROOT \ | |
462 | LFS_PASS="install" \ | |
463 | NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \ | |
464 | CFLAGS="-Os" CXXFLAGS="-Os" \ | |
465 | CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \ | |
c8ead4a5 | 466 | KVER=$KVER IPFVER="$IPFVER" \ |
15679d9f MT |
467 | BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \ |
468 | /bin/bash -x -c "cd /usr/src/lfs && \ | |
469 | make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1 | |
41921bd9 MT |
470 | |
471 | local COMPILE_SUCCESS=$? | |
472 | local PKG_TIME_END=`date +%s` | |
473 | ||
474 | if [ $COMPILE_SUCCESS -ne 0 ]; then | |
475 | beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] | |
476 | exiterror "Building $*"; | |
15679d9f | 477 | else |
41921bd9 | 478 | beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] |
15679d9f MT |
479 | fi |
480 | return 0 | |
481 | } | |
482 | ||
483 | update_logs() { | |
484 | tar cfz log/ipfire-logs-`date +'%Y-%m-%d-%H:%M'`.tgz log/_build.* | |
485 | rm -f log/_build.* | |
486 | } | |
487 | ||
488 | batch_script() { | |
a50d04ab | 489 | echo -ne "${BOLD}***This is our auto buildscript! Have fun...${NORMAL}\n" |
15679d9f MT |
490 | update_logs |
491 | evaluate 1 | |
492 | ||
493 | if [ "$IPFIRE_REBUILD" -eq "0" ]; then | |
15679d9f MT |
494 | export IPFIRE_START_TIME=`date` |
495 | evaluate 1 | |
496 | ||
d6d43509 MT |
497 | $0 git update |
498 | evaluate 1 mail_me UPDATE | |
15679d9f MT |
499 | |
500 | echo "### EXPORT SOURCES" | |
d6d43509 MT |
501 | $0 git dist |
502 | evaluate 1 mail_me DIST | |
15679d9f MT |
503 | fi |
504 | ||
505 | echo "### RUNNING BUILD" | |
d6d43509 | 506 | $0 build |
a50d04ab | 507 | evaluate 1 mail_me ERROR |
15679d9f | 508 | |
8f55c54e MT |
509 | echo "### UPLOADING ISO" |
510 | $0 upload iso | |
511 | evaluate 1 mail_me ISO | |
15679d9f | 512 | |
0d909a4a MT |
513 | echo -ne "### UPLOADING PAKS" |
514 | $0 upload paks | |
515 | evaluate 1 mail_me PAKS | |
15679d9f | 516 | |
c8582074 | 517 | echo -ne "${BOLD}***SUCCESS!${NORMAL}" |
bcbb829a | 518 | mail_me success |
15679d9f MT |
519 | exit 0 |
520 | } | |
521 | ||
522 | watch_screen() { | |
523 | echo -e "${BOLD}Exit with Ctrl+A, Ctrl+D.${NORMAL}" | |
524 | sleep 0.5 | |
525 | screen -x ipfire | |
526 | } | |
527 | ||
a50d04ab | 528 | mail_me() { |
228638e0 MT |
529 | echo "From: $MAIL_FROM" > /tmp/ipfire_mail_body.$$ |
530 | echo "To: $MAIL_TO" >> /tmp/ipfire_mail_body.$$ | |
15679d9f MT |
531 | case "$1" in |
532 | success) | |
228638e0 | 533 | cat <<END >> /tmp/ipfire_mail_body.$$ |
d6d43509 MT |
534 | Subject: SUCCESS: IPFIRE-BUILD on `hostname` |
535 | Building IPFire on `hostname` was successfull! | |
bcbb829a | 536 | You can find the ISO on your ftp server if you told the script where it is. |
15679d9f MT |
537 | |
538 | Statistics: | |
539 | ----------- | |
540 | Started: $IPFIRE_START_TIME | |
541 | Finished: `date` | |
542 | ||
543 | Best Regards | |
544 | Your IPFire-Build-Script | |
545 | ||
546 | END | |
547 | echo -ne "${BOLD}***Sending success message${NORMAL}" | |
548 | ;; | |
549 | *) | |
228638e0 | 550 | cat <<END >> /tmp/ipfire_mail_body.$$ |
d6d43509 | 551 | Subject: ERROR $1: IPFIRE-BUILD on `hostname` |
15679d9f MT |
552 | When I was building IPFire on `hostname`, I have found an ERROR with name $1! |
553 | Here you can see the logs and detect the reason for this error. | |
554 | ||
555 | Best Regards | |
556 | Your IPFire-Build-Script | |
557 | ||
558 | ||
559 | Here is a summary... The full logs are in the attachment. | |
560 | --------------------------------------------------------- | |
561 | ||
562 | `tail log/_*` | |
563 | END | |
564 | echo -ne "${BOLD}***Sending error message${NORMAL}" | |
565 | ;; | |
566 | esac | |
228638e0 | 567 | |
5ad5a6bc | 568 | sleep 15 |
228638e0 | 569 | python tools/sendEmail < /tmp/ipfire_mail_body.$$ |
15679d9f MT |
570 | if [ "$?" -eq "0" ]; then |
571 | beautify message DONE | |
572 | else | |
573 | beautify message FAIL | |
574 | fi | |
228638e0 | 575 | rm -f /tmp/ipfire_mail_body.$$ |
15679d9f MT |
576 | } |
577 | ||
578 | make_config() { | |
a50d04ab MT |
579 | clear |
580 | echo -e "${BOLD}***This will create your configuration...${NORMAL}" | |
581 | echo -ne "***If your are ready press <ENTER>!" | |
582 | read | |
583 | clear | |
584 | echo -ne "***The buildscript will create a full iso image.\n" | |
585 | echo -ne "***If you want to skip any package please enter its name here seperated with space.\n" | |
586 | echo -ne "Actually in the list are: $SKIP_PACKAGE_LIST\n" | |
587 | echo -ne "Do you want to change this? (y/N) " | |
588 | read YESNO | |
589 | if [ "$YESNO" == "y" ]; then | |
590 | echo -ne "Please type: " | |
591 | read SKIP_PACKAGE_LIST | |
592 | echo -ne "You entered: $SKIP_PACKAGE_LIST\n" | |
15679d9f | 593 | fi |
a50d04ab MT |
594 | |
595 | clear | |
596 | echo -ne "***When you have compiled successfully, there is the possibility\n" | |
597 | echo -ne "***to upload the iso image to a ftp server.\n" | |
598 | echo -ne "***If the url is empty there will be no upload.\n" | |
599 | echo -ne "Actually there is: $FTP_ISO_URL\n" | |
600 | echo -ne "Do you want to change this? (y/N) " | |
601 | read YESNO | |
602 | if [ "$YESNO" == "y" ]; then | |
603 | echo -ne "Please type the url: " | |
604 | read FTP_ISO_URL | |
605 | echo -ne "Please type the path: " | |
606 | read FTP_ISO_PATH | |
607 | echo -ne "Please type the username: " | |
608 | read FTP_ISO_USER | |
609 | echo -ne "Please type the password (hidden): " | |
610 | read -s FTP_ISO_PASS | |
611 | ||
612 | fi | |
613 | ||
614 | clear | |
615 | echo -ne "***When you add some new software you can easyly\n" | |
616 | echo -ne "***upload the source code to our repository server.\n" | |
617 | echo -ne "***If the url is empty there will be no upload.\n" | |
618 | echo -ne "Actually there is: $FTP_CACHE_URL\n" | |
619 | echo -ne "Do you want to change this? (y/N) " | |
620 | read YESNO | |
621 | if [ "$YESNO" == "y" ]; then | |
622 | echo -ne "Please type the url: " | |
623 | read FTP_CACHE_URL | |
624 | echo -ne "Please type the path: " | |
625 | read FTP_CACHE_PATH | |
626 | echo -ne "Please type the username: " | |
627 | read FTP_CACHE_USER | |
628 | echo -ne "Please type the password (hidden): " | |
629 | read -s FTP_CACHE_PASS | |
630 | ||
631 | fi | |
632 | ||
633 | clear | |
634 | echo -ne "***If there are some important messages you\n" | |
635 | echo -ne "***can get a notification mail.\n" | |
636 | echo -ne "***Please type one ore more email adresses (seperated by comma).\n" | |
637 | echo -ne "Actually there is: $MAIL_TO\n" | |
638 | echo -ne "Do you want to change this? (y/N) " | |
639 | read YESNO | |
640 | if [ "$YESNO" == "y" ]; then | |
641 | echo -ne "Please type: " | |
642 | read MAIL_TO | |
643 | echo -ne "You should enter a mail server to login...\n" | |
644 | echo -ne "Please type the url: " | |
645 | read MAIL_SERVER | |
a358af8c MT |
646 | echo -ne "Please type where the email is from: " |
647 | read MAIL_FROM | |
a50d04ab MT |
648 | echo -ne "Please type the username: " |
649 | read MAIL_USER | |
650 | echo -ne "Please type the password (hidden): " | |
651 | read -s MAIL_PASS | |
652 | ||
15679d9f | 653 | fi |
1be59789 | 654 | echo -ne "\n${BOLD}***Saving...${NORMAL}" |
a50d04ab MT |
655 | cat <<END > $BASEDIR/.config |
656 | ### iso server | |
657 | FTP_ISO_URL=$FTP_ISO_URL | |
658 | FTP_ISO_PATH=$FTP_ISO_PATH | |
659 | FTP_ISO_USER=$FTP_ISO_USER | |
660 | FTP_ISO_PASS=$FTP_ISO_PASS | |
15679d9f | 661 | ### cache server |
a50d04ab MT |
662 | FTP_CACHE_URL=$FTP_CACHE_URL |
663 | FTP_CACHE_PATH=$FTP_CACHE_PATH | |
664 | FTP_CACHE_USER=$FTP_CACHE_USER | |
665 | FTP_CACHE_PASS=$FTP_CACHE_PASS | |
15679d9f | 666 | ### mail reports |
a50d04ab | 667 | MAIL_TO="$MAIL_TO" |
a358af8c | 668 | MAIL_FROM=$MAIL_FROM |
a50d04ab MT |
669 | MAIL_SERVER=$MAIL_SERVER |
670 | MAIL_USER=$MAIL_USER | |
671 | MAIL_PASS=$MAIL_PASS | |
672 | ### misc | |
673 | SKIP_PACKAGE_LIST="$SKIP_PACKAGE_LIST" | |
15679d9f MT |
674 | END |
675 | beautify message DONE | |
33634aa8 MT |
676 | } |
677 | ||
678 | compile_tftpd() { | |
679 | mkdir $BASEDIR/tmp | |
680 | tar xvfz $BASEDIR/cache/tftp-hpa-0.42.tar.gz -C $BASEDIR/tmp | |
a50d04ab | 681 | cd $BASEDIR/tmp/tftp-hpa-* |
33634aa8 MT |
682 | ./configure --prefix=/ipfire/trunk/tools/ \ |
683 | --sbindir=/ipfire/trunk/tools/ --disable-nls | |
684 | make | |
685 | install -c tftpd/tftpd $BASEDIR/tools/in.tftpd | |
686 | cd - | |
a50d04ab | 687 | rm -rf $BASEDIR/tmp/tftp-hpa-* |
33634aa8 MT |
688 | } |
689 | ||
690 | start_tftpd() { | |
691 | if [ ! -e $BASEDIR/tools/in.tftpd ]; then | |
692 | compile_tftpd | |
693 | fi | |
694 | reload_tftpd | |
695 | if [ "$?" == "0" ]; then | |
696 | $BASEDIR/tools/in.tftpd -l -s $BASEDIR/tftpboot | |
697 | beautify message DONE | |
698 | else | |
699 | echo -en "You don not have a pxe boot image in your base directory.\nPlease compile first." | |
700 | beautify message FAIL | |
701 | exit 1 | |
702 | fi | |
703 | } | |
704 | ||
705 | stop_tftpd() { | |
706 | echo -n "Stopping TFTPD..." | |
707 | killall in.tftpd >/dev/null 2>&1 | |
708 | sleep 3 | |
709 | killall -9 in.tftp >/dev/null 2>&1 | |
710 | beautify message DONE | |
711 | } | |
712 | ||
713 | reload_tftpd() { | |
15854f82 | 714 | if [ -e $BASEDIR/ipfire-$VERSION.$MACHINE-pxe.tgz ]; then |
33634aa8 | 715 | mkdir -p $BASEDIR/tftpboot |
15854f82 | 716 | tar xfz $BASEDIR/ipfire-$VERSION.$MACHINE-pxe.tgz -C $BASEDIR/tftpboot |
33634aa8 MT |
717 | return 0 |
718 | fi | |
719 | return 1 | |
720 | } | |
8a5f0f44 MT |
721 | |
722 | update_langs() { | |
723 | echo -ne "Checking the translations for missing or obsolete strings..." | |
1065bfea | 724 | chmod 755 $BASEDIR/tools/{check_strings.pl,sort_strings.pl,check_langs.sh} |
8a5f0f44 MT |
725 | $BASEDIR/tools/sort_strings.pl en |
726 | $BASEDIR/tools/sort_strings.pl de | |
727 | $BASEDIR/tools/check_strings.pl en > $BASEDIR/doc/language_issues.en | |
728 | $BASEDIR/tools/check_strings.pl de > $BASEDIR/doc/language_issues.de | |
729 | $BASEDIR/tools/check_langs.sh > $BASEDIR/doc/language_missings | |
730 | beautify message DONE | |
731 | } |