2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2011 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
21 ###############################################################################
23 # Beautifying variables & presentation & input output interface
25 ###############################################################################
28 # Find current screen size
29 if [ -z "${COLUMNS}" ]; then
31 COLUMNS
=${COLUMNS##* }
34 # When using remote connections, such as a serial port, stty size returns 0
35 if [ "${COLUMNS}" = "0" ]; then
39 ## Measurements for positioning result messages
44 RESULT_COL
=$
((${COLUMNS} - $RESULT_WIDTH - 4))
45 TIME_COL
=$
((${RESULT_COL} - $TIME_WIDTH - 5))
46 OPT_COL
=$
((${TIME_COL} - $OPT_WIDTH - 5))
47 VER_COL
=$
((${OPT_COL} - $VER_WIDTH - 5))
49 ## Set Cursur Position Commands, used via echo -e
50 SET_RESULT_COL
="\\033[${RESULT_COL}G"
51 SET_TIME_COL
="\\033[${TIME_COL}G"
52 SET_OPT_COL
="\\033[${OPT_COL}G"
53 SET_VER_COL
="\\033[${VER_COL}G"
55 # Define color for messages
64 if [ "$?" -eq "0" ]; then
71 if [ $EXITCODE -ne "0" ]; then
79 # ARG1=starting position on screen
80 # ARG2=string to be printed
81 # ARG3=offset, negative for left movement, positive for right movement, relative to ARG1
82 # For example if your starting position is column 50 and you want to print Hello three columns to the right
83 # of your starting position, your call will look like this:
84 # position_cursor 50 "Hello" 3 (you'll get the string Hello at position 53 (= 50 + 3)
85 # If on the other hand you want your string "Hello" to end three columns to the left of position 50,
86 # your call will look like this:
87 # position_cursor 50 "Hello" -3 (you'll get the string Hello at position 42 (= 50 - 5 -3)
88 # If you want to start printing at the exact starting location, use offset 0
94 STRING_LENGTH
=${#STRING}
96 if [ ${OFFSET} -lt 0 ]; then
97 COL
=$
((${START} + ${OFFSET} - ${STRING_LENGTH}))
99 COL
=$
((${START} + ${OFFSET}))
102 SET_COL
="\\033[${COL}G"
105 } # End of position_cursor()
110 # Commands: build_stage, make_pkg, message, result
115 echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n"
118 echo -ne "${WARN}${3}${NORMAL}${SET_RESULT_COL}[${WARN} WARN ${NORMAL}]\n"
121 echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n"
124 echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n"
130 if [ "$STAGE_TIME_START" ]; then
131 LAST_STAGE_TIME
=$
[ `date +%s` - $STAGE_TIME_START ]
133 STAGE_TIME_START
=`date +%s`
134 echo -ne "${BOLD}*** ${MESSAGE}${NORMAL}"
135 if [ "$LAST_STAGE_TIME" ]; then
136 echo -ne "${DONE} (Last stage took $LAST_STAGE_TIME secs)${NORMAL}"
138 echo -ne "${BOLD}${SET_VER_COL} version${SET_OPT_COL} options${SET_TIME_COL} time (sec)${SET_RESULT_COL} status${NORMAL}\n"
141 BUILD_TIME_START
=`date +%s`
144 BUILD_TIME_END
=`date +%s`
145 seconds
=$
[ $BUILD_TIME_END - $BUILD_TIME_START ]
146 hours
=$
((seconds
/ 3600))
147 seconds
=$
((seconds
% 3600))
148 minutes
=$
((seconds
/ 60))
149 seconds
=$
((seconds
% 60))
151 echo -ne "${DONE}***Build is finished now and took $hours hour(s) $minutes minute(s) $seconds second(s)!${NORMAL}\n"
154 echo "$2" |
while read PKG_VER PROGRAM OPTIONS
156 SET_VER_COL_REAL
=`position_cursor $OPT_COL $PKG_VER -3`
158 if [ "$OPTIONS" == "" ]; then
159 echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}"
160 echo -ne "${NORMAL} ]${SET_RESULT_COL}"
162 echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}"
163 echo -ne "${NORMAL} ]${SET_OPT_COL}[ ${BOLD}${OPTIONS}"
164 echo -ne "${NORMAL} ]${SET_RESULT_COL}"
177 SET_TIME_COL_REAL
=`position_cursor $RESULT_COL $PKG_TIME -3`
180 echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]"
181 echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n"
184 echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]"
185 echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n"
188 echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n"
193 } # End of beautify()
198 PKG_VER
=`grep -E "^VER |^VER=|^VER " $1 | awk '{print $3}'`
200 if [ -z $PKG_VER ]; then
201 PKG_VER
=`grep "Exp " $1 | awk '{print $4}'`
203 if [ -z $PKG_VER ]; then
206 if [ ${#PKG_VER} -gt $VER_WIDTH ]; then
207 # If a package version number is greater than $VER_WIDTH, we keep the first 4 characters
208 # and replace enough characters to fit the resulting string on the screen. We'll replace
209 # the extra character with .. (two dots). That's why the "+ 2" in the formula below.
210 # Example: if we have a 21-long version number that we want to fit into a 10-long space,
211 # we have to remove 11 characters. But if we replace 11 characters with 2 characters, we'll
212 # end up with a 12-character long string. That's why we replace 12 characters with ..
213 REMOVE
=`expr substr "$PKG_VER" 4 $[ ${#PKG_VER} - $VER_WIDTH + 2 ]`
214 PKG_VER
=`echo ${PKG_VER/$REMOVE/..}`
218 } # End of get_pkg_ver()
220 if [ 'x86_64' = $MACHINE -o 'i686' = $MACHINE -o 'i586' = $MACHINE ]; then
221 echo "`date -u '+%b %e %T'`: Machine is iX86 (or equivalent)" >> $LOGFILE
223 BUILDTARGET
=i586-pc-linux-gnu
224 CFLAGS
="-O2 -march=i586 -pipe -fomit-frame-pointer"
225 CXXFLAGS
="-O2 -march=i586 -pipe -fomit-frame-pointer"
226 C2FLAGS
="-O2 -march=i586 -mtune=i586 -pipe -fomit-frame-pointer"
227 CXX2FLAGS
="-O2 -march=i586 -mtune=i586 -pipe -fomit-frame-pointer"
228 elif [ 'armv5tejl' = $MACHINE -o 'armv5tel' = $MACHINE -o 'armv6l' = $MACHINE -o 'armv7l' = $MACHINE ]; then
229 echo "`date -u '+%b %e %T'`: Machine is ARM (or equivalent)" >> $LOGFILE
232 BUILDTARGET
=${MACHINE}-unknown-linux-gnueabi
233 CFLAGS
="-O2 -march=armv5te -mfloat-abi=soft -fomit-frame-pointer -pipe"
236 CXX2FLAGS
="$CXXFLAGS"
238 echo "`date -u '+%b %e %T'`: Can't determine your architecture - $MACHINE"
244 umount
$BASEDIR/build
/sys
2>/dev
/null
;
245 umount
$BASEDIR/build
/dev
/shm
2>/dev
/null
;
246 umount
$BASEDIR/build
/dev
/pts
2>/dev
/null
;
247 umount
$BASEDIR/build
/dev
2>/dev
/null
;
248 umount
$BASEDIR/build
/proc
2>/dev
/null
;
249 umount
$BASEDIR/build
/install
/mnt
2>/dev
/null
;
250 umount
$BASEDIR/build
/usr
/src
/cache
2>/dev
/null
;
251 umount
$BASEDIR/build
/usr
/src
/ccache
2>/dev
/null
;
252 umount
$BASEDIR/build
/usr
/src
/config
2>/dev
/null
;
253 umount
$BASEDIR/build
/usr
/src
/doc
2>/dev
/null
;
254 umount
$BASEDIR/build
/usr
/src
/html
2>/dev
/null
;
255 umount
$BASEDIR/build
/usr
/src
/langs
2>/dev
/null
;
256 umount
$BASEDIR/build
/usr
/src
/lfs
2>/dev
/null
;
257 umount
$BASEDIR/build
/usr
/src
/log
2>/dev
/null
;
258 umount
$BASEDIR/build
/usr
/src
/src
2>/dev
/null
;
263 for i
in `seq 0 7`; do
264 if ( losetup
/dev
/loop
${i} 2>/dev
/null |
grep -q "/install/images" ); then
265 losetup
-d /dev
/loop
${i} 2>/dev
/null
268 echo -e "\nERROR: $*"
269 echo " Check $LOGFILE for errors if applicable"
274 [ -e "${BASEDIR}/build/tools/lib/libpakfire_preload.so" ] ||
return
276 local env
="LD_PRELOAD=/tools/lib/libpakfire_preload.so"
278 # Fake kernel version, because some of the packages do not compile
279 # with kernel 3.0 and later.
280 env
="${env} UTS_RELEASE=${KVER}"
282 # Fake machine version.
283 env
="${env} UTS_MACHINE=${MACHINE}"
289 if [ ! -e $BASEDIR/build
/usr
/src
/lfs
/ ]; then
290 exiterror
"No such file or directory: $BASEDIR/build/usr/src/lfs/"
293 echo "Entering to a shell inside LFS chroot, go out with exit"
294 $linux32 chroot
$LFS /tools
/bin
/env
-i HOME
=/root TERM
=$TERM PS1
='\u:\w\$ ' \
295 PATH
=/usr
/local
/bin
:/bin
:/usr
/bin
:/sbin
:/usr
/sbin
:/tools
/bin \
296 VERSION
=$VERSION CONFIG_ROOT
=$CONFIG_ROOT \
297 NAME
="$NAME" SNAME
="$SNAME" SLOGAN
="$SLOGAN" \
298 CFLAGS
="$CF2LAGS" CXXFLAGS
="$CXX2FLAGS" \
299 CCACHE_DIR
=/usr
/src
/ccache \
303 BUILDTARGET
="$BUILDTARGET" \
305 MACHINE_TYPE
="$MACHINE_TYPE" \
306 KGCC
="ccache /usr/bin/gcc" \
309 if [ $?
-ne 0 ]; then
310 beautify message FAIL
311 exiterror
"chroot error"
317 ############################################################################
319 # Necessary shell functions #
321 ############################################################################
323 # Common checking before entering the chroot and compilling
325 # Return:0 caller can continue
326 # :1 skip (nothing to do)
327 # or fail if no script file found
332 if [ ! -f $BASEDIR/lfs
/$1 ]; then
333 exiterror
"No such file or directory: $BASEDIR/$1"
336 local PKG_VER
=`get_pkg_ver $BASEDIR/lfs/$1`
337 beautify make_pkg
"$PKG_VER $*"
339 # Check if this package is supported by our architecture.
340 # If no SUP_ARCH is found, we assume the package can be built for all.
341 if grep "^SUP_ARCH" ${BASEDIR}/lfs
/${1} >/dev
/null
; then
342 # Check if package supports ${MACHINE} or all architectures.
343 if ! grep -E "^SUP_ARCH.*${MACHINE}|^SUP_ARCH.*all" ${BASEDIR}/lfs/${1} >/dev/null; then
351 for i in $SKIP_PACKAGE_LIST
353 if [ "$i" == "$1" ]; then
359 echo -ne "`date -u '+%b %e %T'`: Building $
* " >> $LOGFILE
361 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MACHINE=$MACHINE \
362 MACHINE_TYPE="$MACHINE_TYPE" \
363 MESSAGE="$1\t " download >> $LOGFILE 2>&1
364 if [ $? -ne 0 ]; then
365 exiterror "Download error
in $1"
368 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MACHINE=$MACHINE \
369 MACHINE_TYPE="$MACHINE_TYPE" \
370 MESSAGE="$1\t md5sum" md5 >> $LOGFILE 2>&1
371 if [ $? -ne 0 ]; then
372 exiterror "md5sum error
in $1, check
file in cache or signature
"
376 } # End of lfsmakecommoncheck()
379 lfsmakecommoncheck $*
380 [ $? == 1 ] && return 0
382 local PKG_TIME_START=`date +%s`
384 cd $BASEDIR/lfs && make -f $* BUILDTARGET=$BUILDTARGET \
386 MACHINE_TYPE=$MACHINE_TYPE \
387 LFS_BASEDIR=$BASEDIR \
390 MAKETUNING=$MAKETUNING \
392 install >> $LOGFILE 2>&1
393 local COMPILE_SUCCESS=$?
394 local PKG_TIME_END=`date +%s`
396 if [ $COMPILE_SUCCESS -ne 0 ]; then
397 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
398 exiterror "Building $
*";
400 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
407 lfsmakecommoncheck $*
408 [ $? == 1 ] && return 0
410 local PKG_TIME_START=`date +%s`
411 $linux32 chroot $LFS /tools/bin/env -i HOME=/root \
412 TERM=$TERM PS1='\u:\w\$ ' \
413 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
415 CONFIG_ROOT=$CONFIG_ROOT \
416 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
417 CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \
418 CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 CCACHE_HASHDIR=1 \
419 KVER=$KVER MAKETUNING=$MAKETUNING \
420 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
421 MACHINE_TYPE="$MACHINE_TYPE" \
423 /tools/bin/bash -x -c "cd /usr
/src
/lfs
&& \
424 make -f $
* LFS_BASEDIR
=/usr
/src
install" >>$LOGFILE 2>&1
425 local COMPILE_SUCCESS=$?
426 local PKG_TIME_END=`date +%s`
428 if [ $COMPILE_SUCCESS -ne 0 ]; then
429 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
430 exiterror "Building $
*";
432 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
439 lfsmakecommoncheck $*
440 [ $? == 1 ] && return 0
442 local PKG_TIME_START=`date +%s`
443 $linux32 chroot $LFS /tools/bin/env -i HOME=/root \
444 TERM=$TERM PS1='\u:\w\$ ' \
445 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
448 CONFIG_ROOT=$CONFIG_ROOT \
449 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
450 CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \
451 CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 CCACHE_HASHDIR=1 \
452 KVER=$KVER MAKETUNING=$MAKETUNING \
453 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
454 MACHINE_TYPE="$MACHINE_TYPE" \
456 /bin/bash -x -c "cd /usr
/src
/lfs
&& \
457 make -f $
* LFS_BASEDIR
=/usr
/src
install" >>$LOGFILE 2>&1
459 local COMPILE_SUCCESS=$?
460 local PKG_TIME_END=`date +%s`
462 if [ $COMPILE_SUCCESS -ne 0 ]; then
463 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
464 exiterror "Building $
*";
466 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
472 lfsmakecommoncheck $*
473 [ $? == 1 ] && return 0
475 local PKG_TIME_START=`date +%s`
476 chroot $LFS /tools/bin/env -i HOME=/root \
477 TERM=$TERM PS1='\u:\w\$ ' \
478 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
480 CONFIG_ROOT=$CONFIG_ROOT \
481 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
482 CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \
483 CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 CCACHE_HASHDIR=1 \
485 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
486 MACHINE_TYPE="$MACHINE_TYPE" \
488 /bin/bash -x -c "cd /usr
/src
/lfs
&& \
489 make -f $1 LFS_BASEDIR
=/usr
/src dist
" >>$LOGFILE 2>&1
491 local COMPILE_SUCCESS=$?
492 local PKG_TIME_END=`date +%s`
494 if [ $COMPILE_SUCCESS -ne 0 ]; then
495 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
496 exiterror "Packaging $
*";
498 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
504 lfsmakecommoncheck $*
505 [ $? == 1 ] && return 0
507 local PKG_TIME_START=`date +%s`
508 $linux32 chroot $LFS /tools/bin/env -i HOME=/root \
509 TERM=$TERM PS1='\u:\w\$ ' \
510 PATH=/opt/i586-uClibc/i586-linux-uclibc/bin:/opt/i586-uClibc/bin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
512 CONFIG_ROOT=$CONFIG_ROOT \
514 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
515 CFLAGS="-Os" CXXFLAGS="-Os" \
516 CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 CCACHE_HASHDIR=1 \
518 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
519 MACHINE_TYPE="$MACHINE_TYPE" \
520 /bin/bash -x -c "cd /usr
/src
/lfs
&& \
521 make -f $
* LFS_BASEDIR
=/usr
/src
install" >>$LOGFILE 2>&1
523 local COMPILE_SUCCESS=$?
524 local PKG_TIME_END=`date +%s`
526 if [ $COMPILE_SUCCESS -ne 0 ]; then
527 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
528 exiterror "Building $
*";
530 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
536 echo -ne "Checking the translations
for missing or obsolete
strings...
"
537 chmod 755 $BASEDIR/tools/{check_strings.pl,sort_strings.pl,check_langs.sh}
538 $BASEDIR/tools/sort_strings.pl en
539 $BASEDIR/tools/sort_strings.pl de
540 $BASEDIR/tools/sort_strings.pl fr
541 $BASEDIR/tools/sort_strings.pl es
542 $BASEDIR/tools/sort_strings.pl pl
543 $BASEDIR/tools/sort_strings.pl ru
544 $BASEDIR/tools/check_strings.pl en > $BASEDIR/doc/language_issues.en
545 $BASEDIR/tools/check_strings.pl de > $BASEDIR/doc/language_issues.de
546 $BASEDIR/tools/check_strings.pl fr > $BASEDIR/doc/language_issues.fr
547 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.es
548 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.pl
549 $BASEDIR/tools/check_strings.pl ru > $BASEDIR/doc/language_issues.ru
550 $BASEDIR/tools/check_langs.sh > $BASEDIR/doc/language_missings
551 beautify message DONE