1 | #!/bin/bash
|
---|
2 | # $Id$
|
---|
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() {
|
---|
17 | echo -e "\n\t${BOLD}Goodbye and thank you for choosing ${L_arrow}jhalfs-X${R_arrow}\n"
|
---|
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 |
|
---|
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 | VERBOSITY=0
|
---|
48 |
|
---|
49 | [[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
|
---|
50 | source $COMMON_DIR/common-functions
|
---|
51 | [[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
|
---|
52 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
53 | #
|
---|
54 | [[ $VERBOSITY > 0 ]] && echo -n "Loading masterscript conf..."
|
---|
55 | source $COMMON_DIR/config
|
---|
56 | [[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
|
---|
57 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
58 | #
|
---|
59 | [[ $VERBOSITY > 0 ]] && echo -n "Loading ICA module..."
|
---|
60 | source $COMMON_DIR/func_ICA.sh
|
---|
61 | [[ $? > 0 ]] && echo "$COMMON_DIR/func_ICA.sh did not load.." && exit
|
---|
62 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
63 | #
|
---|
64 | [[ $VERBOSITY > 0 ]] && echo -n "Loading config module <$MODULE_CONFIG>..."
|
---|
65 | source $MODULE_CONFIG
|
---|
66 | [[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
|
---|
67 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
68 | #
|
---|
69 | [[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
|
---|
70 | source $MODULE
|
---|
71 | [[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
|
---|
72 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
73 | #
|
---|
74 | [[ $VERBOSITY > 0 ]] && echo "---------------${nl_}"
|
---|
75 |
|
---|
76 |
|
---|
77 | #===========================================================
|
---|
78 | # If the var BOOK contains something then, maybe, it points
|
---|
79 | # to a working doc.. set WC=1, else 'null'
|
---|
80 | #===========================================================
|
---|
81 | WC=${BOOK:+1}
|
---|
82 | #===========================================================
|
---|
83 |
|
---|
84 |
|
---|
85 | #*******************************************************************#
|
---|
86 | [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
|
---|
87 | source $COMMON_DIR/func_check_version.sh
|
---|
88 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
89 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
90 |
|
---|
91 | [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
|
---|
92 | source $COMMON_DIR/func_validate_configs.sh
|
---|
93 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
94 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
95 | [[ $VERBOSITY > 0 ]] && echo "---------------${nl_}"
|
---|
96 |
|
---|
97 |
|
---|
98 | ###################################
|
---|
99 | ### MAIN ###
|
---|
100 | ###################################
|
---|
101 |
|
---|
102 | # Evaluate any command line switches
|
---|
103 |
|
---|
104 | while test $# -gt 0 ; do
|
---|
105 | case $1 in
|
---|
106 | # Common options for all books
|
---|
107 | --book | -B )
|
---|
108 | test $# = 1 && eval "$exit_missing_arg"
|
---|
109 | shift
|
---|
110 | case $1 in
|
---|
111 | dev* | SVN | trunk )
|
---|
112 | LFSVRS=development
|
---|
113 | ;;
|
---|
114 | *) if [[ "$PROGNAME" = "lfs" ]]; then
|
---|
115 | case $1 in
|
---|
116 | 6.1.1 )
|
---|
117 | echo "For stable 6.1.1 book, please use jhalfs-0.2."
|
---|
118 | exit 0
|
---|
119 | ;;
|
---|
120 | udev*) LFSVRS=udev_update ;;
|
---|
121 | * ) echo "$1 is an unsupported version at this time." ;;
|
---|
122 | esac
|
---|
123 | else
|
---|
124 | 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."
|
---|
125 | exit 0
|
---|
126 | fi
|
---|
127 | ;;
|
---|
128 | esac
|
---|
129 | ;;
|
---|
130 |
|
---|
131 | --directory | -D )
|
---|
132 | test $# = 1 && eval "$exit_missing_arg"
|
---|
133 | shift
|
---|
134 | case $1 in
|
---|
135 | -* )
|
---|
136 | echo -e "\n$1 isn't a valid build directory."
|
---|
137 | echo -e "Directory names can't start with - .\n"
|
---|
138 | exit 1
|
---|
139 | ;;
|
---|
140 | * )
|
---|
141 | BUILDDIR=$1
|
---|
142 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
143 | LOGDIR=$JHALFSDIR/logs
|
---|
144 | MKFILE=$JHALFSDIR/Makefile
|
---|
145 | ;;
|
---|
146 | esac
|
---|
147 | ;;
|
---|
148 |
|
---|
149 | --get-packages | -G ) HPKG=1 ;;
|
---|
150 |
|
---|
151 | --help | -h ) usage | more && exit ;;
|
---|
152 |
|
---|
153 | --testsuites | -T )
|
---|
154 | test $# = 1 && eval "$exit_missing_arg"
|
---|
155 | shift
|
---|
156 | case $1 in
|
---|
157 | 0 | 1 | 2 | 3 )
|
---|
158 | TEST=$1
|
---|
159 | ;;
|
---|
160 | * )
|
---|
161 | echo -e "\n$1 isn't a valid testsuites level value."
|
---|
162 | echo -e "You must to use 0, 1, 2, or 3.\n"
|
---|
163 | exit 1
|
---|
164 | ;;
|
---|
165 | esac
|
---|
166 | ;;
|
---|
167 |
|
---|
168 | --version | -V )
|
---|
169 | echo "$version"
|
---|
170 | exit 0
|
---|
171 | ;;
|
---|
172 |
|
---|
173 | --working-copy | -W )
|
---|
174 | test $# = 1 && eval "$exit_missing_arg"
|
---|
175 | shift
|
---|
176 | case $PROGNAME in # Poor checks. We should find better ones.
|
---|
177 | lfs)
|
---|
178 | if [ -f $1/patches.ent ] ; then
|
---|
179 | WC=1
|
---|
180 | BOOK=$1
|
---|
181 | else
|
---|
182 | echo -e "\nLooks like $1 isn't a LFS working copy."
|
---|
183 | exit 1
|
---|
184 | fi
|
---|
185 | ;;
|
---|
186 | clfs)
|
---|
187 | if [ -f $1/patches.ent ] && [ -f $1/packages.ent ]; then
|
---|
188 | WC=1
|
---|
189 | BOOK=$1
|
---|
190 | else
|
---|
191 | echo -e "\nLooks like $1 isn't a CLFS working copy."
|
---|
192 | exit 1
|
---|
193 | fi
|
---|
194 | ;;
|
---|
195 | hlfs)
|
---|
196 | if [ -f $1/template.xml ] ; then
|
---|
197 | WC=1
|
---|
198 | BOOK=$1
|
---|
199 | else
|
---|
200 | echo -e "\nLooks like $1 isn't a HLFS working copy."
|
---|
201 | exit 1
|
---|
202 | fi
|
---|
203 | ;;
|
---|
204 | blfs)
|
---|
205 | if [ -f $1/use-unzip.xml ] ; then
|
---|
206 | WC=1
|
---|
207 | BOOK=$1
|
---|
208 | else
|
---|
209 | echo -e "\nLooks like $1 isn't a BLFS working copy."
|
---|
210 | exit 1
|
---|
211 | fi
|
---|
212 | ;;
|
---|
213 | esac
|
---|
214 | ;;
|
---|
215 |
|
---|
216 | # Common options for LFS, CLFS and HLFS
|
---|
217 | --comparasion | -C )
|
---|
218 | test $# = 1 && eval "$exit_missing_arg"
|
---|
219 | shift
|
---|
220 | case $1 in
|
---|
221 | ICA) RUN_ICA=1
|
---|
222 | RUN_FARCE=0
|
---|
223 | COMPARE=1
|
---|
224 | ;;
|
---|
225 | farce) RUN_ICA=0
|
---|
226 | RUN_FARCE=1
|
---|
227 | COMPARE=1
|
---|
228 | ;;
|
---|
229 | both) RUN_ICA=1
|
---|
230 | RUN_FARCE=1
|
---|
231 | COMPARE=1
|
---|
232 | ;;
|
---|
233 | *)
|
---|
234 | echo -e "\n$1 is an unknown analisys method."
|
---|
235 | exit 1
|
---|
236 | ;;
|
---|
237 | esac
|
---|
238 | ;;
|
---|
239 |
|
---|
240 | --fstab | -F )
|
---|
241 | test $# = 1 && eval "$exit_missing_arg"
|
---|
242 | shift
|
---|
243 | if [ -f $1 ] ; then
|
---|
244 | FSTAB=$1
|
---|
245 | else
|
---|
246 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
247 | exit 1
|
---|
248 | fi
|
---|
249 | ;;
|
---|
250 |
|
---|
251 | --kernel-config | -K )
|
---|
252 | test $# = 1 && eval "$exit_missing_arg"
|
---|
253 | shift
|
---|
254 | if [ -f $1 ] ; then
|
---|
255 | CONFIG=$1
|
---|
256 | else
|
---|
257 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
258 | exit 1
|
---|
259 | fi
|
---|
260 | ;;
|
---|
261 |
|
---|
262 | --make | -M ) RUNMAKE=1 ;;
|
---|
263 |
|
---|
264 | --rebuild | -R ) CLEAN=1 ;;
|
---|
265 |
|
---|
266 | # CLFS options
|
---|
267 | --arch | -A )
|
---|
268 | test $# = 1 && eval "$exit_missing_arg"
|
---|
269 | shift
|
---|
270 | case $1 in
|
---|
271 | x86 )
|
---|
272 | ARCH=x86
|
---|
273 | TARGET="i686-pc-linux-gnu"
|
---|
274 | ;;
|
---|
275 | i486 )
|
---|
276 | ARCH=x86
|
---|
277 | TARGET="i486-pc-linux-gnu"
|
---|
278 | ;;
|
---|
279 | i586 )
|
---|
280 | ARCH=x86
|
---|
281 | TARGET="i586-pc-linux-gnu"
|
---|
282 | ;;
|
---|
283 | ppc )
|
---|
284 | ARCH=ppc
|
---|
285 | TARGET="powerpc-unknown-linux-gnu"
|
---|
286 | ;;
|
---|
287 | mips )
|
---|
288 | ARCH=mips
|
---|
289 | TARGET="mips-unknown-linux-gnu"
|
---|
290 | ;;
|
---|
291 | mipsel )
|
---|
292 | ARCH=mips
|
---|
293 | TARGET="mipsel-unknown-linux-gnu"
|
---|
294 | ;;
|
---|
295 | sparc )
|
---|
296 | ARCH=sparc
|
---|
297 | TARGET="sparcv9-unknown-linux-gnu"
|
---|
298 | ;;
|
---|
299 | sparcv8 )
|
---|
300 | ARCH=sparcv8
|
---|
301 | TARGET="sparc-unknown-linux-gnu"
|
---|
302 | ;;
|
---|
303 | x86_64-64 )
|
---|
304 | ARCH=x86_64-64
|
---|
305 | TARGET="x86_64-unknown-linux-gnu"
|
---|
306 | ;;
|
---|
307 | mips64-64 )
|
---|
308 | ARCH=mips64-64
|
---|
309 | TARGET="mips-unknown-linux-gnu"
|
---|
310 | ;;
|
---|
311 | mipsel64-64 )
|
---|
312 | ARCH=mips64-64
|
---|
313 | TARGET="mipsel-unknown-linux-gnu"
|
---|
314 | ;;
|
---|
315 | sparc64-64 )
|
---|
316 | ARCH=sparc64-64
|
---|
317 | TARGET="sparc64-unknown-linux-gnu"
|
---|
318 | ;;
|
---|
319 | alpha )
|
---|
320 | ARCH=alpha
|
---|
321 | TARGET="alpha-unknown-linux-gnu"
|
---|
322 | ;;
|
---|
323 | x86_64 )
|
---|
324 | ARCH=x86_64
|
---|
325 | TARGET="x86_64-unknown-linux-gnu"
|
---|
326 | TARGET32="i686-pc-linux-gnu"
|
---|
327 | ;;
|
---|
328 | mips64 )
|
---|
329 | ARCH=mips64
|
---|
330 | TARGET="mips-unknown-linux-gnu"
|
---|
331 | TARGET32="mips-unknown-linux-gnu"
|
---|
332 | ;;
|
---|
333 | mipsel64 )
|
---|
334 | ARCH=mips64
|
---|
335 | TARGET="mipsel-unknown-linux-gnu"
|
---|
336 | TARGET32="mipsel-unknown-linux-gnu"
|
---|
337 | ;;
|
---|
338 | sparc64 )
|
---|
339 | ARCH=sparc64
|
---|
340 | TARGET="sparc64-unknown-linux-gnu"
|
---|
341 | TARGET32="sparcv9-unknown-linux-gnu"
|
---|
342 | ;;
|
---|
343 | ppc64 )
|
---|
344 | ARCH=ppc64
|
---|
345 | TARGET="powerpc64-unknown-linux-gnu"
|
---|
346 | TARGET32="powerpc-unknown-linux-gnu"
|
---|
347 | ;;
|
---|
348 | * )
|
---|
349 | echo -e "\n$1 is an unknown or unsopported arch."
|
---|
350 | exit 1
|
---|
351 | ;;
|
---|
352 | esac
|
---|
353 | ;;
|
---|
354 |
|
---|
355 | --boot-config )
|
---|
356 | test $# = 1 && eval "$exit_missing_arg"
|
---|
357 | shift
|
---|
358 | if [ -f $1 ] ; then
|
---|
359 | BOOT_CONFIG=$1
|
---|
360 | else
|
---|
361 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
362 | exit 1
|
---|
363 | fi
|
---|
364 | ;;
|
---|
365 |
|
---|
366 | --method )
|
---|
367 | test $# = 1 && eval "$exit_missing_arg"
|
---|
368 | shift
|
---|
369 | case $1 in
|
---|
370 | chroot | boot )
|
---|
371 | METHOD=$1
|
---|
372 | ;;
|
---|
373 | * )
|
---|
374 | echo -e "\n$1 isn't a valid build method."
|
---|
375 | exit 1
|
---|
376 | ;;
|
---|
377 | esac
|
---|
378 | ;;
|
---|
379 |
|
---|
380 | # HLFS options
|
---|
381 | --model )
|
---|
382 | test $# = 1 && eval "$exit_missing_arg"
|
---|
383 | shift
|
---|
384 | case $1 in
|
---|
385 | glibc | uclibc )
|
---|
386 | MODEL=$1
|
---|
387 | ;;
|
---|
388 | * )
|
---|
389 | echo -e "\n$1 isn't a valid libc model."
|
---|
390 | exit 1
|
---|
391 | ;;
|
---|
392 | esac
|
---|
393 | ;;
|
---|
394 |
|
---|
395 | # BLFS options
|
---|
396 | --dependencies )
|
---|
397 | test $# = 1 && eval "$exit_missing_arg"
|
---|
398 | shift
|
---|
399 | case $1 in
|
---|
400 | 0 | 1 | 2 )
|
---|
401 | DEPEND=$1
|
---|
402 | ;;
|
---|
403 | * )
|
---|
404 | echo -e "\n$1 isn't a valid dependencies level."
|
---|
405 | exit 1
|
---|
406 | ;;
|
---|
407 | esac
|
---|
408 | ;;
|
---|
409 |
|
---|
410 | # Unknown options
|
---|
411 | * ) usage ;;
|
---|
412 | esac
|
---|
413 | shift
|
---|
414 | done
|
---|
415 |
|
---|
416 | # Find the download client to use, if not already specified.
|
---|
417 |
|
---|
418 | if [ -z $DL ] ; then
|
---|
419 | if [ `type -p wget` ] ; then
|
---|
420 | DL=wget
|
---|
421 | elif [ `type -p curl` ] ; then
|
---|
422 | DL=curl
|
---|
423 | else
|
---|
424 | eval "$no_dl_client"
|
---|
425 | fi
|
---|
426 | fi
|
---|
427 |
|
---|
428 | #===================================================
|
---|
429 | # Set the document location...
|
---|
430 | # BOOK is either defined in
|
---|
431 | # xxx.config
|
---|
432 | # comand line
|
---|
433 | # default
|
---|
434 | # If set by conf file or cmd line leave it
|
---|
435 | # alone otherwise load the default version
|
---|
436 | #===================================================
|
---|
437 | BOOK=${BOOK:=$PROGNAME-$LFSVRS}
|
---|
438 | #===================================================
|
---|
439 |
|
---|
440 |
|
---|
441 | # Check for minumum gcc and kernel versions
|
---|
442 | #check_requirements 1 # 0/1 0-do not display values.
|
---|
443 | echo
|
---|
444 | check_version "2.6.2" "`uname -r`" "KERNEL"
|
---|
445 | check_version "3.0" "$BASH_VERSION" "BASH"
|
---|
446 | check_version "3.0" "`gcc -dumpversion`" "GCC"
|
---|
447 | tarVer=`tar --version`
|
---|
448 | check_version "1.15.0" "${tarVer##* }" "TAR"
|
---|
449 | echo "---------------${nl_}"
|
---|
450 |
|
---|
451 | validate_config
|
---|
452 | echo "---------------${nl_}"
|
---|
453 |
|
---|
454 | echo -n "Are you happy with these settings? yes/no (no): "
|
---|
455 | read ANSWER
|
---|
456 | if [ x$ANSWER != "xyes" ] ; then
|
---|
457 | echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
|
---|
458 | exit 1
|
---|
459 | fi
|
---|
460 | echo "${nl_}---------------${nl_}"
|
---|
461 |
|
---|
462 | # Prevents setting "-d /" by mistake.
|
---|
463 |
|
---|
464 | if [ $BUILDDIR = / ] ; then
|
---|
465 | echo -ne "\nThe root directory can't be used to build LFS.\n\n"
|
---|
466 | exit 1
|
---|
467 | fi
|
---|
468 |
|
---|
469 | # If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
|
---|
470 | # and notify the user about that.
|
---|
471 |
|
---|
472 | if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
|
---|
473 | eval "$no_empty_builddir"
|
---|
474 | fi
|
---|
475 |
|
---|
476 | # If requested, clean the build directory
|
---|
477 | clean_builddir
|
---|
478 |
|
---|
479 | if [[ ! -d $JHALFSDIR ]]; then
|
---|
480 | mkdir -p $JHALFSDIR
|
---|
481 | fi
|
---|
482 |
|
---|
483 | if [[ "$PWD" != "$JHALFSDIR" ]]; then
|
---|
484 | cp $COMMON_DIR/makefile-functions $JHALFSDIR/
|
---|
485 | if [[ "$COMPARE" != "0" ]] ; then
|
---|
486 | mkdir -p $JHALFSDIR/extras
|
---|
487 | cp extras/* $JHALFSDIR/extras
|
---|
488 | fi
|
---|
489 | if [[ -n "$FILES" ]]; then
|
---|
490 | # pushd/popd necessary to deal with mulitiple files
|
---|
491 | pushd $PACKAGE_DIR 1> /dev/null
|
---|
492 | cp $FILES $JHALFSDIR/
|
---|
493 | popd 1> /dev/null
|
---|
494 | fi
|
---|
495 | sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
|
---|
496 | export XSL=$JHALFSDIR/${XSL}
|
---|
497 | fi
|
---|
498 |
|
---|
499 | if [[ ! -d $LOGDIR ]]; then
|
---|
500 | mkdir $LOGDIR
|
---|
501 | fi
|
---|
502 | >$LOGDIR/$LOG
|
---|
503 |
|
---|
504 | get_book
|
---|
505 | echo "---------------${nl_}"
|
---|
506 |
|
---|
507 | build_Makefile
|
---|
508 | echo "---------------${nl_}"
|
---|
509 |
|
---|
510 | run_make
|
---|
511 |
|
---|