GeƤndert:
[ipfire-2.x.git] / make.sh
1 #!/bin/bash
2 #
3 ############################################################################
4 #                                                                          #
5 # This file is part of the IPFire Firewall.                                #
6 #                                                                          #
7 # IPFire 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 2 of the License, or        #
10 # (at your option) any later version.                                      #
11 #                                                                          #
12 # IPFire 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 IPFire; if not, write to the Free Software                    #
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA #
20 #                                                                          #
21 # Copyright (C) 2006 IPFire-Team <entwickler@ipfire.org>.                  #
22 #                                                                          #
23 ############################################################################
24 #
25
26   NAME="IPFire"                 # Software name
27   SNAME="ipfire"                        # Short name
28   VERSION="2.0"                 # Version number
29   SLOGAN="www.ipfire.org"               # Software slogan
30   CONFIG_ROOT=/var/ipfire               # Configuration rootdir
31   NICE=10
32   MAX_RETRIES=3                 # prefetch/check loop
33   KVER=`grep --max-count=1 VER lfs/linux | awk '{ print $3 }'`
34   MACHINE=`uname -m`
35   SVN_REVISION=`svn info | grep Revision | cut -c 11-`
36
37   # Setzen des IPFire Builds
38   if [ -e ./.svn ]; then
39     FIREBUILD=`cat .svn/entries |sed -n 's/^[ \t]*revision=\"// p' | sed -n 's/\".*$// p'`
40   fi
41
42   # Debian specific settings
43   if [ ! -e /etc/debian_version ]; then
44         FULLPATH=`which $0`
45   else
46         if [ -x /usr/bin/realpath ]; then
47                 FULLPATH=`/usr/bin/realpath $0`
48         else
49                 echo "ERROR: Need to do apt-get install realpath"
50                 exit 1
51         fi
52   fi
53
54   PWD=`pwd`
55   BASENAME=`basename $0`
56   BASEDIR=`echo $FULLPATH | sed "s/\/$BASENAME//g"`
57   LOGFILE=$BASEDIR/log/_build.preparation.log
58   export BASEDIR LOGFILE
59   DIR_CHK=$BASEDIR/cache/check
60   mkdir $BASEDIR/log/ 2>/dev/null
61
62   if [ -f .config ]; then
63         . .config
64   fi
65
66   if [ 'x86_64' = $MACHINE -o 'i686' = $MACHINE -o 'i586' = $MACHINE -o 'i486' = $MACHINE -o 'i386' = $MACHINE ]; then
67         echo "`date -u '+%b %e %T'`: Machine is ix86 (or equivalent)" >> $LOGFILE
68         MACHINE=i386
69         BUILDTARGET=i386-pc-linux-gnu
70         CFLAGS="-O2 -mcpu=i386 -march=i386 -pipe -fomit-frame-pointer"
71         CXXFLAGS="-O2 -mcpu=i386 -march=i386 -pipe -fomit-frame-pointer"
72   elif [ 'alpha' = $MACHINE ]; then
73         echo "`date -u '+%b %e %T'`: Machine is Alpha AXP" >> $LOGFILE
74         BUILDTARGET=alpha-unknown-linux-gnu
75         CFLAGS="-O2 -mcpu=ev4 -mieee -pipe"
76         CXXFLAGS="-O2 -mcpu=ev4 -mieee -pipe"
77   else
78         echo "`date -u '+%b %e %T'`: Can't determine your architecture - $MACHINE" >> $LOGFILE
79         exit 1
80   fi
81
82 # Define immediately
83 stdumount() {
84         umount $BASEDIR/build/dev/pts           2>/dev/null;
85         umount $BASEDIR/build/proc                      2>/dev/null;
86         umount $BASEDIR/build/install/mnt               2>/dev/null;
87         umount $BASEDIR/build/usr/src/cache     2>/dev/null;
88         umount $BASEDIR/build/usr/src/ccache    2>/dev/null;
89         umount $BASEDIR/build/usr/src/config    2>/dev/null;
90         umount $BASEDIR/build/usr/src/doc               2>/dev/null;
91         umount $BASEDIR/build/usr/src/html              2>/dev/null;
92         umount $BASEDIR/build/usr/src/langs     2>/dev/null;
93         umount $BASEDIR/build/usr/src/lfs               2>/dev/null;
94         umount $BASEDIR/build/usr/src/log               2>/dev/null;
95         umount $BASEDIR/build/usr/src/src               2>/dev/null;
96 }
97
98 exiterror() {
99         stdumount
100         for i in `seq 0 7`; do
101             if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then
102                 losetup -d /dev/loop${i} 2>/dev/null
103             fi;
104         done
105         echo "ERROR: $*"
106         echo "       Check $LOGFILE for errors if applicable"
107         exit 1
108 }
109
110 entershell() {
111         if [ ! -e $BASEDIR/build/usr/src/lfs/ ]; then
112                 exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/"
113         fi
114         echo "Entering to a shell inside LFS chroot, go out with exit"
115         chroot $LFS /tools/bin/env -i HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
116                 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
117                 VERSION=$VERSION CONFIG_ROOT=$CONFIG_ROOT \
118                 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
119                 CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" \
120                 CCACHE_DIR=/usr/src/ccache \
121                 CCACHE_HASHDIR=1 \
122                 KVER=$KVER \
123                 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
124                 KGCC="ccache /usr/bin/gcc" \
125                 /tools/bin/bash
126         if [ $? -ne 0 ]; then
127                         exiterror "chroot error"
128         else
129                 stdumount
130         fi
131 }
132
133 prepareenv() {
134     ############################################################################
135     #                                                                          #
136     # Are we running the right shell?                                          #
137     #                                                                          #
138     ############################################################################
139     if [ ! "$BASH" ]; then
140         exiterror "BASH environment variable is not set.  You're probably running the wrong shell."
141     fi
142
143     if [ -z "${BASH_VERSION}" ]; then
144         exiterror "Not running BASH shell."
145     fi
146
147
148     ############################################################################
149     #                                                                          #
150     # Trap on emergency exit                                                   #
151     #                                                                          #
152     ############################################################################
153     trap "exiterror 'Build process interrupted'" SIGINT SIGTERM SIGKILL SIGSTOP SIGQUIT
154
155
156     ############################################################################
157     #                                                                          #
158     # Resetting our nice level                                                 #
159     #                                                                          #
160     ############################################################################
161     echo "`date -u '+%b %e %T'`: Resetting our nice level to $NICE" | tee -a $LOGFILE
162     renice $NICE $$ > /dev/null
163     if [ `nice` != "$NICE" ]; then
164         exiterror "Failed to set correct nice level"
165     fi
166
167     ############################################################################
168     #                                                                          #
169     # Checking if running as root user                                         #
170     #                                                                          #
171     ############################################################################
172     echo "`date -u '+%b %e %T'`: Checking if we're running as root user" | tee -a $LOGFILE
173     if [ `id -u` != 0 ]; then
174         exiterror "Not building as root"
175     fi
176
177
178     ############################################################################
179     #                                                                          #
180     # Checking for necessary temporary space                                   #
181     #                                                                          #
182     ############################################################################
183     echo "`date -u '+%b %e %T'`: Checking for necessary space on disk $BASE_DEV" | tee -a $LOGFILE
184     BASE_DEV=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $1 }'`
185     BASE_ASPACE=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $4 }'`
186     if (( 2202000 > $BASE_ASPACE )); then
187         BASE_USPACE=`du -skx $BASEDIR | awk '{print $1}'`
188         if (( 2202000 - $BASE_USPACE > $BASE_ASPACE )); then
189                 exiterror "Not enough temporary space available, need at least 2.1GB on $BASE_DEV"
190         fi
191     fi
192
193     ############################################################################
194     #                                                                          #
195     # Building Linux From Scratch system                                       #
196     #                                                                          #
197     ############################################################################
198     echo "`date -u '+%b %e %T'`: Building Linux From Scratch system" | tee -a $LOGFILE
199
200     # Set umask
201     umask 022
202
203     # Set LFS Directory
204     LFS=$BASEDIR/build
205
206     # Check /tools symlink
207     if [ -h /tools ]; then
208         rm -f /tools
209     fi
210     if [ ! -a /tools ]; then
211         ln -s $BASEDIR/build/tools /
212     fi
213     if [ ! -h /tools ]; then
214         exiterror "Could not create /tools symbolic link."
215     fi
216
217     # Setup environment
218     set +h
219     LC_ALL=POSIX
220     export LFS LC_ALL CFLAGS CXXFLAGS
221     unset CC CXX CPP LD_LIBRARY_PATH LD_PRELOAD
222
223     # Make some extra directories
224     mkdir -p $BASEDIR/build/{tools,etc,usr/src} 2>/dev/null
225     mkdir -p $BASEDIR/{cache,ccache} 2>/dev/null
226     mkdir -p $BASEDIR/build/dev/pts $BASEDIR/build/proc $BASEDIR/build/usr/src/{cache,config,doc,html,langs,lfs,log,src,ccache}
227
228     # Make all sources and proc available under lfs build
229     mount --bind /dev/pts        $BASEDIR/build/dev/pts
230     mount --bind /proc           $BASEDIR/build/proc
231     mount --bind $BASEDIR/cache  $BASEDIR/build/usr/src/cache
232     mount --bind $BASEDIR/ccache $BASEDIR/build/usr/src/ccache
233     mount --bind $BASEDIR/config $BASEDIR/build/usr/src/config
234     mount --bind $BASEDIR/doc    $BASEDIR/build/usr/src/doc
235     mount --bind $BASEDIR/html   $BASEDIR/build/usr/src/html
236     mount --bind $BASEDIR/langs  $BASEDIR/build/usr/src/langs
237     mount --bind $BASEDIR/lfs    $BASEDIR/build/usr/src/lfs
238     mount --bind $BASEDIR/log    $BASEDIR/build/usr/src/log
239     mount --bind $BASEDIR/src    $BASEDIR/build/usr/src/src
240
241     # Run LFS static binary creation scripts one by one
242     export CCACHE_DIR=$BASEDIR/ccache
243     export CCACHE_HASHDIR=1
244
245     # Remove pre-install list of installed files in case user erase some files before rebuild
246     rm -f $BASEDIR/build/usr/src/lsalr 2>/dev/null
247 }
248
249
250 ############################################################################
251 #                                                                          #
252 # Necessary shell functions                                                #
253 #                                                                          #
254 ############################################################################
255 lfsmake1() {
256         if [ -f $BASEDIR/lfs/$1 ]; then
257                 echo "`date -u '+%b %e %T'`: Building $*" | tee -a $LOGFILE
258                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download  >> $LOGFILE 2>&1
259                 if [ $? -ne 0 ]; then
260                         exiterror "Download error in $1"
261                 fi
262                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t md5sum" md5  >> $LOGFILE 2>&1
263                 if [ $? -ne 0 ]; then
264                         exiterror "md5sum error in $1, check file in cache or signature"
265                 fi
266                 cd $BASEDIR/lfs && make -f $*   BUILDTARGET=$BUILDTARGET \
267                                                 MACHINE=$MACHINE \
268                                                 LFS_BASEDIR=$BASEDIR \
269                                                 ROOT=$LFS \
270                                                 KVER=$KVER \
271                                                 install >> $LOGFILE 2>&1
272                 if [ $? -ne 0 ]; then
273                         exiterror "Building $*";
274                 fi
275         else
276                 exiterror "No such file or directory: $BASEDIR/$1"
277         fi
278         return 0
279 }
280
281 lfsmake2() {
282         if [ -f $BASEDIR/build/usr/src/lfs/$1 ]; then
283                 echo "`date -u '+%b %e %T'`: Building $*" | tee -a $LOGFILE
284                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download  >> $LOGFILE 2>&1
285                 if [ $? -ne 0 ]; then
286                         exiterror "Download error in $1"
287                 fi
288                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t md5sum" md5  >> $LOGFILE 2>&1
289                 if [ $? -ne 0 ]; then
290                         exiterror "md5sum error in $1, check file in cache or signature"
291                 fi
292                 chroot $LFS /tools/bin/env -i   HOME=/root \
293                                                 TERM=$TERM PS1='\u:\w\$ ' \
294                                                 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
295                                                 VERSION=$VERSION \
296                                                 CONFIG_ROOT=$CONFIG_ROOT \
297                                                 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
298                                                 CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" \
299                                                 CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \
300                                                 KVER=$KVER \
301                                                 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
302                     /tools/bin/bash -x -c "cd /usr/src/lfs && \
303                     make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
304                 if [ $? -ne 0 ]; then
305                         exiterror "Building $*"
306                 fi
307         else
308                 exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/$1"
309         fi
310         return 0
311 }
312
313 ipcopmake() {
314         if [ -f $BASEDIR/build/usr/src/lfs/$1 ]; then
315                 echo "`date -u '+%b %e %T'`: Building $*" | tee -a $LOGFILE
316                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download  >> $LOGFILE 2>&1
317                 if [ $? -ne 0 ]; then
318                         exiterror "Download error in $1"
319                 fi
320                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t md5sum" md5  >> $LOGFILE 2>&1
321                 if [ $? -ne 0 ]; then
322                         exiterror "md5sum error in $1, check file in cache or signature"
323                 fi
324                 chroot $LFS /tools/bin/env -i   HOME=/root \
325                                                 TERM=$TERM PS1='\u:\w\$ ' \
326                                                 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
327                                                 VERSION=$VERSION \
328                                                 CONFIG_ROOT=$CONFIG_ROOT \
329                                                 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
330                                                 CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" \
331                                                 CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \
332                                                 KVER=$KVER \
333                                                 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
334                     /bin/bash -x -c "cd /usr/src/lfs && \
335                     make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
336                 if [ $? -ne 0 ]; then
337                         exiterror "Building $*"
338                 fi
339         else
340                 exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/$1"
341         fi
342         return 0
343 }
344
345 ipfiredist() {
346         if [ -f $BASEDIR/build/usr/src/lfs/$1 ]; then
347 #          if [ ! `ls -w1 $BASEDIR/packages/*.tar.gz | grep $1` ]; then
348                 echo "`date -u '+%b %e %T'`: Packaging $1" | tee -a $LOGFILE
349                 chroot $LFS /tools/bin/env -i   HOME=/root \
350                                                 TERM=$TERM PS1='\u:\w\$ ' \
351                                                 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
352                                                 VERSION=$VERSION \
353                                                 CONFIG_ROOT=$CONFIG_ROOT \
354                                                 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
355                                                 CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" \
356                                                 CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \
357                                                 KVER=$KVER \
358                                                 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
359                     /bin/bash -x -c "cd /usr/src/lfs && \
360                     make -f $1 LFS_BASEDIR=/usr/src dist" >>$LOGFILE 2>&1
361                 if [ $? -ne 0 ]; then
362                         exiterror "Packaging $1"
363                 fi
364 #          else
365 #               echo "`date -u '+%b %e %T'`: Packaging: The package $1 already exists"
366 #          fi
367         else
368                 exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/$1"
369         fi
370         return 0
371 }
372
373
374 installmake() {
375         if [ -f $BASEDIR/build/usr/src/lfs/$1 ]; then
376                 echo "`date -u '+%b %e %T'`: Building $*" | tee -a $LOGFILE
377                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download  >> $LOGFILE 2>&1
378                 if [ $? -ne 0 ]; then
379                         exiterror "Download error in $1"
380                 fi
381                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t md5sum" md5  >> $LOGFILE 2>&1
382                 if [ $? -ne 0 ]; then
383                         exiterror "md5sum error in $1, check file in cache or signature"
384                 fi
385                 chroot $LFS /tools/bin/env -i   HOME=/root \
386                                                 TERM=$TERM PS1='\u:\w\$ ' \
387                                                 PATH=/usr/local/bin:/opt/$MACHINE-uClibc/usr/bin:/bin:/usr/bin:/sbin:/usr/sbin \
388                                                 VERSION=$VERSION \
389                                                 CONFIG_ROOT=$CONFIG_ROOT \
390                                                 LFS_PASS="install" \
391                                                 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
392                                                 CFLAGS="-Os" CXXFLAGS="-Os" \
393                                                 CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \
394                                                 KVER=$KVER \
395                                                 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
396                     /bin/bash -x -c "cd /usr/src/lfs && \
397                     make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
398                 if [ $? -ne 0 ]; then
399                         exiterror "Building $*"
400                 fi
401         else
402                 exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/$1"
403         fi
404         return 0
405 }
406
407 buildtoolchain() {
408     LOGFILE="$BASEDIR/log/_build.toolchain.log"
409     export LOGFILE
410     echo -ne "`date -u '+%b %e %T'`: Stage1 toolchain build \n" | tee -a $LOGFILE
411     # Build sed now, as we use some extensions
412     ORG_PATH=$PATH
413     NATIVEGCC=`gcc --version | grep GCC | awk {'print $3'}`
414     export NATIVEGCC GCCmajor=${NATIVEGCC:0:1} GCCminor=${NATIVEGCC:2:1} GCCrelease=${NATIVEGCC:4:1}
415     lfsmake1 ccache
416     lfsmake1 sed        LFS_PASS=1
417     lfsmake1 m4         LFS_PASS=1
418     lfsmake1 bison      LFS_PASS=1
419     lfsmake1 flex       LFS_PASS=1
420     lfsmake1 binutils   LFS_PASS=1
421     lfsmake1 gcc        LFS_PASS=1
422     export PATH=$BASEDIR/build/usr/local/bin:$BASEDIR/build/tools/bin:$PATH
423     
424     lfsmake1 linux
425     lfsmake1 tcl
426     lfsmake1 expect
427     lfsmake1 glibc
428     lfsmake1 dejagnu
429     lfsmake1 gcc        LFS_PASS=2
430     lfsmake1 binutils   LFS_PASS=2
431     lfsmake1 gawk
432     lfsmake1 coreutils
433     lfsmake1 bzip2
434     lfsmake1 gzip
435     lfsmake1 diffutils
436     lfsmake1 findutils
437     lfsmake1 make
438     lfsmake1 grep
439     lfsmake1 sed        LFS_PASS=2
440     lfsmake1 m4         LFS_PASS=2
441     lfsmake1 bison      LFS_PASS=2
442     lfsmake1 flex       LFS_PASS=2
443     lfsmake1 gettext
444     lfsmake1 ncurses
445     lfsmake1 patch
446     lfsmake1 tar
447     lfsmake1 texinfo
448     lfsmake1 bash
449     lfsmake1 util-linux
450     lfsmake1 perl
451     export PATH=$ORG_PATH
452 }
453
454 buildbase() {
455     LOGFILE="$BASEDIR/log/_build.base.log"
456     export LOGFILE
457     echo -ne "`date -u '+%b %e %T'`: Stage2 linux base build \n" | tee -a $LOGFILE
458     # Run LFS dynamic binary creation scripts one by one
459     lfsmake2 stage2
460     lfsmake2 makedev
461     lfsmake2 linux
462     lfsmake2 man-pages
463     lfsmake2 glibc
464     lfsmake2 binutils
465     lfsmake2 gcc
466     lfsmake2 coreutils
467     lfsmake2 zlib
468     lfsmake2 mktemp
469     lfsmake2 iana-etc
470     lfsmake2 findutils
471     lfsmake2 gawk
472     lfsmake2 ncurses
473     lfsmake2 vim
474     lfsmake2 m4
475     lfsmake2 bison
476     lfsmake2 less
477     lfsmake2 groff
478     lfsmake2 sed
479     lfsmake2 flex
480     lfsmake2 gettext
481     lfsmake2 net-tools
482     lfsmake2 inetutils
483     lfsmake2 perl
484     lfsmake2 texinfo
485     lfsmake2 autoconf
486     lfsmake2 automake
487     lfsmake2 bash
488     lfsmake2 file
489     lfsmake2 libtool
490     lfsmake2 bzip2
491     lfsmake2 diffutils
492     lfsmake2 ed
493     lfsmake2 kbd
494     lfsmake2 e2fsprogs
495     lfsmake2 grep
496     if [ 'i386' = $MACHINE ]; then 
497         lfsmake2 grub
498     elif [ 'alpha' = $MACHINE ]; then 
499         lfsmake2 aboot
500     fi
501     lfsmake2 gzip
502     lfsmake2 man
503     lfsmake2 make
504     lfsmake2 modutils
505     lfsmake2 patch
506     lfsmake2 procinfo
507     lfsmake2 procps
508     lfsmake2 psmisc
509     lfsmake2 shadow
510     lfsmake2 sysklogd
511     lfsmake2 sysvinit
512     lfsmake2 tar
513     lfsmake2 util-linux
514 }
515
516 buildipcop() {
517   # Run IPFire make scripts one by one
518   LOGFILE="$BASEDIR/log/_build.ipfire.log"
519   export LOGFILE
520   echo -ne "`date -u '+%b %e %T'`: Stage3 $NAME build \n" | tee -a $LOGFILE
521
522   # Build these first as some of the kernel packages below rely on 
523   # these for some of their client program functionality 
524   ipcopmake configroot
525   ipcopmake dhcp
526   ipcopmake dhcpcd
527   ipcopmake libusb
528   ipcopmake libpcap
529   ipcopmake linux-atm
530   ipcopmake ppp
531   ipcopmake rp-pppoe
532   ipcopmake unzip
533   # Do SMP now
534   if [ 'i386' = $MACHINE ]; then 
535         # abuse the SMP flag, and make an minimal installer kernel first
536         # so that the boot floppy always works.....
537         ipcopmake linux         LFS_PASS=ipfire SMP=installer
538         ipcopmake linux         LFS_PASS=ipfire SMP=1
539         ipcopmake 3cp4218       SMP=1
540         ipcopmake amedyn        SMP=1
541         ipcopmake cxacru        SMP=1
542         ipcopmake eagle         SMP=1
543
544         # These are here because they have i386 only binary libraries
545         # included in the package.
546         ipcopmake cnx_pci       SMP=1
547         ipcopmake fcdsl         SMP=1
548         ipcopmake fcdsl2        SMP=1
549         ipcopmake fcdslsl       SMP=1
550         ipcopmake fcdslusb      SMP=1
551         ipcopmake fcdslslusb    SMP=1
552         ipcopmake fcpci SMP=1
553         ipcopmake fcclassic     SMP=1
554         ipcopmake pulsar        SMP=1
555         ipcopmake unicorn       SMP=1
556         ipcopmake promise-sata-300-tx SMP=1
557   fi
558
559   ipcopmake linux       LFS_PASS=ipfire
560   ipcopmake 3cp4218     
561   ipcopmake amedyn      
562   ipcopmake cxacru      
563   ipcopmake eciadsl     
564   ipcopmake eagle       
565   ipcopmake speedtouch  
566   if [ 'i386' = $MACHINE ]; then 
567         # These are here because they have i386 only binary libraries
568         # included in the package.
569         ipcopmake cnx_pci       
570         ipcopmake fcdsl         
571         ipcopmake fcdsl2        
572         ipcopmake fcdslsl       
573         ipcopmake fcdslusb      
574         ipcopmake fcdslslusb 
575         ipcopmake fcpci
576         ipcopmake fcclassic
577         ipcopmake pulsar        
578         ipcopmake unicorn
579         ipcopmake promise-sata-300-tx
580   fi
581
582   ipcopmake pcmcia-cs
583   ipcopmake expat
584   ipcopmake gdbm
585   ipcopmake gmp
586   ipcopmake openssl
587   ipcopmake python
588   ipcopmake libnet
589   ipcopmake libpng
590   ipcopmake gd
591   ipcopmake popt
592   ipcopmake slang
593   ipcopmake newt
594   ipcopmake libcap
595   ipcopmake pciutils
596   ipcopmake pcre
597   ipcopmake apache
598   ipcopmake arping
599   ipcopmake beep
600   ipcopmake bind
601   ipcopmake capi4k-utils
602   ipcopmake cdrtools
603   ipcopmake dnsmasq
604   ipcopmake dosfstools
605   ipcopmake ethtool
606   ipcopmake ez-ipupdate
607   ipcopmake fcron
608   ipcopmake perl-GD
609   ipcopmake gnupg
610   ipcopmake hdparm
611   ipcopmake ibod
612   ipcopmake initscripts
613   ipcopmake iptables
614   ipcopmake ipac-ng
615   ipcopmake ipaddr
616   ipcopmake iproute2
617   ipcopmake iptstate
618   ipcopmake iputils
619   ipcopmake l7-protocols
620   ipcopmake isapnptools
621   ipcopmake isdn4k-utils
622   ipcopmake kudzu
623   ipcopmake logrotate
624   ipcopmake logwatch
625   ipcopmake mingetty
626   ipcopmake misc-progs
627   ipcopmake mtools
628   ipcopmake nano
629   ipcopmake nash
630   ipcopmake nasm
631   ipcopmake URI
632   ipcopmake HTML-Tagset
633   ipcopmake HTML-Parser
634   ipcopmake Compress-Zlib
635   ipcopmake Digest
636   ipcopmake Digest-SHA1
637   ipcopmake Digest-HMAC
638   ipcopmake libwww-perl
639   ipcopmake Net-DNS
640   ipcopmake Net-IPv4Addr
641   ipcopmake Net_SSLeay
642   ipcopmake IO-Stringy
643   ipcopmake Unix-Syslog
644   ipcopmake Mail-Tools
645   ipcopmake MIME-Tools
646   ipcopmake Net-Server
647   ipcopmake Convert-TNEF
648   ipcopmake Convert-UUlib
649   ipcopmake Archive-Tar
650   ipcopmake Archive-Zip
651   ipcopmake Text-Tabs+Wrap
652   ipcopmake Locale-Country
653   ipcopmake GeoIP
654   ipcopmake fwhits
655   ipcopmake berkeley
656   ipcopmake BerkeleyDB ## The Perl module
657   ipcopmake noip_updater
658   ipcopmake ntp
659   ipcopmake oinkmaster
660   ipcopmake openssh
661   ipcopmake openswan
662   ipcopmake pptpclient
663   ipcopmake rrdtool
664   ipcopmake setserial
665   ipcopmake setup
666   ipcopmake snort
667   #ipcopmake speedycgi
668   ipcopmake saslauthd PASS=1
669   ipcopmake openldap
670   ipcopmake squid
671   ipcopmake squid-graph
672   ipcopmake squidguard
673   ipcopmake tcpdump
674   ipcopmake traceroute
675   ipcopmake vlan
676   #ipcopmake wireless
677   ipcopmake libsafe
678   ipcopmake 3c5x9setup
679 #  echo -ne "`date -u '+%b %e %T'`: Building ### IPFire modules ### \n" | tee -a $LOGFILE
680   ipcopmake pakfire
681   ipcopmake startscripts
682 ## Zuerst die Libs und dann die Programme. Ordnung muss sein!
683   ipcopmake java
684   ipcopmake libtiff
685   ipcopmake libjpeg
686   ipcopmake lcms
687   ipcopmake libmng
688   ipcopmake freetype
689   ipcopmake bootsplash
690   ipcopmake libxml2
691   ipcopmake spandsp
692   ipcopmake lzo
693   ipcopmake openvpn
694   ipcopmake pkg-config
695   ipcopmake glib
696   ipcopmake xampp
697   ipcopmake pam
698   ipcopmake pammysql
699   ipcopmake saslauthd PASS=2
700   ipcopmake xinetd
701   ipcopmake ghostscript
702   ipcopmake cups
703 #  ipcopmake lpd ## Im Moment aus, da CUPS vorhanden ist.
704   ipcopmake samba
705   ipcopmake sudo
706   ipcopmake mc
707 #  ipcopmake pwlib
708 #  ipcopmake openh323
709   ipcopmake wget
710   ipcopmake wput
711   ipcopmake bridge-utils
712   ipcopmake screen
713   ipcopmake hddtemp
714   ipcopmake smartmontools
715   ipcopmake htop
716   ipcopmake lynx
717   echo -ne "`date -u '+%b %e %T'`: Building ### Mailserver ### \n" | tee -a $LOGFILE
718   ipcopmake postfix
719   ipcopmake procmail
720   ipcopmake fetchmail
721   ipcopmake cyrusimap
722   ipcopmake web-cyradm
723   ipcopmake mailx
724   ipcopmake clamav
725   ipcopmake razor
726   ipcopmake spamassassin
727 #  ipcopmake amavisd
728   echo -ne "`date -u '+%b %e %T'`: Building ### VoIP-Server ### \n" | tee -a $LOGFILE
729   ipcopmake stund
730   ipcopmake zaptel
731   ipcopmake libpri
732   ipcopmake bristuff
733   ipcopmake asterisk
734   ipcopmake mpg123
735   echo -ne "`date -u '+%b %e %T'`: Building ### MP3-Server ### \n" | tee -a $LOGFILE
736   ipcopmake lame
737   ipcopmake gnump3d
738   echo -ne "`date -u '+%b %e %T'`: Building ### P2P-Clients ### \n" | tee -a $LOGFILE
739   ipcopmake applejuice
740   ipcopmake ocaml
741   ipcopmake mldonkey
742 #  ipcopmake edonkeyclc
743 #  ipcopmake sane
744   echo -ne "`date -u '+%b %e %T'`: Building ### Net-Tools ### \n" | tee -a $LOGFILE
745   ipcopmake ntop
746 #  ipcopmake rsync
747   ipcopmake tcpwrapper
748   ipcopmake portmap
749   ipcopmake nfs
750   ipcopmake nmap
751   ipcopmake mbmon
752   ipcopmake iftop
753   ipcopmake ncftp
754   ipcopmake cftp
755   ipcopmake etherwake
756   ipcopmake ethereal
757   ipcopmake tftp-hpa
758 #  ipcopmake stunnel # Ausgeschaltet, weil wir es doch nicht nutzen
759 }
760
761 buildinstaller() {
762   # Run installer scripts one by one
763   LOGFILE="$BASEDIR/log/_build.installer.log"
764   export LOGFILE
765   echo -ne "`date -u '+%b %e %T'`: Stage4 installer build \n" | tee -a $LOGFILE
766   if [ 'i386' = $MACHINE ]; then 
767         ipcopmake syslinux
768         ipcopmake as86
769         ipcopmake mbr
770         ipcopmake uClibc
771   fi
772   installmake busybox
773   installmake sysvinit
774   installmake e2fsprogs
775   installmake misc-progs
776   installmake slang
777   installmake util-linux
778   installmake newt
779   installmake pciutils
780   installmake pcmcia-cs
781   installmake kbd
782   installmake installer
783   installmake scsi.img
784   installmake driver.img
785   installmake initrd
786   installmake boot.img
787 }
788
789 buildpackages() {
790   LOGFILE="$BASEDIR/log/_build.packages.log"
791   export LOGFILE
792   echo "... see detailed log in _build.*.log files" >> $LOGFILE
793   echo -ne "`date -u '+%b %e %T'`: Stage5 packages build \n" | tee -a $LOGFILE
794   # Strip files
795   echo "`date -u '+%b %e %T'`: Stripping files" | tee -a $LOGFILE
796   find $LFS/lib $LFS/usr/lib $LFS/usr/share/rrdtool-* $LFS/install ! -type l \( -name '*.so' -o -name '*.so[\.0-9]*' \) \
797         ! -name 'libc.so' ! -name 'libpthread.so' ! -name 'libcrypto.so.0.9.7.sha1' \
798          -exec $LFS/tools/bin/strip --strip-all {} \; >> $LOGFILE 2>&1
799   # add -ls before -exec if you want to verify what files are stripped
800
801   find $LFS/{,s}bin $LFS/usr/{,s}bin $LFS/usr/local/{,s}bin ! -type l \
802         -exec file {} \; | grep " ELF " | cut -f1 -d ':' | xargs $LFS/tools/bin/strip --strip-all >> $LOGFILE 2>&1
803   # there add -v to strip to verify
804
805   if [ 'i386' = $MACHINE ]; then
806         # Create fcdsl packages
807         echo "`date -u '+%b %e %T'`: Building fcdsl tgz" | tee -a $LOGFILE
808         cp $LFS/install/images/fcdsl/license.txt $LFS  >> $LOGFILE 2>&1
809         touch $LFS/var/run/{need-depmod-$KVER,need-depmod-$KVER-smp}
810         cd $LFS && tar cvfz $LFS/install/images/$SNAME-fcdsl-$VERSION.$MACHINE.tgz \
811                 lib/modules/$KVER/misc/fcdsl*.o.gz \
812                 lib/modules/$KVER-smp/misc/fcdsl*.o.gz \
813                 usr/lib/isdn/{fds?base.bin,fd?ubase.frm} \
814                 etc/fcdsl/fcdsl*.conf \
815                 etc/drdsl/{drdsl,drdsl.ini} \
816                 license.txt \
817                 var/run/{need-depmod-$KVER,need-depmod-$KVER-smp} >> $LOGFILE 2>&1
818         rm -f $LFS/license.txt >> $LOGFILE 2>&1
819         cd $BASEDIR
820   fi
821   
822   # Generating list of packages used
823   echo "`date -u '+%b %e %T'`: Generating packages list from logs" | tee -a $LOGFILE
824   rm -f $BASEDIR/doc/packages-list
825   for i in `ls -1tr $BASEDIR/log/[^_]*`; do
826         if [ "$i" != "$BASEDIR/log/FILES" -a -n $i ]; then
827                 echo "  * `basename $i`" >>$BASEDIR/doc/packages-list
828         fi
829   done
830   echo "====== List of softwares used to build $NAME Version: $VERSION ======" > $BASEDIR/doc/packages-list.txt
831   grep -v 'configroot$\|img$\|initrd$\|initscripts$\|installer$\|install$\|ipfire$\|setup$\|pakfire$\|stage2$\|smp$\|tools$\|tools1$\|tools2$\|^ipfire-logs' \
832         $BASEDIR/doc/packages-list | sort >> $BASEDIR/doc/packages-list.txt
833   rm -f $BASEDIR/doc/packages-list
834   # packages-list.txt is ready to be displayed for wiki page
835
836   # Create ISO for CDRom and USB-superfloppy
837   ipcopmake cdrom
838   rm -f $LFS/install/images/*usb*
839   cp $LFS/install/images/{*.iso,*.tgz} $BASEDIR >> $LOGFILE 2>&1
840
841   ipfirepackages
842
843   # Cleanup
844   stdumount
845   rm -rf $BASEDIR/build/tmp/*
846
847   # Generating total list of files
848   echo "`date -u '+%b %e %T'`: Generating files list from logs" | tee -a $LOGFILE
849   rm -f $BASEDIR/log/FILES
850   for i in `ls -1tr $BASEDIR/log/[^_]*`; do
851         if [ "$i" != "$BASEDIR/log/FILES" -a -n $i ]; then
852                 echo "##" >>$BASEDIR/log/FILES
853                 echo "## `basename $i`" >>$BASEDIR/log/FILES
854                 echo "##" >>$BASEDIR/log/FILES
855                 cat $i | sed "s%^\./%#%" | sort >> $BASEDIR/log/FILES
856         fi
857   done
858
859   cd $PWD
860
861 }
862
863 ipfirepackages() {
864   if [ -d "$BASEDIR/packages" ]; then
865           for i in `ls $BASEDIR/packages`; do
866                 touch $BASEDIR/build/install/packages/$i.empty
867           done
868   fi
869   ipfiredist amavisd
870   ipfiredist applejuice
871   # ipfiredist asterisk
872   ipfiredist clamav
873   ipfiredist cups
874   ipfiredist cyrusimap
875   ipfiredist fetchmail
876   ipfiredist gnump3d
877   ipfiredist java
878   ipfiredist lame
879   ipfiredist libtiff
880   ipfiredist libxml2
881   ipfiredist mailx
882   ipfiredist mldonkey
883   ipfiredist nfs
884   ipfiredist nmap
885   ipfiredist ntop
886   ipfiredist postfix
887   ipfiredist procmail
888   ipfiredist samba
889   ipfiredist spamassassin
890   ipfiredist web-cyradm
891   ipfiredist xampp
892 #  ipfiredist xinetd
893   test -d $BASEDIR/packages || mkdir $BASEDIR/packages
894   mv -f $LFS/install/packages/*.{tar.gz,md5} $BASEDIR/packages >> $LOGFILE 2>&1
895   rm -rf  $BASEDIR/build/install/packages/*
896 }
897
898 update_logs() {
899         tar cfz log/ipfire-logs-`date +'%Y-%m-%d-%H:%M'`.tgz log/_build.*
900         rm -f log/_build.*
901 }
902
903 # See what we're supposed to do
904 case "$1" in 
905 build)
906         BUILDMACHINE=`uname -m`
907         PACKAGE=`ls -v -r $BASEDIR/cache/toolchains/$SNAME-$VERSION-toolchain-$BUILDMACHINE.tar.gz 2> /dev/null | head -n 1`
908         #only restore on a clean disk
909         if [ ! -f log/perl-*-tools ]; then
910                 if [ ! -n "$PACKAGE" ]; then
911                         echo "`date -u '+%b %e %T'`: Full toolchain compilation" | tee -a $LOGFILE
912                         prepareenv
913                         buildtoolchain
914                 else
915                         PACKAGENAME=${PACKAGE%.tar.gz}
916                         echo "`date -u '+%b %e %T'`: Restore from $PACKAGE" | tee -a $LOGFILE
917                         if [ `md5sum $PACKAGE | awk '{print $1}'` == `cat $PACKAGENAME.md5 | awk '{print $1}'` ]; then
918                                 tar zxf $PACKAGE
919                                 prepareenv
920                         else
921                                 exiterror "$PACKAGENAME md5 did not match, check downloaded package"
922                         fi
923                 fi
924         else
925                 echo "`date -u '+%b %e %T'`: Using installed toolchain" | tee -a $LOGFILE
926                 prepareenv
927         fi
928
929         buildbase
930         buildipcop
931
932         # Setzen des IPFire Builds
933         if [ "$FIREBUILD" ]; then
934                 echo "$FIREBUILD" > $BASEDIR/build/var/ipfire/firebuild
935         else
936                 echo "_(OvO)_" > $BASEDIR/build/var/ipfire/firebuild
937         fi
938
939         buildinstaller
940         buildpackages
941         ;;
942 shell)
943         # enter a shell inside LFS chroot
944         # may be used to changed kernel settings
945         prepareenv
946         entershell
947         ;;
948 changelog)
949         echo -n "Loading new Changelog from SVN: "
950         svn log http://svn.ipfire.eu/svn/ipfire > doc/ChangeLog
951         echo "Finished!"
952         ;;
953 check)
954         echo "Checking sources files availability on the web"
955         if [ ! -d $DIR_CHK ]; then
956                 mkdir -p $DIR_CHK
957         fi
958         FINISHED=0
959         cd $BASEDIR/lfs
960         for c in `seq $MAX_RETRIES`; do
961                 if (( FINISHED==1 )); then
962                         break
963                 fi
964                 FINISHED=1
965                 cd $BASEDIR/lfs
966                 for i in *; do
967                         if [ -f "$i" -a "$i" != "Config" ]; then
968                                 make -s -f $i MACHINE=$MACHINE LFS_BASEDIR=$BASEDIR ROOT=$BASEDIR/build \
969                                         MESSAGE="$i\t ($c/$MAX_RETRIES)" check
970                                 if [ $? -ne 0 ]; then
971                                         echo "Check : wget error in lfs/$i"
972                                         FINISHED=0
973                                 fi
974                         fi
975                 done
976         done
977         cd -
978         ;;
979 checkclean)
980         echo "Erasing sources files availability tags"
981         rm -rf $DIR_CHK/*
982         ;;
983 clean)
984         for i in `mount | grep $BASEDIR | sed 's/^.*loop=\(.*\))/\1/'`; do
985                 $LOSETUP -d $i 2>/dev/null
986         done
987         for i in `mount | grep $BASEDIR | cut -d " " -f 1`; do
988                 umount $i
989         done
990         stdumount
991         for i in `seq 0 7`; do
992             if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then
993                 umount /dev/loop${i}     2>/dev/null;
994                 losetup -d /dev/loop${i} 2>/dev/null;
995             fi;
996         done
997         rm -rf $BASEDIR/build
998         rm -rf $BASEDIR/cdrom
999         rm -rf $BASEDIR/packages
1000         rm -rf $BASEDIR/log
1001         if [ -h /tools ]; then
1002                 rm -f /tools
1003         fi
1004         ;;
1005 newpak)
1006         # create structure for a new package
1007         echo -e "Name of the new package: $2"
1008         if [ ! -f "lfs/$2" ]; then
1009                 echo "`date -u '+%b %e %T'`: Creating directory src/paks/$2"
1010                 mkdir -p src/paks/$2
1011                 cd src/paks/$2
1012                 echo "`date -u '+%b %e %T'`: Creating files"
1013                 cp $BASEDIR/lfs/postfix $BASEDIR/lfs/$2
1014
1015                 touch ROOTFILES
1016                 touch {,un}install.sh
1017         ## install.sh
1018                 echo '#!/bin/bash' > install.sh
1019                 echo '#' >> install.sh
1020                 echo '#################################################################' >> install.sh
1021                 echo '#                                                               #' >> install.sh
1022                 echo '# This file belongs to IPFire Firewall - GPLv2 - www.ipfire.org #' >> install.sh
1023                 echo '#                                                               #' >> install.sh
1024                 echo '#################################################################' >> install.sh
1025                 echo '#' >> install.sh
1026                 echo '# Extract the files' >> install.sh
1027                 echo 'tar xfz files.tgz -C /' >> install.sh
1028                 echo 'cp -f ROOTFILES /opt/pakfire/installed/ROOTFILES.$2' >> install.sh
1029         ## uninstall.sh
1030                 echo '#!/bin/bash' > uninstall.sh
1031                 echo '#################################################################' >> uninstall.sh
1032                 echo '#                                                               #' >> uninstall.sh
1033                 echo '# This file belongs to IPFire Firewall - GPLv2 - www.ipfire.org #' >> uninstall.sh
1034                 echo '#                                                               #' >> uninstall.sh
1035                 echo '#################################################################' >> uninstall.sh
1036                 echo '#' >> uninstall.sh
1037                 echo '# Delete the files' >> uninstall.sh
1038                 echo '## Befehl fehlt noch' >> uninstall.sh
1039                 echo 'rm -f /opt/pakfire/installed/ROOTFILES.$2' >> uninstall.sh
1040                 echo "`date -u '+%b %e %T'`: Adding files to SVN"
1041                 cd - && svn add lfs/$2 && svn add src/paks/$2
1042
1043                 echo -n "Do you want to remove the folders? [y/n]"
1044                 read REM
1045                 if  [ "$REM" == "y" ]; then
1046                         echo "Removing the folders..."
1047                         svn del src/paks/$2 --force
1048                 else
1049                         echo "Folders are kept."
1050                 fi
1051         else
1052                 echo "$2 already exists"
1053         fi
1054         exit 0
1055         ;;
1056 prefetch)
1057         if [ ! -d $BASEDIR/cache ]; then
1058                 mkdir $BASEDIR/cache
1059         fi
1060         mkdir -p $BASEDIR/log
1061         echo "`date -u '+%b %e %T'`:Preload all source files" | tee -a $LOGFILE
1062         FINISHED=0
1063         cd $BASEDIR/lfs
1064         for c in `seq $MAX_RETRIES`; do
1065                 if (( FINISHED==1 )); then 
1066                         break
1067                 fi
1068                 FINISHED=1
1069                 cd $BASEDIR/lfs
1070                 for i in *; do
1071                         if [ -f "$i" -a "$i" != "Config" ]; then
1072                                 make -s -f $i LFS_BASEDIR=$BASEDIR MESSAGE="$i\t ($c/$MAX_RETRIES)" download >> $LOGFILE 2>&1
1073                                 if [ $? -ne 0 ]; then
1074                                         echo "Prefetch : wget error in lfs/$i"
1075                                         FINISHED=0
1076                                 else
1077                                         if [ $c -eq 1 ]; then
1078                                                 echo "Prefetch : lfs/$i files loaded"
1079                                         fi
1080                                 fi
1081                         fi
1082                 done
1083         done
1084         echo "Prefetch : verifying md5sum"
1085         ERROR=0
1086         for i in *; do
1087                 if [ -f "$i" -a "$i" != "Config" ]; then
1088                         make -s -f $i LFS_BASEDIR=$BASEDIR MESSAGE="$i\t " md5 >> $LOGFILE 2>&1
1089                         if [ $? -ne 0 ]; then
1090                                 echo "md5 difference in lfs/$i"
1091                                 ERROR=1
1092                         fi
1093                 fi
1094         done
1095         if [ $ERROR -eq 0 ]; then
1096                 echo "Prefetch : all files md5sum match"
1097         fi
1098         cd -
1099         ;;
1100 toolchain)
1101         prepareenv
1102         buildtoolchain
1103         BUILDMACHINE=`uname -m`
1104         echo "`date -u '+%b %e %T'`: Create toolchain tar.gz for $BUILDMACHINE" | tee -a $LOGFILE
1105         test -d $BASEDIR/cache/toolchains || mkdir $BASEDIR/cache/toolchains
1106         cd $BASEDIR && tar -zc --exclude='log/_build.*.log' -f cache/toolchains/$SNAME-$VERSION-toolchain-$BUILDMACHINE.tar.gz \
1107                 build/{bin,etc,usr/bin,usr/local} \
1108                 build/tools/{bin,etc,*-linux-gnu,include,lib,libexec,sbin,share,var} \
1109                 log >> $LOGFILE
1110         md5sum cache/toolchains/$SNAME-$VERSION-toolchain-$BUILDMACHINE.tar.gz \
1111                 > cache/toolchains/$SNAME-$VERSION-toolchain-$BUILDMACHINE.md5
1112         stdumount
1113         ;;
1114 gettoolchain)
1115         BUILDMACHINE=`uname -m`
1116         # arbitrary name to be updated in case of new toolchain package upload
1117         PACKAGE=$SNAME-$VERSION-toolchain-$BUILDMACHINE
1118         if [ ! -f $BASEDIR/cache/toolchains/$PACKAGE.tar.gz ]; then
1119                 URL_IPFIRE=`grep URL_IPFIRE lfs/Config | awk '{ print $3 }'`
1120                 test -d $BASEDIR/cache/toolchains || mkdir $BASEDIR/cache/toolchains
1121                 echo "`date -u '+%b %e %T'`: Load toolchain tar.gz for $BUILDMACHINE" | tee -a $LOGFILE
1122                 cd $BASEDIR/cache/toolchains
1123                 wget $URL_IPFIRE/toolchains/$PACKAGE.tar.gz $URL_IPFIRE/toolchains/$PACKAGE.md5 >& /dev/null
1124                 if [ $? -ne 0 ]; then
1125                         echo "`date -u '+%b %e %T'`: error downloading toolchain for $BUILDMACHINE machine" | tee -a $LOGFILE
1126                 else
1127                         if [ "`md5sum $PACKAGE.tar.gz | awk '{print $1}'`" = "`cat $PACKAGE.md5 | awk '{print $1}'`" ]; then
1128                                 echo "`date -u '+%b %e %T'`: toolchain md5 ok" | tee -a $LOGFILE
1129                         else
1130                                 exiterror "$PACKAGE.md5 did not match, check downloaded package"
1131                         fi
1132                 fi
1133         else
1134                 echo "Toolchain is already downloaded. Exiting..."
1135         fi
1136         ;;
1137 svn)
1138         case "$2" in
1139           update|up)
1140                 # clear
1141                 echo -n "Load the latest source files..."
1142                 svn update >> $PWD/log/_build.svn.update.log
1143                 if [ $? -eq 0 ]; then
1144                         echo ".Done!"
1145                 else
1146                         echo ".Fail!"
1147                         exit 1
1148                 fi
1149                 echo -n "Write the svn info to a file..."
1150                 svn info > $PWD/svn_status
1151                 if [ "$?" -eq "0" ]; then
1152                         echo ".Done!"
1153                 else
1154                         echo ".Fail!"
1155                         exit 1
1156                 fi
1157                 chmod 755 $0
1158                 exit 0
1159           ;;
1160           commit|ci)
1161                 clear
1162                 $0 changelog
1163                 echo "Upload the changed files..."
1164                 sleep 1
1165                 svn commit
1166                 $0 svn up
1167           ;;
1168           dist)
1169                 $0 svn up
1170                 echo -ne "Download source package from svn..."
1171                 svn export http://svn.ipfire.eu/svn/ipfire ipfire-source/ --force > /dev/null
1172                 if [ "$?" -eq "0" ]; then
1173                         echo ".Done!"
1174                 else
1175                         echo ".Fail!"
1176                         exit 1
1177                 fi
1178                 echo -n "Compress files..."
1179                 tar cfz ipfire-source-`date +'%Y-%m-%d'`-r`svn info | grep Revision | cut -c 11-`.tar.gz ipfire-source
1180                 if [ "$?" -eq "0" ]; then
1181                         echo ".Done!"
1182                 else
1183                         echo ".Fail!"
1184                         exit 1
1185                 fi
1186                 echo -n "Cleanup..."
1187                 rm ipfire-source/ -r
1188                 if [ "$?" -eq "0" ]; then
1189                         echo ".Done!"
1190                 else
1191                         echo ".Fail!"
1192                         exit 1
1193                 fi
1194           ;;
1195           diff)
1196                 echo -ne "Make a local diff to last svn revision..."
1197                 svn diff > ipfire-diff-`date +'%Y-%m-%d-%H:%M'`-r`svn info | grep Revision | cut -c 11-`.diff
1198                 if [ "$?" -eq "0" ]; then
1199                         echo ".Done!"
1200                 else
1201                         echo ".Fail!"
1202                         exit 1
1203                 fi
1204                 echo "Diff was successfully saved to ipfire-diff-`date +'%Y-%m-%d-%H:%M'`-r`svn info | grep Revision | cut -c 11-`.diff"
1205           ;;
1206         esac
1207         ;;
1208 make-config)
1209         echo -e "This is for creating your configuration..."
1210         echo -e "We will need some input:"
1211         echo -e ""
1212         echo -n "FTP-DOMAIN FOR THE ISO: "
1213         read IPFIRE_FTP_URL_EXT
1214         echo -n "PATH FOR $IPFIRE_FTP_URL_EXT: "
1215         read IPFIRE_FTP_PATH_EXT
1216         echo -n "USERNAME FOR $IPFIRE_FTP_URL_EXT: "
1217         read IPFIRE_FTP_USER_EXT
1218         echo -n "PASSWORD FOR $IPFIRE_FTP_URL_EXT: "
1219         read -s IPFIRE_FTP_PASS_EXT
1220         echo ""
1221         echo "(You can leave this empty if the cache-server is the same as your iso-server.)"
1222         echo -n "FTP-DOMAIN FOR THE CACHE: "
1223         read IPFIRE_FTP_URL_INT
1224         echo -n "PATH FOR $IPFIRE_FTP_URL_INT: "
1225         read IPFIRE_FTP_PATH_INT
1226         if [ $IPFIRE_FTP_URL_INT ]; then
1227                 echo -n "USERNAME FOR $IPFIRE_FTP_URL_INT: "
1228                 read IPFIRE_FTP_USER_INT
1229                 echo -n "PASSWORD FOR $IPFIRE_FTP_URL_INT: "
1230                 read -s IPFIRE_FTP_PASS_INT
1231         else
1232                 IPFIRE_FTP_URL_INT=$IPFIRE_FTP_URL_EXT
1233                 IPFIRE_FTP_USER_INT=$IPFIRE_FTP_USER_EXT
1234                 IPFIRE_FTP_PASS_INT=$IPFIRE_FTP_PASS_EXT
1235                 echo "USERNAME FOR $IPFIRE_FTP_URL_INT: $IPFIRE_FTP_USER_INT"
1236                 echo "PASSWORD FOR $IPFIRE_FTP_URL_INT: !HIDDEN!"
1237         fi
1238         echo ""
1239         echo "(You can leave this empty if the pak-server is the same as your iso-server.)"
1240         echo -n "FTP-DOMAIN FOR THE PAKS: "
1241         read IPFIRE_FTP_URL_PAK
1242         echo -n "PATH FOR $IPFIRE_FTP_URL_PAK: "
1243         read IPFIRE_FTP_PATH_PAK
1244         if [ $IPFIRE_FTP_URL_PAK ]; then
1245                 echo -n "USERNAME FOR $IPFIRE_FTP_URL_PAK: "
1246                 read IPFIRE_FTP_USER_PAK
1247                 echo -n "PASSWORD FOR $IPFIRE_FTP_URL_PAK: "
1248                 read -s IPFIRE_FTP_PASS_PAK
1249         else
1250                 IPFIRE_FTP_URL_PAK=$IPFIRE_FTP_URL_EXT
1251                 IPFIRE_FTP_USER_PAK=$IPFIRE_FTP_USER_EXT
1252                 IPFIRE_FTP_PASS_PAK=$IPFIRE_FTP_PASS_EXT
1253                 echo "USERNAME FOR $IPFIRE_FTP_URL_PAK: $IPFIRE_FTP_USER_PAK"
1254                 echo "PASSWORD FOR $IPFIRE_FTP_URL_PAK: !HIDDEN!"
1255         fi
1256         echo ""
1257         echo -e "ONE OR MORE EMAIL ADDRESS(ES) TO WHICH THE REPORTS WILL BE SENT"
1258         echo -e "(seperated by comma)"
1259         read IPFIRE_MAIL_REPORT
1260         echo -n "EMAIL FROM: "
1261         read IPFIRE_MAIL_FROM
1262         echo -n "EMAIL SERVER: "
1263         read IPFIRE_MAIL_SERVER
1264         echo -n "LOGIN TO MAIL SERVER: "
1265         read IPFIRE_MAIL_USER
1266         echo -n "MAIL PASSWORD: "
1267         read -s IPFIRE_MAIL_PASS
1268         echo -n "Saving..."
1269         for i in `seq 20`; do
1270                 sleep 0.1; echo -n "."
1271         done
1272         echo ".Finished!"
1273         cat <<END > .config
1274 ### ISO server
1275 IPFIRE_FTP_URL_EXT=$IPFIRE_FTP_URL_EXT
1276 IPFIRE_FTP_PATH_EXT=$IPFIRE_FTP_PATH_EXT
1277 IPFIRE_FTP_USER_EXT=$IPFIRE_FTP_USER_EXT
1278 IPFIRE_FTP_PASS_EXT=$IPFIRE_FTP_PASS_EXT
1279 ### cache server
1280 IPFIRE_FTP_URL_INT=$IPFIRE_FTP_URL_INT
1281 IPFIRE_FTP_PATH_INT=$IPFIRE_FTP_PATH_INT
1282 IPFIRE_FTP_USER_INT=$IPFIRE_FTP_USER_INT
1283 IPFIRE_FTP_PASS_INT=$IPFIRE_FTP_PASS_INT
1284 ### paks server
1285 IPFIRE_FTP_URL_PAK=$IPFIRE_FTP_URL_PAK
1286 IPFIRE_FTP_PATH_PAK=$IPFIRE_FTP_PATH_PAK
1287 IPFIRE_FTP_USER_PAK=$IPFIRE_FTP_USER_PAK
1288 IPFIRE_FTP_PASS_PAK=$IPFIRE_FTP_PASS_PAK
1289 ### mail reports
1290 IPFIRE_MAIL_REPORT=$IPFIRE_MAIL_REPORT
1291 IPFIRE_MAIL_FROM=$IPFIRE_MAIL_FROM
1292 IPFIRE_MAIL_SERVER=$IPFIRE_MAIL_SERVER
1293 IPFIRE_MAIL_USER=$IPFIRE_MAIL_USER
1294 IPFIRE_MAIL_PASS=$IPFIRE_MAIL_PASS
1295 END
1296         ;;
1297 sync)
1298         echo -e "Syncing cache to ftp:"
1299         rm -f doc/packages-to-remove-from-ftp
1300         ncftpls -u $IPFIRE_FTP_USER_INT -p $IPFIRE_FTP_PASS_INT ftp://$IPFIRE_FTP_URL_INT$IPFIRE_FTP_PATH_INT/ > ftplist
1301         for i in `ls -w1 cache/`; do
1302                 grep $i ftplist
1303                 if [ "$?" -ne "0" ]; then
1304                         ncftpput -u $IPFIRE_FTP_USER_INT -p $IPFIRE_FTP_PASS_INT $IPFIRE_FTP_URL_INT $IPFIRE_FTP_PATH_INT/ cache/$i
1305                         if [ "$?" -eq "0" ]; then
1306                                 echo -e "$i was successfully uploaded to the ftp server."
1307                         else
1308                                 echo -e "There was an error while uploading $i to the ftp server."
1309                         fi
1310                 fi
1311         done
1312         for i in `cat ftplist`; do
1313                 ls -w1 cache/ | grep $i
1314                 if [ "$?" -eq "1" ]; then
1315                         echo $i | grep -v toolchain >> doc/packages-to-remove-from-ftp
1316                 fi
1317         done
1318         rm -f ftplist
1319         ;;
1320 upload)
1321         case "$2" in
1322           iso)
1323                 echo -e "Uploading the iso to $IPFIRE_FTP_URL_EXT."
1324                 ncftpls -u $IPFIRE_FTP_USER_EXT -p $IPFIRE_FTP_PASS_EXT ftp://$IPFIRE_FTP_URL_EXT$IPFIRE_FTP_PATH_EXT/ | grep $SVN_REVISION
1325                 if [ "$?" -eq "1" ]; then
1326                                 cp $BASEDIR/ipfire-install-$VERSION.i386.iso $BASEDIR/ipfire-install-$VERSION.i386-r`svn info | grep Revision | cut -c 11-`.iso
1327                                 md5sum ipfire-install-$VERSION.i386-r$SVN_REVISION.iso > ipfire-install-$VERSION.i386-r$SVN_REVISION.iso.md5
1328                                 ncftpput -V -u $IPFIRE_FTP_USER_EXT -p $IPFIRE_FTP_PASS_EXT $IPFIRE_FTP_URL_EXT $IPFIRE_FTP_PATH_EXT/ ipfire-install-$VERSION.i386-r$SVN_REVISION.iso
1329                                 ncftpput -V -u $IPFIRE_FTP_USER_EXT -p $IPFIRE_FTP_PASS_EXT $IPFIRE_FTP_URL_EXT $IPFIRE_FTP_PATH_EXT/ ipfire-install-$VERSION.i386-r$SVN_REVISION.iso.md5
1330                                 ncftpput -V -u $IPFIRE_FTP_USER_EXT -p $IPFIRE_FTP_PASS_EXT $IPFIRE_FTP_URL_EXT $IPFIRE_FTP_PATH_EXT/ ipfire-source-*-r$SVN_REVISION.tar.gz
1331                                 if [ "$?" -eq "0" ]; then
1332                                         echo -e "The ISO of Revision $SVN_REVISION was successfully uploaded to the ftp server."
1333                                 else
1334                                         echo -e "There was an error while uploading the iso to the ftp server."
1335                                         exit 1
1336                                 fi
1337                 else
1338                         echo -e "File with name ipfire-install-$VERSION.i386-r$SVN_REVISION.iso already exists on the ftp server!"
1339                 fi
1340                 rm -f ipfire-install-$VERSION.i386-r$SVN_REVISION.iso{,.md5}
1341                 ;;
1342           paks)
1343                 ncftpput -z -u $IPFIRE_FTP_USER_PAK -p $IPFIRE_FTP_PASS_PAK $IPFIRE_FTP_URL_PAK $IPFIRE_FTP_PATH_PAK/ packages/*
1344                 if [ "$?" -eq "0" ]; then
1345                         echo -e "The packages were successfully uploaded to the ftp server."
1346                 else
1347                         echo -e "There was an error while uploading the packages to the ftp server."
1348                         exit 1
1349                 fi
1350           ;;
1351         esac
1352         ;;
1353 build-only)
1354         rm -f $BASEDIR/log/$2*
1355         BUILDMACHINE=`uname -m`
1356         prepareenv
1357         ipcopmake $2
1358         ;;
1359 build-silent)
1360         screen -dmS ipfire $0 build
1361         echo "Build started... This will take a while!"
1362         echo "You can see the status with 'screen -x ipfire'."
1363         ;;
1364 mail)
1365         chmod 755 tools/sendEmail
1366         ATTACHMENT=/tmp/ipfire-build-logs-R$SVN_REVISION.tar.gz
1367         if [ "$2" = "ERROR" ]; then
1368                 SUBJECT="ERROR: IPFIRE-BUILD R$SVN_REVISION on `hostname`"
1369                 echo "ERROR: $0 build!"
1370                 cat <<END > /tmp/ipfire_mail_body
1371 When I was building IPFire on `hostname`, I have found an ERROR!
1372 Here you can see the logs and detect the reason for this error.
1373
1374 Best Regards
1375 Your IPFire-Build-Script
1376 END
1377         fi
1378         if [ "$2" = "SUCCESS" ]; then
1379                 SUBJECT="SUCCESS: IPFIRE-BUILD R$SVN_REVISION on `hostname`"
1380                 cat <<END > /tmp/ipfire_mail_body
1381 Building IPFire on `hostname` in Revision $SVN_REVISION was successfull!
1382 You can find the ISO on your ftp server.
1383
1384 Statistics:
1385 -----------
1386 Started:        $IPFIRE_START_TIME
1387 Finished:       `date`
1388
1389 Best Regards
1390 Your IPFire-Build-Script
1391 END
1392         fi
1393         if [ "$2" = "SVNUPDATE" ]; then
1394                 SUBJECT="SVNUPDATE: IPFIRE-BUILD R$SVN_REVISION on `hostname`"
1395                 echo "ERROR: $0 svn up!"
1396                 cat <<END > /tmp/ipfire_mail_body
1397 When I was downloading the latest svn source,
1398 I have found an ERROR!
1399 Here you can see the logs and detect the reason for this error.
1400
1401 Best Regards
1402 Your IPFire-Build-Script
1403 END
1404         fi
1405
1406         if [ "$2" = "SVNDIST" ]; then
1407                 SUBJECT="SVNDIST: IPFIRE-BUILD R$SVN_REVISION on `hostname`"
1408                 echo "ERROR: $0 svn dist!"
1409                 cat <<END > /tmp/ipfire_mail_body
1410 When I was exporting the latest svn source,
1411 I have found an ERROR!
1412 Here you can see the logs and detect the reason for this error.
1413
1414 Best Regards
1415 Your IPFire-Build-Script
1416 END
1417         fi
1418
1419         if [ "$2" = "PREFETCH" ]; then
1420                 SUBJECT="PREFETCH: IPFIRE-BUILD R$SVN_REVISION on `hostname`"
1421                 echo "ERROR: $0 prefetch!"
1422                 cat <<END > /tmp/ipfire_mail_body
1423 When I was downloading the source packages,
1424 I have found an ERROR!
1425 Here you can see the logs and detect the reason for this error.
1426
1427 Best Regards
1428 Your IPFire-Build-Script
1429 END
1430         fi
1431
1432         if [ "$2" = "ISO" ]; then
1433                 SUBJECT="ISO: IPFIRE-BUILD R$SVN_REVISION on `hostname`"
1434                 echo "ERROR: $0 upload iso!"
1435                 cat <<END > /tmp/ipfire_mail_body
1436 When I was uploading the iso image,
1437 I have found an ERROR!
1438 Here you can see the logs and detect the reason for this error.
1439
1440 Best Regards
1441 Your IPFire-Build-Script
1442 END
1443         fi
1444
1445         if [ "$2" = "PAKS" ]; then
1446                 SUBJECT="PAKS: IPFIRE-BUILD R$SVN_REVISION on `hostname`"
1447                 echo "ERROR: $0 upload paks!"
1448                 cat <<END > /tmp/ipfire_mail_body
1449 When I was uploading the packages,
1450 I have found an ERROR!
1451 Here you can see the logs and detect the reason for this error.
1452
1453 Best Regards
1454 Your IPFire-Build-Script
1455 END
1456         fi
1457
1458         tar cfz $ATTACHMENT log/_build*
1459         cat <<END >> /tmp/ipfire_mail_body
1460
1461 Here is a summary... The full logs are in the attachment.
1462 ---------------------------------------------------------
1463
1464 `tail log/_*`
1465 END
1466         cat /tmp/ipfire_mail_body | tools/sendEmail -q \
1467                 -f $IPFIRE_MAIL_FROM \
1468                 -t $IPFIRE_MAIL_REPORT \
1469                 -u $SUBJECT \
1470                 -s $IPFIRE_MAIL_SERVER:25 \
1471                 -xu $IPFIRE_MAIL_USER \
1472                 -xp $IPFIRE_MAIL_PASS \
1473                 -l log/_build.mail.log \
1474                 -a $ATTACHMENT # -v
1475         rm -f /tmp/ipfire_mail_body $ATTACHMENT
1476         ;;
1477 unattended)
1478         if [ ! -f .config ]; then
1479                 echo "No configuration found. Try ./make.sh make-config."
1480         fi
1481         ### This is our procedure that will compile the IPFire by herself...
1482         echo "### UPDATE LOGS"
1483         update_logs
1484         echo "### SAVING TIME"
1485         export IPFIRE_START_TIME=`date`
1486
1487         echo "### RUNNING SVN-UPDATE"
1488         $0 svn update
1489         if [ $? -ne 0 ]; then
1490                 $0 mail SVNUPDATE
1491                 exit 1
1492         fi
1493         
1494         echo "### EXPORT SOURCES"
1495         $0 svn dist
1496         if [ $? -ne 0 ]; then
1497                 $0 mail SVNDIST
1498                 exit 1
1499         fi
1500
1501         echo "### RUNNING PREFETCH"
1502         $0 prefetch | grep -q "md5 difference"
1503         if [ $? -eq 0 ]; then
1504                 $0 mail PREFETCH
1505                 exit 1
1506         fi
1507
1508         echo "### RUNNING BUILD"
1509         $0 build
1510         if [ $? -ne 0 ]; then
1511                 $0 mail ERROR
1512                 exit 1
1513         fi
1514
1515         echo "### UPLOADING ISO"
1516         $0 upload iso
1517         if [ $? -ne 0 ]; then
1518                 $0 mail ISO
1519                 exit 1
1520         fi
1521         
1522         echo "### UPLOADING PAKS"
1523         $0 upload paks
1524         if [ $? -ne 0 ]; then
1525                 $0 mail PAKS
1526                 exit 1
1527         fi
1528
1529         echo "### SUCCESS!"
1530         $0 mail SUCCESS
1531         exit 0
1532         ;;
1533 batch)
1534         if [ `screen -ls | grep batch` ]; then
1535                 echo "Build is already running, sorry!"
1536                 exit 1
1537         else
1538                 echo -n "IPFire-Batch-Build is starting..."
1539                 screen -dmS ipfire $0 unattended
1540                 if [ "$?" -eq "0" ]; then
1541                         echo ".Done!"
1542                 else
1543                         echo ".ERROR!"
1544                         exit 1
1545                 fi
1546                 #if [ "$2" -eq "-v" ]; then
1547                 #       screen -x ipfire
1548                 #else
1549                 #       echo "You may attach you with '-v'."
1550                 #fi
1551                 exit 0
1552         fi
1553         ;;
1554 *)
1555         clear
1556         svn info
1557         select name in "Exit" "IPFIRE: Prefetch" "IPFIRE: Build (silent)" "IPFIRE: Watch Build" "IPFIRE: Batch" "IPFIRE: Clean" "SVN: Commit" "SVN: Update" "SVN: Status" "SVN: Diff" "LOG: Tail" "Help"
1558         do
1559         case $name in
1560         "IPFIRE: Prefetch")
1561                 $0 prefetch
1562                 ;;
1563         "IPFIRE: Build (silent)")
1564                 $0 build-silent
1565                 ;;
1566         "IPFIRE: Watch Build")
1567                 echo "Exit with Ctrl+A, Ctrl+D."
1568                 echo -n "Preparing..."
1569                 for i in `seq 10`; do
1570                         sleep 0.1; echo -n "."
1571                 done
1572                 echo ".Ready!"
1573                 sleep 0.3
1574                 screen -x ipfire
1575                 ;;
1576         "IPFIRE: Batch")
1577                 $0 batch
1578                 ;;
1579         "IPFIRE: Clean")
1580                 $0 clean
1581                 ;;
1582         "SVN: Commit")
1583                 $0 svn commit
1584                 ;;
1585         "SVN: Update")
1586                 $0 svn update
1587                 ;;
1588         "SVN: Status")
1589                 svn status # | grep -v ^?
1590                 ;;
1591         "SVN: Diff")
1592                 $0 svn diff
1593                 ;;
1594         "Help")
1595                 echo "Usage: $0 {build|changelog|check|checkclean|clean|gettoolchain|newpak|prefetch|shell|sync|toolchain}"
1596                 cat doc/make.sh-usage
1597                 ;;
1598         "LOG: Tail")
1599                 tail -f log/_*
1600                 ;;
1601         "Exit")
1602                 break
1603                 ;;
1604         esac
1605         done
1606         ;;
1607 esac