source: jhalfs@ ef32ce5

2.4 ablfs-more legacy new_features trunk
Last change on this file since ef32ce5 was bbcdeab, checked in by Pierre Labastie <pierre@…>, 11 years ago

Handle errors while installing blfs tools and makes the error
message more accurate

  • Property mode set to 100755
File size: 12.3 KB
RevLine 
[4da2512]1#!/bin/bash
2# $Id$
3set -e
[bbcdeab]4# Pass trap handlers to functions
5set -E
[4da2512]6
7# VT100 colors
8declare -r BLACK=$'\e[1;30m'
9declare -r DK_GRAY=$'\e[0;30m'
10
11declare -r RED=$'\e[31m'
12declare -r GREEN=$'\e[32m'
13declare -r YELLOW=$'\e[33m'
14declare -r BLUE=$'\e[34m'
15declare -r MAGENTA=$'\e[35m'
16declare -r CYAN=$'\e[36m'
17declare -r WHITE=$'\e[37m'
18
19declare -r OFF=$'\e[0m'
20declare -r BOLD=$'\e[1m'
21declare -r REVERSE=$'\e[7m'
22declare -r HIDDEN=$'\e[8m'
23
24declare -r tab_=$'\t'
25declare -r nl_=$'\n'
26
27declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
28declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
29declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
30
31# bold yellow > < pair
32declare -r R_arrow=$'\e[1;33m>\e[0m'
33declare -r L_arrow=$'\e[1;33m<\e[0m'
34
35
36#>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
37#-----------------------#
38simple_error() { # Basic error trap.... JUST DIE
39#-----------------------#
40 # If +e then disable text output
[a96109a]41 if [[ "$-" =~ e ]]; then
[bbcdeab]42 LASTLINE="$1"
43 LASTERR="$2"
44 LASTFUNC="$3"
45 LASTSOURCE="$4"
46# echo -e "\n${RED}ERROR:${GREEN} basic error trapped!${OFF}\n" >&2
47 echo -e "\n${RED}ERROR:${GREEN} Error $LASTERR at $LASTSOURCE line ${LASTLINE}!${OFF}\n" >&2
[4da2512]48 fi
[bbcdeab]49 exit $LASTERR
[4da2512]50}
51
52see_ya() {
[401aac8]53 echo -e "\n${L_arrow}${BOLD}jhalfs-trunk${R_arrow} exit${OFF}\n"
[4da2512]54}
55##### Simple error TRAPS
56# ctrl-c SIGINT
57# ctrl-y
58# ctrl-z SIGTSTP
59# SIGHUP 1 HANGUP
60# SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
61# SIGQUIT 3
62# SIGKILL 9 KILL
63# SIGTERM 15 TERMINATION
64# SIGSTOP 17,18,23 STOP THE PROCESS
65#####
66set -e
67trap see_ya 0
[bbcdeab]68trap 'simple_error "${LINENO}" "$?" "${FUNCNAME}" "${BASH_SOURCE}"' ERR
[4da2512]69trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
70#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
71
72version="
[401aac8]73${BOLD} \"jhalfs-trunk\"${OFF} builder tool (development) \$Rev$
[4da2512]74 \$Date$
75
76 Written by George Boudreau and Manuel Canales Esparcia,
77 plus several contributions.
78
79 Based on an idea from Jeremy Huntwork
80
81 This set of files are published under the
82 ${BOLD}Gnu General Public License, Version 2.${OFF}
83"
84
85case $1 in
86 -v ) echo "$version" && exit 1 ;;
87 run ) : ;;
88 * )
89 echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
90 exit 1
91 ;;
92esac
93
[65c998b]94# If the user has not saved his configuration file, let's ask
95# if he or she really wants to run this stuff
96if [ $(ls -l --time-style='+%Y%m%d%H%M%S' configuration.old | cut -d' ' -f 6) \
97 -ge $(ls -l --time-style='+%Y%m%d%H%M%S' configuration | cut -d' ' -f 6) ]
98 then echo -n "Do you want to run jhalfs? yes/no (yes): "
99 read ANSWER
100 if [ x${ANSWER:0:1} = "xn" -o x${ANSWER:0:1} = "xN" ] ; then
101 echo "${nl_}Exiting gracefully.${nl_}"
102 exit
103 fi
104fi
105
106# Change this to 0 to suppress almost all messages
[4da2512]107VERBOSITY=1
108
109[[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..."
110source configuration
[7072e1f]111[[ $? > 0 ]] && echo "file: configuration did not load.." && exit 1
[4da2512]112[[ $VERBOSITY > 0 ]] && echo "OK"
113
114# These are boolean vars generated from Config.in.
[7072e1f]115# ISSUE: If a boolean parameter is not set to y(es) there
116# is no variable defined by the menu app. This can
117# cause a headache if you are not aware.
118# The following variables MUST exist. If they don't, the
119# default value is n(o).
[4da2512]120RUNMAKE=${RUNMAKE:-n}
121GETPKG=${GETPKG:-n}
122COMPARE=${COMPARE:-n}
123RUN_FARCE=${RUN_FARCE:-n}
124RUN_ICA=${RUN_ICA:-n}
[7072e1f]125PKGMNGT=${PKGMNGT:-n}
[4da2512]126BOMB_TEST=${BOMB_TEST:-n}
127STRIP=${STRIP:=n}
128REPORT=${REPORT:=n}
129VIMLANG=${VIMLANG:-n}
[b339c94]130FULL_LOCALE=${FULL_LOCALE:-n}
[4da2512]131GRSECURITY_HOST=${GRSECURITY_HOST:-n}
[9a536f7]132CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
[a16f769]133REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
[93346ee]134INSTALL_LOG=${INSTALL_LOG:-n}
[486e9a7]135CLEAN=${CLEAN:=n}
[d035526]136SET_SSP=${SET_SSP:=n}
137SET_ASLR=${SET_ASLR:=n}
138SET_PAX=${SET_PAX:=n}
139SET_HARDENED_TMP=${SET_HARDENED_TMP:=n}
140SET_WARNINGS=${SET_WARNINGS:=n}
141SET_MISC=${SET_MISC:=n}
142SET_BLOWFISH=${SET_BLOWFISH:=n}
[4da2512]143
[75d6d1c]144if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
145 NO_PROGRESS="#"
146fi
147
148
[38ae01f]149# Sanity check on the location of $BUILDDIR / $JHALFSDIR
150CWD=$(cd `dirname $0` && pwd)
151if [[ $JHALFSDIR == $CWD ]]; then
152 echo " The jhalfs source directory conflicts with the jhalfs build directory."
153 echo " Please move the source directory or change the build directory."
154 exit 2
155fi
156
[0873ccc]157# Book sources envars
[4965fa8]158BRANCH_ID=${BRANCH_ID:=development}
159
160case $BRANCH_ID in
161 development )
162 case $PROGNAME in
[92b7cb8]163 clfs* ) TREE="" ;;
[4965fa8]164 *) TREE=trunk/BOOK ;;
165 esac
166 LFSVRS=development
167 ;;
168 *EDIT* ) echo " You forgot to set the branch or stable book version."
169 echo " Please rerun make and fix the configuration."
170 exit 2 ;;
171 branch-* )
172 LFSVRS=${BRANCH_ID}
173 TREE=branches/${BRANCH_ID#branch-}/BOOK
174 ;;
175 * )
176 case $PROGNAME in
[e650dc7]177 lfs )
178 LFSVRS=${BRANCH_ID}
179 TREE=tags/${BRANCH_ID}
180 if (( ${BRANCH_ID:0:1} < 7 )) ; then
181 TREE=${TREE}/BOOK
182 fi
183 ;;
184 hlfs )
[4965fa8]185 LFSVRS=${BRANCH_ID}
186 TREE=tags/${BRANCH_ID}/BOOK
187 ;;
[92b7cb8]188 clfs* )
[4965fa8]189 LFSVRS=${BRANCH_ID}
[34d1b6a]190 TREE=clfs-${BRANCH_ID}
[4965fa8]191 ;;
[92b7cb8]192 * )
[4965fa8]193 esac
194 ;;
195esac
196
[4da2512]197# Set the document location...
[1cf621b]198BOOK=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
[4da2512]199
[4965fa8]200
[728955b]201#--- Envars not sourced from configuration
202case $PROGNAME in
[7072e1f]203# TODO: clfs is now on git
[92b7cb8]204 clfs ) declare -r GIT="git://git.cross-lfs.org/cross-lfs" ;;
205 clfs2 ) declare -r GIT="git://git.cross-lfs.org/clfs-sysroot" ;;
206 clfs3 ) declare -r GIT="git://git.cross-lfs.org/clfs-embedded" ;;
207 *) declare -r SVN="svn://svn.linuxfromscratch.org" ;;
[728955b]208esac
209declare -r LOG=000-masterscript.log
[7072e1f]210 # Needed for fetching BLFS book sources when building CLFS
[728955b]211declare -r SVN_2="svn://svn.linuxfromscratch.org"
212
[4da2512]213# Set true internal variables
214COMMON_DIR="common"
[52b0d10]215PACKAGE_DIR=$(echo $PROGNAME | tr '[a-z]' '[A-Z]')
[4da2512]216MODULE=$PACKAGE_DIR/master.sh
[7072e1f]217PKGMNGTDIR="pkgmngt"
218# The name packageManager.xml is hardcoded in *.xsl, so no variable.
[4da2512]219
220[[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
221source $COMMON_DIR/common-functions
222[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
223[[ $VERBOSITY > 0 ]] && echo "OK"
224[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
225source $MODULE
226[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
227[[ $VERBOSITY > 0 ]] && echo "OK"
228#
229[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
230
231
232#*******************************************************************#
233[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
[d517356]234source $COMMON_DIR/libs/func_check_version.sh
[4da2512]235[[ $? > 0 ]] && echo " function module did not load.." && exit 2
236[[ $VERBOSITY > 0 ]] && echo "OK"
237
238[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
[d517356]239source $COMMON_DIR/libs/func_validate_configs.sh
[4da2512]240[[ $? > 0 ]] && echo " function module did not load.." && exit 2
241[[ $VERBOSITY > 0 ]] && echo "OK"
[9a536f7]242
[fe30c61]243[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_custom_pkgs>..."
244source $COMMON_DIR/libs/func_custom_pkgs
[9a536f7]245[[ $? > 0 ]] && echo " function module did not load.." && exit 2
246[[ $VERBOSITY > 0 ]] && echo "OK"
247
248
[4da2512]249[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
250
[e576789]251# blfs-tool envars
252BLFS_TOOL=${BLFS_TOOL:-n}
253if [[ "${BLFS_TOOL}" = "y" ]] ; then
254 BLFS_BRANCH_ID=${BLFS_BRANCH_ID:=development}
255 case $BLFS_BRANCH_ID in
256 development ) BLFS_TREE=trunk/BOOK ;;
257 *EDIT* ) echo " You forgot to set the BLFS branch or stable book version."
258 echo " Please rerun make and fix the configuration."
259 exit 2 ;;
260 branch-* ) BLFS_TREE=branches/${BLFS_BRANCH_ID#branch-} ;;
261 * ) BLFS_TREE=tags/${BLFS_BRANCH_ID} ;;
262 esac
263 [[ $VERBOSITY > 0 ]] && echo -n "Loading blfs tools installation function..."
264 source $COMMON_DIR/libs/func_install_blfs
265 [[ $? > 0 ]] && echo "function module did not load.." && exit 1
266 [[ $VERBOSITY > 0 ]] && echo "OK"
267fi
[4da2512]268
269###################################
270### MAIN ###
271###################################
272
273
274validate_config
275echo "${SD_BORDER}${nl_}"
276echo -n "Are you happy with these settings? yes/no (no): "
277read ANSWER
278if [ x$ANSWER != "xyes" ] ; then
[881c96f]279 echo "${nl_}Rerun make to fix the configuration options.${nl_}"
[4da2512]280 exit 1
281fi
282echo "${nl_}${SD_BORDER}${nl_}"
283
284# Load additional modules or configuration files based on global settings
285# compare module
286if [[ "$COMPARE" = "y" ]]; then
287 [[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..."
[d517356]288 source $COMMON_DIR/libs/func_compare.sh
289 [[ $? > 0 ]] && echo "$COMMON_DIR/libs/func_compare.sh did not load.." && exit
[4da2512]290 [[ $VERBOSITY > 0 ]] && echo "OK"
291fi
292#
293# optimize module
294if [[ "$OPTIMIZE" != "0" ]]; then
295 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
296 source optimize/optimize_functions
297 [[ $? > 0 ]] && echo " optimize/optimize_functions did not load.." && exit
298 [[ $VERBOSITY > 0 ]] && echo "OK"
299 #
300 # optimize configurations
301 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..."
302 source optimize/opt_config
303 [[ $? > 0 ]] && echo " optimize/opt_config did not load.." && exit
304 [[ $VERBOSITY > 0 ]] && echo "OK"
305 # Validate optimize settings, if required
306 validate_opt_settings
307fi
308#
309
[a16f769]310if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
[4da2512]311
[7b6ecc5]312 # If requested, clean the build directory
313 clean_builddir
[4da2512]314
[7b6ecc5]315 if [[ ! -d $JHALFSDIR ]]; then
316 mkdir -p $JHALFSDIR
317 fi
[3e7ceed]318
[7b6ecc5]319 # Create $BUILDDIR/sources even though it could be created by get_sources()
320 if [[ ! -d $BUILDDIR/sources ]]; then
321 mkdir -p $BUILDDIR/sources
322 fi
323 #
324 # Create the log directory
325 if [[ ! -d $LOGDIR ]]; then
326 mkdir $LOGDIR
327 fi
328 >$LOGDIR/$LOG
329 #
[3e7ceed]330 # Copy common helper files
331 cp $COMMON_DIR/{makefile-functions,progress_bar.sh,packages.xsl} $JHALFSDIR/
[7b6ecc5]332 #
[3e7ceed]333 # Fix the XSL book parser
[92b7cb8]334 case $PROGNAME in
335 clfs* ) sed 's,FAKEDIR,'${BOOK}/BOOK',' ${PACKAGE_DIR}/${XSL} > $JHALFSDIR/${XSL} ;;
336 lfs | hlfs ) sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL} ;;
337 * ) ;;
338 esac
[3e7ceed]339 export XSL=$JHALFSDIR/${XSL}
[7b6ecc5]340 #
341
[7072e1f]342 # Copy packageManager.xml, if needed
343 [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] &&
344 cp $PKGMNGTDIR/packageManager.xml $JHALFSDIR/ &&
345 cp $PKGMNGTDIR/packInstall.sh $JHALFSDIR/
346 #
[3e7ceed]347 # Copy urls.xsl, if needed
348 [[ "$GETPKG" = "y" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
[7b6ecc5]349 #
[3e7ceed]350 # Create the test-log directory, if needed
351 [[ "$TEST" != "0" ]] && [[ ! -d $TESTLOGDIR ]] && install -d -m 1777 $TESTLOGDIR
352 #
[93346ee]353 # Create the installed-files directory, if needed
354 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 $FILELOGDIR
355 #
[3e7ceed]356 # Prepare report creation, if needed
[7b6ecc5]357 if [[ "$REPORT" = "y" ]]; then
358 cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
[7072e1f]359 # After making sure that all looks sane, dump the settings to a file
[7b6ecc5]360 # This file will be used to create the REPORT header
361 validate_config > $JHALFSDIR/jhalfs.config
362 fi
363 #
[3e7ceed]364 # Copy optimize files, if needed
365 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
[7b6ecc5]366 #
[3e7ceed]367 # Copy compare files, if needed
368 if [[ "$COMPARE" = "y" ]]; then
369 mkdir -p $JHALFSDIR/extras
370 cp extras/* $JHALFSDIR/extras
371 fi
[7b6ecc5]372 #
[3e7ceed]373 # Copy custom tools config files, if requested
374 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
375 echo "Copying custom tool scripts to $JHALFSDIR"
376 mkdir -p $JHALFSDIR/custom-commands
377 cp -f custom/config/* $JHALFSDIR/custom-commands
378 fi
379 #
[7b6ecc5]380 # Install blfs-tool, if requested.
381 if [[ "${BLFS_TOOL}" = "y" ]] ; then
[e576789]382 echo Downloading and validating the BLFS book
383 echo '(may take some time...)'
384 install_blfs_tools 2>&1 | tee -a $LOGDIR/$LOG
[bbcdeab]385 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
[7b6ecc5]386 fi
[3e7ceed]387 #
[7b6ecc5]388
[1cf621b]389# Download or updates the book source
[7b6ecc5]390 get_book
[1cf621b]391 extract_commands
[4965fa8]392 echo "${SD_BORDER}${nl_}"
[7b6ecc5]393
[4965fa8]394fi
395
[e576789]396# When regenerating the Makefile, we need to know also the
397# canonical book version
[a16f769]398if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
399 case $PROGNAME in
[92b7cb8]400 clfs* )
[a16f769]401 VERSION=$(xmllint --noent $JHALFSDIR/$BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
402 *)
403 VERSION=$(xmllint --noent $JHALFSDIR/$BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
404 esac
405fi
406
[4da2512]407build_Makefile
[3e7ceed]408
[4da2512]409echo "${SD_BORDER}${nl_}"
410
[1cf621b]411# Check for build prerequisites.
412 echo
413 cd $CWD
414 check_prerequisites
415 echo "${SD_BORDER}${nl_}"
416# All is well, run the build (if requested)
[4da2512]417run_make
Note: See TracBrowser for help on using the repository browser.