source: jhalfs@ dfc023a

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

typo

  • Property mode set to 100755
File size: 13.9 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 Written by George Boudreau, Manuel Canales Esparcia, Pierre Labastie,
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}
113 See the ${BOLD}LICENSE${OFF} file in this directory.
114"
115
116case $1 in
117 -v ) echo "$version" && exit ;;
118 run ) : ;;
119 * )
120 echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
121 exit 1
122 ;;
123esac
124
125# If the user has not saved his configuration file, let's ask
126# if he or she really wants to run this stuff
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): '
131 read -r ANSWER
132 case ${ANSWER:0:1} in
133 n|N) printf "\nExiting gracefully.\n"; exit ;;
134 esac
135fi
136
137# Change this to 0 to suppress almost all messages
138VERBOSITY=1
139
140load_file configuration "Loading config params from <configuration>"
141
142# These are boolean vars generated from Config.in.
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).
148RUNMAKE=${RUNMAKE:-n}
149GETPKG=${GETPKG:-n}
150COMPARE=${COMPARE:-n}
151RUN_FARCE=${RUN_FARCE:-n}
152RUN_ICA=${RUN_ICA:-n}
153PKGMNGT=${PKGMNGT:-n}
154WRAP_INSTALL=${WRAP_INSTALL:-n}
155BOMB_TEST=${BOMB_TEST:-n}
156STRIP=${STRIP:=n}
157REPORT=${REPORT:=n}
158VIMLANG=${VIMLANG:-n}
159DEL_LA_FILES=${DEL_LA_FILES:-n}
160FULL_LOCALE=${FULL_LOCALE:-n}
161GRSECURITY_HOST=${GRSECURITY_HOST:-n}
162CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
163REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
164INSTALL_LOG=${INSTALL_LOG:-n}
165CLEAN=${CLEAN:=n}
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}
173UNICODE=${UNICODE:=n}
174LOCAL=${LOCAL:=n}
175REALSBU=${REALSBU:=n}
176
177if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
178# shellcheck disable=SC2034
179 NO_PROGRESS="#"
180fi
181
182
183# Sanity check on the location of $BUILDDIR / $JHALFSDIR
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
189fi
190
191# Book sources envars
192BRANCH_ID=${BRANCH_ID:=development}
193
194case $BRANCH_ID in
195 development )
196 case $PROGNAME in
197 clfs* ) TREE="" ;;
198 * ) TREE=trunk/BOOK ;;
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-* )
206 case $PROGNAME in
207 lfs )
208 LFSVRS=${BRANCH_ID}
209 TREE=branches/${BRANCH_ID#branch-}
210 if [ ${BRANCH_ID:7:1} = 6 ]; then
211 TREE=${TREE}/BOOK
212 fi
213 ;;
214 clfs* )
215 LFSVRS=${BRANCH_ID}
216 TREE=${BRANCH_ID#branch-}
217 ;;
218 esac
219 ;;
220 * )
221 case $PROGNAME in
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 )
230 LFSVRS=${BRANCH_ID}
231 TREE=tags/${BRANCH_ID}/BOOK
232 ;;
233 clfs* )
234 LFSVRS=${BRANCH_ID}
235 TREE=clfs-${BRANCH_ID}
236 ;;
237 * )
238 esac
239 ;;
240esac
241
242# Set the document location...
243BOOK=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
244
245
246#--- Envars not sourced from configuration
247# shellcheck disable=SC2034
248case $PROGNAME in
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" ;;
253esac
254
255declare -r LOG=000-masterscript.log
256# Needed for fetching BLFS book sources when building CLFS
257# shellcheck disable=SC2034
258declare -r SVN_2="svn://svn.linuxfromscratch.org"
259
260# Set true internal variables
261COMMON_DIR="common"
262PACKAGE_DIR=$(echo "$PROGNAME" | tr '[:lower:]' '[:upper:]')
263MODULE=$PACKAGE_DIR/master.sh
264PKGMNGTDIR="pkgmngt"
265# The name packageManager.xml is hardcoded in *.xsl, so no variable.
266
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
275
276simple_message "${SD_BORDER}${nl_}"
277
278
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_}"
290simple_message 'Checking tools required for jhalfs'
291check_alfs_tools
292simple_message "${SD_BORDER}${nl_}"
293
294# blfs-tool envars
295BLFS_TOOL=${BLFS_TOOL:-n}
296if [[ "${BLFS_TOOL}" = "y" ]] ; then
297 simple_message 'Checking supplementary tools for installing BLFS'
298 check_blfs_tools
299 simple_message "${SD_BORDER}${nl_}"
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
307 if [[ ! -d "$BLFS_WC_LOCATION/postlfs" ]] ; then
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
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@@')
317 elif [[ "${BLFS_BRANCH}" = "y" ]] ; then
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 ;;
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} ;;
325 * ) BLFS_TREE=tags/${BLFS_BRANCH_ID}/BOOK ;;
326 esac
327 fi
328 load_file "${COMMON_DIR}/libs/func_install_blfs"
329fi
330
331###################################
332### MAIN ###
333###################################
334
335
336validate_config
337echo "${SD_BORDER}${nl_}"
338echo -n "Are you happy with these settings? yes/no (no): "
339read -r ANSWER
340if [ "x$ANSWER" != "xyes" ] ; then
341 echo "${nl_}Rerun make to fix the configuration options.${nl_}"
342 exit
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
349 load_file "${COMMON_DIR}/libs/func_compare.sh" 'Loading compare module'
350fi
351#
352# optimize module
353if [[ "$OPTIMIZE" != "0" ]]; then
354 load_file optimize/optimize_functions 'Loading optimization module'
355 #
356 # optimize configurations
357 load_file optimize/opt_config 'Loading optimization config'
358 # The number of parallel jobs is taken from configuration now
359 # shellcheck disable=SC2034
360 MAKEFLAGS="-j${N_PARALLEL}"
361 # Validate optimize settings, if required
362 validate_opt_settings
363fi
364#
365
366if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
367
368# If requested, clean the build directory
369 clean_builddir
370
371 if [[ ! -d $JHALFSDIR ]]; then
372 sudo mkdir -p "$JHALFSDIR"
373 sudo chown "$USER":"$USER" "$JHALFSDIR"
374 fi
375
376# Create $BUILDDIR/sources even though it could be created by get_sources()
377 if [[ ! -d $BUILDDIR/sources ]]; then
378 sudo mkdir -p "$BUILDDIR/sources"
379 sudo chmod a+wt "$BUILDDIR/sources"
380 fi
381
382# Create the log directory
383 if [[ ! -d $LOGDIR ]]; then
384 mkdir "$LOGDIR"
385 fi
386 true >"$LOGDIR/$LOG"
387
388# Copy common helper files
389 cp "$COMMON_DIR"/{makefile-functions,progress_bar.sh} "$JHALFSDIR/"
390
391# Copy needed stylesheets
392 cp "$COMMON_DIR"/{packages.xsl,chroot.xsl,kernfs.xsl} "$JHALFSDIR/"
393
394# Fix the XSL book parser
395 case $PROGNAME in
396 clfs* ) sed 's,FAKEDIR,'"${BOOK}/BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;;
397 lfs | hlfs ) sed 's,FAKEDIR,'"$BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;;
398 * ) ;;
399 esac
400 export XSL=$JHALFSDIR/${XSL}
401
402# Copy packageManager.xml, if needed
403 [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] && {
404 cp "$PKGMNGTDIR/packageManager.xml" "$JHALFSDIR/"
405 cp "$PKGMNGTDIR/packInstall.sh" "$JHALFSDIR/"
406 }
407
408# Copy urls.xsl, if needed
409 [[ "$GETPKG" = "y" ]] && cp "$COMMON_DIR/urls.xsl" "$JHALFSDIR/"
410
411# Always create the test-log directory to allow user to "uncomment" test
412# instructions
413 install -d -m 1777 "$TESTLOGDIR"
414
415# Create the installed-files directory, if needed
416 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 "$FILELOGDIR"
417
418# Prepare report creation, if needed
419 if [[ "$REPORT" = "y" ]]; then
420 cp $COMMON_DIR/create-sbu_du-report.sh "$JHALFSDIR/"
421 # After making sure that all looks sane, dump the settings to a file
422 # This file will be used to create the REPORT header
423 validate_config >"$JHALFSDIR/jhalfs.config"
424 fi
425
426# Copy optimize files, if needed
427 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override "$JHALFSDIR/"
428
429# Copy compare files, if needed
430 if [[ "$COMPARE" = "y" ]]; then
431 mkdir -p "$JHALFSDIR/extras"
432 cp extras/* "$JHALFSDIR/extras"
433 fi
434
435# Copy custom tools config files, if requested
436 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
437 echo "Copying custom tool scripts to $JHALFSDIR"
438 mkdir -p "$JHALFSDIR/custom-commands"
439 cp -f custom/config/* "$JHALFSDIR/custom-commands"
440 fi
441
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_}"
448 cd "$CWD" # the functions above change directory
449
450# Install blfs-tool, if requested.
451 if [[ "${BLFS_TOOL}" = "y" ]] ; then
452 echo Installing BLFS book and tools
453 install_blfs_tools 2>&1 | tee -a "$LOGDIR/$LOG"
454 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
455 fi
456
457fi
458
459# When regenerating the Makefile, we need to know also the
460# canonical book version
461# shellcheck disable=SC2034
462if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
463 case $PROGNAME in
464 clfs* )
465 VERSION=$(xmllint --noent "$BOOK/prologue/$ARCH/bookinfo.xml" 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
466 lfs)
467 if [[ "$INITSYS" = "sysv" ]] ; then
468 VERSION=$(grep 'ENTITY version ' "$BOOK/general.ent" | cut -d\" -f2)
469 else
470 VERSION=$(grep 'ENTITY versiond' "$BOOK/general.ent" | cut -d\" -f2)
471 fi
472 ;;
473 *)
474 VERSION=$(xmllint --noent "$BOOK/prologue/bookinfo.xml" 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
475 esac
476fi
477
478build_Makefile
479
480echo "${SD_BORDER}${nl_}"
481
482# Check for build prerequisites.
483 echo
484 cd "$CWD"
485 check_prerequisites
486 echo "${SD_BORDER}${nl_}"
487# All is well, run the build (if requested)
488run_make
Note: See TracBrowser for help on using the repository browser.