source: master.sh@ 075115a

experimental
Last change on this file since 075115a was 0170229, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Added base files from George's jhalfs-experimental-2 POC.
WARNING: This code is broken due files renaming.

  • Property mode set to 100755
File size: 12.3 KB
Line 
1#!/bin/bash
2set -e
3
4
5#>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
6#-----------------------#
7simple_error() { # Basic error trap.... JUST DIE
8#-----------------------#
9 # If +e then disable text output
10 if [[ "$-" =~ "e" ]]; then
11 echo -e "\n${RED}ERROR:${GREEN} basic error trapped!${OFF}\n" >&2
12 fi
13}
14
15see_ya() {
16 echo -e "\n\t${BOLD}Goodbye and thank you for choosing ${L_arrow}JHALFS${R_arrow}\n"
17}
18##### Simple error TRAPS
19# ctrl-c SIGINT
20# ctrl-y
21# ctrl-z SIGTSTP
22# SIGHUP 1 HANGUP
23# SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
24# SIGQUIT 3
25# SIGKILL 9 KILL
26# SIGTERM 15 TERMINATION
27# SIGSTOP 17,18,23 STOP THE PROCESS
28#####
29set -e
30trap see_ya 0
31trap simple_error ERR
32trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
33#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
34
35
36 PROGNAME=$(basename $0)
37 VERSION="0.0.1"
38 MODULE=$PROGNAME.module
39MODULE_CONFIG=$PROGNAME.conf
40
41echo -n "Loading common-func.module..."
42source common-func.module
43[[ $? > 0 ]] && echo "common-func.module did not load.." && exit
44echo "OK"
45#
46
47if [ ! -L $0 ] ; then
48 echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
49 exit 1
50fi
51
52echo -n "Loading masterscript.conf..."
53source masterscript.conf
54[[ $? > 0 ]] && echo "masterscript.conf did not load.." && exit
55echo "OK"
56#
57echo -n "Loading config module <$MODULE_CONFIG>..."
58source $MODULE_CONFIG
59[[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
60echo "OK"
61#
62echo -n "Loading code module <$MODULE>..."
63source $MODULE
64if [[ $? > 0 ]]; then
65 echo "$MODULE did not load.."
66 exit 2
67fi
68echo "OK"
69#
70echo "---------------${nl_}"
71
72
73#===========================================================
74# If the var BOOK contains something then, maybe, it points
75# to a working doc.. set WC=1, else 'null'
76#===========================================================
77WC=${BOOK:+1}
78#===========================================================
79
80
81#*******************************************************************#
82
83
84#----------------------------#
85check_requirements() { # Simple routine to validate gcc and kernel versions against requirements
86#----------------------------#
87 # Minimum values acceptable
88 # bash 3.0>
89 # gcc 3.0>
90 # kernel 2.6.2>
91
92 [[ $1 = "1" ]] && echo "${nl_}BASH: ${L_arrow}${BOLD}${BASH_VERSION}${R_arrow}"
93 case $BASH_VERSION in
94 [3-9].*) ;;
95 *) 'clear'
96 echo -e "
97$DD_BORDER
98\t\t${OFF}${RED}BASH version ${BOLD}${YELLOW}-->${WHITE} $BASH_VERSION ${YELLOW}<--${OFF}${RED} is too old.
99\t\t This script requires 3.0${OFF}${RED} or greater
100$DD_BORDER"
101 exit 1
102 ;;
103 esac
104
105 [[ $1 = "1" ]] && echo "GCC: ${L_arrow}${BOLD}`gcc -dumpversion`${R_arrow}"
106 case `gcc -dumpversion` in
107 [3-9].[0-9].* ) ;;
108 *) 'clear'
109 echo -e "
110$DD_BORDER
111\t\t${OFF}${RED}GCC version ${BOLD}${YELLOW}-->${WHITE} $(gcc -dumpversion) ${YELLOW}<--${OFF}${RED} is too old.
112\t\t This script requires ${BOLD}${WHITE}3.0${OFF}${RED} or greater
113$DD_BORDER"
114 exit 1
115 ;;
116 esac
117
118 #
119 # >>>> Check kernel version against the minimum acceptable level <<<<
120 #
121 [[ $1 = "1" ]] && echo "LINUX: ${L_arrow}${BOLD}`uname -r`${R_arrow}"
122
123 local IFS
124 declare -i major minor revision change
125 min_kernel_vers=2.6.2
126
127 IFS=".-" # Split up w.x.y.z as well as w.x.y-rc (catch release candidates)
128 set -- $min_kernel_vers # set postional parameters to minimum ver values
129 major=$1; minor=$2; revision=$3
130 #
131 set -- `uname -r` # Set postional parameters to user kernel version
132 #Compare against minimum acceptable kernel version..
133 (( $1 > major )) && return
134 (( $1 == major )) && ((( $2 > minor )) ||
135 ((( $2 == minor )) && (( $3 >= revision )))) && return
136
137 # oops.. write error msg and die
138 echo -e "
139$DD_BORDER
140\t\t${OFF}${RED}The kernel version ${BOLD}${YELLOW}-->${WHITE} $(uname -r) ${YELLOW}<--${OFF}${RED} is too old.
141\t\tThis script requires version ${BOLD}${WHITE}$min_kernel_vers${OFF}${RED} or greater
142$DD_BORDER"
143 exit 1
144}
145
146
147#----------------------------#
148validate_config() { # Are the config values sane (within reason)
149#----------------------------#
150 local -r lfs_PARAM_LIST="BUILDDIR HPKG TEST TOOLCHAINTEST STRIP VIMLANG PAGE RUNMAKE"
151 local -r blfs_PARAM_LIST="BUILDDIR TEST DEPEND"
152 local -r hlfs_PARAM_LIST="BUILDDIR HPKG MODEL TEST TOOLCHAINTEST STRIP VIMLANG PAGE GRSECURITY_HOST RUNMAKE TIMEZONE"
153 local -r clfs_PARAM_LIST="ARCH BOOTMINIMAL RUNMAKE MKFILE"
154 local -r global_PARAM_LIST="BUILDDIR HPKG RUNMAKE TEST TOOLCHAINTEST STRIP PAGE TIMEZONE VIMLANG"
155
156 local PARAM_LIST=
157
158 local -r ERROR_MSG='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid, ${nl_}check the config file ${BOLD}${GREEN}\<$PROGNAME.conf\>${OFF}'
159 local -r PARAM_VALS='${config_param}: ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
160 local config_param
161 local validation_str
162
163 write_error_and_die() {
164 echo -e "\n${DD_BORDER}"
165 echo -e "`eval echo ${ERROR_MSG}`" >&2
166 echo -e "${DD_BORDER}\n"
167 exit 1
168 }
169
170 set +e
171 for PARAM_GROUP in global_PARAM_LIST ${PROGNAME}_PARAM_LIST; do
172 for config_param in ${!PARAM_GROUP}; do
173 # This is a tricky little piece of code.. executes a cmd string.
174 [[ $1 = "1" ]] && echo -e "`eval echo $PARAM_VALS`"
175 case $config_param in
176 BUILDDIR) # We cannot have an <empty> or </> root mount point
177 if [[ "xx x/x" =~ "x${!config_param}x" ]]; then
178 write_error_and_die
179 fi
180 continue ;;
181 TIMEZONE) continue;;
182 MKFILE) continue;;
183 HPKG) validation_str="x0x x1x" ;;
184 RUNMAKE) validation_str="x0x x1x" ;;
185 TEST) validation_str="x0x x1x" ;;
186 STRIP) validation_str="x0x x1x" ;;
187 VIMLANG) validation_str="x0x x1x" ;;
188 DEPEND) validation_str="x0x x1x x2x" ;;
189 MODEL) validation_str="xglibcx xuclibcx" ;;
190 PAGE) validation_str="xletterx xA4x" ;;
191 ARCH) validation_str="xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xalphax" ;;
192 TOOLCHAINTEST) validation_str="x0x x1x" ;;
193 GRSECURITY_HOST) validation_str="x0x x1x" ;;
194 BOOTMINIMAL) validation_str="x0x x1x";;
195 *)
196 echo "WHAT PARAMETER IS THIS.. <<${config_param}>>"
197 exit
198 ;;
199 esac
200 #
201 # This is the 'regexp' test available in bash-3.0..
202 # using it as a poor man's test for substring
203 if [[ ! "${validation_str}" =~ "x${!config_param}x" ]] ; then
204 # parameter value entered is no good
205 write_error_and_die
206 fi
207 done # for loop
208
209 # Not further tests needed on globals
210 if [[ "$PARAM_GROUP" = "global_PARAM_LIST" ]]; then
211 echo " ${BOLD}${GREEN}${PARAM_GROUP%%_*T} parameters are valid${OFF}"
212 continue
213 fi
214
215 for config_param in LC_ALL LANG; do
216 [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
217 [[ -z "${!config_param}" ]] && continue
218 # See it the locale values exist on this machine
219 [[ "`locale -a | grep -c ${!config_param}`" > 0 ]] && continue
220
221 # If you make it this far then there is a problem
222 write_error_and_die
223 done
224
225 for config_param in FSTAB CONFIG KEYMAP BOOK; do
226 [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
227 if [[ $config_param = BOOK ]]; then
228 [[ ! "${WC}" = 1 ]] && continue
229 fi
230 [[ -z "${!config_param}" ]] && continue
231 [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue
232
233 # If you make it this far then there is a problem
234 write_error_and_die
235 done
236 echo " ${BOLD}${GREEN}${PARAM_GROUP%%_*T} parameters are valid${OFF}"
237 done
238 set -e
239 echo "$tab_***${BOLD}${GREEN}Config parameters look good${OFF}***"
240}
241
242
243
244###################################
245### MAIN ###
246###################################
247
248# Evaluate any command line switches
249
250while test $# -gt 0 ; do
251 case $1 in
252 --version | -V )
253 clear
254 echo "$version"
255 exit 0
256 ;;
257
258 --help | -h )
259 if [[ "$PROGNAME" = "blfs" ]]; then
260 blfs_usage
261 else
262 usage
263 fi
264 ;;
265
266 --LFS-version | -L )
267 test $# = 1 && eval "$exit_missing_arg"
268 shift
269 case $1 in
270 dev* | SVN | trunk )
271 LFSVRS=development
272 ;;
273 6.1.1 )
274 echo "For stable 6.1.1 book, please use jhalfs-0.2."
275 exit 0
276 ;;
277 alpha*)
278 LFSVRS=alphabetical
279 ;;
280 * )
281 echo "$1 is an unsupported version at this time."
282 exit 1
283 ;;
284 esac
285 ;;
286
287 --directory | -d )
288 test $# = 1 && eval "$exit_missing_arg"
289 shift
290 BUILDDIR=$1
291 JHALFSDIR=$BUILDDIR/jhalfs
292 LOGDIR=$JHALFSDIR/logs
293 MKFILE=$JHALFSDIR/${PROGNAME}-Makefile
294 ;;
295
296 --rebuild ) CLEAN=1 ;;
297
298 --download-client | -D )
299 echo "The download feature is temporarily disable.."
300 exit
301 test $# = 1 && eval "$exit_missing_arg"
302 shift
303 DL=$1
304 ;;
305
306 --working-copy | -W )
307 test $# = 1 && eval "$exit_missing_arg"
308 shift
309 if [ -f $1/patches.ent ] ; then
310 WC=1
311 BOOK=$1
312 else
313 echo -e "\nLook like $1 isn't a supported working copy."
314 echo -e "Verify your selection and the command line.\n"
315 exit 1
316 fi
317 ;;
318
319 --testsuites | -T ) TEST=1 ;;
320 --get-packages | -P ) HPKG=1 ;;
321 --run-make | -M ) RUNMAKE=1 ;;
322 --no-toolchain-test ) TOOLCHAINTEST=0 ;;
323 --no-strip ) STRIP=0 ;;
324 --no-vim-lang ) VIMLANG=0 ;;
325
326 --page_size )
327 test $# = 1 && eval "$exit_missing_arg"
328 shift
329 case $1 in
330 letter | A4 )
331 PAGE=$1
332 ;;
333 * )
334 echo "$1 isn't a supported page size."
335 exit 1
336 ;;
337 esac
338 ;;
339
340 --timezone )
341 test $# = 1 && eval "$exit_missing_arg"
342 shift
343 if [ -f /usr/share/zoneinfo/$1 ] ; then
344 TIMEZONE=$1
345 else
346 echo -e "\nLooks like $1 isn't a valid timezone description."
347 echo -e "Verify your selection and the command line.\n"
348 exit 1
349 fi
350 ;;
351
352 --fstab )
353 test $# = 1 && eval "$exit_missing_arg"
354 shift
355 if [ -f $1 ] ; then
356 FSTAB=$1
357 else
358 echo -e "\nFile $1 not found. Verify your command line.\n"
359 exit 1
360 fi
361 ;;
362
363 --kernel-config | -C )
364 test $# = 1 && eval "$exit_missing_arg"
365 shift
366 if [ -f $1 ] ; then
367 CONFIG=$1
368 else
369 echo -e "\nFile $1 not found. Verify your command line.\n"
370 exit 1
371 fi
372 ;;
373
374 * )
375 if [[ "$PROGNAME" = "blfs" ]]; then
376 blfs_usage
377 else
378 usage
379 fi
380 ;;
381 esac
382 shift
383done
384
385
386# Prevents setting "-d /" by mistake.
387
388if [ $BUILDDIR = / ] ; then
389 echo -ne "\nThe root directory can't be used to build LFS.\n\n"
390 exit 1
391fi
392
393# If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
394# and notify the user about that.
395
396if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
397 eval "$no_empty_builddir"
398fi
399
400# If requested, clean the build directory
401clean_builddir
402
403# Find the download client to use, if not already specified.
404
405if [ -z $DL ] ; then
406 if [ `type -p wget` ] ; then
407 DL=wget
408 elif [ `type -p curl` ] ; then
409 DL=curl
410 else
411 eval "$no_dl_client"
412 fi
413fi
414
415#===================================================
416# Set the document location...
417# BOOK is either defined in
418# xxx.config
419# comand line
420# default
421# If set by conf file leave or cmd line leave it
422# alone otherwise load the default version
423#===================================================
424BOOK=${BOOK:=$PROGNAME-$LFSVRS}
425#===================================================
426
427if [[ ! -d $JHALFSDIR ]]; then
428 mkdir -pv $JHALFSDIR
429fi
430
431if [[ "$PWD" != "$JHALFSDIR" ]]; then
432 cp -v makefile-functions $JHALFSDIR/
433 if [[ -n "$FILES" ]]; then
434 cp -v $FILES $JHALFSDIR/
435 fi
436 sed 's,FAKEDIR,'$BOOK',' $XSL > $JHALFSDIR/${XSL}
437 export XSL=$JHALFSDIR/${XSL}
438fi
439
440if [[ ! -d $LOGDIR ]]; then
441 mkdir -v $LOGDIR
442fi
443>$LOGDIR/$LOG
444echo "---------------${nl_}"
445
446
447# Check for minumum gcc and kernel versions
448check_requirements 1 # 0/1 0-do not display values.
449echo "---------------${nl_}"
450validate_config 1 # 0/1 0-do not display values
451echo "---------------${nl_}"
452get_book
453echo "---------------${nl_}"
454build_Makefile
455echo "---------------${nl_}"
456#run_make
457
Note: See TracBrowser for help on using the repository browser.