4 # Pass trap handlers to functions
8 declare -r RED
=$
'\e[31m'
9 declare -r GREEN
=$
'\e[32m'
10 declare -r YELLOW
=$
'\e[33m'
12 # shellcheck disable=SC2034
13 declare -r BLUE
=$
'\e[34m'
14 declare -r OFF
=$
'\e[0m'
15 declare -r BOLD
=$
'\e[1m'
19 # shellcheck disable=SC2034
20 declare -r DD_BORDER
="${BOLD}==============================================================================${OFF}"
21 # shellcheck disable=SC2034
22 declare -r SD_BORDER
="${BOLD}------------------------------------------------------------------------------${OFF}"
23 # shellcheck disable=SC2034
24 declare -r STAR_BORDER
="${BOLD}******************************************************************************${OFF}"
26 # bold yellow > < pair
27 declare -r R_arrow
=$
'\e[1;33m>\e[0m'
28 declare -r L_arrow
=$
'\e[1;33m<\e[0m'
31 #>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
32 #-----------------------#
33 simple_error
() { # Basic error trap.... JUST DIE
34 #-----------------------#
38 error_message
"${GREEN} Error $LASTERR at $LASTSOURCE line ${LASTLINE}!"
42 printf '\n%b%bjhalfs%b exit%b\n' "$L_arrow" "$BOLD" "$R_arrow" "$OFF"
44 ##### Simple error TRAPS
49 # SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
52 # SIGTERM 15 TERMINATION
53 # SIGSTOP 17,18,23 STOP THE PROCESS
57 trap 'simple_error "${LINENO}" "$?" "${FUNCNAME}" "${BASH_SOURCE}"' ERR
58 trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' \
59 HUP INT QUIT TERM
# STOP stops tterminal output and does not seem to
61 #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
64 # Prevents having to check $VERBOSITY everywhere
65 if [ "$VERBOSITY" -ne 0 ] ; then
66 # shellcheck disable=SC2059
72 simple_message
"${YELLOW}\\nWARNING:${OFF} $*\\n\\n"
76 # Prints an error message and exits with LASTERR or 1
77 if [ -n "$LASTERR" ] ; then
78 LASTERR
=$
(printf '%d' "$LASTERR")
82 # If +e then disable text output
83 if [[ "$-" =~ e
]]; then
84 printf '\n\n%bERROR:%b %s\n' "$RED" "$OFF" "$*" >&2
90 # source files in a consistent way with an optional message
93 msg
="Loading file ${file}..."
94 [ -z "$*" ] || msg
="$*..."
97 # shellcheck disable=SC1090
98 source "$file" 2>/dev
/null || error_message
"$file did not load"
99 simple_message
"OK\\n"
103 ${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$
106 Copyright (C) 2005-2019, the jhalfs team:
109 Manuel Canales Esparcia
114 Unless specified, all the files in this directory and its sub-directories
115 are subjected to the ${BOLD}MIT license${OFF}. See the ${BOLD}LICENSE${OFF} file.
117 The files in the ${BOLD}menu${OFF} directory are subjected to the ${BOLD}ISC License${OFF}.
118 See ${BOLD}LICENSE.txt${OFF} and ${BOLD}README${OFF} in that directory.
121 usage
="${nl_}${tab_}${BOLD}${RED}This script cannot be called directly${OFF}
122 ${tab_}Type ${BOLD}make${OFF} to run the tool, or
123 ${tab_}Type ${BOLD}./jhalfs -v${OFF} to display version information."
126 -v ) echo "$version" && exit ;;
128 * ) echo "$usage" && exit 1 ;;
131 # If the user has not saved his configuration file, let's ask
132 # if he or she really wants to run this stuff
133 time_current
=$
(stat
-c '%Y' configuration
2>/dev
/null ||
date +%s
)
134 time_old
=$
(stat
-c '%Y' configuration.old
2>/dev
/null ||
printf '%s' "$time_current")
135 if [ "$(printf '%d' "$time_old")" -ge "$(printf '%d' "$time_current")" ] ; then
136 printf 'Do you want to run jhalfs? yes/no (yes): '
138 case ${ANSWER:0:1} in
139 n|N
) printf "\nExiting gracefully.\n"; exit ;;
143 # Change this to 0 to suppress almost all messages
146 load_file configuration
"Loading config params from <configuration>"
148 # These are boolean vars generated from Config.in.
149 # ISSUE: If a boolean parameter is not set to y(es) there
150 # is no variable defined by the menu app. This can
151 # cause a headache if you are not aware.
152 # The following variables MUST exist. If they don't, the
153 # default value is n(o).
154 RUNMAKE
=${RUNMAKE:-n}
156 COMPARE
=${COMPARE:-n}
157 RUN_ICA
=${RUN_ICA:-n}
158 PKGMNGT
=${PKGMNGT:-n}
159 WRAP_INSTALL
=${WRAP_INSTALL:-n}
160 BOMB_TEST
=${BOMB_TEST:-n}
163 NCURSES5
=${NCURSES5:-n}
164 DEL_LA_FILES
=${DEL_LA_FILES:-n}
165 FULL_LOCALE
=${FULL_LOCALE:-n}
166 GRSECURITY_HOST
=${GRSECURITY_HOST:-n}
167 CUSTOM_TOOLS
=${CUSTOM_TOOLS:-n}
168 REBUILD_MAKEFILE
=${REBUILD_MAKEFILE:-n}
169 INSTALL_LOG
=${INSTALL_LOG:-n}
171 SET_SSP
=${SET_SSP:=n}
172 SET_ASLR
=${SET_ASLR:=n}
173 SET_PAX
=${SET_PAX:=n}
174 SET_HARDENED_TMP
=${SET_HARDENED_TMP:=n}
175 SET_WARNINGS
=${SET_WARNINGS:=n}
176 SET_MISC
=${SET_MISC:=n}
177 SET_BLOWFISH
=${SET_BLOWFISH:=n}
178 UNICODE
=${UNICODE:=n}
180 REALSBU
=${REALSBU:=n}
181 SAVE_CH5
=${SAVE_CH5:=n}
183 if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
184 # shellcheck disable=SC2034
188 # Sanity check on the location of $BUILDDIR / $JHALFSDIR
189 CWD
="$(cd "$
(dirname "$0")" && pwd)"
190 if [[ $JHALFSDIR == "$CWD" ]]; then
191 echo " The jhalfs source directory conflicts with the jhalfs build directory."
192 echo " Please move the source directory or change the build directory."
196 # Book sources envars
197 BRANCH_ID
=${BRANCH_ID:=development}
203 * ) TREE
=trunk
/BOOK
;;
207 *EDIT
* ) echo " You forgot to set the branch or stable book version."
208 echo " Please rerun make and fix the configuration."
214 TREE
=branches
/${BRANCH_ID#branch-}
215 if [ ${BRANCH_ID:7:1} = 6 ]; then
221 TREE
=${BRANCH_ID#branch-}
229 TREE
=tags
/${BRANCH_ID}
230 case ${BRANCH_ID:0:2} in
233 *) TREE
=${TREE}/BOOK
;;
238 TREE
=tags
/${BRANCH_ID}/BOOK
242 TREE
=clfs-
${BRANCH_ID}
249 # Set the document location...
250 BOOK
=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
253 #--- Envars not sourced from configuration
254 # shellcheck disable=SC2034
256 clfs
) declare -r GIT
="git://git.clfs.org/cross-lfs" ;;
257 clfs2
) declare -r GIT
="git://git.clfs.org/clfs-sysroot" ;;
258 clfs3
) declare -r GIT
="git://git.clfs.org/clfs-embedded" ;;
259 *) declare -r SVN
="svn://svn.linuxfromscratch.org" ;;
262 declare -r LOG
=000-masterscript.log
263 # Needed for fetching BLFS book sources when building CLFS
264 # shellcheck disable=SC2034
265 declare -r SVN_2
="svn://svn.linuxfromscratch.org"
267 # Set true internal variables
269 PACKAGE_DIR
=$
(echo "$PROGNAME" |
tr '[:lower:]' '[:upper:]')
270 MODULE
=$PACKAGE_DIR/master.sh
272 # The name packageManager.xml is hardcoded in *.xsl, so no variable.
275 "$COMMON_DIR/common-functions" \
276 "$COMMON_DIR/libs/func_book_parser" \
277 "$COMMON_DIR/libs/func_download_pkgs" \
278 "$COMMON_DIR/libs/func_wrt_Makefile" \
283 simple_message
"${SD_BORDER}${nl_}"
286 #*******************************************************************#
289 "$COMMON_DIR/libs/func_check_version.sh" \
290 "$COMMON_DIR/libs/func_validate_configs.sh" \
291 "$COMMON_DIR/libs/func_custom_pkgs" ; do
296 simple_message
"${SD_BORDER}${nl_}"
297 simple_message
"Checking tools required for jhalfs${nl_}"
299 simple_message
"${SD_BORDER}${nl_}"
302 BLFS_TOOL
=${BLFS_TOOL:-n}
303 if [[ "${BLFS_TOOL}" = "y" ]] ; then
304 simple_message
'Checking supplementary tools for installing BLFS'
306 simple_message
"${SD_BORDER}${nl_}"
307 BLFS_SVN
=${BLFS_SVN:-n}
308 BLFS_WORKING_COPY
=${BLFS_WORKING_COPY:-n}
309 BLFS_BRANCH
=${BLFS_BRANCH:-n}
310 if [[ "${BLFS_SVN}" = "y" ]]; then
311 BLFS_BRANCH_ID
=development
313 elif [[ "${BLFS_WORKING_COPY}" = "y" ]]; then
314 if [[ ! -d "$BLFS_WC_LOCATION/postlfs" ]] ; then
315 echo " BLFS tools: This is not a working copy: $BLFS_WC_LOCATION."
316 echo " Please rerun make and fix the configuration."
319 BLFS_TREE
=$
(cd "$BLFS_WC_LOCATION"; svn info |
grep '^URL' |
sed 's@.*BLFS/@@')
320 BLFS_BRANCH_ID
=$
(echo "$BLFS_TREE" |
sed -e 's@trunk/BOOK@development@' \
321 -e 's@branches/@branch-@' \
324 elif [[ "${BLFS_BRANCH}" = "y" ]] ; then
325 case $BLFS_BRANCH_ID in
326 *EDIT
* ) echo " You forgot to set the BLFS branch or stable book version."
327 echo " Please rerun make and fix the configuration."
329 branch-6.
* ) BLFS_TREE
=branches
/${BLFS_BRANCH_ID#branch-}/BOOK
;;
330 branch-
* ) BLFS_TREE
=branches
/${BLFS_BRANCH_ID#branch-} ;;
331 [isv
]* |
6.3* ) BLFS_TREE
=tags
/${BLFS_BRANCH_ID}/BOOK
;;
332 * ) BLFS_TREE
=tags
/${BLFS_BRANCH_ID} ;;
335 load_file
"${COMMON_DIR}/libs/func_install_blfs"
338 ###################################
340 ###################################
344 echo "${SD_BORDER}${nl_}"
345 echo -n "Are you happy with these settings? yes/no (no): "
347 if [ "x$ANSWER" != "xyes" ] ; then
348 echo "${nl_}Rerun make to fix the configuration options.${nl_}"
351 echo "${nl_}${SD_BORDER}${nl_}"
353 # Load additional modules or configuration files based on global settings
355 if [[ "$COMPARE" = "y" ]]; then
356 load_file
"${COMMON_DIR}/libs/func_compare.sh" 'Loading compare module'
360 if [[ "$SAVE_CH5" = "y" ]]; then
361 load_file
"${COMMON_DIR}/libs/func_save.sh" 'Loading save module'
365 if [[ "$OPTIMIZE" != "0" ]]; then
366 load_file optimize
/optimize_functions
'Loading optimization module'
368 # optimize configurations
369 load_file optimize
/opt_config
'Loading optimization config'
370 # The number of parallel jobs is taken from configuration now
371 # shellcheck disable=SC2034
372 JH_MAKEFLAGS
="-j${N_PARALLEL}"
373 # Validate optimize settings, if required
374 validate_opt_settings
378 if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
380 # If requested, clean the build directory
383 if [[ ! -d $JHALFSDIR ]]; then
384 sudo mkdir
-p "$JHALFSDIR"
385 sudo chown
"$USER":"$USER" "$JHALFSDIR"
388 # Create $BUILDDIR/sources even though it could be created by get_sources()
389 if [[ ! -d $BUILDDIR/sources
]]; then
390 sudo mkdir
-p "$BUILDDIR/sources"
391 sudo
chmod a
+wt
"$BUILDDIR/sources"
394 # Create the log directory
395 if [[ ! -d $LOGDIR ]]; then
400 # Copy common helper files
401 cp "$COMMON_DIR"/{makefile-functions
,progress_bar.sh
} "$JHALFSDIR/"
403 # Copy needed stylesheets
404 cp "$COMMON_DIR"/{packages.xsl
,chroot.xsl
,kernfs.xsl
} "$JHALFSDIR/"
406 # Fix the XSL book parser
408 clfs
* ) sed 's,FAKEDIR,'"${BOOK}/BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;;
409 lfs | hlfs
) sed 's,FAKEDIR,'"$BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;;
412 export XSL
=$JHALFSDIR/${XSL}
414 # Copy packageManager.xml, if needed
415 [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] && {
416 sed s@BOOK@
"$BOOK"@
"$PKGMNGTDIR/packageManager.xml" > \
417 "$JHALFSDIR/"packageManager.xml
418 cp "$PKGMNGTDIR/packInstall.sh" "$JHALFSDIR/"
421 # Copy urls.xsl, if needed
422 [[ "$GETPKG" = "y" ]] && cp "$COMMON_DIR/urls.xsl" "$JHALFSDIR/"
424 # Always create the test-log directory to allow user to "uncomment" test
426 install -d -m 1777 "$TESTLOGDIR"
428 # Create the installed-files directory, if needed
429 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 "$FILELOGDIR"
431 # Prepare report creation, if needed
432 if [[ "$REPORT" = "y" ]]; then
433 cp $COMMON_DIR/create-sbu_du-report.sh
"$JHALFSDIR/"
434 # After making sure that all looks sane, dump the settings to a file
435 # This file will be used to create the REPORT header
436 validate_config
>"$JHALFSDIR/jhalfs.config"
439 # Copy optimize files, if needed
440 [[ "$OPTIMIZE" != "0" ]] && cp optimize
/opt_override
"$JHALFSDIR/"
442 # Copy compare files, if needed
443 if [[ "$COMPARE" = "y" ]]; then
444 mkdir
-p "$JHALFSDIR/extras"
445 cp extras
/* "$JHALFSDIR/extras"
448 # Copy custom tools config files, if requested
449 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
450 echo "Copying custom tool scripts to $JHALFSDIR"
451 mkdir
-p "$JHALFSDIR/custom-commands"
452 cp -f custom
/config
/* "$JHALFSDIR/custom-commands"
455 # Download or updates the book source
456 # Note that all customization to $JHALFSDIR have to be done before this.
457 # But the LFS book is needed for BLFS tools.
459 # At this point, we should have a way to know whether we have a cross
460 # or regular book... In case of cross, prohibite TEST=3
461 # the position of gcc-pass2 (chapter 6 or 5) tells us (not valid for
462 # cross-chap5 branch).
463 if (( TEST
== 3 )) && \
464 [ -f "$BOOK/chapter06/gcc-pass2.xml" ]; then
468 echo "${SD_BORDER}${nl_}"
469 cd "$CWD" # the functions above change directory
471 # Install blfs-tool, if requested.
472 if [[ "${BLFS_TOOL}" = "y" ]] ; then
473 echo Installing BLFS book and tools
474 install_blfs_tools
2>&1 |
tee -a "$LOGDIR/$LOG"
475 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
480 # shellcheck disable=SC2034
481 if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
482 # Sanity check: users tend to tick "rebuild Makefile"
483 # without generating one first. Check we have one:
484 if [ ! -f $MKFILE ]; then
486 error_message
"You cannot \"rebuild Makefile\" without first building one"
488 # When regenerating the Makefile, we need to know also the
489 # canonical book version
492 VERSION
=$
(xmllint
--noent "$BOOK/prologue/$ARCH/bookinfo.xml" 2>/dev
/null |
grep subtitle |
sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
494 if [[ "$INITSYS" = "sysv" ]] ; then
495 VERSION
=$
(grep 'ENTITY version ' "$BOOK/general.ent" | cut
-d\" -f2)
497 VERSION
=$
(grep 'ENTITY versiond' "$BOOK/general.ent" | cut
-d\" -f2)
501 VERSION
=$
(xmllint
--noent "$BOOK/prologue/bookinfo.xml" 2>/dev
/null |
grep subtitle |
sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
507 echo "${SD_BORDER}${nl_}"
509 # Check for build prerequisites.
513 echo "${SD_BORDER}${nl_}"
514 # All is well, run the build (if requested)