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