- Timestamp:
- 04/13/2019 04:31:24 PM (5 years ago)
- Branches:
- ablfs-more, legacy, trunk
- Children:
- bc2f591
- Parents:
- 2758d94
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
jhalfs
r2758d94 r0e4ddfa 6 6 7 7 # VT100 colors 8 declare -r BLACK=$'\e[1;30m'9 declare -r DK_GRAY=$'\e[0;30m'10 11 8 declare -r RED=$'\e[31m' 12 9 declare -r GREEN=$'\e[32m' 13 10 declare -r YELLOW=$'\e[33m' 11 12 # shellcheck disable=SC2034 14 13 declare -r BLUE=$'\e[34m' 15 declare -r MAGENTA=$'\e[35m'16 declare -r CYAN=$'\e[36m'17 declare -r WHITE=$'\e[37m'18 19 14 declare -r OFF=$'\e[0m' 20 15 declare -r BOLD=$'\e[1m' 21 declare -r REVERSE=$'\e[7m'22 declare -r HIDDEN=$'\e[8m'23 24 16 declare -r tab_=$'\t' 25 17 declare -r nl_=$'\n' 26 18 19 # shellcheck disable=SC2034 27 20 declare -r DD_BORDER="${BOLD}==============================================================================${OFF}" 21 # shellcheck disable=SC2034 28 22 declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}" 23 # shellcheck disable=SC2034 29 24 declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}" 30 25 … … 38 33 simple_error() { # Basic error trap.... JUST DIE 39 34 #-----------------------# 40 # If +e then disable text output 41 if [[ "$-" =~ e ]]; then 42 LASTLINE="$1" 43 LASTERR="$2" 44 LASTFUNC="$3" 45 LASTSOURCE="$4" 46 # echo -e "\n${RED}ERROR:${GREEN} basic error trapped!${OFF}\n" >&2 47 echo -e "\n${RED}ERROR:${GREEN} Error $LASTERR at $LASTSOURCE line ${LASTLINE}!${OFF}\n" >&2 48 fi 49 exit $LASTERR 35 LASTLINE="$1" 36 LASTERR="$2" 37 LASTSOURCE="$4" 38 error_message "${GREEN} Error $LASTERR at $LASTSOURCE line ${LASTLINE}!" 50 39 } 51 40 52 41 see_ya() { 53 echo -e "\n${L_arrow}${BOLD}jhalfs${R_arrow} exit${OFF}\n"42 printf '\n%b%bjhalfs%b exit%b\n' "$L_arrow" "$BOLD" "$R_arrow" "$OFF" 54 43 } 55 44 ##### Simple error TRAPS … … 72 61 #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 73 62 63 simple_message() { 64 # Prevents having to check $VERBOSITY everywhere 65 if [ "$VERBOSITY" -ne 0 ] ; then 66 # shellcheck disable=SC2059 67 printf "$*" 68 fi 69 } 70 71 warning_message() { 72 simple_message "${YELLOW}\\nWARNING:${OFF} $*\\n\\n" 73 } 74 75 error_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 89 load_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 74 102 version=" 75 103 ${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$ … … 97 125 # If the user has not saved his configuration file, let's ask 98 126 # if he or she really wants to run this stuff 99 if [ $(ls -l --time-style='+%Y%m%d%H%M%S' configuration.old | cut -d' ' -f 6) \ 100 -ge $(ls -l --time-style='+%Y%m%d%H%M%S' configuration | cut -d' ' -f 6) ] 127 time_old=$(stat -c '%Y' configuration.old 2>/dev/null) 128 time_current=$(stat -c '%Y' configuration 2>/dev/null) 129 if [ "$(printf '%d' "$time_old")" -ge "$(printf '%d' "$time_current")" ] 101 130 then echo -n "Do you want to run jhalfs? yes/no (yes): " 102 read ANSWER103 if [ x${ANSWER:0:1} = "xn" -o x${ANSWER:0:1}= "xN" ] ; then131 read -r ANSWER 132 if [ "x${ANSWER:0:1}" = "xn" ] || [ "x${ANSWER:0:1}" = "xN" ] ; then 104 133 echo "${nl_}Exiting gracefully.${nl_}" 105 134 exit … … 110 139 VERBOSITY=1 111 140 112 [[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..." 113 source configuration 114 [[ $? > 0 ]] && echo "file: configuration did not load.." && exit 1 115 [[ $VERBOSITY > 0 ]] && echo "OK" 141 load_file configuration "Loading config params from <configuration>" 116 142 117 143 # These are boolean vars generated from Config.in. … … 151 177 152 178 if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then 153 NO_PROGRESS="#" 179 # shellcheck disable=SC2034 180 NO_PROGRESS="#" 154 181 fi 155 182 156 183 157 184 # Sanity check on the location of $BUILDDIR / $JHALFSDIR 158 CWD= $(cd `dirname $0` && pwd)159 if [[ $JHALFSDIR == $CWD]]; then160 161 162 185 CWD="$(cd "$(dirname "$0")" && pwd)" 186 if [[ $JHALFSDIR == "$CWD" ]]; then 187 echo " The jhalfs source directory conflicts with the jhalfs build directory." 188 echo " Please move the source directory or change the build directory." 189 exit 2 163 190 fi 164 191 … … 219 246 220 247 #--- Envars not sourced from configuration 248 # shellcheck disable=SC2034 221 249 case $PROGNAME in 222 223 224 225 250 clfs ) declare -r GIT="git://git.clfs.org/cross-lfs" ;; 251 clfs2 ) declare -r GIT="git://git.clfs.org/clfs-sysroot" ;; 252 clfs3 ) declare -r GIT="git://git.clfs.org/clfs-embedded" ;; 253 *) declare -r SVN="svn://svn.linuxfromscratch.org" ;; 226 254 esac 255 227 256 declare -r LOG=000-masterscript.log 228 # Needed for fetching BLFS book sources when building CLFS 257 # Needed for fetching BLFS book sources when building CLFS 258 # shellcheck disable=SC2034 229 259 declare -r SVN_2="svn://svn.linuxfromscratch.org" 230 260 231 261 # Set true internal variables 232 262 COMMON_DIR="common" 233 PACKAGE_DIR=$(echo $PROGNAME | tr '[a-z]' '[A-Z]')263 PACKAGE_DIR=$(echo "$PROGNAME" | tr '[:lower:]' '[:upper:]') 234 264 MODULE=$PACKAGE_DIR/master.sh 235 265 PKGMNGTDIR="pkgmngt" 236 266 # The name packageManager.xml is hardcoded in *.xsl, so no variable. 237 267 238 [[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..." 239 source $COMMON_DIR/common-functions 240 [[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit 241 [[ $VERBOSITY > 0 ]] && echo "OK" 242 [[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..." 243 source $MODULE 244 [[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2 245 [[ $VERBOSITY > 0 ]] && echo "OK" 246 # 247 [[ $VERBOSITY > 0 ]] && echo"${SD_BORDER}${nl_}"268 for file in \ 269 "$COMMON_DIR/common-functions" \ 270 "$COMMON_DIR/libs/func_book_parser" \ 271 "$COMMON_DIR/libs/func_download_pkgs" \ 272 "$COMMON_DIR/libs/func_wrt_Makefile" \ 273 "$MODULE" ; do 274 load_file "$file" 275 done 276 277 simple_message "${SD_BORDER}${nl_}" 248 278 249 279 250 280 #*******************************************************************# 251 [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..." 252 source $COMMON_DIR/libs/func_check_version.sh 253 [[ $? > 0 ]] && echo " function module did not load.." && exit 2 254 [[ $VERBOSITY > 0 ]] && echo "OK" 255 256 [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..." 257 source $COMMON_DIR/libs/func_validate_configs.sh 258 [[ $? > 0 ]] && echo " function module did not load.." && exit 2 259 [[ $VERBOSITY > 0 ]] && echo "OK" 260 261 [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_custom_pkgs>..." 262 source $COMMON_DIR/libs/func_custom_pkgs 263 [[ $? > 0 ]] && echo " function module did not load.." && exit 2 264 [[ $VERBOSITY > 0 ]] && echo "OK" 265 266 267 [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}" 268 269 [[ $VERBOSITY > 0 ]] && echo Checking tools required for jhalfs 281 LASTERR=2 282 for file in \ 283 "$COMMON_DIR/libs/func_check_version.sh" \ 284 "$COMMON_DIR/libs/func_validate_configs.sh" \ 285 "$COMMON_DIR/libs/func_custom_pkgs" ; do 286 load_file "$file" 287 done 288 unset LASTERR 289 290 simple_message "${SD_BORDER}${nl_}" 291 simple_message 'Checking tools required for jhalfs' 270 292 check_alfs_tools 271 272 [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}" 293 simple_message "${SD_BORDER}${nl_}" 273 294 274 295 # blfs-tool envars 275 296 BLFS_TOOL=${BLFS_TOOL:-n} 276 297 if [[ "${BLFS_TOOL}" = "y" ]] ; then 277 [[ $VERBOSITY > 0 ]] && echo Checking supplementary tools for installing BLFS298 simple_message 'Checking supplementary tools for installing BLFS' 278 299 check_blfs_tools 279 [[ $VERBOSITY > 0 ]] && echo"${SD_BORDER}${nl_}"300 simple_message "${SD_BORDER}${nl_}" 280 301 BLFS_SVN=${BLFS_SVN:-n} 281 302 BLFS_WORKING_COPY=${BLFS_WORKING_COPY:-n} … … 285 306 BLFS_TREE=trunk/BOOK 286 307 elif [[ "${BLFS_WORKING_COPY}" = "y" ]]; then 287 [[ -d "$BLFS_WC_LOCATION" ]] && 288 [[ -d "$BLFS_WC_LOCATION/postlfs" ]] || { 308 if [[ ! -d "$BLFS_WC_LOCATION/postlfs" ]] ; then 289 309 echo " BLFS tools: This is not a working copy: $BLFS_WC_LOCATION." 290 310 echo " Please rerun make and fix the configuration." 291 311 exit 2 292 }293 BLFS_TREE=$(cd $BLFS_WC_LOCATION; svn info | grep '^URL' | sed 's@.*BLFS/@@')294 BLFS_BRANCH_ID=$(echo $BLFS_TREE| sed -e 's@trunk/BOOK@development@' \295 -e 's@branches/@branch-@' \296 -e 's@tags/@@' \297 -e 's@/BOOK@@')312 fi 313 BLFS_TREE=$(cd "$BLFS_WC_LOCATION"; svn info | grep '^URL' | sed 's@.*BLFS/@@') 314 BLFS_BRANCH_ID=$(echo "$BLFS_TREE" | sed -e 's@trunk/BOOK@development@' \ 315 -e 's@branches/@branch-@' \ 316 -e 's@tags/@@' \ 317 -e 's@/BOOK@@') 298 318 elif [[ "${BLFS_BRANCH}" = "y" ]] ; then 299 319 case $BLFS_BRANCH_ID in … … 307 327 esac 308 328 fi 309 [[ $VERBOSITY > 0 ]] && echo -n "Loading blfs tools installation function..." 310 source $COMMON_DIR/libs/func_install_blfs 311 [[ $? > 0 ]] && echo "function module did not load.." && exit 1 312 [[ $VERBOSITY > 0 ]] && echo "OK" 329 load_file "${COMMON_DIR}/libs/func_install_blfs" 313 330 fi 314 331 … … 321 338 echo "${SD_BORDER}${nl_}" 322 339 echo -n "Are you happy with these settings? yes/no (no): " 323 read ANSWER324 if [ x$ANSWER!= "xyes" ] ; then340 read -r ANSWER 341 if [ "x$ANSWER" != "xyes" ] ; then 325 342 echo "${nl_}Rerun make to fix the configuration options.${nl_}" 326 343 exit … … 331 348 # compare module 332 349 if [[ "$COMPARE" = "y" ]]; then 333 [[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..." 334 source $COMMON_DIR/libs/func_compare.sh 335 [[ $? > 0 ]] && echo "$COMMON_DIR/libs/func_compare.sh did not load.." && exit 336 [[ $VERBOSITY > 0 ]] && echo "OK" 350 load_file "${COMMON_DIR}/libs/func_compare.sh" 'Loading compare module' 337 351 fi 338 352 # 339 353 # optimize module 340 354 if [[ "$OPTIMIZE" != "0" ]]; then 341 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..." 342 source optimize/optimize_functions 343 [[ $? > 0 ]] && echo " optimize/optimize_functions did not load.." && exit 344 [[ $VERBOSITY > 0 ]] && echo "OK" 355 load_file optimize/optimize_functions 'Loading optimization module' 345 356 # 346 357 # optimize configurations 347 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..." 348 source optimize/opt_config 349 [[ $? > 0 ]] && echo " optimize/opt_config did not load.." && exit 350 [[ $VERBOSITY > 0 ]] && echo "OK" 358 load_file optimize/opt_config 'Loading optimization config' 351 359 # The number of parallel jobs is taken from configuration now 360 # shellcheck disable=SC2034 352 361 MAKEFLAGS="-j${N_PARALLEL}" 353 362 # Validate optimize settings, if required … … 362 371 363 372 if [[ ! -d $JHALFSDIR ]]; then 364 sudo mkdir -p $JHALFSDIR365 sudo chown $USER:$USER $JHALFSDIR373 sudo mkdir -p "$JHALFSDIR" 374 sudo chown "$USER":"$USER" "$JHALFSDIR" 366 375 fi 367 376 368 377 # Create $BUILDDIR/sources even though it could be created by get_sources() 369 378 if [[ ! -d $BUILDDIR/sources ]]; then 370 sudo mkdir -p $BUILDDIR/sources371 sudo chmod a+wt $BUILDDIR/sources379 sudo mkdir -p "$BUILDDIR/sources" 380 sudo chmod a+wt "$BUILDDIR/sources" 372 381 fi 373 382 374 383 # Create the log directory 375 384 if [[ ! -d $LOGDIR ]]; then 376 mkdir $LOGDIR377 fi 378 >$LOGDIR/$LOG385 mkdir "$LOGDIR" 386 fi 387 true >"$LOGDIR/$LOG" 379 388 380 389 # Copy common helper files 381 cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/390 cp "$COMMON_DIR"/{makefile-functions,progress_bar.sh} "$JHALFSDIR/" 382 391 383 392 # Copy needed stylesheets 384 cp $COMMON_DIR/{packages.xsl,chroot.xsl,kernfs.xsl} $JHALFSDIR/393 cp "$COMMON_DIR"/{packages.xsl,chroot.xsl,kernfs.xsl} "$JHALFSDIR/" 385 394 386 395 # Fix the XSL book parser 387 396 case $PROGNAME in 388 clfs* ) sed 's,FAKEDIR,' ${BOOK}/BOOK',' ${PACKAGE_DIR}/${XSL} > $JHALFSDIR/${XSL};;389 lfs | hlfs ) sed 's,FAKEDIR,' $BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL};;397 clfs* ) sed 's,FAKEDIR,'"${BOOK}/BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;; 398 lfs | hlfs ) sed 's,FAKEDIR,'"$BOOK"',' "${PACKAGE_DIR}/${XSL}" > "${JHALFSDIR}/${XSL}" ;; 390 399 * ) ;; 391 400 esac … … 394 403 # Copy packageManager.xml, if needed 395 404 [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] && { 396 cp $PKGMNGTDIR/packageManager.xml $JHALFSDIR/397 cp $PKGMNGTDIR/packInstall.sh $JHALFSDIR/405 cp "$PKGMNGTDIR/packageManager.xml" "$JHALFSDIR/" 406 cp "$PKGMNGTDIR/packInstall.sh" "$JHALFSDIR/" 398 407 } 399 408 400 409 # Copy urls.xsl, if needed 401 [[ "$GETPKG" = "y" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/410 [[ "$GETPKG" = "y" ]] && cp "$COMMON_DIR/urls.xsl" "$JHALFSDIR/" 402 411 403 412 # Always create the test-log directory to allow user to "uncomment" test 404 413 # instructions 405 install -d -m 1777 $TESTLOGDIR414 install -d -m 1777 "$TESTLOGDIR" 406 415 407 416 # Create the installed-files directory, if needed 408 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 $FILELOGDIR417 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 "$FILELOGDIR" 409 418 410 419 # Prepare report creation, if needed 411 420 if [[ "$REPORT" = "y" ]]; then 412 cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/421 cp $COMMON_DIR/create-sbu_du-report.sh "$JHALFSDIR/" 413 422 # After making sure that all looks sane, dump the settings to a file 414 423 # This file will be used to create the REPORT header 415 validate_config > $JHALFSDIR/jhalfs.config424 validate_config >"$JHALFSDIR/jhalfs.config" 416 425 fi 417 426 418 427 # Copy optimize files, if needed 419 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/428 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override "$JHALFSDIR/" 420 429 421 430 # Copy compare files, if needed 422 431 if [[ "$COMPARE" = "y" ]]; then 423 mkdir -p $JHALFSDIR/extras424 cp extras/* $JHALFSDIR/extras432 mkdir -p "$JHALFSDIR/extras" 433 cp extras/* "$JHALFSDIR/extras" 425 434 fi 426 435 … … 428 437 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then 429 438 echo "Copying custom tool scripts to $JHALFSDIR" 430 mkdir -p $JHALFSDIR/custom-commands431 cp -f custom/config/* $JHALFSDIR/custom-commands439 mkdir -p "$JHALFSDIR/custom-commands" 440 cp -f custom/config/* "$JHALFSDIR/custom-commands" 432 441 fi 433 442 … … 438 447 extract_commands 439 448 echo "${SD_BORDER}${nl_}" 440 cd $CWD# the functions above change directory449 cd "$CWD" # the functions above change directory 441 450 442 451 # Install blfs-tool, if requested. 443 452 if [[ "${BLFS_TOOL}" = "y" ]] ; then 444 453 echo Installing BLFS book and tools 445 install_blfs_tools 2>&1 | tee -a $LOGDIR/$LOG454 install_blfs_tools 2>&1 | tee -a "$LOGDIR/$LOG" 446 455 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1 447 456 fi … … 451 460 # When regenerating the Makefile, we need to know also the 452 461 # canonical book version 462 # shellcheck disable=SC2034 453 463 if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then 454 464 case $PROGNAME in 455 465 clfs* ) 456 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;466 VERSION=$(xmllint --noent "$BOOK/prologue/$ARCH/bookinfo.xml" 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;; 457 467 lfs) 458 468 if [[ "$INITSYS" = "sysv" ]] ; then 459 VERSION=$(grep 'ENTITY version ' $BOOK/general.ent| cut -d\" -f2)469 VERSION=$(grep 'ENTITY version ' "$BOOK/general.ent" | cut -d\" -f2) 460 470 else 461 VERSION=$(grep 'ENTITY versiond' $BOOK/general.ent| cut -d\" -f2)471 VERSION=$(grep 'ENTITY versiond' "$BOOK/general.ent" | cut -d\" -f2) 462 472 fi 463 473 ;; 464 474 *) 465 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;475 VERSION=$(xmllint --noent "$BOOK/prologue/bookinfo.xml" 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;; 466 476 esac 467 477 fi … … 473 483 # Check for build prerequisites. 474 484 echo 475 cd $CWD485 cd "$CWD" 476 486 check_prerequisites 477 487 echo "${SD_BORDER}${nl_}"
Note:
See TracChangeset
for help on using the changeset viewer.