Improve top-level jhalfs based on shellcheck

* Various improvements from shellcheck around quoting, the use of
   read, `` vs $() and other logical comparisons
 * Provide a function for sourcing/loading files so we can remove a lot
   of duplication. Move loading of some functions from
   common/common-functions to ./jhalfs for consistency
 * Provide some functions for standardized messaging
 * Remove other duplication in the code, especially checking VERBOSITY
 * Standardize indentation. Two spaces seemed the most prevalent so I
   went with that.

Patch by Jeremy Huntwork, with slight modifications.
This commit is contained in:
Pierre Labastie 2019-04-13 16:31:24 +00:00
parent 2758d9421e
commit 0e4ddfa0c1
2 changed files with 140 additions and 154 deletions

View file

@ -34,9 +34,9 @@ run_make() { #
exit 1 exit 1
fi fi
# Build the system # Build the system
if [ -e $MKFILE ] ; then if [ -e "$MKFILE" ] ; then
echo -ne "Building the system...\n" echo -ne "Building the system...\n"
cd $JHALFSDIR && make cd "$JHALFSDIR" && make
echo -ne "done\n" echo -ne "done\n"
fi fi
fi fi
@ -97,27 +97,3 @@ if [ "${CLEAN}" = "y" ]; then
fi fi
fi fi
} }
VERBOSITY2=$VERBOSITY
[[ $VERBOSITY2 > 0 ]] && echo ""
[[ $VERBOSITY2 > 0 ]] && echo -n "Loading <func_book_parser>..."
source $COMMON_DIR/libs/func_book_parser
[[ $? > 0 ]] && echo "file libs/func_book_parser did not load.." && exit 1
[[ $VERBOSITY2 > 0 ]] && echo "OK"
[[ $VERBOSITY2 > 0 ]] && echo -n "Loading <func_download_pkgs>..."
source $COMMON_DIR/libs/func_download_pkgs
[[ $? > 0 ]] && echo "file libs/func_download_pkgs did not load.." && exit 1
[[ $VERBOSITY2 > 0 ]] && echo "OK"
[[ $VERBOSITY2 > 0 ]] && echo -n "Loading <func_wrt_Makefile>..."
source $COMMON_DIR/libs/func_wrt_Makefile
[[ $? > 0 ]] && echo "file libs/func_wrt_Makefile did not load.." && exit 1
[[ $VERBOSITY2 > 0 ]] && echo "OK"
[[ $VERBOSITY2 > 0 ]] && echo -n " ..."

238
jhalfs
View file

@ -5,27 +5,22 @@ set -e
set -E set -E
# VT100 colors # VT100 colors
declare -r BLACK=$'\e[1;30m'
declare -r DK_GRAY=$'\e[0;30m'
declare -r RED=$'\e[31m' declare -r RED=$'\e[31m'
declare -r GREEN=$'\e[32m' declare -r GREEN=$'\e[32m'
declare -r YELLOW=$'\e[33m' declare -r YELLOW=$'\e[33m'
declare -r BLUE=$'\e[34m'
declare -r MAGENTA=$'\e[35m'
declare -r CYAN=$'\e[36m'
declare -r WHITE=$'\e[37m'
# shellcheck disable=SC2034
declare -r BLUE=$'\e[34m'
declare -r OFF=$'\e[0m' declare -r OFF=$'\e[0m'
declare -r BOLD=$'\e[1m' declare -r BOLD=$'\e[1m'
declare -r REVERSE=$'\e[7m'
declare -r HIDDEN=$'\e[8m'
declare -r tab_=$'\t' declare -r tab_=$'\t'
declare -r nl_=$'\n' declare -r nl_=$'\n'
# shellcheck disable=SC2034
declare -r DD_BORDER="${BOLD}==============================================================================${OFF}" declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
# shellcheck disable=SC2034
declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}" declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
# shellcheck disable=SC2034
declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}" declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
# bold yellow > < pair # bold yellow > < pair
@ -37,20 +32,14 @@ declare -r L_arrow=$'\e[1;33m<\e[0m'
#-----------------------# #-----------------------#
simple_error() { # Basic error trap.... JUST DIE simple_error() { # Basic error trap.... JUST DIE
#-----------------------# #-----------------------#
# If +e then disable text output
if [[ "$-" =~ e ]]; then
LASTLINE="$1" LASTLINE="$1"
LASTERR="$2" LASTERR="$2"
LASTFUNC="$3"
LASTSOURCE="$4" LASTSOURCE="$4"
# echo -e "\n${RED}ERROR:${GREEN} basic error trapped!${OFF}\n" >&2 error_message "${GREEN} Error $LASTERR at $LASTSOURCE line ${LASTLINE}!"
echo -e "\n${RED}ERROR:${GREEN} Error $LASTERR at $LASTSOURCE line ${LASTLINE}!${OFF}\n" >&2
fi
exit $LASTERR
} }
see_ya() { see_ya() {
echo -e "\n${L_arrow}${BOLD}jhalfs${R_arrow} exit${OFF}\n" printf '\n%b%bjhalfs%b exit%b\n' "$L_arrow" "$BOLD" "$R_arrow" "$OFF"
} }
##### Simple error TRAPS ##### Simple error TRAPS
# ctrl-c SIGINT # ctrl-c SIGINT
@ -71,6 +60,45 @@ trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' \
# execute the handler # execute the handler
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
simple_message() {
# Prevents having to check $VERBOSITY everywhere
if [ "$VERBOSITY" -ne 0 ] ; then
# shellcheck disable=SC2059
printf "$*"
fi
}
warning_message() {
simple_message "${YELLOW}\\nWARNING:${OFF} $*\\n\\n"
}
error_message() {
# Prints an error message and exits with LASTERR or 1
if [ -n "$LASTERR" ] ; then
LASTERR=$(printf '%d' "$LASTERR")
else
LASTERR=1
fi
# If +e then disable text output
if [[ "$-" =~ e ]]; then
printf '\n\n%bERROR:%b %s\n' "$RED" "$OFF" "$*" >&2
fi
exit "$LASTERR"
}
load_file() {
# source files in a consistent way with an optional message
file="$1"
shift
msg="Loading file ${file}..."
[ -z "$*" ] || msg="$*..."
simple_message "$msg"
# shellcheck disable=SC1090
source "$file" 2>/dev/null || error_message "$file did not load"
simple_message "OK\\n"
}
version=" version="
${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$ ${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$
\$Date$ \$Date$
@ -96,11 +124,12 @@ esac
# If the user has not saved his configuration file, let's ask # If the user has not saved his configuration file, let's ask
# if he or she really wants to run this stuff # if he or she really wants to run this stuff
if [ $(ls -l --time-style='+%Y%m%d%H%M%S' configuration.old | cut -d' ' -f 6) \ time_old=$(stat -c '%Y' configuration.old 2>/dev/null)
-ge $(ls -l --time-style='+%Y%m%d%H%M%S' configuration | cut -d' ' -f 6) ] time_current=$(stat -c '%Y' configuration 2>/dev/null)
if [ "$(printf '%d' "$time_old")" -ge "$(printf '%d' "$time_current")" ]
then echo -n "Do you want to run jhalfs? yes/no (yes): " then echo -n "Do you want to run jhalfs? yes/no (yes): "
read ANSWER read -r ANSWER
if [ x${ANSWER:0:1} = "xn" -o x${ANSWER:0:1} = "xN" ] ; then if [ "x${ANSWER:0:1}" = "xn" ] || [ "x${ANSWER:0:1}" = "xN" ] ; then
echo "${nl_}Exiting gracefully.${nl_}" echo "${nl_}Exiting gracefully.${nl_}"
exit exit
fi fi
@ -109,10 +138,7 @@ fi
# Change this to 0 to suppress almost all messages # Change this to 0 to suppress almost all messages
VERBOSITY=1 VERBOSITY=1
[[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..." load_file configuration "Loading config params from <configuration>"
source configuration
[[ $? > 0 ]] && echo "file: configuration did not load.." && exit 1
[[ $VERBOSITY > 0 ]] && echo "OK"
# These are boolean vars generated from Config.in. # These are boolean vars generated from Config.in.
# ISSUE: If a boolean parameter is not set to y(es) there # ISSUE: If a boolean parameter is not set to y(es) there
@ -150,13 +176,14 @@ LOCAL=${LOCAL:=n}
REALSBU=${REALSBU:=n} REALSBU=${REALSBU:=n}
if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
# shellcheck disable=SC2034
NO_PROGRESS="#" NO_PROGRESS="#"
fi fi
# Sanity check on the location of $BUILDDIR / $JHALFSDIR # Sanity check on the location of $BUILDDIR / $JHALFSDIR
CWD=$(cd `dirname $0` && pwd) CWD="$(cd "$(dirname "$0")" && pwd)"
if [[ $JHALFSDIR == $CWD ]]; then if [[ $JHALFSDIR == "$CWD" ]]; then
echo " The jhalfs source directory conflicts with the jhalfs build directory." echo " The jhalfs source directory conflicts with the jhalfs build directory."
echo " Please move the source directory or change the build directory." echo " Please move the source directory or change the build directory."
exit 2 exit 2
@ -218,65 +245,59 @@ BOOK=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
#--- Envars not sourced from configuration #--- Envars not sourced from configuration
# shellcheck disable=SC2034
case $PROGNAME in case $PROGNAME in
clfs ) declare -r GIT="git://git.clfs.org/cross-lfs" ;; clfs ) declare -r GIT="git://git.clfs.org/cross-lfs" ;;
clfs2 ) declare -r GIT="git://git.clfs.org/clfs-sysroot" ;; clfs2 ) declare -r GIT="git://git.clfs.org/clfs-sysroot" ;;
clfs3 ) declare -r GIT="git://git.clfs.org/clfs-embedded" ;; clfs3 ) declare -r GIT="git://git.clfs.org/clfs-embedded" ;;
*) declare -r SVN="svn://svn.linuxfromscratch.org" ;; *) declare -r SVN="svn://svn.linuxfromscratch.org" ;;
esac esac
declare -r LOG=000-masterscript.log declare -r LOG=000-masterscript.log
# Needed for fetching BLFS book sources when building CLFS # Needed for fetching BLFS book sources when building CLFS
# shellcheck disable=SC2034
declare -r SVN_2="svn://svn.linuxfromscratch.org" declare -r SVN_2="svn://svn.linuxfromscratch.org"
# Set true internal variables # Set true internal variables
COMMON_DIR="common" COMMON_DIR="common"
PACKAGE_DIR=$(echo $PROGNAME | tr '[a-z]' '[A-Z]') PACKAGE_DIR=$(echo "$PROGNAME" | tr '[:lower:]' '[:upper:]')
MODULE=$PACKAGE_DIR/master.sh MODULE=$PACKAGE_DIR/master.sh
PKGMNGTDIR="pkgmngt" PKGMNGTDIR="pkgmngt"
# The name packageManager.xml is hardcoded in *.xsl, so no variable. # The name packageManager.xml is hardcoded in *.xsl, so no variable.
[[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..." for file in \
source $COMMON_DIR/common-functions "$COMMON_DIR/common-functions" \
[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit "$COMMON_DIR/libs/func_book_parser" \
[[ $VERBOSITY > 0 ]] && echo "OK" "$COMMON_DIR/libs/func_download_pkgs" \
[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..." "$COMMON_DIR/libs/func_wrt_Makefile" \
source $MODULE "$MODULE" ; do
[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2 load_file "$file"
[[ $VERBOSITY > 0 ]] && echo "OK" done
#
[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}" simple_message "${SD_BORDER}${nl_}"
#*******************************************************************# #*******************************************************************#
[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..." LASTERR=2
source $COMMON_DIR/libs/func_check_version.sh for file in \
[[ $? > 0 ]] && echo " function module did not load.." && exit 2 "$COMMON_DIR/libs/func_check_version.sh" \
[[ $VERBOSITY > 0 ]] && echo "OK" "$COMMON_DIR/libs/func_validate_configs.sh" \
"$COMMON_DIR/libs/func_custom_pkgs" ; do
load_file "$file"
done
unset LASTERR
[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..." simple_message "${SD_BORDER}${nl_}"
source $COMMON_DIR/libs/func_validate_configs.sh simple_message 'Checking tools required for jhalfs'
[[ $? > 0 ]] && echo " function module did not load.." && exit 2
[[ $VERBOSITY > 0 ]] && echo "OK"
[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_custom_pkgs>..."
source $COMMON_DIR/libs/func_custom_pkgs
[[ $? > 0 ]] && echo " function module did not load.." && exit 2
[[ $VERBOSITY > 0 ]] && echo "OK"
[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
[[ $VERBOSITY > 0 ]] && echo Checking tools required for jhalfs
check_alfs_tools check_alfs_tools
simple_message "${SD_BORDER}${nl_}"
[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
# blfs-tool envars # blfs-tool envars
BLFS_TOOL=${BLFS_TOOL:-n} BLFS_TOOL=${BLFS_TOOL:-n}
if [[ "${BLFS_TOOL}" = "y" ]] ; then if [[ "${BLFS_TOOL}" = "y" ]] ; then
[[ $VERBOSITY > 0 ]] && echo Checking supplementary tools for installing BLFS simple_message 'Checking supplementary tools for installing BLFS'
check_blfs_tools check_blfs_tools
[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}" simple_message "${SD_BORDER}${nl_}"
BLFS_SVN=${BLFS_SVN:-n} BLFS_SVN=${BLFS_SVN:-n}
BLFS_WORKING_COPY=${BLFS_WORKING_COPY:-n} BLFS_WORKING_COPY=${BLFS_WORKING_COPY:-n}
BLFS_BRANCH=${BLFS_BRANCH:-n} BLFS_BRANCH=${BLFS_BRANCH:-n}
@ -284,14 +305,13 @@ if [[ "${BLFS_TOOL}" = "y" ]] ; then
BLFS_BRANCH_ID=development BLFS_BRANCH_ID=development
BLFS_TREE=trunk/BOOK BLFS_TREE=trunk/BOOK
elif [[ "${BLFS_WORKING_COPY}" = "y" ]]; then elif [[ "${BLFS_WORKING_COPY}" = "y" ]]; then
[[ -d "$BLFS_WC_LOCATION" ]] && if [[ ! -d "$BLFS_WC_LOCATION/postlfs" ]] ; then
[[ -d "$BLFS_WC_LOCATION/postlfs" ]] || {
echo " BLFS tools: This is not a working copy: $BLFS_WC_LOCATION." echo " BLFS tools: This is not a working copy: $BLFS_WC_LOCATION."
echo " Please rerun make and fix the configuration." echo " Please rerun make and fix the configuration."
exit 2 exit 2
} fi
BLFS_TREE=$(cd $BLFS_WC_LOCATION; svn info | grep '^URL' | sed 's@.*BLFS/@@') BLFS_TREE=$(cd "$BLFS_WC_LOCATION"; svn info | grep '^URL' | sed 's@.*BLFS/@@')
BLFS_BRANCH_ID=$(echo $BLFS_TREE | sed -e 's@trunk/BOOK@development@' \ BLFS_BRANCH_ID=$(echo "$BLFS_TREE" | sed -e 's@trunk/BOOK@development@' \
-e 's@branches/@branch-@' \ -e 's@branches/@branch-@' \
-e 's@tags/@@' \ -e 's@tags/@@' \
-e 's@/BOOK@@') -e 's@/BOOK@@')
@ -306,10 +326,7 @@ if [[ "${BLFS_TOOL}" = "y" ]] ; then
* ) BLFS_TREE=tags/${BLFS_BRANCH_ID}/BOOK ;; * ) BLFS_TREE=tags/${BLFS_BRANCH_ID}/BOOK ;;
esac esac
fi fi
[[ $VERBOSITY > 0 ]] && echo -n "Loading blfs tools installation function..." load_file "${COMMON_DIR}/libs/func_install_blfs"
source $COMMON_DIR/libs/func_install_blfs
[[ $? > 0 ]] && echo "function module did not load.." && exit 1
[[ $VERBOSITY > 0 ]] && echo "OK"
fi fi
################################### ###################################
@ -320,8 +337,8 @@ fi
validate_config validate_config
echo "${SD_BORDER}${nl_}" echo "${SD_BORDER}${nl_}"
echo -n "Are you happy with these settings? yes/no (no): " echo -n "Are you happy with these settings? yes/no (no): "
read ANSWER read -r ANSWER
if [ x$ANSWER != "xyes" ] ; then if [ "x$ANSWER" != "xyes" ] ; then
echo "${nl_}Rerun make to fix the configuration options.${nl_}" echo "${nl_}Rerun make to fix the configuration options.${nl_}"
exit exit
fi fi
@ -330,25 +347,17 @@ echo "${nl_}${SD_BORDER}${nl_}"
# Load additional modules or configuration files based on global settings # Load additional modules or configuration files based on global settings
# compare module # compare module
if [[ "$COMPARE" = "y" ]]; then if [[ "$COMPARE" = "y" ]]; then
[[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..." load_file "${COMMON_DIR}/libs/func_compare.sh" 'Loading compare module'
source $COMMON_DIR/libs/func_compare.sh
[[ $? > 0 ]] && echo "$COMMON_DIR/libs/func_compare.sh did not load.." && exit
[[ $VERBOSITY > 0 ]] && echo "OK"
fi fi
# #
# optimize module # optimize module
if [[ "$OPTIMIZE" != "0" ]]; then if [[ "$OPTIMIZE" != "0" ]]; then
[[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..." load_file optimize/optimize_functions 'Loading optimization module'
source optimize/optimize_functions
[[ $? > 0 ]] && echo " optimize/optimize_functions did not load.." && exit
[[ $VERBOSITY > 0 ]] && echo "OK"
# #
# optimize configurations # optimize configurations
[[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..." load_file optimize/opt_config 'Loading optimization config'
source optimize/opt_config
[[ $? > 0 ]] && echo " optimize/opt_config did not load.." && exit
[[ $VERBOSITY > 0 ]] && echo "OK"
# The number of parallel jobs is taken from configuration now # The number of parallel jobs is taken from configuration now
# shellcheck disable=SC2034
MAKEFLAGS="-j${N_PARALLEL}" MAKEFLAGS="-j${N_PARALLEL}"
# Validate optimize settings, if required # Validate optimize settings, if required
validate_opt_settings validate_opt_settings
@ -361,74 +370,74 @@ if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
clean_builddir clean_builddir
if [[ ! -d $JHALFSDIR ]]; then if [[ ! -d $JHALFSDIR ]]; then
sudo mkdir -p $JHALFSDIR sudo mkdir -p "$JHALFSDIR"
sudo chown $USER:$USER $JHALFSDIR sudo chown "$USER":"$USER" "$JHALFSDIR"
fi fi
# Create $BUILDDIR/sources even though it could be created by get_sources() # Create $BUILDDIR/sources even though it could be created by get_sources()
if [[ ! -d $BUILDDIR/sources ]]; then if [[ ! -d $BUILDDIR/sources ]]; then
sudo mkdir -p $BUILDDIR/sources sudo mkdir -p "$BUILDDIR/sources"
sudo chmod a+wt $BUILDDIR/sources sudo chmod a+wt "$BUILDDIR/sources"
fi fi
# Create the log directory # Create the log directory
if [[ ! -d $LOGDIR ]]; then if [[ ! -d $LOGDIR ]]; then
mkdir $LOGDIR mkdir "$LOGDIR"
fi fi
>$LOGDIR/$LOG true >"$LOGDIR/$LOG"
# Copy common helper files # Copy common helper files
cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/ cp "$COMMON_DIR"/{makefile-functions,progress_bar.sh} "$JHALFSDIR/"
# Copy needed stylesheets # Copy needed stylesheets
cp $COMMON_DIR/{packages.xsl,chroot.xsl,kernfs.xsl} $JHALFSDIR/ cp "$COMMON_DIR"/{packages.xsl,chroot.xsl,kernfs.xsl} "$JHALFSDIR/"
# Fix the XSL book parser # Fix the XSL book parser
case $PROGNAME in case $PROGNAME in
clfs* ) sed 's,FAKEDIR,'${BOOK}/BOOK',' ${PACKAGE_DIR}/${XSL} > $JHALFSDIR/${XSL} ;; clfs* ) sed 's,FAKEDIR,'"${BOOK}/BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;;
lfs | hlfs ) sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL} ;; lfs | hlfs ) sed 's,FAKEDIR,'"$BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;;
* ) ;; * ) ;;
esac esac
export XSL=$JHALFSDIR/${XSL} export XSL=$JHALFSDIR/${XSL}
# Copy packageManager.xml, if needed # Copy packageManager.xml, if needed
[[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] && { [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] && {
cp $PKGMNGTDIR/packageManager.xml $JHALFSDIR/ cp "$PKGMNGTDIR/packageManager.xml" "$JHALFSDIR/"
cp $PKGMNGTDIR/packInstall.sh $JHALFSDIR/ cp "$PKGMNGTDIR/packInstall.sh" "$JHALFSDIR/"
} }
# Copy urls.xsl, if needed # Copy urls.xsl, if needed
[[ "$GETPKG" = "y" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/ [[ "$GETPKG" = "y" ]] && cp "$COMMON_DIR/urls.xsl" "$JHALFSDIR/"
# Always create the test-log directory to allow user to "uncomment" test # Always create the test-log directory to allow user to "uncomment" test
# instructions # instructions
install -d -m 1777 $TESTLOGDIR install -d -m 1777 "$TESTLOGDIR"
# Create the installed-files directory, if needed # Create the installed-files directory, if needed
[[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 $FILELOGDIR [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 "$FILELOGDIR"
# Prepare report creation, if needed # Prepare report creation, if needed
if [[ "$REPORT" = "y" ]]; then if [[ "$REPORT" = "y" ]]; then
cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/ cp $COMMON_DIR/create-sbu_du-report.sh "$JHALFSDIR/"
# After making sure that all looks sane, dump the settings to a file # After making sure that all looks sane, dump the settings to a file
# This file will be used to create the REPORT header # This file will be used to create the REPORT header
validate_config > $JHALFSDIR/jhalfs.config validate_config >"$JHALFSDIR/jhalfs.config"
fi fi
# Copy optimize files, if needed # Copy optimize files, if needed
[[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/ [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override "$JHALFSDIR/"
# Copy compare files, if needed # Copy compare files, if needed
if [[ "$COMPARE" = "y" ]]; then if [[ "$COMPARE" = "y" ]]; then
mkdir -p $JHALFSDIR/extras mkdir -p "$JHALFSDIR/extras"
cp extras/* $JHALFSDIR/extras cp extras/* "$JHALFSDIR/extras"
fi fi
# Copy custom tools config files, if requested # Copy custom tools config files, if requested
if [[ "${CUSTOM_TOOLS}" = "y" ]]; then if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
echo "Copying custom tool scripts to $JHALFSDIR" echo "Copying custom tool scripts to $JHALFSDIR"
mkdir -p $JHALFSDIR/custom-commands mkdir -p "$JHALFSDIR/custom-commands"
cp -f custom/config/* $JHALFSDIR/custom-commands cp -f custom/config/* "$JHALFSDIR/custom-commands"
fi fi
# Download or updates the book source # Download or updates the book source
@ -437,12 +446,12 @@ if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
get_book get_book
extract_commands extract_commands
echo "${SD_BORDER}${nl_}" echo "${SD_BORDER}${nl_}"
cd $CWD # the functions above change directory cd "$CWD" # the functions above change directory
# Install blfs-tool, if requested. # Install blfs-tool, if requested.
if [[ "${BLFS_TOOL}" = "y" ]] ; then if [[ "${BLFS_TOOL}" = "y" ]] ; then
echo Installing BLFS book and tools echo Installing BLFS book and tools
install_blfs_tools 2>&1 | tee -a $LOGDIR/$LOG install_blfs_tools 2>&1 | tee -a "$LOGDIR/$LOG"
[[ ${PIPESTATUS[0]} != 0 ]] && exit 1 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
fi fi
@ -450,19 +459,20 @@ fi
# When regenerating the Makefile, we need to know also the # When regenerating the Makefile, we need to know also the
# canonical book version # canonical book version
# shellcheck disable=SC2034
if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
case $PROGNAME in case $PROGNAME in
clfs* ) clfs* )
VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;; VERSION=$(xmllint --noent "$BOOK/prologue/$ARCH/bookinfo.xml" 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
lfs) lfs)
if [[ "$INITSYS" = "sysv" ]] ; then if [[ "$INITSYS" = "sysv" ]] ; then
VERSION=$(grep 'ENTITY version ' $BOOK/general.ent| cut -d\" -f2) VERSION=$(grep 'ENTITY version ' "$BOOK/general.ent" | cut -d\" -f2)
else else
VERSION=$(grep 'ENTITY versiond' $BOOK/general.ent| cut -d\" -f2) VERSION=$(grep 'ENTITY versiond' "$BOOK/general.ent" | cut -d\" -f2)
fi fi
;; ;;
*) *)
VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;; VERSION=$(xmllint --noent "$BOOK/prologue/bookinfo.xml" 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
esac esac
fi fi
@ -472,7 +482,7 @@ echo "${SD_BORDER}${nl_}"
# Check for build prerequisites. # Check for build prerequisites.
echo echo
cd $CWD cd "$CWD"
check_prerequisites check_prerequisites
echo "${SD_BORDER}${nl_}" echo "${SD_BORDER}${nl_}"
# All is well, run the build (if requested) # All is well, run the build (if requested)