Add MACHINE_TYPE variable to be able to support multiple versions of one platform.
[ipfire-2.x.git] / tools / make-functions
1 #!/bin/bash
2 ###############################################################################
3 #                                                                             #
4 # IPFire.org - A linux based firewall                                         #
5 # Copyright (C) 2010  IPFire Team  <info@ipfire.org>                          #
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 ###############################################################################
22 #
23 # Beautifying variables & presentation & input output interface
24 #
25 ###############################################################################
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                         ;;
128                 build_stage)
129                         MESSAGE=$2
130                         if [ "$STAGE_TIME_START" ]; then
131                                 LAST_STAGE_TIME=$[ `date +%s` - $STAGE_TIME_START ]
132                         fi
133                         STAGE_TIME_START=`date +%s`
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"
139                         ;;
140                 build_start)
141                         BUILD_TIME_START=`date +%s`
142                         ;;
143                 build_end)
144                         BUILD_TIME_END=`date +%s`
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"
152                         ;;
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
223         CFLAGS="-O2 -march=i586 -pipe -fomit-frame-pointer"
224         CXXFLAGS="-O2 -march=i586 -pipe -fomit-frame-pointer"
225         C2FLAGS="-O2 -march=i586 -mtune=i586 -pipe -fomit-frame-pointer"
226         CXX2FLAGS="-O2 -march=i586 -mtune=i586 -pipe -fomit-frame-pointer"
227 elif [ 'armv5tejl' = $MACHINE -o 'armv5tel' = $MACHINE ]; then
228         echo "`date -u '+%b %e %T'`: Machine is ARM (or equivalent)" >> $LOGFILE
229         MACHINE=armv5tel
230         MACHINE_TYPE=arm
231         BUILDTARGET=${MACHINE}-unknown-linux-gnueabi
232         CFLAGS="-O2 -march=armv5te -fomit-frame-pointer -pipe"
233         CXXFLAGS="$CFLAGS"
234         C2FLAGS="$CFLAGS"
235         CXX2FLAGS="$CXXFLAGS"
236 else
237         echo "`date -u '+%b %e %T'`: Can't determine your architecture - $MACHINE" >> $LOGFILE
238         exit 1
239 fi
240
241 # Define immediately
242 stdumount() {
243         umount $BASEDIR/build/sys                       2>/dev/null;
244         umount $BASEDIR/build/dev/shm           2>/dev/null;
245         umount $BASEDIR/build/dev/pts           2>/dev/null;
246         umount $BASEDIR/build/dev                       2>/dev/null;
247         umount $BASEDIR/build/proc                      2>/dev/null;
248         umount $BASEDIR/build/install/mnt               2>/dev/null;
249         umount $BASEDIR/build/usr/src/cache     2>/dev/null;
250         umount $BASEDIR/build/usr/src/ccache    2>/dev/null;
251         umount $BASEDIR/build/usr/src/config    2>/dev/null;
252         umount $BASEDIR/build/usr/src/doc               2>/dev/null;
253         umount $BASEDIR/build/usr/src/html              2>/dev/null;
254         umount $BASEDIR/build/usr/src/langs     2>/dev/null;
255         umount $BASEDIR/build/usr/src/lfs               2>/dev/null;
256         umount $BASEDIR/build/usr/src/log               2>/dev/null;
257         umount $BASEDIR/build/usr/src/src               2>/dev/null;
258 }
259
260 exiterror() {
261         stdumount
262         for i in `seq 0 7`; do
263             if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then
264                 losetup -d /dev/loop${i} 2>/dev/null
265             fi;
266         done
267         echo -e "\nERROR: $*"
268         echo "       Check $LOGFILE for errors if applicable"
269         exit 1
270 }
271
272 entershell() {
273         if [ ! -e $BASEDIR/build/usr/src/lfs/ ]; then
274                 exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/"
275         fi
276         echo "Entering to a shell inside LFS chroot, go out with exit"
277         $linux32 chroot $LFS /tools/bin/env -i HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
278                 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
279                 VERSION=$VERSION CONFIG_ROOT=$CONFIG_ROOT \
280                 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
281                 CFLAGS="$CF2LAGS" CXXFLAGS="$CXX2FLAGS" \
282                 CCACHE_DIR=/usr/src/ccache \
283                 CCACHE_COMPRESS=1 \
284                 CCACHE_HASHDIR=1 \
285                 KVER=$KVER \
286                 BUILDTARGET="$BUILDTARGET" \
287                 MACHINE="$MACHINE" \
288                 MACHINE_TYPE="$MACHINE_TYPE" \
289                 KGCC="ccache /usr/bin/gcc" \
290                 /tools/bin/bash
291         if [ $? -ne 0 ]; then
292                         beautify message FAIL
293                         exiterror "chroot error"
294         else
295                 stdumount
296         fi
297 }
298
299 ############################################################################
300 #                                                                          #
301 # Necessary shell functions                                                #
302 #                                                                          #
303 ############################################################################
304 #
305 # Common checking before entering the chroot and compilling
306 #
307 # Return:0 caller can continue
308 #       :1 skip (nothing to do)
309 #       or fail if no script file found
310 #
311 lfsmakecommoncheck()
312 {
313         # Script present?
314         if [ ! -f $BASEDIR/lfs/$1 ]; then
315                 exiterror "No such file or directory: $BASEDIR/$1"
316         fi
317
318         local PKG_VER=`get_pkg_ver $BASEDIR/lfs/$1`
319         beautify make_pkg "$PKG_VER $*"
320
321         # Script slipped?
322         local i
323         for i in $SKIP_PACKAGE_LIST
324         do
325                 if [ "$i" == "$1" ]; then
326                         beautify result SKIP
327                         return 1;
328                 fi 
329         done
330
331         echo -ne "`date -u '+%b %e %T'`: Building $* " >> $LOGFILE
332
333         cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MACHINE=$MACHINE \
334                 MACHINE_TYPE="$MACHINE_TYPE" \
335                 MESSAGE="$1\t " download  >> $LOGFILE 2>&1
336         if [ $? -ne 0 ]; then
337                 exiterror "Download error in $1"
338         fi
339
340         cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MACHINE=$MACHINE \
341                 MACHINE_TYPE="$MACHINE_TYPE" \
342                 MESSAGE="$1\t md5sum" md5  >> $LOGFILE 2>&1
343         if [ $? -ne 0 ]; then
344                 exiterror "md5sum error in $1, check file in cache or signature"
345         fi
346
347         return 0        # pass all!
348 } # End of lfsmakecommoncheck()
349
350 lfsmake1() {
351         lfsmakecommoncheck $*
352         [ $? == 1 ] && return 0
353
354         local PKG_TIME_START=`date +%s`
355
356         cd $BASEDIR/lfs && make -f $*   BUILDTARGET=$BUILDTARGET \
357                                                 MACHINE=$MACHINE \
358                                                 MACHINE_TYPE=$MACHINE_TYPE \
359                                                 LFS_BASEDIR=$BASEDIR \
360                                                 ROOT=$LFS \
361                                                 KVER=$KVER \
362                                                 MAKETUNING=$MAKETUNING \
363                                                 install >> $LOGFILE 2>&1
364         local COMPILE_SUCCESS=$?
365         local PKG_TIME_END=`date +%s`
366
367         if [ $COMPILE_SUCCESS -ne 0 ]; then
368                 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
369                 exiterror "Building $*";
370         else
371                 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
372         fi
373
374         return 0
375 }
376
377 lfsmake2() {
378         lfsmakecommoncheck $*
379         [ $? == 1 ] && return 0
380
381         local PKG_TIME_START=`date +%s`
382         $linux32 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:/tools/bin \
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_COMPRESS=1 CCACHE_HASHDIR=1 \
390                                                 KVER=$KVER MAKETUNING=$MAKETUNING \
391                                                 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
392                                                 MACHINE_TYPE="$MACHINE_TYPE" \
393                                                 IPFVER="$IPFVER" \
394                                                 /tools/bin/bash -x -c "cd /usr/src/lfs && \
395                                                 make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
396         local COMPILE_SUCCESS=$?
397         local PKG_TIME_END=`date +%s`
398
399         if [ $COMPILE_SUCCESS -ne 0 ]; then
400                 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
401                 exiterror "Building $*";
402         else
403                 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
404         fi
405
406         return 0
407 }
408
409 ipfiremake() {
410         lfsmakecommoncheck $*
411         [ $? == 1 ] && return 0
412
413         local PKG_TIME_START=`date +%s`
414         $linux32 chroot $LFS /tools/bin/env -i  HOME=/root \
415                                                 TERM=$TERM PS1='\u:\w\$ ' \
416                                                 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
417                                                 VERSION=$VERSION \
418                                                 CORE=$CORE \
419                                                 CONFIG_ROOT=$CONFIG_ROOT \
420                                                 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
421                                                 CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \
422                                                 CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 CCACHE_HASHDIR=1 \
423                                                 KVER=$KVER MAKETUNING=$MAKETUNING \
424                                                 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
425                                                 MACHINE_TYPE="$MACHINE_TYPE" \
426                                                 IPFVER="$IPFVER" \
427                                                 /bin/bash -x -c "cd /usr/src/lfs && \
428                                                 make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
429
430         local COMPILE_SUCCESS=$?
431         local PKG_TIME_END=`date +%s`
432
433         if [ $COMPILE_SUCCESS -ne 0 ]; then
434                 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
435                 exiterror "Building $*";
436         else
437                 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
438         fi
439         return 0
440 }
441
442 ipfiredist() {
443         lfsmakecommoncheck $*
444         [ $? == 1 ] && return 0
445         
446         local PKG_TIME_START=`date +%s`
447         chroot $LFS /tools/bin/env -i   HOME=/root \
448                                         TERM=$TERM PS1='\u:\w\$ ' \
449                                         PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
450                                         VERSION=$VERSION \
451                                         CONFIG_ROOT=$CONFIG_ROOT \
452                                         NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
453                                         CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \
454                                         CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 CCACHE_HASHDIR=1 \
455                                         KVER=$KVER IPFVER="$IPFVER" \
456                                         BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
457                                         MACHINE_TYPE="$MACHINE_TYPE" \
458                                         /bin/bash -x -c "cd /usr/src/lfs && \
459                                         make -f $1 LFS_BASEDIR=/usr/src dist" >>$LOGFILE 2>&1
460
461         local COMPILE_SUCCESS=$?
462         local PKG_TIME_END=`date +%s`
463
464         if [ $COMPILE_SUCCESS -ne 0 ]; then
465                 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
466                 exiterror "Packaging $*";
467         else
468                 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
469         fi
470         return 0
471 }
472
473 installmake() {
474         lfsmakecommoncheck $*
475         [ $? == 1 ] && return 0
476
477         local PKG_TIME_START=`date +%s`
478         $linux32 chroot $LFS /tools/bin/env -i  HOME=/root \
479                                                 TERM=$TERM PS1='\u:\w\$ ' \
480                                                 PATH=/opt/i586-uClibc/i586-linux-uclibc/bin:/opt/i586-uClibc/bin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
481                                                 VERSION=$VERSION \
482                                                 CONFIG_ROOT=$CONFIG_ROOT \
483                                                 LFS_PASS="install" \
484                                                 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
485                                                 CFLAGS="-Os" CXXFLAGS="-Os" \
486                                                 CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 CCACHE_HASHDIR=1 \
487                                                 KVER=$KVER IPFVER="$IPFVER" \
488                                                 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
489                                                 MACHINE_TYPE="$MACHINE_TYPE" \
490                     /bin/bash -x -c "cd /usr/src/lfs && \
491                     make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
492
493         local COMPILE_SUCCESS=$?
494         local PKG_TIME_END=`date +%s`
495
496         if [ $COMPILE_SUCCESS -ne 0 ]; then
497                 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
498                 exiterror "Building $*";
499         else
500                 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
501         fi
502         return 0
503 }
504
505 update_logs() {
506         tar cfz log/ipfire-logs-`date +'%Y-%m-%d-%H:%M'`.tgz log/_build.*
507         rm -f log/_build.*
508 }
509
510 batch_script() {
511         echo -ne "${BOLD}***This is our auto buildscript! Have fun...${NORMAL}\n"
512         update_logs
513         evaluate 1
514
515         if [ "$IPFIRE_REBUILD" -eq "0" ]; then
516                 export IPFIRE_START_TIME=`date`
517
518                 $0 clean
519                 evaluate 1
520
521                 $0 git update --force
522                 evaluate 1 mail_me UPDATE
523
524                 echo "### EXPORT SOURCES"
525                 $0 git dist
526                 evaluate 1 mail_me DIST
527         fi
528
529         echo "### RUNNING BUILD"
530         $0 build
531         evaluate 1 mail_me ERROR
532
533         echo "### UPLOADING ISO"
534         $0 upload iso
535         evaluate 1 mail_me ISO
536         
537         echo -ne "### UPLOADING PAKS"
538         $0 upload paks
539         evaluate 1 mail_me PAKS
540
541         echo -ne "${BOLD}***SUCCESS!${NORMAL}"
542         mail_me success
543         exit 0
544 }
545
546 watch_screen() {
547         echo -e "${BOLD}Exit with Ctrl+A, Ctrl+D.${NORMAL}"
548         sleep 0.5
549         screen -x ipfire
550 }
551
552 mail_me() {
553         echo "From: $MAIL_FROM" > /tmp/ipfire_mail_body.$$
554         echo "To: $MAIL_TO" >> /tmp/ipfire_mail_body.$$
555         case "$1" in
556                 success)
557                         cat <<END >> /tmp/ipfire_mail_body.$$
558 Subject: SUCCESS: IPFIRE-BUILD on `hostname`
559 Building IPFire on `hostname` was successfull!
560 You can find the ISO on your ftp server if you told the script where it is.
561
562 Statistics:
563 -----------
564 Started:        $IPFIRE_START_TIME
565 Finished:       `date`
566
567 Best Regards
568 Your IPFire-Build-Script
569
570 END
571                 echo -ne "${BOLD}***Sending success message${NORMAL}"
572                 ;;
573                 *)
574                         cat <<END >> /tmp/ipfire_mail_body.$$
575 Subject: ERROR $1: IPFIRE-BUILD on `hostname`
576 When I was building IPFire on `hostname`, I have found an ERROR with name $1!
577 Here you can see the logs and detect the reason for this error.
578
579 Best Regards
580 Your IPFire-Build-Script
581
582
583 Here is a summary... The full logs are in the attachment.
584 ---------------------------------------------------------
585
586 `tail log/_*`
587 END
588                 echo -ne "${BOLD}***Sending error message${NORMAL}"
589                 ;;
590         esac
591
592 sleep 15
593         python tools/sendEmail < /tmp/ipfire_mail_body.$$
594         if [ "$?" -eq "0" ]; then
595                 beautify message DONE
596         else
597                 beautify message FAIL
598         fi
599         rm -f /tmp/ipfire_mail_body.$$
600 }
601
602 make_config() {
603         clear
604         echo -e "${BOLD}***This will create your configuration...${NORMAL}"
605         echo -ne "***If your are ready press <ENTER>!"
606         read
607         clear
608         echo -ne "***The buildscript will create a full iso image.\n"
609         echo -ne "***If you want to skip any package please enter its name here seperated with space.\n"
610         echo -ne "Actually in the list are: $SKIP_PACKAGE_LIST\n"
611         echo -ne "Do you want to change this? (y/N) "
612         read YESNO
613         if [ "$YESNO" == "y" ]; then
614                 echo -ne "Please type: "
615                 read SKIP_PACKAGE_LIST
616                 echo -ne "You entered: $SKIP_PACKAGE_LIST\n"
617         fi
618
619         clear
620         echo -ne "***When you have compiled successfully, there is the possibility\n"
621         echo -ne "***to upload the iso image to a ftp server.\n"
622         echo -ne "***If the url is empty there will be no upload.\n"
623         echo -ne "Actually there is: $FTP_ISO_URL\n"
624         echo -ne "Do you want to change this? (y/N) "
625         read YESNO
626         if [ "$YESNO" == "y" ]; then
627                 echo -ne "Please type the url: "
628                 read FTP_ISO_URL
629                 echo -ne "Please type the path: "
630                 read FTP_ISO_PATH
631                 echo -ne "Please type the username: "
632                 read FTP_ISO_USER
633                 echo -ne "Please type the password (hidden): "
634                 read -s FTP_ISO_PASS
635                 
636         fi
637
638         clear
639         echo -ne "***When you add some new software you can easyly\n"
640         echo -ne "***upload the source code to our repository server.\n"
641         echo -ne "***If the url is empty there will be no upload.\n"
642         echo -ne "Actually there is: $FTP_CACHE_URL\n"
643         echo -ne "Do you want to change this? (y/N) "
644         read YESNO
645         if [ "$YESNO" == "y" ]; then
646                 echo -ne "Please type the url: "
647                 read FTP_CACHE_URL
648                 echo -ne "Please type the path: "
649                 read FTP_CACHE_PATH
650                 echo -ne "Please type the username: "
651                 read FTP_CACHE_USER
652                 echo -ne "Please type the password (hidden): "
653                 read -s FTP_CACHE_PASS
654                 
655         fi
656
657         clear
658         echo -ne "***If there are some important messages you\n"
659         echo -ne "***can get a notification mail.\n"
660         echo -ne "***Please type one ore more email adresses (seperated by comma).\n"
661         echo -ne "Actually there is: $MAIL_TO\n"
662         echo -ne "Do you want to change this? (y/N) "
663         read YESNO
664         if [ "$YESNO" == "y" ]; then
665                 echo -ne "Please type: "
666                 read MAIL_TO
667                 echo -ne "You should enter a mail server to login...\n"
668                 echo -ne "Please type the url: "
669                 read MAIL_SERVER
670                 echo -ne "Please type where the email is from: "
671                 read MAIL_FROM
672                 echo -ne "Please type the username: "
673                 read MAIL_USER
674                 echo -ne "Please type the password (hidden): "
675                 read -s MAIL_PASS
676                 
677         fi
678         echo -ne "\n${BOLD}***Saving...${NORMAL}"
679         cat <<END > $BASEDIR/.config
680 ### iso server
681 FTP_ISO_URL=$FTP_ISO_URL
682 FTP_ISO_PATH=$FTP_ISO_PATH
683 FTP_ISO_USER=$FTP_ISO_USER
684 FTP_ISO_PASS=$FTP_ISO_PASS
685 ### cache server
686 FTP_CACHE_URL=$FTP_CACHE_URL
687 FTP_CACHE_PATH=$FTP_CACHE_PATH
688 FTP_CACHE_USER=$FTP_CACHE_USER
689 FTP_CACHE_PASS=$FTP_CACHE_PASS
690 ### mail reports
691 MAIL_TO="$MAIL_TO"
692 MAIL_FROM=$MAIL_FROM
693 MAIL_SERVER=$MAIL_SERVER
694 MAIL_USER=$MAIL_USER
695 MAIL_PASS=$MAIL_PASS
696 ### misc
697 SKIP_PACKAGE_LIST="$SKIP_PACKAGE_LIST"
698 END
699         beautify message DONE
700 }
701
702 compile_tftpd() {
703         mkdir $BASEDIR/tmp
704         tar xvfz $BASEDIR/cache/tftp-hpa-0.42.tar.gz -C $BASEDIR/tmp
705         cd $BASEDIR/tmp/tftp-hpa-*
706                 ./configure --prefix=/ipfire/trunk/tools/ \
707                         --sbindir=/ipfire/trunk/tools/ --disable-nls
708                 make
709                 install -c tftpd/tftpd $BASEDIR/tools/in.tftpd
710         cd -
711         rm -rf $BASEDIR/tmp/tftp-hpa-*
712 }
713
714 start_tftpd() {
715         if [ ! -e $BASEDIR/tools/in.tftpd ]; then
716                 compile_tftpd
717         fi
718         reload_tftpd
719         if [ "$?" == "0" ]; then
720                 $BASEDIR/tools/in.tftpd -l -s $BASEDIR/tftpboot
721                 beautify message DONE
722         else
723                 echo -en "You don not have a pxe boot image in your base directory.\nPlease compile first."
724                 beautify message FAIL
725                 exit 1
726         fi
727 }
728
729 stop_tftpd() {
730         echo -n "Stopping TFTPD..."
731         killall in.tftpd >/dev/null 2>&1
732         sleep 3
733         killall -9 in.tftp >/dev/null 2>&1
734         beautify message DONE
735 }
736
737 reload_tftpd() {
738         if [ -e $BASEDIR/ipfire-$VERSION.$MACHINE-pxe.tgz ]; then
739                 mkdir -p $BASEDIR/tftpboot
740                 tar xfz $BASEDIR/ipfire-$VERSION.$MACHINE-pxe.tgz -C $BASEDIR/tftpboot
741                 return 0
742         fi
743         return 1
744 }
745
746 update_langs() {
747                 echo -ne "Checking the translations for missing or obsolete strings..."
748                 chmod 755 $BASEDIR/tools/{check_strings.pl,sort_strings.pl,check_langs.sh}
749                 $BASEDIR/tools/sort_strings.pl en
750                 $BASEDIR/tools/sort_strings.pl de
751                 $BASEDIR/tools/sort_strings.pl fr
752                 $BASEDIR/tools/sort_strings.pl es
753                 $BASEDIR/tools/sort_strings.pl pl
754                 $BASEDIR/tools/sort_strings.pl ru
755                 $BASEDIR/tools/check_strings.pl en > $BASEDIR/doc/language_issues.en
756                 $BASEDIR/tools/check_strings.pl de > $BASEDIR/doc/language_issues.de
757                 $BASEDIR/tools/check_strings.pl fr > $BASEDIR/doc/language_issues.fr
758                 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.es
759                 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.pl
760                 $BASEDIR/tools/check_strings.pl ru > $BASEDIR/doc/language_issues.ru
761                 $BASEDIR/tools/check_langs.sh > $BASEDIR/doc/language_missings
762                 beautify message DONE
763 }