source: master.sh@ 5627958

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

Revising command line switches. First round.

  • Property mode set to 100755
File size: 8.0 KB
Line 
1#!/bin/bash
2# $Id$
3set -e
4
5
6#>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
7#-----------------------#
8simple_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
16see_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#####
30set -e
31trap see_ya 0
32trap simple_error ERR
33trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
34#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
35
36
37if [ ! -L $0 ] ; then
38 echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
39 exit 1
40fi
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
46MODULE_CONFIG=$PACKAGE_DIR/config
47
48echo -n "Loading common-functions module..."
49source $COMMON_DIR/common-functions
50[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
51echo "OK"
52#
53
54echo -n "Loading masterscript conf..."
55source $COMMON_DIR/config
56[[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
57echo "OK"
58#
59echo -n "Loading config module <$MODULE_CONFIG>..."
60source $MODULE_CONFIG
61[[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
62echo "OK"
63#
64echo -n "Loading code module <$MODULE>..."
65source $MODULE
66[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
67echo "OK"
68#
69echo "---------------${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#===========================================================
76WC=${BOOK:+1}
77#===========================================================
78
79
80#*******************************************************************#
81echo -n "Loading function <func_check_version.sh>..."
82source $COMMON_DIR/func_check_version.sh
83[[ $? > 0 ]] && echo " function module did not load.." && exit 2
84echo "OK"
85
86echo -n "Loading function <func_validate_configs.sh>..."
87source $COMMON_DIR/func_validate_configs.sh
88[[ $? > 0 ]] && echo " function module did not load.." && exit 2
89echo "OK"
90echo "---------------${nl_}"
91
92
93###################################
94### MAIN ###
95###################################
96
97# Evaluate any command line switches
98
99while test $# -gt 0 ; do
100 case $1 in
101 --version | -V )
102 clear
103 echo "$version"
104 exit 0
105 ;;
106
107 --help | -h )
108 if [[ "$PROGNAME" = "blfs" ]]; then
109 blfs_usage
110 else
111 usage
112 fi
113 ;;
114
115 --book | -B )
116 test $# = 1 && eval "$exit_missing_arg"
117 shift
118 case $1 in
119 dev* | SVN | trunk )
120 LFSVRS=development
121 ;;
122 *) if [[ "$PROGNAME" = "lfs" ]]; then
123 case $1 in
124 6.1.1 )
125 echo "For stable 6.1.1 book, please use jhalfs-0.2."
126 exit 0
127 ;;
128 alpha*) LFSVRS=alphabetical ;;
129 udev*) LFSVRS=udev_update ;;
130 * ) echo "$1 is an unsupported version at this time." ;;
131 esac
132 else
133 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."
134 exit 0
135 fi
136 ;;
137 esac
138 ;;
139
140 --directory | -d )
141 test $# = 1 && eval "$exit_missing_arg"
142 shift
143 BUILDDIR=$1
144 JHALFSDIR=$BUILDDIR/jhalfs
145 LOGDIR=$JHALFSDIR/logs
146 MKFILE=$JHALFSDIR/Makefile
147 ;;
148
149 --working-copy | -W )
150 test $# = 1 && eval "$exit_missing_arg"
151 shift
152 case $PROGNAME in # Poor checks. We should find better ones.
153 lfs)
154 if [ -f $1/patches.ent ] ; then
155 WC=1
156 BOOK=$1
157 else
158 echo -e "\nLook like $1 isn't a LFS working copy."
159 exit 1
160 fi
161 ;;
162 clfs)
163 if [ -f $1/patches.ent ] && [ -f $1/packages.ent ]; then
164 WC=1
165 BOOK=$1
166 else
167 echo -e "\nLook like $1 isn't a CLFS working copy."
168 exit 1
169 fi
170 ;;
171 hlfs)
172 if [ -f $1/template.xml ] ; then
173 WC=1
174 BOOK=$1
175 else
176 echo -e "\nLook like $1 isn't a HLFS working copy."
177 exit 1
178 fi
179 ;;
180 blfs)
181 if [ -f $1/use-unzip.xml ] ; then
182 WC=1
183 BOOK=$1
184 else
185 echo -e "\nLook like $1 isn't a BLFS working copy."
186 exit 1
187 fi
188 ;;
189
190 --testsuites | -T )
191 test $# = 1 && eval "$exit_missing_arg"
192 shift
193 case $1 in
194 0 | 1 | 2 | 3 )
195 TEST=$1
196 ;;
197 * )
198 echo -e "\n$1 isn't a valid testsuites level value."
199 echo -e "You must to use 0, 1, 2, or 3.\n"
200 exit 1
201 ;;
202 esac
203 ;;
204
205 --get-packages | -P ) HPKG=1 ;;
206 --run-make | -M ) RUNMAKE=1 ;;
207 --rebuild ) CLEAN=1 ;;
208
209 --fstab )
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 | -C )
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
231 * )
232 if [[ "$PROGNAME" = "blfs" ]]; then
233 blfs_usage
234 else
235 usage
236 fi
237 ;;
238 esac
239 shift
240done
241
242# Find the download client to use, if not already specified.
243
244if [ -z $DL ] ; then
245 if [ `type -p wget` ] ; then
246 DL=wget
247 elif [ `type -p curl` ] ; then
248 DL=curl
249 else
250 eval "$no_dl_client"
251 fi
252fi
253
254#===================================================
255# Set the document location...
256# BOOK is either defined in
257# xxx.config
258# comand line
259# default
260# If set by conf file or cmd line leave it
261# alone otherwise load the default version
262#===================================================
263BOOK=${BOOK:=$PROGNAME-$LFSVRS}
264#===================================================
265
266
267# Check for minumum gcc and kernel versions
268#check_requirements 1 # 0/1 0-do not display values.
269check_version "2.6.2" "`uname -r`" "KERNEL"
270check_version "3.0" "$BASH_VERSION" "BASH"
271check_version "3.0" "`gcc -dumpversion`" "GCC"
272tarVer=`tar --version`
273check_version "1.15.0" "${tarVer##* }" "TAR"
274echo "---------------${nl_}"
275
276validate_config 1 # 0/1 0-do not display values
277echo "---------------${nl_}"
278
279echo -n "Are you happy with that settings? yes/no (no): "
280read ANSWER
281if [ x$ANSWER != "xyes" ] ; then
282 echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
283 exit 1
284fi
285
286# Prevents setting "-d /" by mistake.
287
288if [ $BUILDDIR = / ] ; then
289 echo -ne "\nThe root directory can't be used to build LFS.\n\n"
290 exit 1
291fi
292
293# If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
294# and notify the user about that.
295
296if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
297 eval "$no_empty_builddir"
298fi
299
300# If requested, clean the build directory
301clean_builddir
302
303if [[ ! -d $JHALFSDIR ]]; then
304 mkdir -pv $JHALFSDIR
305fi
306
307if [[ "$PWD" != "$JHALFSDIR" ]]; then
308 cp -v $COMMON_DIR/makefile-functions $JHALFSDIR/
309 if [[ -n "$FILES" ]]; then
310 # pushd/popd necessary to deal with mulitiple files
311 pushd $PACKAGE_DIR
312 cp -v $FILES $JHALFSDIR/
313 popd
314 fi
315 sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
316 export XSL=$JHALFSDIR/${XSL}
317fi
318
319if [[ ! -d $LOGDIR ]]; then
320 mkdir -v $LOGDIR
321fi
322>$LOGDIR/$LOG
323echo "---------------${nl_}"
324
325get_book
326echo "---------------${nl_}"
327
328build_Makefile
329echo "---------------${nl_}"
330
331run_make
332
Note: See TracBrowser for help on using the repository browser.