source: LFS/master.sh@ ac35c8e

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since ac35c8e was ac35c8e, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

MOUNT_PT permissions fixes in LFS and HLFS. In CLFSx it need be revised after 2.1 release.
Fixed /etc/lfs-release creation.

  • Property mode set to 100644
File size: 17.3 KB
Line 
1#!/bin/bash
2
3# $Id$
4
5###################################
6### FUNCTIONS ###
7###################################
8
9
10#############################################################
11
12
13#----------------------------#
14chapter4_Makefiles() { #
15#----------------------------#
16 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4 ( SETUP ) ${R_arrow}"
17
18# If /home/$LUSER is already present in the host, we asume that the
19# lfs user and group are also presents in the host, and a backup
20# of their bash init files is made.
21(
22 cat << EOF
23020-creatingtoolsdir:
24 @\$(call echo_message, Building)
25 @mkdir \$(MOUNT_PT)/tools && \\
26 rm -f /tools && \\
27 ln -s \$(MOUNT_PT)/tools / && \\
28 touch \$@ && \\
29 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
30 echo --------------------------------------------------------------------------------\$(WHITE)
31
32021-addinguser: 020-creatingtoolsdir
33 @\$(call echo_message, Building)
34 @if [ ! -d /home/\$(LUSER) ]; then \\
35 groupadd \$(LGROUP); \\
36 useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
37 else \\
38 touch luser-exist; \\
39 fi;
40 @chown \$(LUSER) \$(MOUNT_PT)/tools && \\
41 chmod -R a+wt \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
42 chmod a+wt \$(SRCSDIR) && \\
43 touch \$@ && \\
44 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
45 echo --------------------------------------------------------------------------------\$(WHITE)
46
47022-settingenvironment: 021-addinguser
48 @\$(call echo_message, Building)
49 @if [ -f /home/\$(LUSER)/.bashrc -a ! -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
50 mv /home/\$(LUSER)/.bashrc /home/\$(LUSER)/.bashrc.XXX; \\
51 fi;
52 @if [ -f /home/\$(LUSER)/.bash_profile -a ! -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
53 mv /home/\$(LUSER)/.bash_profile /home/\$(LUSER)/.bash_profile.XXX; \\
54 fi;
55 @echo "set +h" > /home/\$(LUSER)/.bashrc && \\
56 echo "umask 022" >> /home/\$(LUSER)/.bashrc && \\
57 echo "LFS=\$(MOUNT_PT)" >> /home/\$(LUSER)/.bashrc && \\
58 echo "LC_ALL=POSIX" >> /home/\$(LUSER)/.bashrc && \\
59 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/\$(LUSER)/.bashrc && \\
60 echo "export LFS LC_ALL PATH" >> /home/\$(LUSER)/.bashrc && \\
61 echo "source $JHALFSDIR/envars" >> /home/\$(LUSER)/.bashrc && \\
62 chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bashrc && \\
63 touch envars && \\
64 chown \$(LUSER) envars && \\
65 touch \$@ && \\
66 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
67 echo --------------------------------------------------------------------------------\$(WHITE)
68EOF
69) > $MKFILE.tmp
70
71 chapter4=" 020-creatingtoolsdir 021-addinguser 022-settingenvironment"
72}
73
74
75
76#----------------------------#
77chapter5_Makefiles() {
78#----------------------------#
79 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5 ( LUSER ) ${R_arrow}"
80
81 for file in chapter05/* ; do
82 # Keep the script file name
83 this_script=`basename $file`
84
85 # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
86 # Fix also locales creation when running chapter05 testsuites (ugly)
87 case "${this_script}" in
88 *tcl) [[ "${TEST}" = "0" ]] && continue ;;
89 *expect) [[ "${TEST}" = "0" ]] && continue ;;
90 *dejagnu) [[ "${TEST}" = "0" ]] && continue ;;
91 *stripping) [[ "${STRIP}" = "n" ]] && continue ;;
92 *glibc) [[ "${TEST}" = "3" ]] && \
93 sed -i 's@/usr/lib/locale@/tools/lib/locale@' $file ;;
94 esac
95
96 # First append each name of the script files to a list (this will become
97 # the names of the targets in the Makefile
98 # DO NOT append the changingowner script, it need be run as root.
99 # A hack is necessary: create script in chap5 BUT run as a dependency for
100 # SUDO target
101 case "${this_script}" in
102 *changingowner) runasroot="$runasroot ${this_script}" ;;
103 *) chapter5="$chapter5 ${this_script}" ;;
104 esac
105
106 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
107 # and binutils in chapter 5)
108 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
109
110 # Set the dependency for the first target.
111 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
112
113 #--------------------------------------------------------------------#
114 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
115 #--------------------------------------------------------------------#
116 #
117 # Drop in the name of the target on a new line, and the previous target
118 # as a dependency. Also call the echo_message function.
119 LUSER_wrt_target "${this_script}" "$PREV"
120
121 # Find the version of the command files, if it corresponds with the building of
122 # a specific package
123 pkg_tarball=$(get_package_tarball_name $name)
124
125 # If $pkg_tarball isn't empty, we've got a package...
126 if [ "$pkg_tarball" != "" ] ; then
127 # Insert instructions for unpacking the package and to set the PKGDIR variable.
128 LUSER_wrt_unpack "$pkg_tarball"
129 # If the testsuites must be run, initialize the log file
130 [[ "$TEST" = "3" ]] && LUSER_wrt_test_log "${this_script}"
131 # If using optimizations, write the instructions
132 [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
133 fi
134
135 # Insert date and disk usage at the top of the log file, the script run
136 # and date and disk usage again at the bottom of the log file.
137 # The changingowner script must be run as root.
138 case "${this_script}" in
139 *changingowner) wrt_RunAsRoot "$file" ;;
140 *) LUSER_wrt_RunAsUser "$file" ;;
141 esac
142
143 # Remove the build directory(ies) except if the package build fails
144 # (so we can review config.cache, config.log, etc.)
145 if [ "$pkg_tarball" != "" ] ; then
146 LUSER_RemoveBuildDirs "$name"
147 fi
148
149 # Include a touch of the target name so make can check
150 # if it's already been made.
151 wrt_touch
152 #
153 #--------------------------------------------------------------------#
154 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
155 #--------------------------------------------------------------------#
156
157 # Keep the script file name for Makefile dependencies.
158 PREV=${this_script}
159 done # end for file in chapter05/*
160}
161
162
163#----------------------------#
164chapter6_Makefiles() {
165#----------------------------#
166
167 # Set envars and scripts for iteration targets
168 LOGS="" # Start with an empty global LOGS envar
169 if [[ -z "$1" ]] ; then
170 local N=""
171 else
172 local N=-build_$1
173 local chapter6=""
174 mkdir chapter06$N
175 cp chapter06/* chapter06$N
176 for script in chapter06$N/* ; do
177 # Overwrite existing symlinks, files, and dirs
178 sed -e 's/ln -sv/&f/g' \
179 -e 's/mv -v/&f/g' \
180 -e 's/mkdir -v/&p/g' -i ${script}
181 done
182 # Remove Bzip2 binaries before make install
183 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2
184 fi
185
186 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
187
188 for file in chapter06$N/* ; do
189 # Keep the script file name
190 this_script=`basename $file`
191
192 # We'll run the chroot commands differently than the others, so skip them in the
193 # dependencies and target creation.
194 case "${this_script}" in
195 *chroot) continue ;;
196 *stripping*) [[ "${STRIP}" = "n" ]] && continue ;;
197 esac
198
199 # Grab the name of the target.
200 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
201
202 # Find the version of the command files, if it corresponds with the building of
203 # a specific package. We need this here to can skip scripts not needed for
204 # iterations rebuilds
205 pkg_tarball=$(get_package_tarball_name $name)
206
207 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
208 case "${this_script}" in
209 *stripping*) ;;
210 *) continue ;;
211 esac
212 fi
213
214 # Append each name of the script files to a list (this will become
215 # the names of the targets in the Makefile)
216 # The kernfs script must be run as part of SUDO target.
217 case "${this_script}" in
218 *kernfs) runasroot="$runasroot ${this_script}" ;;
219 *) chapter6="$chapter6 ${this_script}${N}" ;;
220 esac
221
222 # Append each name of the script files to a list (this will become
223 # the names of the logs to be moved for each iteration)
224 LOGS="$LOGS ${this_script}"
225
226 #--------------------------------------------------------------------#
227 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
228 #--------------------------------------------------------------------#
229 #
230 # Drop in the name of the target on a new line, and the previous target
231 # as a dependency. Also call the echo_message function.
232 # In the mount of kernel filesystems we need to set LFS
233 # and not to use chroot.
234 case "${this_script}" in
235 *kernfs) LUSER_wrt_target "${this_script}" "$PREV" ;;
236 *) CHROOT_wrt_target "${this_script}${N}" "$PREV" ;;
237 esac
238
239 # If $pkg_tarball isn't empty, we've got a package...
240 # Insert instructions for unpacking the package and changing directories
241 if [ "$pkg_tarball" != "" ] ; then
242 CHROOT_Unpack "$pkg_tarball"
243 # If the testsuites must be run, initialize the log file
244 case $name in
245 binutils | gcc | glibc )
246 [[ "$TEST" != "0" ]] && CHROOT_wrt_test_log "${this_script}"
247 ;;
248 * )
249 [[ "$TEST" = "2" ]] || [[ "$TEST" = "3" ]] && CHROOT_wrt_test_log "${this_script}"
250 ;;
251 esac
252 # If using optimizations, write the instructions
253 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
254 fi
255
256 # In the mount of kernel filesystems we need to set LFS
257 # and not to use chroot.
258 case "${this_script}" in
259 *kernfs) wrt_RunAsRoot "$file" ;;
260 *) CHROOT_wrt_RunAsRoot "$file" ;;
261 esac
262
263 # Remove the build directory(ies) except if the package build fails.
264 if [ "$pkg_tarball" != "" ] ; then
265 CHROOT_wrt_RemoveBuildDirs "$name"
266 fi
267
268 # Include a touch of the target name so make can check
269 # if it's already been made.
270 wrt_touch
271 #
272 #--------------------------------------------------------------------#
273 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
274 #--------------------------------------------------------------------#
275
276 # Keep the script file name for Makefile dependencies.
277 PREV=${this_script}${N}
278 # Set system_build envar for iteration targets
279 system_build=$chapter6
280 done # end for file in chapter06/*
281}
282
283#----------------------------#
284chapter78_Makefiles() {
285#----------------------------#
286 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8 ( BOOT ) ${R_arrow}"
287
288 for file in chapter0{7,8}/* ; do
289 # Keep the script file name
290 this_script=`basename $file`
291
292 # Grub must be configured manually.
293 # Handle fstab creation.
294 # If no .config file is supplied, the kernel build is skipped
295 case ${this_script} in
296 *grub) continue ;;
297 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
298 *kernel) [[ -z ${CONFIG} ]] && continue
299 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
300 esac
301
302 # First append each name of the script files to a list (this will become
303 # the names of the targets in the Makefile
304 chapter78="$chapter78 ${this_script}"
305
306 #--------------------------------------------------------------------#
307 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
308 #--------------------------------------------------------------------#
309 #
310 # Drop in the name of the target on a new line, and the previous target
311 # as a dependency. Also call the echo_message function.
312 CHROOT_wrt_target "${this_script}" "$PREV"
313
314 # Find the bootscripts and kernel package names
315 case "${this_script}" in
316 *bootscripts)
317 name="lfs-bootscripts"
318 pkg_tarball=$(get_package_tarball_name $name)
319 CHROOT_Unpack "$pkg_tarball"
320 ;;
321 *kernel)
322 name="linux"
323 pkg_tarball=$(get_package_tarball_name $name)
324 CHROOT_Unpack "$pkg_tarball"
325 ;;
326 esac
327
328 # Check if we have a real /etc/fstab file
329 case "${this_script}" in
330 *fstab) if [[ -n $FSTAB ]]; then
331 CHROOT_wrt_CopyFstab
332 else
333 CHROOT_wrt_RunAsRoot "$file"
334 fi
335 ;;
336 *) CHROOT_wrt_RunAsRoot "$file"
337 ;;
338 esac
339
340 case "${this_script}" in
341 *bootscripts) CHROOT_wrt_RemoveBuildDirs "dummy" ;;
342 *kernel) CHROOT_wrt_RemoveBuildDirs "dummy" ;;
343 esac
344
345 # Include a touch of the target name so make can check
346 # if it's already been made.
347 wrt_touch
348 #
349 #--------------------------------------------------------------------#
350 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
351 #--------------------------------------------------------------------#
352
353 # Keep the script file name for Makefile dependencies.
354 PREV=${this_script}
355 done # for file in chapter0{7,8}/*
356
357}
358
359
360
361#----------------------------#
362build_Makefile() { #
363#----------------------------#
364
365 echo "Creating Makefile... ${BOLD}START${OFF}"
366
367 cd $JHALFSDIR/${PROGNAME}-commands
368
369 # Start with a clean Makefile.tmp file
370 >$MKFILE
371
372 chapter4_Makefiles
373 chapter5_Makefiles
374 chapter6_Makefiles
375 # Add the iterations targets, if needed
376 [[ "$COMPARE" = "y" ]] && wrt_compare_targets
377 chapter78_Makefiles
378 # Add the BLFS_TOOL targets, if needed
379 [[ "$BLFS_TOOL" = "y" ]] && wrt_blfs_tool_targets
380
381 # Add a header, some variables and include the function file
382 # to the top of the real Makefile.
383 wrt_Makefile_header
384
385 # Add chroot commands
386 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
387 i=1
388 for file in chapter06/*chroot* ; do
389 chroot=`cat $file | \
390 sed -e "s@chroot@$CHROOT_LOC@" \
391 -e '/#!\/bin\/bash/d' \
392 -e 's@ \\\@ @g' | \
393 tr -d '\n' | \
394 sed -e 's/ */ /g' \
395 -e 's|\\$|&&|g' \
396 -e 's|exit||g' \
397 -e 's|$| -c|' \
398 -e 's|"$$LFS"|$(MOUNT_PT)|' \
399 -e 's|set -e||' \
400 -e 's|set +h||'`
401 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
402 i=`expr $i + 1`
403 done
404
405 # Drop in the main target 'all:' and the chapter targets with each sub-target
406 # as a dependency.
407(
408 cat << EOF
409
410all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_BLFS_TOOL
411 @sudo make do_housekeeping
412 @echo "$VERSION - jhalfs build" > lfs-release && \\
413 sudo mv lfs-release \$(MOUNT_PT)/etc
414 @\$(call echo_finished,$VERSION)
415
416ck_UID:
417 @if [ \`id -u\` = "0" ]; then \\
418 echo "--------------------------------------------------"; \\
419 echo "You cannot run this makefile from the root account"; \\
420 echo "--------------------------------------------------"; \\
421 exit 1; \\
422 fi
423
424mk_SETUP:
425 @\$(call echo_SU_request)
426 @sudo make SHELL=/bin/bash SETUP
427 @touch \$@
428
429mk_LUSER: mk_SETUP
430 @\$(call echo_SULUSER_request)
431 @( sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make SHELL=/bin/bash LUSER" )
432 @sudo make restore-luser-env
433 @touch \$@
434
435mk_SUDO: mk_LUSER
436 @sudo make SHELL=/bin/bash SUDO
437 touch \$@
438#
439# The convoluted piece of code below is necessary to provide 'make' with a valid shell in the
440# chroot environment. (Unless someone knows a different way)
441# Manually create the /bin directory and provide link to the /tools dir.
442# Also change the original symlink creation to include (f)orce to prevent failure due to
443# pre-existing links.
444#
445mk_CHROOT: mk_SUDO
446 @if [ ! -e \$(MOUNT_PT)/bin ]; then \\
447 mkdir \$(MOUNT_PT)/bin; \\
448 cd \$(MOUNT_PT)/bin && \\
449 ln -sf /tools/bin/bash bash; ln -sf bash sh; \\
450 sudo chown -R 0:0 \$(MOUNT_PT)/bin; \\
451 fi;
452 @sudo sed -e 's|^ln -sv |ln -svf |' -i \$(CMDSDIR)/chapter06/*-createfiles
453 @\$(call echo_CHROOT_request)
454 @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make CHROOT")
455 @touch \$@
456
457mk_BOOT: mk_CHROOT
458 @\$(call echo_CHROOT_request)
459 @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BOOT")
460 @touch \$@
461
462mk_BLFS_TOOL: create-sbu_du-report
463 @\$(call echo_PHASE,Building BLFS-TOOLS)
464 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
465 sudo mkdir -p $BUILDDIR$TRACKING_DIR; \\
466 sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BLFS_TOOL"; \\
467 fi;
468 @touch \$@
469
470
471SETUP: $chapter4
472LUSER: $chapter5
473SUDO: $runasroot
474CHROOT: $chapter6
475BOOT: $chapter78
476BLFS_TOOL: $blfs_tool
477
478
479create-sbu_du-report: mk_BOOT
480 @\$(call echo_message, Building)
481 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
482 ./create-sbu_du-report.sh logs $VERSION; \\
483 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
484 fi;
485 @touch \$@
486
487restore-luser-env:
488 @\$(call echo_message, Building)
489 @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
490 mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
491 fi;
492 @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
493 mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
494 fi;
495 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
496 touch \$@ && \\
497 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
498 echo --------------------------------------------------------------------------------\$(WHITE)
499
500do_housekeeping:
501 @-umount \$(MOUNT_PT)/sys
502 @-umount \$(MOUNT_PT)/proc
503 @-umount \$(MOUNT_PT)/dev/shm
504 @-umount \$(MOUNT_PT)/dev/pts
505 @-umount \$(MOUNT_PT)/dev
506 @-rm /tools
507 @-if [ ! -f luser-exist ]; then \\
508 userdel \$(LUSER); \\
509 rm -rf /home/\$(LUSER); \\
510 fi;
511
512
513EOF
514) >> $MKFILE
515
516 # Bring over the items from the Makefile.tmp
517 cat $MKFILE.tmp >> $MKFILE
518 rm $MKFILE.tmp
519 echo "Creating Makefile... ${BOLD}DONE${OFF}"
520}
Note: See TracBrowser for help on using the repository browser.