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 |
|
---|
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
|
---|
56 | [[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
|
---|
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
|
---|
66 | [[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
|
---|
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 | #*******************************************************************#
|
---|
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"
|
---|
85 |
|
---|
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_}"
|
---|
91 |
|
---|
92 |
|
---|
93 | ###################################
|
---|
94 | ### MAIN ###
|
---|
95 | ###################################
|
---|
96 |
|
---|
97 | # Evaluate any command line switches
|
---|
98 |
|
---|
99 | while test $# -gt 0 ; do
|
---|
100 | case $1 in
|
---|
101 | --book | -B )
|
---|
102 | test $# = 1 && eval "$exit_missing_arg"
|
---|
103 | shift
|
---|
104 | case $1 in
|
---|
105 | dev* | SVN | trunk )
|
---|
106 | LFSVRS=development
|
---|
107 | ;;
|
---|
108 | *) if [[ "$PROGNAME" = "lfs" ]]; then
|
---|
109 | case $1 in
|
---|
110 | 6.1.1 )
|
---|
111 | echo "For stable 6.1.1 book, please use jhalfs-0.2."
|
---|
112 | exit 0
|
---|
113 | ;;
|
---|
114 | alpha*) LFSVRS=alphabetical ;;
|
---|
115 | udev*) LFSVRS=udev_update ;;
|
---|
116 | * ) echo "$1 is an unsupported version at this time." ;;
|
---|
117 | esac
|
---|
118 | else
|
---|
119 | 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."
|
---|
120 | exit 0
|
---|
121 | fi
|
---|
122 | ;;
|
---|
123 | esac
|
---|
124 | ;;
|
---|
125 |
|
---|
126 | --directory | -D )
|
---|
127 | test $# = 1 && eval "$exit_missing_arg"
|
---|
128 | shift
|
---|
129 | BUILDDIR=$1
|
---|
130 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
131 | LOGDIR=$JHALFSDIR/logs
|
---|
132 | MKFILE=$JHALFSDIR/Makefile
|
---|
133 | ;;
|
---|
134 |
|
---|
135 | --fstab | -F )
|
---|
136 | test $# = 1 && eval "$exit_missing_arg"
|
---|
137 | shift
|
---|
138 | if [ -f $1 ] ; then
|
---|
139 | FSTAB=$1
|
---|
140 | else
|
---|
141 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
142 | exit 1
|
---|
143 | fi
|
---|
144 | ;;
|
---|
145 |
|
---|
146 | --get-packages | -G ) HPKG=1 ;;
|
---|
147 |
|
---|
148 | --help | -h )
|
---|
149 | if [[ "$PROGNAME" = "blfs" ]]; then
|
---|
150 | blfs_usage
|
---|
151 | else
|
---|
152 | usage
|
---|
153 | fi
|
---|
154 | ;;
|
---|
155 |
|
---|
156 | --kernel-config | -K )
|
---|
157 | test $# = 1 && eval "$exit_missing_arg"
|
---|
158 | shift
|
---|
159 | if [ -f $1 ] ; then
|
---|
160 | CONFIG=$1
|
---|
161 | else
|
---|
162 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
163 | exit 1
|
---|
164 | fi
|
---|
165 | ;;
|
---|
166 |
|
---|
167 | --make | -M ) RUNMAKE=1 ;;
|
---|
168 |
|
---|
169 | --rebuild | -R ) CLEAN=1 ;;
|
---|
170 |
|
---|
171 | --testsuites | -T )
|
---|
172 | test $# = 1 && eval "$exit_missing_arg"
|
---|
173 | shift
|
---|
174 | case $1 in
|
---|
175 | 0 | 1 | 2 | 3 )
|
---|
176 | TEST=$1
|
---|
177 | ;;
|
---|
178 | * )
|
---|
179 | echo -e "\n$1 isn't a valid testsuites level value."
|
---|
180 | echo -e "You must to use 0, 1, 2, or 3.\n"
|
---|
181 | exit 1
|
---|
182 | ;;
|
---|
183 | esac
|
---|
184 | ;;
|
---|
185 |
|
---|
186 | --version | -V )
|
---|
187 | clear
|
---|
188 | echo "$version"
|
---|
189 | exit 0
|
---|
190 | ;;
|
---|
191 |
|
---|
192 | --working-copy | -W )
|
---|
193 | test $# = 1 && eval "$exit_missing_arg"
|
---|
194 | shift
|
---|
195 | case $PROGNAME in # Poor checks. We should find better ones.
|
---|
196 | lfs)
|
---|
197 | if [ -f $1/patches.ent ] ; then
|
---|
198 | WC=1
|
---|
199 | BOOK=$1
|
---|
200 | else
|
---|
201 | echo -e "\nLook like $1 isn't a LFS working copy."
|
---|
202 | exit 1
|
---|
203 | fi
|
---|
204 | ;;
|
---|
205 | clfs)
|
---|
206 | if [ -f $1/patches.ent ] && [ -f $1/packages.ent ]; then
|
---|
207 | WC=1
|
---|
208 | BOOK=$1
|
---|
209 | else
|
---|
210 | echo -e "\nLook like $1 isn't a CLFS working copy."
|
---|
211 | exit 1
|
---|
212 | fi
|
---|
213 | ;;
|
---|
214 | hlfs)
|
---|
215 | if [ -f $1/template.xml ] ; then
|
---|
216 | WC=1
|
---|
217 | BOOK=$1
|
---|
218 | else
|
---|
219 | echo -e "\nLook like $1 isn't a HLFS working copy."
|
---|
220 | exit 1
|
---|
221 | fi
|
---|
222 | ;;
|
---|
223 | blfs)
|
---|
224 | if [ -f $1/use-unzip.xml ] ; then
|
---|
225 | WC=1
|
---|
226 | BOOK=$1
|
---|
227 | else
|
---|
228 | echo -e "\nLook like $1 isn't a BLFS working copy."
|
---|
229 | exit 1
|
---|
230 | fi
|
---|
231 | ;;
|
---|
232 |
|
---|
233 | * )
|
---|
234 | if [[ "$PROGNAME" = "blfs" ]]; then
|
---|
235 | blfs_usage
|
---|
236 | else
|
---|
237 | usage
|
---|
238 | fi
|
---|
239 | ;;
|
---|
240 | esac
|
---|
241 | shift
|
---|
242 | done
|
---|
243 |
|
---|
244 | # Find the download client to use, if not already specified.
|
---|
245 |
|
---|
246 | if [ -z $DL ] ; then
|
---|
247 | if [ `type -p wget` ] ; then
|
---|
248 | DL=wget
|
---|
249 | elif [ `type -p curl` ] ; then
|
---|
250 | DL=curl
|
---|
251 | else
|
---|
252 | eval "$no_dl_client"
|
---|
253 | fi
|
---|
254 | fi
|
---|
255 |
|
---|
256 | #===================================================
|
---|
257 | # Set the document location...
|
---|
258 | # BOOK is either defined in
|
---|
259 | # xxx.config
|
---|
260 | # comand line
|
---|
261 | # default
|
---|
262 | # If set by conf file or cmd line leave it
|
---|
263 | # alone otherwise load the default version
|
---|
264 | #===================================================
|
---|
265 | BOOK=${BOOK:=$PROGNAME-$LFSVRS}
|
---|
266 | #===================================================
|
---|
267 |
|
---|
268 |
|
---|
269 | # Check for minumum gcc and kernel versions
|
---|
270 | #check_requirements 1 # 0/1 0-do not display values.
|
---|
271 | check_version "2.6.2" "`uname -r`" "KERNEL"
|
---|
272 | check_version "3.0" "$BASH_VERSION" "BASH"
|
---|
273 | check_version "3.0" "`gcc -dumpversion`" "GCC"
|
---|
274 | tarVer=`tar --version`
|
---|
275 | check_version "1.15.0" "${tarVer##* }" "TAR"
|
---|
276 | echo "---------------${nl_}"
|
---|
277 |
|
---|
278 | validate_config 1 # 0/1 0-do not display values
|
---|
279 | echo "---------------${nl_}"
|
---|
280 |
|
---|
281 | echo -n "Are you happy with that settings? yes/no (no): "
|
---|
282 | read ANSWER
|
---|
283 | if [ x$ANSWER != "xyes" ] ; then
|
---|
284 | echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
|
---|
285 | exit 1
|
---|
286 | fi
|
---|
287 |
|
---|
288 | # Prevents setting "-d /" by mistake.
|
---|
289 |
|
---|
290 | if [ $BUILDDIR = / ] ; then
|
---|
291 | echo -ne "\nThe root directory can't be used to build LFS.\n\n"
|
---|
292 | exit 1
|
---|
293 | fi
|
---|
294 |
|
---|
295 | # If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
|
---|
296 | # and notify the user about that.
|
---|
297 |
|
---|
298 | if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
|
---|
299 | eval "$no_empty_builddir"
|
---|
300 | fi
|
---|
301 |
|
---|
302 | # If requested, clean the build directory
|
---|
303 | clean_builddir
|
---|
304 |
|
---|
305 | if [[ ! -d $JHALFSDIR ]]; then
|
---|
306 | mkdir -pv $JHALFSDIR
|
---|
307 | fi
|
---|
308 |
|
---|
309 | if [[ "$PWD" != "$JHALFSDIR" ]]; then
|
---|
310 | cp -v $COMMON_DIR/makefile-functions $JHALFSDIR/
|
---|
311 | if [[ -n "$FILES" ]]; then
|
---|
312 | # pushd/popd necessary to deal with mulitiple files
|
---|
313 | pushd $PACKAGE_DIR
|
---|
314 | cp -v $FILES $JHALFSDIR/
|
---|
315 | popd
|
---|
316 | fi
|
---|
317 | sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
|
---|
318 | export XSL=$JHALFSDIR/${XSL}
|
---|
319 | fi
|
---|
320 |
|
---|
321 | if [[ ! -d $LOGDIR ]]; then
|
---|
322 | mkdir -v $LOGDIR
|
---|
323 | fi
|
---|
324 | >$LOGDIR/$LOG
|
---|
325 | echo "---------------${nl_}"
|
---|
326 |
|
---|
327 | get_book
|
---|
328 | echo "---------------${nl_}"
|
---|
329 |
|
---|
330 | build_Makefile
|
---|
331 | echo "---------------${nl_}"
|
---|
332 |
|
---|
333 | run_make
|
---|
334 |
|
---|