]> git.ipfire.org Git - ipfire-2.x.git/blame - tools/make-functions
Remove start and stop beep sounds.
[ipfire-2.x.git] / tools / make-functions
CommitLineData
15679d9f 1#!/bin/bash
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
e73e134c 5# Copyright (C) 2010 IPFire Team <info@ipfire.org> #
70df8302
MT
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
29if [ -z "${COLUMNS}" ]; then
30 COLUMNS=$(stty size)
31 COLUMNS=${COLUMNS##* }
32fi
33
34# When using remote connections, such as a serial port, stty size returns 0
35if [ "${COLUMNS}" = "0" ]; then
36 COLUMNS=80
37fi
38
39## Measurements for positioning result messages
40RESULT_WIDTH=4
41TIME_WIDTH=8
42OPT_WIDTH=6
43VER_WIDTH=10
44RESULT_COL=$((${COLUMNS} - $RESULT_WIDTH - 4))
45TIME_COL=$((${RESULT_COL} - $TIME_WIDTH - 5))
46OPT_COL=$((${TIME_COL} - $OPT_WIDTH - 5))
47VER_COL=$((${OPT_COL} - $VER_WIDTH - 5))
48
49## Set Cursur Position Commands, used via echo -e
50SET_RESULT_COL="\\033[${RESULT_COL}G"
51SET_TIME_COL="\\033[${TIME_COL}G"
52SET_OPT_COL="\\033[${OPT_COL}G"
53SET_VER_COL="\\033[${VER_COL}G"
54
55# Define color for messages
56BOLD="\\033[1;39m"
57DONE="\\033[1;32m"
58SKIP="\\033[1;34m"
59WARN="\\033[1;35m"
60FAIL="\\033[1;31m"
61NORMAL="\\033[0;39m"
62
63evaluate() {
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
77position_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
108beautify()
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)
15679d9f
MT
188 echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n"
189 ;;
190 esac
191 ;;
192 esac
193} # End of beautify()
194
195
196get_pkg_ver()
197{
198 PKG_VER=`grep ^VER $1 | awk '{print $3}'`
199
200 if [ -z $PKG_VER ]; then
201 PKG_VER=`grep "Exp " $1 | awk '{print $4}'`
202 fi
203
204 if [ ${#PKG_VER} -gt $VER_WIDTH ]; then
205 # If a package version number is greater than $VER_WIDTH, we keep the first 4 characters
206 # and replace enough characters to fit the resulting string on the screen. We'll replace
207 # the extra character with .. (two dots). That's why the "+ 2" in the formula below.
208 # Example: if we have a 21-long version number that we want to fit into a 10-long space,
209 # we have to remove 11 characters. But if we replace 11 characters with 2 characters, we'll
210 # end up with a 12-character long string. That's why we replace 12 characters with ..
211 REMOVE=`expr substr "$PKG_VER" 4 $[ ${#PKG_VER} - $VER_WIDTH + 2 ]`
212 PKG_VER=`echo ${PKG_VER/$REMOVE/..}`
213 fi
214
215 echo "$PKG_VER"
216} # End of get_pkg_ver()
217
218if [ 'x86_64' = $MACHINE -o 'i686' = $MACHINE -o 'i586' = $MACHINE ]; then
219 echo "`date -u '+%b %e %T'`: Machine is iX86 (or equivalent)" >> $LOGFILE
220 MACHINE=i586
221 BUILDTARGET=i586-pc-linux-gnu
9b0ff0a0 222 CFLAGS="-O2 -march=i586 -pipe -fomit-frame-pointer"
b4b6bcdb 223 CXXFLAGS="-O2 -march=i586 -pipe -fomit-frame-pointer"
15679d9f
MT
224 C2FLAGS="-O2 -march=i586 -mtune=i586 -pipe -fomit-frame-pointer"
225 CXX2FLAGS="-O2 -march=i586 -mtune=i586 -pipe -fomit-frame-pointer"
51f9e7ac
MT
226elif [ 'armv5tejl' = $MACHINE -o 'armv5tel' = $MACHINE ]; then
227 echo "`date -u '+%b %e %T'`: Machine is ARM (or equivalent)" >> $LOGFILE
df94e866
MT
228 MACHINE=armv5tel
229 MACHINE_TYPE=arm
230 BUILDTARGET=${MACHINE}-unknown-linux-gnueabi
51f9e7ac
MT
231 CFLAGS="-O2 -march=armv5te -fomit-frame-pointer -pipe"
232 CXXFLAGS="$CFLAGS"
233 C2FLAGS="$CFLAGS"
234 CXX2FLAGS="$CXXFLAGS"
15679d9f
MT
235else
236 echo "`date -u '+%b %e %T'`: Can't determine your architecture - $MACHINE" >> $LOGFILE
237 exit 1
238fi
239
240# Define immediately
241stdumount() {
b4b6bcdb
MT
242 umount $BASEDIR/build/sys 2>/dev/null;
243 umount $BASEDIR/build/dev/shm 2>/dev/null;
15679d9f 244 umount $BASEDIR/build/dev/pts 2>/dev/null;
b4b6bcdb 245 umount $BASEDIR/build/dev 2>/dev/null;
15679d9f
MT
246 umount $BASEDIR/build/proc 2>/dev/null;
247 umount $BASEDIR/build/install/mnt 2>/dev/null;
248 umount $BASEDIR/build/usr/src/cache 2>/dev/null;
249 umount $BASEDIR/build/usr/src/ccache 2>/dev/null;
250 umount $BASEDIR/build/usr/src/config 2>/dev/null;
251 umount $BASEDIR/build/usr/src/doc 2>/dev/null;
252 umount $BASEDIR/build/usr/src/html 2>/dev/null;
253 umount $BASEDIR/build/usr/src/langs 2>/dev/null;
254 umount $BASEDIR/build/usr/src/lfs 2>/dev/null;
255 umount $BASEDIR/build/usr/src/log 2>/dev/null;
256 umount $BASEDIR/build/usr/src/src 2>/dev/null;
257}
258
259exiterror() {
260 stdumount
261 for i in `seq 0 7`; do
262 if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then
263 losetup -d /dev/loop${i} 2>/dev/null
264 fi;
265 done
266 echo -e "\nERROR: $*"
267 echo " Check $LOGFILE for errors if applicable"
268 exit 1
269}
270
271entershell() {
272 if [ ! -e $BASEDIR/build/usr/src/lfs/ ]; then
273 exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/"
274 fi
275 echo "Entering to a shell inside LFS chroot, go out with exit"
0381e7a6 276 $linux32 chroot $LFS /tools/bin/env -i HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
15679d9f
MT
277 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
278 VERSION=$VERSION CONFIG_ROOT=$CONFIG_ROOT \
279 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
280 CFLAGS="$CF2LAGS" CXXFLAGS="$CXX2FLAGS" \
281 CCACHE_DIR=/usr/src/ccache \
36d351ff 282 CCACHE_COMPRESS=1 \
15679d9f
MT
283 CCACHE_HASHDIR=1 \
284 KVER=$KVER \
df94e866
MT
285 BUILDTARGET="$BUILDTARGET" \
286 MACHINE="$MACHINE" \
287 MACHINE_TYPE="$MACHINE_TYPE" \
15679d9f
MT
288 KGCC="ccache /usr/bin/gcc" \
289 /tools/bin/bash
290 if [ $? -ne 0 ]; then
291 beautify message FAIL
292 exiterror "chroot error"
293 else
294 stdumount
295 fi
296}
297
298############################################################################
299# #
300# Necessary shell functions #
301# #
302############################################################################
303#
304# Common checking before entering the chroot and compilling
305#
306# Return:0 caller can continue
307# :1 skip (nothing to do)
308# or fail if no script file found
309#
310lfsmakecommoncheck()
311{
15679d9f
MT
312 # Script present?
313 if [ ! -f $BASEDIR/lfs/$1 ]; then
314 exiterror "No such file or directory: $BASEDIR/$1"
315 fi
316
317 local PKG_VER=`get_pkg_ver $BASEDIR/lfs/$1`
318 beautify make_pkg "$PKG_VER $*"
319
846e756e
MT
320 # Check if this package is supported by our architecture.
321 # If no SUP_ARCH is found, we assume the package can be built for all.
322 if grep "^SUP_ARCH" ${BASEDIR}/lfs/${1} >/dev/null; then
323 # Check if package supports ${MACHINE} or all architectures.
324 if ! grep -E "^SUP_ARCH.*${MACHINE}|^SUP_ARCH.*all" ${BASEDIR}/lfs/${1} >/dev/null; then
325 beautify result SKIP
326 return 1
327 fi
328 fi
329
15679d9f
MT
330 # Script slipped?
331 local i
332 for i in $SKIP_PACKAGE_LIST
333 do
a50d04ab 334 if [ "$i" == "$1" ]; then
15679d9f
MT
335 beautify result SKIP
336 return 1;
337 fi
338 done
339
340 echo -ne "`date -u '+%b %e %T'`: Building $* " >> $LOGFILE
341
51f9e7ac 342 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MACHINE=$MACHINE \
df94e866 343 MACHINE_TYPE="$MACHINE_TYPE" \
51f9e7ac 344 MESSAGE="$1\t " download >> $LOGFILE 2>&1
15679d9f
MT
345 if [ $? -ne 0 ]; then
346 exiterror "Download error in $1"
347 fi
348
51f9e7ac 349 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MACHINE=$MACHINE \
df94e866 350 MACHINE_TYPE="$MACHINE_TYPE" \
51f9e7ac 351 MESSAGE="$1\t md5sum" md5 >> $LOGFILE 2>&1
15679d9f
MT
352 if [ $? -ne 0 ]; then
353 exiterror "md5sum error in $1, check file in cache or signature"
354 fi
355
356 return 0 # pass all!
357} # End of lfsmakecommoncheck()
358
359lfsmake1() {
360 lfsmakecommoncheck $*
361 [ $? == 1 ] && return 0
362
363 local PKG_TIME_START=`date +%s`
364
365 cd $BASEDIR/lfs && make -f $* BUILDTARGET=$BUILDTARGET \
366 MACHINE=$MACHINE \
df94e866 367 MACHINE_TYPE=$MACHINE_TYPE \
15679d9f
MT
368 LFS_BASEDIR=$BASEDIR \
369 ROOT=$LFS \
370 KVER=$KVER \
371 MAKETUNING=$MAKETUNING \
372 install >> $LOGFILE 2>&1
373 local COMPILE_SUCCESS=$?
374 local PKG_TIME_END=`date +%s`
375
376 if [ $COMPILE_SUCCESS -ne 0 ]; then
377 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
378 exiterror "Building $*";
379 else
380 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
381 fi
382
383 return 0
384}
385
386lfsmake2() {
387 lfsmakecommoncheck $*
388 [ $? == 1 ] && return 0
389
390 local PKG_TIME_START=`date +%s`
94571564 391 $linux32 chroot $LFS /tools/bin/env -i HOME=/root \
15679d9f
MT
392 TERM=$TERM PS1='\u:\w\$ ' \
393 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
394 VERSION=$VERSION \
395 CONFIG_ROOT=$CONFIG_ROOT \
396 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
397 CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \
36d351ff 398 CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 CCACHE_HASHDIR=1 \
15679d9f
MT
399 KVER=$KVER MAKETUNING=$MAKETUNING \
400 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
df94e866 401 MACHINE_TYPE="$MACHINE_TYPE" \
c8ead4a5 402 IPFVER="$IPFVER" \
15679d9f
MT
403 /tools/bin/bash -x -c "cd /usr/src/lfs && \
404 make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
405 local COMPILE_SUCCESS=$?
406 local PKG_TIME_END=`date +%s`
407
408 if [ $COMPILE_SUCCESS -ne 0 ]; then
409 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
410 exiterror "Building $*";
411 else
412 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
413 fi
414
415 return 0
416}
417
418ipfiremake() {
419 lfsmakecommoncheck $*
420 [ $? == 1 ] && return 0
421
422 local PKG_TIME_START=`date +%s`
94571564 423 $linux32 chroot $LFS /tools/bin/env -i HOME=/root \
15679d9f
MT
424 TERM=$TERM PS1='\u:\w\$ ' \
425 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
426 VERSION=$VERSION \
a01fc474 427 CORE=$CORE \
15679d9f
MT
428 CONFIG_ROOT=$CONFIG_ROOT \
429 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
430 CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \
36d351ff 431 CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 CCACHE_HASHDIR=1 \
15679d9f
MT
432 KVER=$KVER MAKETUNING=$MAKETUNING \
433 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
df94e866 434 MACHINE_TYPE="$MACHINE_TYPE" \
c8ead4a5 435 IPFVER="$IPFVER" \
15679d9f
MT
436 /bin/bash -x -c "cd /usr/src/lfs && \
437 make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
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 $*";
445 else
446 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
447 fi
448 return 0
449}
450
451ipfiredist() {
0d909a4a
MT
452 lfsmakecommoncheck $*
453 [ $? == 1 ] && return 0
454
455 local PKG_TIME_START=`date +%s`
456 chroot $LFS /tools/bin/env -i HOME=/root \
457 TERM=$TERM PS1='\u:\w\$ ' \
458 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
459 VERSION=$VERSION \
460 CONFIG_ROOT=$CONFIG_ROOT \
461 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
462 CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \
36d351ff 463 CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 CCACHE_HASHDIR=1 \
0d909a4a
MT
464 KVER=$KVER IPFVER="$IPFVER" \
465 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
df94e866 466 MACHINE_TYPE="$MACHINE_TYPE" \
0d909a4a
MT
467 /bin/bash -x -c "cd /usr/src/lfs && \
468 make -f $1 LFS_BASEDIR=/usr/src dist" >>$LOGFILE 2>&1
469
470 local COMPILE_SUCCESS=$?
471 local PKG_TIME_END=`date +%s`
472
473 if [ $COMPILE_SUCCESS -ne 0 ]; then
474 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
475 exiterror "Packaging $*";
15679d9f 476 else
0d909a4a 477 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
15679d9f
MT
478 fi
479 return 0
480}
481
482installmake() {
41921bd9
MT
483 lfsmakecommoncheck $*
484 [ $? == 1 ] && return 0
485
486 local PKG_TIME_START=`date +%s`
94571564 487 $linux32 chroot $LFS /tools/bin/env -i HOME=/root \
15679d9f 488 TERM=$TERM PS1='\u:\w\$ ' \
4da401bc 489 PATH=/opt/i586-uClibc/i586-linux-uclibc/bin:/opt/i586-uClibc/bin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
15679d9f
MT
490 VERSION=$VERSION \
491 CONFIG_ROOT=$CONFIG_ROOT \
492 LFS_PASS="install" \
493 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
494 CFLAGS="-Os" CXXFLAGS="-Os" \
36d351ff 495 CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 CCACHE_HASHDIR=1 \
c8ead4a5 496 KVER=$KVER IPFVER="$IPFVER" \
15679d9f 497 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
df94e866 498 MACHINE_TYPE="$MACHINE_TYPE" \
15679d9f
MT
499 /bin/bash -x -c "cd /usr/src/lfs && \
500 make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
41921bd9
MT
501
502 local COMPILE_SUCCESS=$?
503 local PKG_TIME_END=`date +%s`
504
505 if [ $COMPILE_SUCCESS -ne 0 ]; then
506 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
507 exiterror "Building $*";
15679d9f 508 else
41921bd9 509 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
15679d9f
MT
510 fi
511 return 0
512}
513
514update_logs() {
515 tar cfz log/ipfire-logs-`date +'%Y-%m-%d-%H:%M'`.tgz log/_build.*
516 rm -f log/_build.*
517}
518
519batch_script() {
a50d04ab 520 echo -ne "${BOLD}***This is our auto buildscript! Have fun...${NORMAL}\n"
15679d9f
MT
521 update_logs
522 evaluate 1
523
524 if [ "$IPFIRE_REBUILD" -eq "0" ]; then
15679d9f 525 export IPFIRE_START_TIME=`date`
1a3c8253
MT
526
527 $0 clean
15679d9f
MT
528 evaluate 1
529
533bebcc 530 $0 git update --force
d6d43509 531 evaluate 1 mail_me UPDATE
15679d9f
MT
532
533 echo "### EXPORT SOURCES"
d6d43509
MT
534 $0 git dist
535 evaluate 1 mail_me DIST
15679d9f
MT
536 fi
537
538 echo "### RUNNING BUILD"
d6d43509 539 $0 build
a50d04ab 540 evaluate 1 mail_me ERROR
15679d9f 541
8f55c54e 542 echo "### UPLOADING ISO"
1a3c8253
MT
543 $0 upload iso
544 evaluate 1 mail_me ISO
15679d9f 545
0d909a4a 546 echo -ne "### UPLOADING PAKS"
1a3c8253
MT
547 $0 upload paks
548 evaluate 1 mail_me PAKS
15679d9f 549
c8582074 550 echo -ne "${BOLD}***SUCCESS!${NORMAL}"
bcbb829a 551 mail_me success
15679d9f
MT
552 exit 0
553}
554
555watch_screen() {
556 echo -e "${BOLD}Exit with Ctrl+A, Ctrl+D.${NORMAL}"
557 sleep 0.5
558 screen -x ipfire
559}
560
a50d04ab 561mail_me() {
228638e0
MT
562 echo "From: $MAIL_FROM" > /tmp/ipfire_mail_body.$$
563 echo "To: $MAIL_TO" >> /tmp/ipfire_mail_body.$$
15679d9f
MT
564 case "$1" in
565 success)
228638e0 566 cat <<END >> /tmp/ipfire_mail_body.$$
d6d43509
MT
567Subject: SUCCESS: IPFIRE-BUILD on `hostname`
568Building IPFire on `hostname` was successfull!
bcbb829a 569You can find the ISO on your ftp server if you told the script where it is.
15679d9f
MT
570
571Statistics:
572-----------
573Started: $IPFIRE_START_TIME
574Finished: `date`
575
576Best Regards
577Your IPFire-Build-Script
578
579END
580 echo -ne "${BOLD}***Sending success message${NORMAL}"
581 ;;
582 *)
228638e0 583 cat <<END >> /tmp/ipfire_mail_body.$$
d6d43509 584Subject: ERROR $1: IPFIRE-BUILD on `hostname`
15679d9f
MT
585When I was building IPFire on `hostname`, I have found an ERROR with name $1!
586Here you can see the logs and detect the reason for this error.
587
588Best Regards
589Your IPFire-Build-Script
590
591
592Here is a summary... The full logs are in the attachment.
593---------------------------------------------------------
594
595`tail log/_*`
596END
597 echo -ne "${BOLD}***Sending error message${NORMAL}"
598 ;;
599 esac
228638e0 600
5ad5a6bc 601sleep 15
228638e0 602 python tools/sendEmail < /tmp/ipfire_mail_body.$$
15679d9f
MT
603 if [ "$?" -eq "0" ]; then
604 beautify message DONE
605 else
606 beautify message FAIL
607 fi
228638e0 608 rm -f /tmp/ipfire_mail_body.$$
15679d9f
MT
609}
610
611make_config() {
a50d04ab
MT
612 clear
613 echo -e "${BOLD}***This will create your configuration...${NORMAL}"
614 echo -ne "***If your are ready press <ENTER>!"
615 read
616 clear
617 echo -ne "***The buildscript will create a full iso image.\n"
618 echo -ne "***If you want to skip any package please enter its name here seperated with space.\n"
619 echo -ne "Actually in the list are: $SKIP_PACKAGE_LIST\n"
620 echo -ne "Do you want to change this? (y/N) "
621 read YESNO
622 if [ "$YESNO" == "y" ]; then
623 echo -ne "Please type: "
624 read SKIP_PACKAGE_LIST
625 echo -ne "You entered: $SKIP_PACKAGE_LIST\n"
15679d9f 626 fi
a50d04ab
MT
627
628 clear
629 echo -ne "***When you have compiled successfully, there is the possibility\n"
630 echo -ne "***to upload the iso image to a ftp server.\n"
631 echo -ne "***If the url is empty there will be no upload.\n"
632 echo -ne "Actually there is: $FTP_ISO_URL\n"
633 echo -ne "Do you want to change this? (y/N) "
634 read YESNO
635 if [ "$YESNO" == "y" ]; then
636 echo -ne "Please type the url: "
637 read FTP_ISO_URL
638 echo -ne "Please type the path: "
639 read FTP_ISO_PATH
640 echo -ne "Please type the username: "
641 read FTP_ISO_USER
642 echo -ne "Please type the password (hidden): "
643 read -s FTP_ISO_PASS
644
645 fi
646
647 clear
648 echo -ne "***When you add some new software you can easyly\n"
649 echo -ne "***upload the source code to our repository server.\n"
650 echo -ne "***If the url is empty there will be no upload.\n"
651 echo -ne "Actually there is: $FTP_CACHE_URL\n"
652 echo -ne "Do you want to change this? (y/N) "
653 read YESNO
654 if [ "$YESNO" == "y" ]; then
655 echo -ne "Please type the url: "
656 read FTP_CACHE_URL
657 echo -ne "Please type the path: "
658 read FTP_CACHE_PATH
659 echo -ne "Please type the username: "
660 read FTP_CACHE_USER
661 echo -ne "Please type the password (hidden): "
662 read -s FTP_CACHE_PASS
663
664 fi
665
666 clear
667 echo -ne "***If there are some important messages you\n"
668 echo -ne "***can get a notification mail.\n"
669 echo -ne "***Please type one ore more email adresses (seperated by comma).\n"
670 echo -ne "Actually there is: $MAIL_TO\n"
671 echo -ne "Do you want to change this? (y/N) "
672 read YESNO
673 if [ "$YESNO" == "y" ]; then
674 echo -ne "Please type: "
675 read MAIL_TO
676 echo -ne "You should enter a mail server to login...\n"
677 echo -ne "Please type the url: "
678 read MAIL_SERVER
a358af8c
MT
679 echo -ne "Please type where the email is from: "
680 read MAIL_FROM
a50d04ab
MT
681 echo -ne "Please type the username: "
682 read MAIL_USER
683 echo -ne "Please type the password (hidden): "
684 read -s MAIL_PASS
685
15679d9f 686 fi
1be59789 687 echo -ne "\n${BOLD}***Saving...${NORMAL}"
a50d04ab
MT
688 cat <<END > $BASEDIR/.config
689### iso server
690FTP_ISO_URL=$FTP_ISO_URL
691FTP_ISO_PATH=$FTP_ISO_PATH
692FTP_ISO_USER=$FTP_ISO_USER
693FTP_ISO_PASS=$FTP_ISO_PASS
15679d9f 694### cache server
a50d04ab
MT
695FTP_CACHE_URL=$FTP_CACHE_URL
696FTP_CACHE_PATH=$FTP_CACHE_PATH
697FTP_CACHE_USER=$FTP_CACHE_USER
698FTP_CACHE_PASS=$FTP_CACHE_PASS
15679d9f 699### mail reports
a50d04ab 700MAIL_TO="$MAIL_TO"
a358af8c 701MAIL_FROM=$MAIL_FROM
a50d04ab
MT
702MAIL_SERVER=$MAIL_SERVER
703MAIL_USER=$MAIL_USER
704MAIL_PASS=$MAIL_PASS
705### misc
706SKIP_PACKAGE_LIST="$SKIP_PACKAGE_LIST"
15679d9f
MT
707END
708 beautify message DONE
33634aa8
MT
709}
710
711compile_tftpd() {
712 mkdir $BASEDIR/tmp
713 tar xvfz $BASEDIR/cache/tftp-hpa-0.42.tar.gz -C $BASEDIR/tmp
a50d04ab 714 cd $BASEDIR/tmp/tftp-hpa-*
33634aa8
MT
715 ./configure --prefix=/ipfire/trunk/tools/ \
716 --sbindir=/ipfire/trunk/tools/ --disable-nls
717 make
718 install -c tftpd/tftpd $BASEDIR/tools/in.tftpd
719 cd -
a50d04ab 720 rm -rf $BASEDIR/tmp/tftp-hpa-*
33634aa8
MT
721}
722
723start_tftpd() {
724 if [ ! -e $BASEDIR/tools/in.tftpd ]; then
725 compile_tftpd
726 fi
727 reload_tftpd
728 if [ "$?" == "0" ]; then
729 $BASEDIR/tools/in.tftpd -l -s $BASEDIR/tftpboot
730 beautify message DONE
731 else
732 echo -en "You don not have a pxe boot image in your base directory.\nPlease compile first."
733 beautify message FAIL
734 exit 1
735 fi
736}
737
738stop_tftpd() {
739 echo -n "Stopping TFTPD..."
740 killall in.tftpd >/dev/null 2>&1
741 sleep 3
742 killall -9 in.tftp >/dev/null 2>&1
743 beautify message DONE
744}
745
746reload_tftpd() {
15854f82 747 if [ -e $BASEDIR/ipfire-$VERSION.$MACHINE-pxe.tgz ]; then
33634aa8 748 mkdir -p $BASEDIR/tftpboot
15854f82 749 tar xfz $BASEDIR/ipfire-$VERSION.$MACHINE-pxe.tgz -C $BASEDIR/tftpboot
33634aa8
MT
750 return 0
751 fi
752 return 1
753}
8a5f0f44
MT
754
755update_langs() {
756 echo -ne "Checking the translations for missing or obsolete strings..."
1065bfea 757 chmod 755 $BASEDIR/tools/{check_strings.pl,sort_strings.pl,check_langs.sh}
8a5f0f44
MT
758 $BASEDIR/tools/sort_strings.pl en
759 $BASEDIR/tools/sort_strings.pl de
e73e134c
AF
760 $BASEDIR/tools/sort_strings.pl fr
761 $BASEDIR/tools/sort_strings.pl es
196e5f8f 762 $BASEDIR/tools/sort_strings.pl pl
2bb7b134 763 $BASEDIR/tools/sort_strings.pl ru
8a5f0f44
MT
764 $BASEDIR/tools/check_strings.pl en > $BASEDIR/doc/language_issues.en
765 $BASEDIR/tools/check_strings.pl de > $BASEDIR/doc/language_issues.de
e73e134c
AF
766 $BASEDIR/tools/check_strings.pl fr > $BASEDIR/doc/language_issues.fr
767 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.es
196e5f8f 768 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.pl
2bb7b134 769 $BASEDIR/tools/check_strings.pl ru > $BASEDIR/doc/language_issues.ru
8a5f0f44
MT
770 $BASEDIR/tools/check_langs.sh > $BASEDIR/doc/language_missings
771 beautify message DONE
772}