source: jhalfs@ 7fa9369

ablfs-more legacy trunk
Last change on this file since 7fa9369 was 183cc33, checked in by Pierre Labastie <pierre@…>, 6 years ago

Fix a missing newline in one message

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