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