[0170229] | 1 | #!/bin/bash
|
---|
[12a5707] | 2 | # $Id$
|
---|
[0170229] | 3 | set -e
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | #>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
|
---|
| 7 | #-----------------------#
|
---|
| 8 | simple_error() { # Basic error trap.... JUST DIE
|
---|
| 9 | #-----------------------#
|
---|
| 10 | # If +e then disable text output
|
---|
| 11 | if [[ "$-" =~ "e" ]]; then
|
---|
| 12 | echo -e "\n${RED}ERROR:${GREEN} basic error trapped!${OFF}\n" >&2
|
---|
| 13 | fi
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | see_ya() {
|
---|
[d95b8f2] | 17 | echo -e "\n\t${BOLD}Goodbye and thank you for choosing ${L_arrow}JHALFS-X${R_arrow}\n"
|
---|
[0170229] | 18 | }
|
---|
| 19 | ##### Simple error TRAPS
|
---|
| 20 | # ctrl-c SIGINT
|
---|
| 21 | # ctrl-y
|
---|
| 22 | # ctrl-z SIGTSTP
|
---|
| 23 | # SIGHUP 1 HANGUP
|
---|
| 24 | # SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
|
---|
| 25 | # SIGQUIT 3
|
---|
| 26 | # SIGKILL 9 KILL
|
---|
| 27 | # SIGTERM 15 TERMINATION
|
---|
| 28 | # SIGSTOP 17,18,23 STOP THE PROCESS
|
---|
| 29 | #####
|
---|
| 30 | set -e
|
---|
| 31 | trap see_ya 0
|
---|
| 32 | trap simple_error ERR
|
---|
| 33 | trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
|
---|
| 34 | #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | if [ ! -L $0 ] ; then
|
---|
| 38 | echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
|
---|
| 39 | exit 1
|
---|
| 40 | fi
|
---|
| 41 |
|
---|
[12a5707] | 42 | PROGNAME=$(basename $0)
|
---|
| 43 | COMMON_DIR="common"
|
---|
| 44 | PACKAGE_DIR=$(echo $PROGNAME | tr [a-z] [A-Z])
|
---|
| 45 | MODULE=$PACKAGE_DIR/master.sh
|
---|
| 46 | MODULE_CONFIG=$PACKAGE_DIR/config
|
---|
| 47 |
|
---|
| 48 | echo -n "Loading common-functions module..."
|
---|
| 49 | source $COMMON_DIR/common-functions
|
---|
| 50 | [[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
|
---|
| 51 | echo "OK"
|
---|
| 52 | #
|
---|
| 53 |
|
---|
| 54 | echo -n "Loading masterscript conf..."
|
---|
| 55 | source $COMMON_DIR/config
|
---|
[13e816f] | 56 | [[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
|
---|
[0170229] | 57 | echo "OK"
|
---|
| 58 | #
|
---|
| 59 | echo -n "Loading config module <$MODULE_CONFIG>..."
|
---|
| 60 | source $MODULE_CONFIG
|
---|
| 61 | [[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
|
---|
| 62 | echo "OK"
|
---|
| 63 | #
|
---|
| 64 | echo -n "Loading code module <$MODULE>..."
|
---|
| 65 | source $MODULE
|
---|
[12a5707] | 66 | [[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
|
---|
[0170229] | 67 | echo "OK"
|
---|
| 68 | #
|
---|
| 69 | echo "---------------${nl_}"
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | #===========================================================
|
---|
| 73 | # If the var BOOK contains something then, maybe, it points
|
---|
| 74 | # to a working doc.. set WC=1, else 'null'
|
---|
| 75 | #===========================================================
|
---|
| 76 | WC=${BOOK:+1}
|
---|
| 77 | #===========================================================
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | #*******************************************************************#
|
---|
[12a5707] | 81 | echo -n "Loading function <func_check_version.sh>..."
|
---|
| 82 | source $COMMON_DIR/func_check_version.sh
|
---|
| 83 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
| 84 | echo "OK"
|
---|
[0170229] | 85 |
|
---|
[12a5707] | 86 | echo -n "Loading function <func_validate_configs.sh>..."
|
---|
| 87 | source $COMMON_DIR/func_validate_configs.sh
|
---|
| 88 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
| 89 | echo "OK"
|
---|
| 90 | echo "---------------${nl_}"
|
---|
[0170229] | 91 |
|
---|
| 92 |
|
---|
| 93 | ###################################
|
---|
| 94 | ### MAIN ###
|
---|
| 95 | ###################################
|
---|
| 96 |
|
---|
| 97 | # Evaluate any command line switches
|
---|
| 98 |
|
---|
| 99 | while test $# -gt 0 ; do
|
---|
| 100 | case $1 in
|
---|
[40ccddf] | 101 | # Common options for all books
|
---|
[5627958] | 102 | --book | -B )
|
---|
[0170229] | 103 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 104 | shift
|
---|
| 105 | case $1 in
|
---|
| 106 | dev* | SVN | trunk )
|
---|
| 107 | LFSVRS=development
|
---|
| 108 | ;;
|
---|
[5627958] | 109 | *) if [[ "$PROGNAME" = "lfs" ]]; then
|
---|
| 110 | case $1 in
|
---|
[d95b8f2] | 111 | 6.1.1 )
|
---|
| 112 | echo "For stable 6.1.1 book, please use jhalfs-0.2."
|
---|
| 113 | exit 0
|
---|
| 114 | ;;
|
---|
| 115 | alpha*) LFSVRS=alphabetical ;;
|
---|
| 116 | udev*) LFSVRS=udev_update ;;
|
---|
| 117 | * ) echo "$1 is an unsupported version at this time." ;;
|
---|
[5627958] | 118 | esac
|
---|
| 119 | else
|
---|
| 120 | echo "The requested version, ${L_arrow} ${BOLD}$1${OFF} ${R_arrow}, is undefined in the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} series."
|
---|
[d95b8f2] | 121 | exit 0
|
---|
| 122 | fi
|
---|
[0170229] | 123 | ;;
|
---|
| 124 | esac
|
---|
| 125 | ;;
|
---|
| 126 |
|
---|
[c16cedc] | 127 | --directory | -D )
|
---|
[0170229] | 128 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 129 | shift
|
---|
| 130 | BUILDDIR=$1
|
---|
| 131 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
| 132 | LOGDIR=$JHALFSDIR/logs
|
---|
[a6b81cd] | 133 | MKFILE=$JHALFSDIR/Makefile
|
---|
[0170229] | 134 | ;;
|
---|
| 135 |
|
---|
[c16cedc] | 136 | --get-packages | -G ) HPKG=1 ;;
|
---|
| 137 |
|
---|
| 138 | --help | -h )
|
---|
| 139 | if [[ "$PROGNAME" = "blfs" ]]; then
|
---|
| 140 | blfs_usage
|
---|
| 141 | else
|
---|
| 142 | usage
|
---|
| 143 | fi
|
---|
| 144 | ;;
|
---|
| 145 |
|
---|
| 146 | --testsuites | -T )
|
---|
| 147 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 148 | shift
|
---|
| 149 | case $1 in
|
---|
| 150 | 0 | 1 | 2 | 3 )
|
---|
| 151 | TEST=$1
|
---|
| 152 | ;;
|
---|
| 153 | * )
|
---|
| 154 | echo -e "\n$1 isn't a valid testsuites level value."
|
---|
| 155 | echo -e "You must to use 0, 1, 2, or 3.\n"
|
---|
| 156 | exit 1
|
---|
| 157 | ;;
|
---|
| 158 | esac
|
---|
| 159 | ;;
|
---|
| 160 |
|
---|
| 161 | --version | -V )
|
---|
| 162 | clear
|
---|
| 163 | echo "$version"
|
---|
| 164 | exit 0
|
---|
| 165 | ;;
|
---|
| 166 |
|
---|
[0170229] | 167 | --working-copy | -W )
|
---|
| 168 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 169 | shift
|
---|
[5627958] | 170 | case $PROGNAME in # Poor checks. We should find better ones.
|
---|
| 171 | lfs)
|
---|
| 172 | if [ -f $1/patches.ent ] ; then
|
---|
| 173 | WC=1
|
---|
| 174 | BOOK=$1
|
---|
| 175 | else
|
---|
| 176 | echo -e "\nLook like $1 isn't a LFS working copy."
|
---|
| 177 | exit 1
|
---|
| 178 | fi
|
---|
| 179 | ;;
|
---|
| 180 | clfs)
|
---|
| 181 | if [ -f $1/patches.ent ] && [ -f $1/packages.ent ]; then
|
---|
| 182 | WC=1
|
---|
| 183 | BOOK=$1
|
---|
| 184 | else
|
---|
| 185 | echo -e "\nLook like $1 isn't a CLFS working copy."
|
---|
| 186 | exit 1
|
---|
| 187 | fi
|
---|
| 188 | ;;
|
---|
| 189 | hlfs)
|
---|
| 190 | if [ -f $1/template.xml ] ; then
|
---|
| 191 | WC=1
|
---|
| 192 | BOOK=$1
|
---|
| 193 | else
|
---|
| 194 | echo -e "\nLook like $1 isn't a HLFS working copy."
|
---|
| 195 | exit 1
|
---|
| 196 | fi
|
---|
| 197 | ;;
|
---|
| 198 | blfs)
|
---|
| 199 | if [ -f $1/use-unzip.xml ] ; then
|
---|
| 200 | WC=1
|
---|
| 201 | BOOK=$1
|
---|
| 202 | else
|
---|
| 203 | echo -e "\nLook like $1 isn't a BLFS working copy."
|
---|
| 204 | exit 1
|
---|
| 205 | fi
|
---|
| 206 | ;;
|
---|
[0170229] | 207 |
|
---|
[40ccddf] | 208 | # Common options for LFS, CLFS and HLFS
|
---|
| 209 | --fstab | -F )
|
---|
| 210 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 211 | shift
|
---|
| 212 | if [ -f $1 ] ; then
|
---|
| 213 | FSTAB=$1
|
---|
| 214 | else
|
---|
| 215 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
| 216 | exit 1
|
---|
| 217 | fi
|
---|
| 218 | ;;
|
---|
| 219 |
|
---|
| 220 | --kernel-config | -K )
|
---|
| 221 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 222 | shift
|
---|
| 223 | if [ -f $1 ] ; then
|
---|
| 224 | CONFIG=$1
|
---|
| 225 | else
|
---|
| 226 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
| 227 | exit 1
|
---|
| 228 | fi
|
---|
| 229 | ;;
|
---|
| 230 |
|
---|
[bd99331] | 231 | --make | -M ) RUNMAKE=1 ;;
|
---|
[40ccddf] | 232 |
|
---|
| 233 | --rebuild | -R ) CLEAN=1 ;;
|
---|
| 234 |
|
---|
[bd99331] | 235 | # CLFS options
|
---|
| 236 | --arch | -A )
|
---|
| 237 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 238 | shift
|
---|
| 239 | case $1 in
|
---|
| 240 | x86 )
|
---|
| 241 | ARCH=x86
|
---|
| 242 | TARGET="i686-pc-linux-gnu"
|
---|
| 243 | ;;
|
---|
| 244 | i486 )
|
---|
| 245 | ARCH=x86
|
---|
| 246 | TARGET="i486-pc-linux-gnu"
|
---|
| 247 | ;;
|
---|
| 248 | i586 )
|
---|
| 249 | ARCH=x86
|
---|
| 250 | TARGET="i586-pc-linux-gnu"
|
---|
| 251 | ;;
|
---|
| 252 | ppc )
|
---|
| 253 | ARCH=ppc
|
---|
| 254 | TARGET="powerpc-unknown-linux-gnu"
|
---|
| 255 | ;;
|
---|
| 256 | mips )
|
---|
| 257 | ARCH=mips
|
---|
| 258 | TARGET="mips-unknown-linux-gnu"
|
---|
| 259 | ;;
|
---|
| 260 | mipsel )
|
---|
| 261 | ARCH=mips
|
---|
| 262 | TARGET="mipsel-unknown-linux-gnu"
|
---|
| 263 | ;;
|
---|
| 264 | sparc )
|
---|
| 265 | ARCH=sparc
|
---|
| 266 | TARGET="sparcv9-unknown-linux-gnu"
|
---|
| 267 | ;;
|
---|
| 268 | sparcv8 )
|
---|
| 269 | ARCH=sparcv8
|
---|
| 270 | TARGET="sparc-unknown-linux-gnu"
|
---|
| 271 | ;;
|
---|
| 272 | x86_64-64 )
|
---|
| 273 | ARCH=x86_64-64
|
---|
| 274 | TARGET="x86_64-unknown-linux-gnu"
|
---|
| 275 | ;;
|
---|
| 276 | mips64-64 )
|
---|
| 277 | ARCH=mips64-64
|
---|
| 278 | TARGET="mips-unknown-linux-gnu"
|
---|
| 279 | ;;
|
---|
| 280 | mipsel64-64 )
|
---|
| 281 | ARCH=mips64-64
|
---|
| 282 | TARGET="mipsel-unknown-linux-gnu"
|
---|
| 283 | ;;
|
---|
| 284 | sparc64-64 )
|
---|
| 285 | ARCH=sparc64-64
|
---|
| 286 | TARGET="sparc64-unknown-linux-gnu"
|
---|
| 287 | ;;
|
---|
| 288 | alpha )
|
---|
| 289 | ARCH=alpha
|
---|
| 290 | TARGET="alpha-unknown-linux-gnu"
|
---|
| 291 | ;;
|
---|
| 292 | x86_64 )
|
---|
| 293 | ARCH=x86_64
|
---|
| 294 | TARGET="x86_64-unknown-linux-gnu"
|
---|
| 295 | TARGET32="i686-pc-linux-gnu"
|
---|
| 296 | ;;
|
---|
| 297 | mips64 )
|
---|
| 298 | ARCH=mips64
|
---|
| 299 | TARGET="mips-unknown-linux-gnu"
|
---|
| 300 | TARGET32="mips-unknown-linux-gnu"
|
---|
| 301 | ;;
|
---|
| 302 | mipsel64 )
|
---|
| 303 | ARCH=mips64
|
---|
| 304 | TARGET="mipsel-unknown-linux-gnu"
|
---|
| 305 | TARGET32="mipsel-unknown-linux-gnu"
|
---|
| 306 | ;;
|
---|
| 307 | sparc64 )
|
---|
| 308 | ARCH=sparc64
|
---|
| 309 | TARGET="sparc64-unknown-linux-gnu"
|
---|
| 310 | TARGET32="sparcv9-unknown-linux-gnu"
|
---|
| 311 | ;;
|
---|
| 312 | ppc64 )
|
---|
| 313 | ARCH=ppc64
|
---|
| 314 | TARGET="powerpc64-unknown-linux-gnu"
|
---|
| 315 | TARGET32="powerpc-unknown-linux-gnu"
|
---|
| 316 | ;;
|
---|
| 317 | * )
|
---|
| 318 | echo -e "\n$1 is an unknown or unsopported arch."
|
---|
| 319 | exit 1
|
---|
| 320 | ;;
|
---|
| 321 | esac
|
---|
| 322 | ;;
|
---|
| 323 |
|
---|
| 324 | --method )
|
---|
| 325 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 326 | shift
|
---|
| 327 | case $1 in
|
---|
| 328 | chroot | boot )
|
---|
| 329 | METHOD=$1
|
---|
| 330 | ;;
|
---|
| 331 | * )
|
---|
| 332 | echo -e "\n$1 isn't a valid build method."
|
---|
| 333 | exit 1
|
---|
| 334 | ;;
|
---|
| 335 | esac
|
---|
| 336 | ;;
|
---|
| 337 |
|
---|
| 338 | --boot-config )
|
---|
| 339 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 340 | shift
|
---|
| 341 | if [ -f $1 ] ; then
|
---|
| 342 | BOOT_CONFIG=$1
|
---|
| 343 | else
|
---|
| 344 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
| 345 | exit 1
|
---|
| 346 | fi
|
---|
| 347 | ;;
|
---|
| 348 |
|
---|
| 349 | # Unknown options
|
---|
[0170229] | 350 | * )
|
---|
| 351 | if [[ "$PROGNAME" = "blfs" ]]; then
|
---|
| 352 | blfs_usage
|
---|
| 353 | else
|
---|
| 354 | usage
|
---|
| 355 | fi
|
---|
| 356 | ;;
|
---|
| 357 | esac
|
---|
| 358 | shift
|
---|
| 359 | done
|
---|
| 360 |
|
---|
| 361 | # Find the download client to use, if not already specified.
|
---|
| 362 |
|
---|
| 363 | if [ -z $DL ] ; then
|
---|
| 364 | if [ `type -p wget` ] ; then
|
---|
| 365 | DL=wget
|
---|
| 366 | elif [ `type -p curl` ] ; then
|
---|
| 367 | DL=curl
|
---|
| 368 | else
|
---|
| 369 | eval "$no_dl_client"
|
---|
| 370 | fi
|
---|
| 371 | fi
|
---|
| 372 |
|
---|
| 373 | #===================================================
|
---|
| 374 | # Set the document location...
|
---|
[13e816f] | 375 | # BOOK is either defined in
|
---|
[0170229] | 376 | # xxx.config
|
---|
| 377 | # comand line
|
---|
[13e816f] | 378 | # default
|
---|
[d95b8f2] | 379 | # If set by conf file or cmd line leave it
|
---|
[0170229] | 380 | # alone otherwise load the default version
|
---|
| 381 | #===================================================
|
---|
| 382 | BOOK=${BOOK:=$PROGNAME-$LFSVRS}
|
---|
| 383 | #===================================================
|
---|
| 384 |
|
---|
[13e816f] | 385 |
|
---|
| 386 | # Check for minumum gcc and kernel versions
|
---|
| 387 | #check_requirements 1 # 0/1 0-do not display values.
|
---|
| 388 | check_version "2.6.2" "`uname -r`" "KERNEL"
|
---|
| 389 | check_version "3.0" "$BASH_VERSION" "BASH"
|
---|
| 390 | check_version "3.0" "`gcc -dumpversion`" "GCC"
|
---|
[e1edff3] | 391 | tarVer=`tar --version`
|
---|
| 392 | check_version "1.15.0" "${tarVer##* }" "TAR"
|
---|
[13e816f] | 393 | echo "---------------${nl_}"
|
---|
| 394 |
|
---|
| 395 | validate_config 1 # 0/1 0-do not display values
|
---|
| 396 | echo "---------------${nl_}"
|
---|
| 397 |
|
---|
[164afa2] | 398 | echo -n "Are you happy with that settings? yes/no (no): "
|
---|
[13e816f] | 399 | read ANSWER
|
---|
| 400 | if [ x$ANSWER != "xyes" ] ; then
|
---|
| 401 | echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
|
---|
| 402 | exit 1
|
---|
| 403 | fi
|
---|
| 404 |
|
---|
| 405 | # Prevents setting "-d /" by mistake.
|
---|
| 406 |
|
---|
| 407 | if [ $BUILDDIR = / ] ; then
|
---|
| 408 | echo -ne "\nThe root directory can't be used to build LFS.\n\n"
|
---|
| 409 | exit 1
|
---|
| 410 | fi
|
---|
| 411 |
|
---|
| 412 | # If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
|
---|
| 413 | # and notify the user about that.
|
---|
| 414 |
|
---|
| 415 | if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
|
---|
| 416 | eval "$no_empty_builddir"
|
---|
| 417 | fi
|
---|
| 418 |
|
---|
| 419 | # If requested, clean the build directory
|
---|
| 420 | clean_builddir
|
---|
| 421 |
|
---|
[0170229] | 422 | if [[ ! -d $JHALFSDIR ]]; then
|
---|
| 423 | mkdir -pv $JHALFSDIR
|
---|
| 424 | fi
|
---|
| 425 |
|
---|
[13e816f] | 426 | if [[ "$PWD" != "$JHALFSDIR" ]]; then
|
---|
[12a5707] | 427 | cp -v $COMMON_DIR/makefile-functions $JHALFSDIR/
|
---|
[0170229] | 428 | if [[ -n "$FILES" ]]; then
|
---|
[9c90294] | 429 | # pushd/popd necessary to deal with mulitiple files
|
---|
| 430 | pushd $PACKAGE_DIR
|
---|
| 431 | cp -v $FILES $JHALFSDIR/
|
---|
| 432 | popd
|
---|
[0170229] | 433 | fi
|
---|
[12a5707] | 434 | sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
|
---|
[0170229] | 435 | export XSL=$JHALFSDIR/${XSL}
|
---|
| 436 | fi
|
---|
| 437 |
|
---|
| 438 | if [[ ! -d $LOGDIR ]]; then
|
---|
| 439 | mkdir -v $LOGDIR
|
---|
| 440 | fi
|
---|
| 441 | >$LOGDIR/$LOG
|
---|
| 442 | echo "---------------${nl_}"
|
---|
| 443 |
|
---|
| 444 | get_book
|
---|
| 445 | echo "---------------${nl_}"
|
---|
[12a5707] | 446 |
|
---|
[0170229] | 447 | build_Makefile
|
---|
| 448 | echo "---------------${nl_}"
|
---|
[12a5707] | 449 |
|
---|
[386bc75] | 450 | run_make
|
---|
[0170229] | 451 |
|
---|