4 # Pass trap handlers to functions
8 declare -r BLACK
=$
'\e[1;30m'
9 declare -r DK_GRAY
=$
'\e[0;30m'
11 declare -r RED
=$
'\e[31m'
12 declare -r GREEN
=$
'\e[32m'
13 declare -r YELLOW
=$
'\e[33m'
14 declare -r BLUE
=$
'\e[34m'
15 declare -r MAGENTA
=$
'\e[35m'
16 declare -r CYAN
=$
'\e[36m'
17 declare -r WHITE
=$
'\e[37m'
19 declare -r OFF
=$
'\e[0m'
20 declare -r BOLD
=$
'\e[1m'
21 declare -r REVERSE
=$
'\e[7m'
22 declare -r HIDDEN
=$
'\e[8m'
27 declare -r DD_BORDER
="${BOLD}==============================================================================${OFF}"
28 declare -r SD_BORDER
="${BOLD}------------------------------------------------------------------------------${OFF}"
29 declare -r STAR_BORDER
="${BOLD}******************************************************************************${OFF}"
31 # bold yellow > < pair
32 declare -r R_arrow
=$
'\e[1;33m>\e[0m'
33 declare -r L_arrow
=$
'\e[1;33m<\e[0m'
36 #>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
37 #-----------------------#
38 simple_error
() { # Basic error trap.... JUST DIE
39 #-----------------------#
40 # If +e then disable text output
41 if [[ "$-" =~ e
]]; then
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
53 echo -e "\n${L_arrow}${BOLD}jhalfs${R_arrow} exit${OFF}\n"
55 ##### Simple error TRAPS
60 # SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
63 # SIGTERM 15 TERMINATION
64 # SIGSTOP 17,18,23 STOP THE PROCESS
68 trap 'simple_error "${LINENO}" "$?" "${FUNCNAME}" "${BASH_SOURCE}"' ERR
69 trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
70 #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
73 ${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$
76 Written by George Boudreau, Manuel Canales Esparcia, Pierre Labastie,
77 plus several contributions.
79 Based on an idea from Jeremy Huntwork
81 This set of files are published under the
82 ${BOLD}Gnu General Public License, Version 2.${OFF}
83 See the ${BOLD}LICENCE${OFF} file in this directory.
87 -v ) echo "$version" && exit ;;
90 echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
95 # If the user has not saved his configuration file, let's ask
96 # if he or she really wants to run this stuff
97 if [ $
(ls -l --time-style='+%Y%m%d%H%M%S' configuration.old | cut
-d' ' -f 6) \
98 -ge $
(ls -l --time-style='+%Y%m%d%H%M%S' configuration | cut
-d' ' -f 6) ]
99 then echo -n "Do you want to run jhalfs? yes/no (yes): "
101 if [ x
${ANSWER:0:1} = "xn" -o x
${ANSWER:0:1} = "xN" ] ; then
102 echo "${nl_}Exiting gracefully.${nl_}"
107 # Change this to 0 to suppress almost all messages
110 [[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..."
112 [[ $?
> 0 ]] && echo "file: configuration did not load.." && exit 1
113 [[ $VERBOSITY > 0 ]] && echo "OK"
115 # These are boolean vars generated from Config.in.
116 # ISSUE: If a boolean parameter is not set to y(es) there
117 # is no variable defined by the menu app. This can
118 # cause a headache if you are not aware.
119 # The following variables MUST exist. If they don't, the
120 # default value is n(o).
121 RUNMAKE
=${RUNMAKE:-n}
123 COMPARE
=${COMPARE:-n}
124 RUN_FARCE
=${RUN_FARCE:-n}
125 RUN_ICA
=${RUN_ICA:-n}
126 PKGMNGT
=${PKGMNGT:-n}
127 WRAP_INSTALL
=${WRAP_INSTALL:-n}
128 BOMB_TEST
=${BOMB_TEST:-n}
131 VIMLANG
=${VIMLANG:-n}
132 FULL_LOCALE
=${FULL_LOCALE:-n}
133 GRSECURITY_HOST
=${GRSECURITY_HOST:-n}
134 CUSTOM_TOOLS
=${CUSTOM_TOOLS:-n}
135 REBUILD_MAKEFILE
=${REBUILD_MAKEFILE:-n}
136 INSTALL_LOG
=${INSTALL_LOG:-n}
138 SET_SSP
=${SET_SSP:=n}
139 SET_ASLR
=${SET_ASLR:=n}
140 SET_PAX
=${SET_PAX:=n}
141 SET_HARDENED_TMP
=${SET_HARDENED_TMP:=n}
142 SET_WARNINGS
=${SET_WARNINGS:=n}
143 SET_MISC
=${SET_MISC:=n}
144 SET_BLOWFISH
=${SET_BLOWFISH:=n}
145 UNICODE
=${UNICODE:=n}
147 if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
152 # Sanity check on the location of $BUILDDIR / $JHALFSDIR
153 CWD
=$
(cd `dirname $0` && pwd)
154 if [[ $JHALFSDIR == $CWD ]]; then
155 echo " The jhalfs source directory conflicts with the jhalfs build directory."
156 echo " Please move the source directory or change the build directory."
160 # Book sources envars
161 BRANCH_ID
=${BRANCH_ID:=development}
167 * ) TREE
=trunk
/BOOK
;;
171 *EDIT
* ) echo " You forgot to set the branch or stable book version."
172 echo " Please rerun make and fix the configuration."
178 TREE
=branches
/${BRANCH_ID#branch-}
179 if [ ${BRANCH_ID#branch-} = 6 ]; then
185 TREE
=${BRANCH_ID#branch-}
193 TREE
=tags
/${BRANCH_ID}
194 if (( ${BRANCH_ID:0:1} < 7 )) ; then
200 TREE
=tags
/${BRANCH_ID}/BOOK
204 TREE
=clfs-
${BRANCH_ID}
211 # Set the document location...
212 BOOK
=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
215 #--- Envars not sourced from configuration
217 clfs
) declare -r GIT
="git://git.clfs.org/cross-lfs" ;;
218 clfs2
) declare -r GIT
="git://git.clfs.org/clfs-sysroot" ;;
219 clfs3
) declare -r GIT
="git://git.clfs.org/clfs-embedded" ;;
220 *) declare -r SVN
="svn://svn.linuxfromscratch.org" ;;
222 declare -r LOG
=000-masterscript.log
223 # Needed for fetching BLFS book sources when building CLFS
224 declare -r SVN_2
="svn://svn.linuxfromscratch.org"
226 # Set true internal variables
228 PACKAGE_DIR
=$
(echo $PROGNAME |
tr '[a-z]' '[A-Z]')
229 MODULE
=$PACKAGE_DIR/master.sh
231 # The name packageManager.xml is hardcoded in *.xsl, so no variable.
233 [[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
234 source $COMMON_DIR/common-functions
235 [[ $?
> 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
236 [[ $VERBOSITY > 0 ]] && echo "OK"
237 [[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
239 [[ $?
> 0 ]] && echo "$MODULE did not load.." && exit 2
240 [[ $VERBOSITY > 0 ]] && echo "OK"
242 [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
245 #*******************************************************************#
246 [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
247 source $COMMON_DIR/libs
/func_check_version.sh
248 [[ $?
> 0 ]] && echo " function module did not load.." && exit 2
249 [[ $VERBOSITY > 0 ]] && echo "OK"
251 [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
252 source $COMMON_DIR/libs
/func_validate_configs.sh
253 [[ $?
> 0 ]] && echo " function module did not load.." && exit 2
254 [[ $VERBOSITY > 0 ]] && echo "OK"
256 [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_custom_pkgs>..."
257 source $COMMON_DIR/libs
/func_custom_pkgs
258 [[ $?
> 0 ]] && echo " function module did not load.." && exit 2
259 [[ $VERBOSITY > 0 ]] && echo "OK"
262 [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
264 [[ $VERBOSITY > 0 ]] && echo Checking tools required
for jhalfs
267 [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
270 BLFS_TOOL
=${BLFS_TOOL:-n}
271 if [[ "${BLFS_TOOL}" = "y" ]] ; then
272 [[ $VERBOSITY > 0 ]] && echo Checking supplementary tools
for installing BLFS
274 [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
275 BLFS_SVN
=${BLFS_SVN:-n}
276 BLFS_WORKING_COPY
=${BLFS_WORKING_COPY:-n}
277 BLFS_BRANCH
=${BLFS_BRANCH:-n}
278 if [[ "${BLFS_SVN}" = "y" ]]; then
279 BLFS_BRANCH_ID
=development
281 elif [[ "${BLFS_WORKING_COPY}" = "y" ]]; then
282 [[ -d "$BLFS_WC_LOCATION" ]] &&
283 [[ -d "$BLFS_WC_LOCATION/postlfs" ]] ||
{
284 echo " BLFS tools: This is not a working copy: $BLFS_WC_LOCATION."
285 echo " Please rerun make and fix the configuration."
288 BLFS_TREE
=$
(cd $BLFS_WC_LOCATION; svn info |
grep '^URL' |
sed 's@.*BLFS/@@')
289 BLFS_BRANCH_ID
=$
(echo $BLFS_TREE |
sed -e 's@trunk/BOOK@development@' \
290 -e 's@branches/@branch-@' \
293 elif [[ "${BLFS_BRANCH}" = "y" ]] ; then
294 case $BLFS_BRANCH_ID in
295 *EDIT
* ) echo " You forgot to set the BLFS branch or stable book version."
296 echo " Please rerun make and fix the configuration."
298 branch-systemd
) BLFS_TREE
=branches
/systemd
;;
299 branch-
* ) BLFS_TREE
=branches
/${BLFS_BRANCH_ID#branch-}/BOOK
;;
300 6.2* |
7.
* ) BLFS_TREE
=tags
/${BLFS_BRANCH_ID} ;;
301 * ) BLFS_TREE
=tags
/${BLFS_BRANCH_ID}/BOOK
;;
304 [[ $VERBOSITY > 0 ]] && echo -n "Loading blfs tools installation function..."
305 source $COMMON_DIR/libs
/func_install_blfs
306 [[ $?
> 0 ]] && echo "function module did not load.." && exit 1
307 [[ $VERBOSITY > 0 ]] && echo "OK"
310 ###################################
312 ###################################
316 echo "${SD_BORDER}${nl_}"
317 echo -n "Are you happy with these settings? yes/no (no): "
319 if [ x
$ANSWER != "xyes" ] ; then
320 echo "${nl_}Rerun make to fix the configuration options.${nl_}"
323 echo "${nl_}${SD_BORDER}${nl_}"
325 # Load additional modules or configuration files based on global settings
327 if [[ "$COMPARE" = "y" ]]; then
328 [[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..."
329 source $COMMON_DIR/libs
/func_compare.sh
330 [[ $?
> 0 ]] && echo "$COMMON_DIR/libs/func_compare.sh did not load.." && exit
331 [[ $VERBOSITY > 0 ]] && echo "OK"
335 if [[ "$OPTIMIZE" != "0" ]]; then
336 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
337 source optimize
/optimize_functions
338 [[ $?
> 0 ]] && echo " optimize/optimize_functions did not load.." && exit
339 [[ $VERBOSITY > 0 ]] && echo "OK"
341 # optimize configurations
342 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..."
343 source optimize
/opt_config
344 [[ $?
> 0 ]] && echo " optimize/opt_config did not load.." && exit
345 [[ $VERBOSITY > 0 ]] && echo "OK"
346 # The number of parallel jobs is taken from configuration now
347 MAKEFLAGS
="-j${N_PARALLEL}"
348 # Validate optimize settings, if required
349 validate_opt_settings
353 if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
355 # If requested, clean the build directory
358 if [[ ! -d $JHALFSDIR ]]; then
362 # Create $BUILDDIR/sources even though it could be created by get_sources()
363 if [[ ! -d $BUILDDIR/sources
]]; then
364 mkdir
-p $BUILDDIR/sources
367 # Create the log directory
368 if [[ ! -d $LOGDIR ]]; then
373 # Copy common helper files
374 cp $COMMON_DIR/{makefile-functions
,progress_bar.sh
} $JHALFSDIR/
375 # Copy needed stylesheets
376 cp $COMMON_DIR/{packages.xsl
,chroot.xsl
} $JHALFSDIR/
378 # Fix the XSL book parser
380 clfs
* ) sed 's,FAKEDIR,'${BOOK}/BOOK',' ${PACKAGE_DIR}/${XSL} > $JHALFSDIR/${XSL} ;;
381 lfs | hlfs
) sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL} ;;
384 export XSL
=$JHALFSDIR/${XSL}
387 # Copy packageManager.xml, if needed
388 [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] && {
389 cp $PKGMNGTDIR/packageManager.xml
$JHALFSDIR/
390 cp $PKGMNGTDIR/packInstall.sh
$JHALFSDIR/
393 # Copy urls.xsl, if needed
394 [[ "$GETPKG" = "y" ]] && cp $COMMON_DIR/urls.xsl
$JHALFSDIR/
396 # Create the test-log directory, if needed
397 [[ "$TEST" != "0" ]] && [[ ! -d $TESTLOGDIR ]] && install -d -m 1777 $TESTLOGDIR
399 # Create the installed-files directory, if needed
400 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 $FILELOGDIR
402 # Prepare report creation, if needed
403 if [[ "$REPORT" = "y" ]]; then
404 cp $COMMON_DIR/create-sbu_du-report.sh
$JHALFSDIR/
405 # After making sure that all looks sane, dump the settings to a file
406 # This file will be used to create the REPORT header
407 validate_config
> $JHALFSDIR/jhalfs.config
410 # Copy optimize files, if needed
411 [[ "$OPTIMIZE" != "0" ]] && cp optimize
/opt_override
$JHALFSDIR/
413 # Copy compare files, if needed
414 if [[ "$COMPARE" = "y" ]]; then
415 mkdir
-p $JHALFSDIR/extras
416 cp extras
/* $JHALFSDIR/extras
419 # Copy custom tools config files, if requested
420 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
421 echo "Copying custom tool scripts to $JHALFSDIR"
422 mkdir
-p $JHALFSDIR/custom-commands
423 cp -f custom
/config
/* $JHALFSDIR/custom-commands
426 # Install blfs-tool, if requested.
427 if [[ "${BLFS_TOOL}" = "y" ]] ; then
428 echo Installing BLFS book and tools
429 install_blfs_tools
2>&1 |
tee -a $LOGDIR/$LOG
430 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
434 # Download or updates the book source
437 echo "${SD_BORDER}${nl_}"
441 # When regenerating the Makefile, we need to know also the
442 # canonical book version
443 if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
446 VERSION
=$
(xmllint
--noent $JHALFSDIR/$BOOK/prologue
/$ARCH/bookinfo.xml
2>/dev
/null |
grep subtitle |
sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
448 if [[ "$INITSYS" = "sysv" ]] ; then
449 VERSION
=$
(grep 'ENTITY version ' $JHALFSDIR/$BOOK/general.ent| cut
-d\" -f2)
451 VERSION
=$
(grep 'ENTITY versiond' $JHALFSDIR/$BOOK/general.ent| cut
-d\" -f2)
455 VERSION
=$
(xmllint
--noent $JHALFSDIR/$BOOK/prologue
/bookinfo.xml
2>/dev
/null |
grep subtitle |
sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
461 echo "${SD_BORDER}${nl_}"
463 # Check for build prerequisites.
467 echo "${SD_BORDER}${nl_}"
468 # All is well, run the build (if requested)