source: jhalfs@ 90f5b6d

ablfs-more legacy trunk
Last change on this file since 90f5b6d was d505128, checked in by Pierre Labastie <pierre@…>, 6 years ago

Do not exit on SIGCHLD:

With bash 5.0, a SIGCHLD signal is sent whenever a subshell exits. The signal
numbers passed to the trap instruction in jhalfs contain SIGCHLD, and this
new behavior causes jhalfs to exit. Fix this by using names instead of numbers
for the trap, and (of course) not trapping SIGCHLD.

  • Property mode set to 100755
File size: 14.5 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() {
[8d56c87]53 echo -e "\n${L_arrow}${BOLD}jhalfs${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
[d505128]69trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' \
70 HUP INT QUIT TERM # STOP stops tterminal output and does not seem to
71 # execute the handler
[4da2512]72#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
73
74version="
[8d56c87]75${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$
[4da2512]76 \$Date$
77
[8d56c87]78 Written by George Boudreau, Manuel Canales Esparcia, Pierre Labastie,
[4da2512]79 plus several contributions.
80
81 Based on an idea from Jeremy Huntwork
82
83 This set of files are published under the
84 ${BOLD}Gnu General Public License, Version 2.${OFF}
[8d56c87]85 See the ${BOLD}LICENCE${OFF} file in this directory.
[4da2512]86"
87
88case $1 in
[909ee37]89 -v ) echo "$version" && exit ;;
[4da2512]90 run ) : ;;
91 * )
92 echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
93 exit 1
94 ;;
95esac
96
[65c998b]97# If the user has not saved his configuration file, let's ask
98# if he or she really wants to run this stuff
99if [ $(ls -l --time-style='+%Y%m%d%H%M%S' configuration.old | cut -d' ' -f 6) \
100 -ge $(ls -l --time-style='+%Y%m%d%H%M%S' configuration | cut -d' ' -f 6) ]
101 then echo -n "Do you want to run jhalfs? yes/no (yes): "
102 read ANSWER
103 if [ x${ANSWER:0:1} = "xn" -o x${ANSWER:0:1} = "xN" ] ; then
104 echo "${nl_}Exiting gracefully.${nl_}"
105 exit
106 fi
107fi
108
109# Change this to 0 to suppress almost all messages
[4da2512]110VERBOSITY=1
111
112[[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..."
113source configuration
[7072e1f]114[[ $? > 0 ]] && echo "file: configuration did not load.." && exit 1
[4da2512]115[[ $VERBOSITY > 0 ]] && echo "OK"
116
117# These are boolean vars generated from Config.in.
[7072e1f]118# ISSUE: If a boolean parameter is not set to y(es) there
119# is no variable defined by the menu app. This can
120# cause a headache if you are not aware.
121# The following variables MUST exist. If they don't, the
122# default value is n(o).
[4da2512]123RUNMAKE=${RUNMAKE:-n}
124GETPKG=${GETPKG:-n}
125COMPARE=${COMPARE:-n}
126RUN_FARCE=${RUN_FARCE:-n}
127RUN_ICA=${RUN_ICA:-n}
[7072e1f]128PKGMNGT=${PKGMNGT:-n}
[945ccaa]129WRAP_INSTALL=${WRAP_INSTALL:-n}
[4da2512]130BOMB_TEST=${BOMB_TEST:-n}
131STRIP=${STRIP:=n}
132REPORT=${REPORT:=n}
133VIMLANG=${VIMLANG:-n}
[dc7fd7b]134DEL_LA_FILES=${DEL_LA_FILES:-n}
[b339c94]135FULL_LOCALE=${FULL_LOCALE:-n}
[4da2512]136GRSECURITY_HOST=${GRSECURITY_HOST:-n}
[9a536f7]137CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
[a16f769]138REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
[93346ee]139INSTALL_LOG=${INSTALL_LOG:-n}
[486e9a7]140CLEAN=${CLEAN:=n}
[d035526]141SET_SSP=${SET_SSP:=n}
142SET_ASLR=${SET_ASLR:=n}
143SET_PAX=${SET_PAX:=n}
144SET_HARDENED_TMP=${SET_HARDENED_TMP:=n}
145SET_WARNINGS=${SET_WARNINGS:=n}
146SET_MISC=${SET_MISC:=n}
147SET_BLOWFISH=${SET_BLOWFISH:=n}
[945ccaa]148UNICODE=${UNICODE:=n}
[84a3fda]149REALSBU=${REALSBU:=n}
[4da2512]150
[75d6d1c]151if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
152 NO_PROGRESS="#"
153fi
154
155
[38ae01f]156# Sanity check on the location of $BUILDDIR / $JHALFSDIR
157CWD=$(cd `dirname $0` && pwd)
158if [[ $JHALFSDIR == $CWD ]]; then
159 echo " The jhalfs source directory conflicts with the jhalfs build directory."
160 echo " Please move the source directory or change the build directory."
161 exit 2
162fi
163
[0873ccc]164# Book sources envars
[4965fa8]165BRANCH_ID=${BRANCH_ID:=development}
166
167case $BRANCH_ID in
168 development )
169 case $PROGNAME in
[92b7cb8]170 clfs* ) TREE="" ;;
[c4ad7bf]171 * ) TREE=trunk/BOOK ;;
[4965fa8]172 esac
173 LFSVRS=development
174 ;;
175 *EDIT* ) echo " You forgot to set the branch or stable book version."
176 echo " Please rerun make and fix the configuration."
177 exit 2 ;;
178 branch-* )
[c4ad7bf]179 case $PROGNAME in
180 lfs )
181 LFSVRS=${BRANCH_ID}
[bb2862d]182 TREE=branches/${BRANCH_ID#branch-}
[dd08e14]183 if [ ${BRANCH_ID:7:1} = 6 ]; then
[bb2862d]184 TREE=${TREE}/BOOK
185 fi
[c4ad7bf]186 ;;
187 clfs* )
188 LFSVRS=${BRANCH_ID}
189 TREE=${BRANCH_ID#branch-}
190 ;;
191 esac
[4965fa8]192 ;;
193 * )
194 case $PROGNAME in
[e650dc7]195 lfs )
196 LFSVRS=${BRANCH_ID}
197 TREE=tags/${BRANCH_ID}
198 if (( ${BRANCH_ID:0:1} < 7 )) ; then
199 TREE=${TREE}/BOOK
200 fi
201 ;;
202 hlfs )
[4965fa8]203 LFSVRS=${BRANCH_ID}
204 TREE=tags/${BRANCH_ID}/BOOK
205 ;;
[92b7cb8]206 clfs* )
[4965fa8]207 LFSVRS=${BRANCH_ID}
[34d1b6a]208 TREE=clfs-${BRANCH_ID}
[4965fa8]209 ;;
[92b7cb8]210 * )
[4965fa8]211 esac
212 ;;
213esac
214
[4da2512]215# Set the document location...
[1cf621b]216BOOK=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
[4da2512]217
[4965fa8]218
[728955b]219#--- Envars not sourced from configuration
220case $PROGNAME in
[4195a40]221 clfs ) declare -r GIT="git://git.clfs.org/cross-lfs" ;;
222 clfs2 ) declare -r GIT="git://git.clfs.org/clfs-sysroot" ;;
223 clfs3 ) declare -r GIT="git://git.clfs.org/clfs-embedded" ;;
[92b7cb8]224 *) declare -r SVN="svn://svn.linuxfromscratch.org" ;;
[728955b]225esac
226declare -r LOG=000-masterscript.log
[7072e1f]227 # Needed for fetching BLFS book sources when building CLFS
[728955b]228declare -r SVN_2="svn://svn.linuxfromscratch.org"
229
[4da2512]230# Set true internal variables
231COMMON_DIR="common"
[52b0d10]232PACKAGE_DIR=$(echo $PROGNAME | tr '[a-z]' '[A-Z]')
[4da2512]233MODULE=$PACKAGE_DIR/master.sh
[7072e1f]234PKGMNGTDIR="pkgmngt"
235# The name packageManager.xml is hardcoded in *.xsl, so no variable.
[4da2512]236
237[[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
238source $COMMON_DIR/common-functions
239[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
240[[ $VERBOSITY > 0 ]] && echo "OK"
241[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
242source $MODULE
243[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
244[[ $VERBOSITY > 0 ]] && echo "OK"
245#
246[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
247
248
249#*******************************************************************#
250[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
[d517356]251source $COMMON_DIR/libs/func_check_version.sh
[4da2512]252[[ $? > 0 ]] && echo " function module did not load.." && exit 2
253[[ $VERBOSITY > 0 ]] && echo "OK"
254
255[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
[d517356]256source $COMMON_DIR/libs/func_validate_configs.sh
[4da2512]257[[ $? > 0 ]] && echo " function module did not load.." && exit 2
258[[ $VERBOSITY > 0 ]] && echo "OK"
[9a536f7]259
[fe30c61]260[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_custom_pkgs>..."
261source $COMMON_DIR/libs/func_custom_pkgs
[9a536f7]262[[ $? > 0 ]] && echo " function module did not load.." && exit 2
263[[ $VERBOSITY > 0 ]] && echo "OK"
264
265
[6ed3dd7]266[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
267
268[[ $VERBOSITY > 0 ]] && echo Checking tools required for jhalfs
269check_alfs_tools
270
[4da2512]271[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
272
[e576789]273# blfs-tool envars
274BLFS_TOOL=${BLFS_TOOL:-n}
275if [[ "${BLFS_TOOL}" = "y" ]] ; then
[6ed3dd7]276 [[ $VERBOSITY > 0 ]] && echo Checking supplementary tools for installing BLFS
277 check_blfs_tools
278 [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
[854854e]279 BLFS_SVN=${BLFS_SVN:-n}
280 BLFS_WORKING_COPY=${BLFS_WORKING_COPY:-n}
281 BLFS_BRANCH=${BLFS_BRANCH:-n}
282 if [[ "${BLFS_SVN}" = "y" ]]; then
283 BLFS_BRANCH_ID=development
284 BLFS_TREE=trunk/BOOK
285 elif [[ "${BLFS_WORKING_COPY}" = "y" ]]; then
286 [[ -d "$BLFS_WC_LOCATION" ]] &&
287 [[ -d "$BLFS_WC_LOCATION/postlfs" ]] || {
288 echo " BLFS tools: This is not a working copy: $BLFS_WC_LOCATION."
289 echo " Please rerun make and fix the configuration."
290 exit 2
291 }
[2c4be7f]292 BLFS_TREE=$(cd $BLFS_WC_LOCATION; svn info | grep '^URL' | sed 's@.*BLFS/@@')
[854854e]293 BLFS_BRANCH_ID=$(echo $BLFS_TREE | sed -e 's@trunk/BOOK@development@' \
294 -e 's@branches/@branch-@' \
295 -e 's@tags/@@' \
296 -e 's@/BOOK@@')
[0ba80be]297 elif [[ "${BLFS_BRANCH}" = "y" ]] ; then
[854854e]298 case $BLFS_BRANCH_ID in
299 *EDIT* ) echo " You forgot to set the BLFS branch or stable book version."
300 echo " Please rerun make and fix the configuration."
301 exit 2 ;;
[dd08e14]302 branch-6.* ) BLFS_TREE=branches/${BLFS_BRANCH_ID#branch-}/BOOK ;;
303 branch-* ) BLFS_TREE=branches/${BLFS_BRANCH_ID#branch-} ;;
304 6.2* | 7.* | 8.*) BLFS_TREE=tags/${BLFS_BRANCH_ID} ;;
[854854e]305 * ) BLFS_TREE=tags/${BLFS_BRANCH_ID}/BOOK ;;
306 esac
307 fi
[e576789]308 [[ $VERBOSITY > 0 ]] && echo -n "Loading blfs tools installation function..."
309 source $COMMON_DIR/libs/func_install_blfs
310 [[ $? > 0 ]] && echo "function module did not load.." && exit 1
311 [[ $VERBOSITY > 0 ]] && echo "OK"
312fi
[4da2512]313
314###################################
315### MAIN ###
316###################################
317
318
319validate_config
320echo "${SD_BORDER}${nl_}"
321echo -n "Are you happy with these settings? yes/no (no): "
322read ANSWER
323if [ x$ANSWER != "xyes" ] ; then
[881c96f]324 echo "${nl_}Rerun make to fix the configuration options.${nl_}"
[d023a35]325 exit
[4da2512]326fi
327echo "${nl_}${SD_BORDER}${nl_}"
328
329# Load additional modules or configuration files based on global settings
330# compare module
331if [[ "$COMPARE" = "y" ]]; then
332 [[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..."
[d517356]333 source $COMMON_DIR/libs/func_compare.sh
334 [[ $? > 0 ]] && echo "$COMMON_DIR/libs/func_compare.sh did not load.." && exit
[4da2512]335 [[ $VERBOSITY > 0 ]] && echo "OK"
336fi
337#
338# optimize module
339if [[ "$OPTIMIZE" != "0" ]]; then
340 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
341 source optimize/optimize_functions
342 [[ $? > 0 ]] && echo " optimize/optimize_functions did not load.." && exit
343 [[ $VERBOSITY > 0 ]] && echo "OK"
344 #
345 # optimize configurations
346 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..."
347 source optimize/opt_config
348 [[ $? > 0 ]] && echo " optimize/opt_config did not load.." && exit
349 [[ $VERBOSITY > 0 ]] && echo "OK"
[854854e]350 # The number of parallel jobs is taken from configuration now
351 MAKEFLAGS="-j${N_PARALLEL}"
[4da2512]352 # Validate optimize settings, if required
353 validate_opt_settings
354fi
355#
356
[a16f769]357if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
[4da2512]358
[200fbde]359# If requested, clean the build directory
[7b6ecc5]360 clean_builddir
[4da2512]361
[7b6ecc5]362 if [[ ! -d $JHALFSDIR ]]; then
[c7b535b]363 sudo mkdir -p $JHALFSDIR
364 sudo chown $USER:$USER $JHALFSDIR
[7b6ecc5]365 fi
[3e7ceed]366
[200fbde]367# Create $BUILDDIR/sources even though it could be created by get_sources()
[7b6ecc5]368 if [[ ! -d $BUILDDIR/sources ]]; then
[c7b535b]369 sudo mkdir -p $BUILDDIR/sources
370 sudo chmod a+wt $BUILDDIR/sources
[7b6ecc5]371 fi
[200fbde]372
373# Create the log directory
[7b6ecc5]374 if [[ ! -d $LOGDIR ]]; then
375 mkdir $LOGDIR
376 fi
377 >$LOGDIR/$LOG
[200fbde]378
379# Copy common helper files
[d68eb1b]380 cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/
[200fbde]381
382# Copy needed stylesheets
[d68eb1b]383 cp $COMMON_DIR/{packages.xsl,chroot.xsl} $JHALFSDIR/
[200fbde]384
385# Fix the XSL book parser
[92b7cb8]386 case $PROGNAME in
387 clfs* ) sed 's,FAKEDIR,'${BOOK}/BOOK',' ${PACKAGE_DIR}/${XSL} > $JHALFSDIR/${XSL} ;;
388 lfs | hlfs ) sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL} ;;
389 * ) ;;
390 esac
[3e7ceed]391 export XSL=$JHALFSDIR/${XSL}
[7b6ecc5]392
[200fbde]393# Copy packageManager.xml, if needed
[3aa1acd]394 [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] && {
395 cp $PKGMNGTDIR/packageManager.xml $JHALFSDIR/
[7072e1f]396 cp $PKGMNGTDIR/packInstall.sh $JHALFSDIR/
[3aa1acd]397 }
[200fbde]398
399# Copy urls.xsl, if needed
[3e7ceed]400 [[ "$GETPKG" = "y" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
[200fbde]401
[c672fa8]402# Always create the test-log directory to allow user to "uncomment" test
403# instructions
404 install -d -m 1777 $TESTLOGDIR
[200fbde]405
406# Create the installed-files directory, if needed
[93346ee]407 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 $FILELOGDIR
[200fbde]408
409# Prepare report creation, if needed
[7b6ecc5]410 if [[ "$REPORT" = "y" ]]; then
411 cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
[7072e1f]412 # After making sure that all looks sane, dump the settings to a file
[7b6ecc5]413 # This file will be used to create the REPORT header
414 validate_config > $JHALFSDIR/jhalfs.config
415 fi
[200fbde]416
417# Copy optimize files, if needed
[3e7ceed]418 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
[200fbde]419
420# Copy compare files, if needed
[3e7ceed]421 if [[ "$COMPARE" = "y" ]]; then
422 mkdir -p $JHALFSDIR/extras
423 cp extras/* $JHALFSDIR/extras
424 fi
[200fbde]425
426# Copy custom tools config files, if requested
[3e7ceed]427 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
428 echo "Copying custom tool scripts to $JHALFSDIR"
429 mkdir -p $JHALFSDIR/custom-commands
430 cp -f custom/config/* $JHALFSDIR/custom-commands
431 fi
[200fbde]432
[f733772]433# Download or updates the book source
434# Note that all customization to $JHALFSDIR have to be done before this.
435# But the LFS book is needed for BLFS tools.
436 get_book
437 extract_commands
438 echo "${SD_BORDER}${nl_}"
439 cd $CWD # the functions above change directory
440
[200fbde]441# Install blfs-tool, if requested.
[7b6ecc5]442 if [[ "${BLFS_TOOL}" = "y" ]] ; then
[6ed3dd7]443 echo Installing BLFS book and tools
[e576789]444 install_blfs_tools 2>&1 | tee -a $LOGDIR/$LOG
[bbcdeab]445 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
[7b6ecc5]446 fi
447
[4965fa8]448fi
449
[e576789]450# When regenerating the Makefile, we need to know also the
451# canonical book version
[a16f769]452if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
453 case $PROGNAME in
[92b7cb8]454 clfs* )
[46ac330]455 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
[c9598f2]456 lfs)
457 if [[ "$INITSYS" = "sysv" ]] ; then
[46ac330]458 VERSION=$(grep 'ENTITY version ' $BOOK/general.ent| cut -d\" -f2)
[c9598f2]459 else
[46ac330]460 VERSION=$(grep 'ENTITY versiond' $BOOK/general.ent| cut -d\" -f2)
[c9598f2]461 fi
462 ;;
[a16f769]463 *)
[46ac330]464 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
[a16f769]465 esac
466fi
467
[4da2512]468build_Makefile
[3e7ceed]469
[4da2512]470echo "${SD_BORDER}${nl_}"
471
[1cf621b]472# Check for build prerequisites.
473 echo
474 cd $CWD
475 check_prerequisites
476 echo "${SD_BORDER}${nl_}"
477# All is well, run the build (if requested)
[4da2512]478run_make
Note: See TracBrowser for help on using the repository browser.