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