source: jhalfs@ 5a965ad

ablfs-more legacy trunk
Last change on this file since 5a965ad was 5a965ad, checked in by Pierre Labastie <pierre@…>, 4 years ago

When copying packageManager.xml, use a sed to replace BOOK with $BOOK

This allows loading entities from the lfs book

  • Property mode set to 100755
File size: 14.7 KB
Line 
1#!/bin/bash
2# $Id$
3set -e
4# Pass trap handlers to functions
5set -E
6
7# VT100 colors
8declare -r RED=$'\e[31m'
9declare -r GREEN=$'\e[32m'
10declare -r YELLOW=$'\e[33m'
11
12# shellcheck disable=SC2034
13declare -r BLUE=$'\e[34m'
14declare -r OFF=$'\e[0m'
15declare -r BOLD=$'\e[1m'
16declare -r tab_=$'\t'
17declare -r nl_=$'\n'
18
19# shellcheck disable=SC2034
20declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
21# shellcheck disable=SC2034
22declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
23# shellcheck disable=SC2034
24declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
25
26# bold yellow > < pair
27declare -r R_arrow=$'\e[1;33m>\e[0m'
28declare -r L_arrow=$'\e[1;33m<\e[0m'
29
30
31#>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
32#-----------------------#
33simple_error() { # Basic error trap.... JUST DIE
34#-----------------------#
35 LASTLINE="$1"
36 LASTERR="$2"
37 LASTSOURCE="$4"
38 error_message "${GREEN} Error $LASTERR at $LASTSOURCE line ${LASTLINE}!"
39}
40
41see_ya() {
42 printf '\n%b%bjhalfs%b exit%b\n' "$L_arrow" "$BOLD" "$R_arrow" "$OFF"
43}
44##### Simple error TRAPS
45# ctrl-c SIGINT
46# ctrl-y
47# ctrl-z SIGTSTP
48# SIGHUP 1 HANGUP
49# SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
50# SIGQUIT 3
51# SIGKILL 9 KILL
52# SIGTERM 15 TERMINATION
53# SIGSTOP 17,18,23 STOP THE PROCESS
54#####
55set -e
56trap see_ya 0
57trap 'simple_error "${LINENO}" "$?" "${FUNCNAME}" "${BASH_SOURCE}"' ERR
58trap '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
60 # execute the handler
61#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
62
63simple_message() {
64 # Prevents having to check $VERBOSITY everywhere
65 if [ "$VERBOSITY" -ne 0 ] ; then
66 # shellcheck disable=SC2059
67 printf "$*"
68 fi
69}
70
71warning_message() {
72 simple_message "${YELLOW}\\nWARNING:${OFF} $*\\n\\n"
73}
74
75error_message() {
76 # Prints an error message and exits with LASTERR or 1
77 if [ -n "$LASTERR" ] ; then
78 LASTERR=$(printf '%d' "$LASTERR")
79 else
80 LASTERR=1
81 fi
82 # If +e then disable text output
83 if [[ "$-" =~ e ]]; then
84 printf '\n\n%bERROR:%b %s\n' "$RED" "$OFF" "$*" >&2
85 fi
86 exit "$LASTERR"
87}
88
89load_file() {
90 # source files in a consistent way with an optional message
91 file="$1"
92 shift
93 msg="Loading file ${file}..."
94 [ -z "$*" ] || msg="$*..."
95 simple_message "$msg"
96
97 # shellcheck disable=SC1090
98 source "$file" 2>/dev/null || error_message "$file did not load"
99 simple_message "OK\\n"
100}
101
102version="
103${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$
104 \$Date$
105
106 Copyright (C) 2005-2019, the jhalfs team:
107 Jeremy Huntwork
108 George Boudreau
109 Manuel Canales Esparcia
110 Thomas Pegg
111 Matthew Burgess
112 Pierre Labastie
113
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.
116
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.
119"
120
121usage="${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."
124
125case $1 in
126 -v ) echo "$version" && exit ;;
127 run ) : ;;
128 * ) echo "$usage" && exit 1 ;;
129esac
130
131# If the user has not saved his configuration file, let's ask
132# if he or she really wants to run this stuff
133time_current=$(stat -c '%Y' configuration 2>/dev/null || date +%s)
134time_old=$(stat -c '%Y' configuration.old 2>/dev/null || printf '%s' "$time_current")
135if [ "$(printf '%d' "$time_old")" -ge "$(printf '%d' "$time_current")" ] ; then
136 printf 'Do you want to run jhalfs? yes/no (yes): '
137 read -r ANSWER
138 case ${ANSWER:0:1} in
139 n|N) printf "\nExiting gracefully.\n"; exit ;;
140 esac
141fi
142
143# Change this to 0 to suppress almost all messages
144VERBOSITY=1
145
146load_file configuration "Loading config params from <configuration>"
147
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).
154RUNMAKE=${RUNMAKE:-n}
155GETPKG=${GETPKG:-n}
156COMPARE=${COMPARE:-n}
157RUN_ICA=${RUN_ICA:-n}
158PKGMNGT=${PKGMNGT:-n}
159WRAP_INSTALL=${WRAP_INSTALL:-n}
160BOMB_TEST=${BOMB_TEST:-n}
161STRIP=${STRIP:=n}
162REPORT=${REPORT:=n}
163NCURSES5=${NCURSES5:-n}
164DEL_LA_FILES=${DEL_LA_FILES:-n}
165FULL_LOCALE=${FULL_LOCALE:-n}
166GRSECURITY_HOST=${GRSECURITY_HOST:-n}
167CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
168REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
169INSTALL_LOG=${INSTALL_LOG:-n}
170CLEAN=${CLEAN:=n}
171SET_SSP=${SET_SSP:=n}
172SET_ASLR=${SET_ASLR:=n}
173SET_PAX=${SET_PAX:=n}
174SET_HARDENED_TMP=${SET_HARDENED_TMP:=n}
175SET_WARNINGS=${SET_WARNINGS:=n}
176SET_MISC=${SET_MISC:=n}
177SET_BLOWFISH=${SET_BLOWFISH:=n}
178UNICODE=${UNICODE:=n}
179LOCAL=${LOCAL:=n}
180REALSBU=${REALSBU:=n}
181SAVE_CH5=${SAVE_CH5:=n}
182
183if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
184# shellcheck disable=SC2034
185 NO_PROGRESS="#"
186fi
187
188# Sanity check on the location of $BUILDDIR / $JHALFSDIR
189CWD="$(cd "$(dirname "$0")" && pwd)"
190if [[ $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."
193 exit 2
194fi
195
196# Book sources envars
197BRANCH_ID=${BRANCH_ID:=development}
198
199case $BRANCH_ID in
200 development )
201 case $PROGNAME in
202 clfs* ) TREE="" ;;
203 * ) TREE=trunk/BOOK ;;
204 esac
205 LFSVRS=development
206 ;;
207 *EDIT* ) echo " You forgot to set the branch or stable book version."
208 echo " Please rerun make and fix the configuration."
209 exit 2 ;;
210 branch-* )
211 case $PROGNAME in
212 lfs )
213 LFSVRS=${BRANCH_ID}
214 TREE=branches/${BRANCH_ID#branch-}
215 if [ ${BRANCH_ID:7:1} = 6 ]; then
216 TREE=${TREE}/BOOK
217 fi
218 ;;
219 clfs* )
220 LFSVRS=${BRANCH_ID}
221 TREE=${BRANCH_ID#branch-}
222 ;;
223 esac
224 ;;
225 * )
226 case $PROGNAME in
227 lfs )
228 LFSVRS=${BRANCH_ID}
229 TREE=tags/${BRANCH_ID}
230 if (( ${BRANCH_ID:0:1} < 7 )) ; then
231 TREE=${TREE}/BOOK
232 fi
233 ;;
234 hlfs )
235 LFSVRS=${BRANCH_ID}
236 TREE=tags/${BRANCH_ID}/BOOK
237 ;;
238 clfs* )
239 LFSVRS=${BRANCH_ID}
240 TREE=clfs-${BRANCH_ID}
241 ;;
242 * )
243 esac
244 ;;
245esac
246
247# Set the document location...
248BOOK=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
249
250
251#--- Envars not sourced from configuration
252# shellcheck disable=SC2034
253case $PROGNAME in
254 clfs ) declare -r GIT="git://git.clfs.org/cross-lfs" ;;
255 clfs2 ) declare -r GIT="git://git.clfs.org/clfs-sysroot" ;;
256 clfs3 ) declare -r GIT="git://git.clfs.org/clfs-embedded" ;;
257 *) declare -r SVN="svn://svn.linuxfromscratch.org" ;;
258esac
259
260declare -r LOG=000-masterscript.log
261# Needed for fetching BLFS book sources when building CLFS
262# shellcheck disable=SC2034
263declare -r SVN_2="svn://svn.linuxfromscratch.org"
264
265# Set true internal variables
266COMMON_DIR="common"
267PACKAGE_DIR=$(echo "$PROGNAME" | tr '[:lower:]' '[:upper:]')
268MODULE=$PACKAGE_DIR/master.sh
269PKGMNGTDIR="pkgmngt"
270# The name packageManager.xml is hardcoded in *.xsl, so no variable.
271
272for file in \
273 "$COMMON_DIR/common-functions" \
274 "$COMMON_DIR/libs/func_book_parser" \
275 "$COMMON_DIR/libs/func_download_pkgs" \
276 "$COMMON_DIR/libs/func_wrt_Makefile" \
277 "$MODULE" ; do
278 load_file "$file"
279done
280
281simple_message "${SD_BORDER}${nl_}"
282
283
284#*******************************************************************#
285LASTERR=2
286for file in \
287 "$COMMON_DIR/libs/func_check_version.sh" \
288 "$COMMON_DIR/libs/func_validate_configs.sh" \
289 "$COMMON_DIR/libs/func_custom_pkgs" ; do
290 load_file "$file"
291done
292unset LASTERR
293
294simple_message "${SD_BORDER}${nl_}"
295simple_message "Checking tools required for jhalfs${nl_}"
296check_alfs_tools
297simple_message "${SD_BORDER}${nl_}"
298
299# blfs-tool envars
300BLFS_TOOL=${BLFS_TOOL:-n}
301if [[ "${BLFS_TOOL}" = "y" ]] ; then
302 simple_message 'Checking supplementary tools for installing BLFS'
303 check_blfs_tools
304 simple_message "${SD_BORDER}${nl_}"
305 BLFS_SVN=${BLFS_SVN:-n}
306 BLFS_WORKING_COPY=${BLFS_WORKING_COPY:-n}
307 BLFS_BRANCH=${BLFS_BRANCH:-n}
308 if [[ "${BLFS_SVN}" = "y" ]]; then
309 BLFS_BRANCH_ID=development
310 BLFS_TREE=trunk/BOOK
311 elif [[ "${BLFS_WORKING_COPY}" = "y" ]]; then
312 if [[ ! -d "$BLFS_WC_LOCATION/postlfs" ]] ; then
313 echo " BLFS tools: This is not a working copy: $BLFS_WC_LOCATION."
314 echo " Please rerun make and fix the configuration."
315 exit 2
316 fi
317 BLFS_TREE=$(cd "$BLFS_WC_LOCATION"; svn info | grep '^URL' | sed 's@.*BLFS/@@')
318 BLFS_BRANCH_ID=$(echo "$BLFS_TREE" | sed -e 's@trunk/BOOK@development@' \
319 -e 's@branches/@branch-@' \
320 -e 's@tags/@@' \
321 -e 's@/BOOK@@')
322 elif [[ "${BLFS_BRANCH}" = "y" ]] ; then
323 case $BLFS_BRANCH_ID in
324 *EDIT* ) echo " You forgot to set the BLFS branch or stable book version."
325 echo " Please rerun make and fix the configuration."
326 exit 2 ;;
327 branch-6.* ) BLFS_TREE=branches/${BLFS_BRANCH_ID#branch-}/BOOK ;;
328 branch-* ) BLFS_TREE=branches/${BLFS_BRANCH_ID#branch-} ;;
329 [isv]* | 6.3* ) BLFS_TREE=tags/${BLFS_BRANCH_ID}/BOOK ;;
330 * ) BLFS_TREE=tags/${BLFS_BRANCH_ID} ;;
331 esac
332 fi
333 load_file "${COMMON_DIR}/libs/func_install_blfs"
334fi
335
336###################################
337### MAIN ###
338###################################
339
340
341validate_config
342echo "${SD_BORDER}${nl_}"
343echo -n "Are you happy with these settings? yes/no (no): "
344read -r ANSWER
345if [ "x$ANSWER" != "xyes" ] ; then
346 echo "${nl_}Rerun make to fix the configuration options.${nl_}"
347 exit
348fi
349echo "${nl_}${SD_BORDER}${nl_}"
350
351# Load additional modules or configuration files based on global settings
352# compare module
353if [[ "$COMPARE" = "y" ]]; then
354 load_file "${COMMON_DIR}/libs/func_compare.sh" 'Loading compare module'
355fi
356#
357# save module
358if [[ "$SAVE_CH5" = "y" ]]; then
359 load_file "${COMMON_DIR}/libs/func_save.sh" 'Loading save module'
360fi
361#
362# optimize module
363if [[ "$OPTIMIZE" != "0" ]]; then
364 load_file optimize/optimize_functions 'Loading optimization module'
365 #
366 # optimize configurations
367 load_file optimize/opt_config 'Loading optimization config'
368 # The number of parallel jobs is taken from configuration now
369 # shellcheck disable=SC2034
370 JH_MAKEFLAGS="-j${N_PARALLEL}"
371 # Validate optimize settings, if required
372 validate_opt_settings
373fi
374#
375
376if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
377
378# If requested, clean the build directory
379 clean_builddir
380
381 if [[ ! -d $JHALFSDIR ]]; then
382 sudo mkdir -p "$JHALFSDIR"
383 sudo chown "$USER":"$USER" "$JHALFSDIR"
384 fi
385
386# Create $BUILDDIR/sources even though it could be created by get_sources()
387 if [[ ! -d $BUILDDIR/sources ]]; then
388 sudo mkdir -p "$BUILDDIR/sources"
389 sudo chmod a+wt "$BUILDDIR/sources"
390 fi
391
392# Create the log directory
393 if [[ ! -d $LOGDIR ]]; then
394 mkdir "$LOGDIR"
395 fi
396 true >"$LOGDIR/$LOG"
397
398# Copy common helper files
399 cp "$COMMON_DIR"/{makefile-functions,progress_bar.sh} "$JHALFSDIR/"
400
401# Copy needed stylesheets
402 cp "$COMMON_DIR"/{packages.xsl,chroot.xsl,kernfs.xsl} "$JHALFSDIR/"
403
404# Fix the XSL book parser
405 case $PROGNAME in
406 clfs* ) sed 's,FAKEDIR,'"${BOOK}/BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;;
407 lfs | hlfs ) sed 's,FAKEDIR,'"$BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;;
408 * ) ;;
409 esac
410 export XSL=$JHALFSDIR/${XSL}
411
412# Copy packageManager.xml, if needed
413 [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] && {
414 sed s@BOOK@"$BOOK"@ "$PKGMNGTDIR/packageManager.xml" > \
415 "$JHALFSDIR/"packageManager.xml
416 cp "$PKGMNGTDIR/packInstall.sh" "$JHALFSDIR/"
417 }
418
419# Copy urls.xsl, if needed
420 [[ "$GETPKG" = "y" ]] && cp "$COMMON_DIR/urls.xsl" "$JHALFSDIR/"
421
422# Always create the test-log directory to allow user to "uncomment" test
423# instructions
424 install -d -m 1777 "$TESTLOGDIR"
425
426# Create the installed-files directory, if needed
427 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 "$FILELOGDIR"
428
429# Prepare report creation, if needed
430 if [[ "$REPORT" = "y" ]]; then
431 cp $COMMON_DIR/create-sbu_du-report.sh "$JHALFSDIR/"
432 # After making sure that all looks sane, dump the settings to a file
433 # This file will be used to create the REPORT header
434 validate_config >"$JHALFSDIR/jhalfs.config"
435 fi
436
437# Copy optimize files, if needed
438 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override "$JHALFSDIR/"
439
440# Copy compare files, if needed
441 if [[ "$COMPARE" = "y" ]]; then
442 mkdir -p "$JHALFSDIR/extras"
443 cp extras/* "$JHALFSDIR/extras"
444 fi
445
446# Copy custom tools config files, if requested
447 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
448 echo "Copying custom tool scripts to $JHALFSDIR"
449 mkdir -p "$JHALFSDIR/custom-commands"
450 cp -f custom/config/* "$JHALFSDIR/custom-commands"
451 fi
452
453# Download or updates the book source
454# Note that all customization to $JHALFSDIR have to be done before this.
455# But the LFS book is needed for BLFS tools.
456 get_book
457# At this point, we should have a way to know whether we have a cross
458# or regular book... In case of cross, prohibite TEST=3
459# the position of gcc-pass2 (chapter 6 or 5) tells us (not valid for
460# cross-chap5 branch).
461 if (( TEST == 3 )) && \
462 [ -f "$BOOK/chapter06/gcc-pass2.xml" ]; then
463 TEST=2
464 fi
465 extract_commands
466 echo "${SD_BORDER}${nl_}"
467 cd "$CWD" # the functions above change directory
468
469# Install blfs-tool, if requested.
470 if [[ "${BLFS_TOOL}" = "y" ]] ; then
471 echo Installing BLFS book and tools
472 install_blfs_tools 2>&1 | tee -a "$LOGDIR/$LOG"
473 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
474 fi
475
476fi
477
478# When regenerating the Makefile, we need to know also the
479# canonical book version
480# shellcheck disable=SC2034
481if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
482 case $PROGNAME in
483 clfs* )
484 VERSION=$(xmllint --noent "$BOOK/prologue/$ARCH/bookinfo.xml" 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
485 lfs)
486 if [[ "$INITSYS" = "sysv" ]] ; then
487 VERSION=$(grep 'ENTITY version ' "$BOOK/general.ent" | cut -d\" -f2)
488 else
489 VERSION=$(grep 'ENTITY versiond' "$BOOK/general.ent" | cut -d\" -f2)
490 fi
491 ;;
492 *)
493 VERSION=$(xmllint --noent "$BOOK/prologue/bookinfo.xml" 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
494 esac
495fi
496
497build_Makefile
498
499echo "${SD_BORDER}${nl_}"
500
501# Check for build prerequisites.
502 echo
503 cd "$CWD"
504 check_prerequisites
505 echo "${SD_BORDER}${nl_}"
506# All is well, run the build (if requested)
507run_make
Note: See TracBrowser for help on using the repository browser.