source: LFS/master.sh@ 16cef03

ablfs-more trunk
Last change on this file since 16cef03 was 20051e0, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Use only CHROOT1 in LFS/master.sh

There is only one chroot command in newer LFS, and using the first one
with previous versions does not hurt.

  • Property mode set to 100644
File size: 15.7 KB
Line 
1#!/bin/bash
2
3###################################
4### FUNCTIONS ###
5###################################
6
7
8#############################################################
9
10
11#-------------------------#
12chapter_targets() { #
13#-------------------------#
14# $1 is the chapter number. Pad it with 0 to the left to obtain a 2-digit
15# number:
16 printf -v dir chapter%02d $1
17
18# $2 contains the build number if rebuilding for ICA
19 if [[ -z "$2" ]] ; then
20 local N=""
21 else
22 local N=-build_$2
23 local CHROOT_TGT=""
24 mkdir ${dir}$N
25 cp ${dir}/* ${dir}$N
26 for script in ${dir}$N/* ; do
27 # Overwrite existing symlinks, files, and dirs
28 sed -e 's/ln *-sv/&f/g' \
29 -e 's/mv *-v/&f/g' \
30 -e 's/mkdir *-v/&p/g' -i ${script}
31 # Rename the scripts
32 mv ${script} ${script}$N
33 done
34 # Remove Bzip2 binaries before make install (LFS-6.2 compatibility)
35 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i ${dir}$N/*-bzip2$N
36 # Remove openssl-<version> from /usr/share/doc (LFS-9.x), because
37 # otherwise the mv command creates an openssl directory.
38 sed -e 's@mv -v@rm -rfv /usr/share/doc/openssl-*\n&@' \
39 -i ${dir}$N/*-openssl$N
40 fi
41
42 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter $1$N${R_arrow}"
43
44 for file in ${dir}$N/* ; do
45 # Keep the script file name
46 this_script=`basename $file`
47
48 # Some scripts need peculiar actions:
49 # - glibc chap 5: fix locales creation when running chapter05 testsuites
50 # - Stripping at the end of system build: lfs.xsl does not generate
51 # correct commands if the user does not want to strip, so skip it
52 # in this case
53 # - do not reinstall linux-headers when rebuilding
54 # - grub config: must be done manually; skip it
55 # - handle fstab and .config. Skip kernel if .config not supplied
56 case "${this_script}" in
57 5*glibc) [[ "${TEST}" = "3" ]] && \
58 sed -i 's@/usr/lib/locale@/tools/lib/locale@' $file ;;
59 *strippingagain) [[ "${STRIP}" = "n" ]] && continue ;;
60 *stripping) [[ "${STRIP}" = "n" ]] && continue ;;
61 *linux-headers*) [[ -n "$N" ]] && continue ;;
62 8*grub) (( nb_chaps == 5 )) && continue ;;
63 10*grub) continue ;;
64 *fstab) [[ -z "${FSTAB}" ]] ||
65 [[ ${FSTAB} == $BUILDDIR/sources/fstab ]] ||
66 cp ${FSTAB} $BUILDDIR/sources/fstab ;;
67 *kernel) [[ -z ${CONFIG} ]] && continue
68 [[ ${CONFIG} == $BUILDDIR/sources/kernel-config ]] ||
69 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
70 esac
71 # Grab the name of the target
72 # This is only used to check the name in "opt_override" or "BLACKIST"
73 name=`echo ${this_script} | sed -e 's@[0-9]\{3,4\}-@@' \
74 -e 's@-pass[0-9]\{1\}@@' \
75 -e 's@-libstdc++@@' \
76 -e 's,'$N',,' \
77 -e 's@-32@@'`
78
79 # Find the name of the tarball and the version of the package
80 # If it doesn't exist, we skip it in iterations rebuilds (except stripping
81 # and revisedchroot, where .a and .la files are removed).
82 pkg_tarball=$(sed -n 's/tar -xf \(.*\)/\1/p' $file)
83 pkg_version=$(sed -n 's/VERSION=\(.*\)/\1/p' $file)
84
85 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
86 case "${this_script}" in
87 *stripping*|*cleanup*|*revised*) ;;
88 *) continue ;;
89 esac
90 fi
91
92 # Append the name of the script to a list. The name of the
93 # list is contained in the variable Makefile_target. We adjust this
94 # variable at various points. Note that it is initialized to "SETUP"
95 # in the main function, before calling this function for the first time.
96 case "${this_script}" in
97 *settingenvironment) Makefile_target=LUSER_TGT ;;
98 *changingowner ) Makefile_target=SUDO_TGT ;;
99 *creatingdirs ) Makefile_target=CHROOT_TGT ;;
100 *bootscripts ) Makefile_target=BOOT_TGT ;; # case of sysv book
101 *network ) Makefile_target=BOOT_TGT ;; # case of systemd book
102 esac
103 eval $Makefile_target=\"\$$Makefile_target ${this_script}\"
104
105 #--------------------------------------------------------------------#
106 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
107 #--------------------------------------------------------------------#
108
109 # Drop in the name of the target on a new line, and the previous target
110 # as a dependency. Also call the echo_message function.
111 case $Makefile_target in
112 CHROOT_TGT) CHROOT_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
113 *) LUSER_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
114 esac
115
116 # If $pkg_tarball isn't empty, we've got a package...
117 if [ "$pkg_tarball" != "" ] ; then
118 # Touch timestamp file if installed files logs shall be created.
119 # But only for the final install chapter and not when rebuilding it
120 if [ "${INSTALL_LOG}" = "y" ] &&
121 (( 1+nb_chaps <= $1 )) &&
122 [ "x$N" = x ] ; then
123 CHROOT_wrt_TouchTimestamp
124 fi
125 # Always initialize the test log file, since the test instructions may
126 # be "uncommented" by the user
127 case $Makefile_target in
128 CHROOT_TGT) CHROOT_wrt_test_log "${this_script}" "$pkg_version" ;;
129 LUSER_TGT ) LUSER_wrt_test_log "${this_script}" "$pkg_version" ;;
130 esac
131
132 # If using optimizations, write the instructions
133 case "${OPTIMIZE}$1${nb_chaps}${this_script}${REALSBU}" in
134 0* | *binutils-pass1y | 15* | 167* | 177*) ;;
135 *kernel*) wrt_makeflags "$name" ;; # No CFLAGS for kernel
136 *) wrt_optimize "$name" && wrt_makeflags "$name" ;;
137 esac
138 fi
139
140# Some scriptlet have a special treatment; otherwise standard
141 case "${this_script}" in
142 *addinguser)
143(
144# /var/lib may already exist and be owned by root if blfs tools
145# have been installed.
146cat << EOF
147 @if [ -f luser-id ]; then \\
148 function useradd() { true; }; \\
149 function groupadd() { true; }; \\
150 export -f useradd groupadd; \\
151 fi; \\
152 export LFS=\$(MOUNT_PT) && \\
153 \$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@ 2>&1; \\
154 \$(PRT_DU) >>logs/\$@
155 @chown \$(LUSER):\$(LGROUP) envars
156 @if [ -d "\$(MOUNT_PT)/var/lib" ]; then \\
157 chown \$(LUSER):\$(LGROUP) \$(MOUNT_PT)/var/lib; \\
158 fi
159 @chmod -R a+wt $JHALFSDIR
160 @chmod a+wt \$(SRCSDIR)
161EOF
162) >> $MKFILE.tmp
163 ;;
164 *settingenvironment)
165(
166cat << EOF
167 @cd && \\
168 function source() { true; } && \\
169 export -f source && \\
170 \$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@ 2>&1 && \\
171 sed 's|/mnt/lfs|\$(MOUNT_PT)|' -i .bashrc && \\
172 echo source $JHALFSDIR/envars >> .bashrc
173 @\$(PRT_DU) >>logs/\$@
174EOF
175) >> $MKFILE.tmp
176 ;;
177 *fstab) if [[ -n "$FSTAB" ]]; then
178 CHROOT_wrt_CopyFstab
179 else
180 CHROOT_wrt_RunAsRoot "$file"
181 fi
182 ;;
183
184 *)
185 # Insert date and disk usage at the top of the log file, the script
186 # run and date and disk usage again at the bottom of the log file.
187 case "${Makefile_target}" in
188 SETUP_TGT | SUDO_TGT) wrt_RunAsRoot "$file" "$pkg_version" ;;
189 LUSER_TGT) LUSER_wrt_RunAsUser "$file" "$pkg_version" ;;
190 CHROOT_TGT | BOOT_TGT) CHROOT_wrt_RunAsRoot "$file" "$pkg_version" ;;
191 esac
192 ;;
193 esac
194
195 # Write installed files log and remove the build directory(ies)
196 # except if the package build fails.
197 if [ "$pkg_tarball" != "" ] ; then
198 if [ "${INSTALL_LOG}" = "y" ] &&
199 (( 1+nb_chaps <= $1 )) &&
200 [ "x${N}" = "x" ] ; then
201 CHROOT_wrt_LogNewFiles "${this_script}"
202 fi
203 fi
204
205 # Include a touch of the target name so make can check
206 # if it's already been made.
207 wrt_touch
208 #
209 #--------------------------------------------------------------------#
210 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
211 #--------------------------------------------------------------------#
212
213 # Keep the script file name for Makefile dependencies.
214 PREV=${this_script}
215 # Set "system_build" var for iteration targets
216 if [ -z "$N" ] && (( 1+nb_chaps == $1 )); then
217 system_build="$system_build $this_script"
218 fi
219
220 done # end for file in $dir/*
221 # Set "system_build" when rebuilding: note the CHROOT_TGT is local
222 # in that case.
223 if [ -n "$N" ]; then
224 system_build="$CHROOT_TGT"
225 fi
226}
227
228#----------------------------#
229build_Makefile() { #
230#----------------------------#
231
232 echo "Creating Makefile... ${BOLD}START${OFF}"
233
234 cd $JHALFSDIR/${PROGNAME}-commands
235
236 # Start with empty files
237 >$MKFILE
238 >$MKFILE.tmp
239
240 # Ensure the first dependency is empty
241 unset PREV
242
243 # We begin with the SETUP target; successive targets will be assigned in
244 # the chapter_targets function.
245 Makefile_target=SETUP_TGT
246
247 # We need to know the chapter numbering, which depends on the version
248 # of the book. Use the number of subdirs to know which version we have
249 chaps=($(echo chapter*))
250 nb_chaps=${#chaps[*]} # 5 if classical version, 7 if new version
251# DEBUG
252# echo chaps: ${chaps[*]}
253# echo nb_chaps: $nb_chaps
254# end DEBUG
255
256 # Make a temporary file with all script targets
257 for (( i = 4; i < nb_chaps+4; i++ )); do
258 chapter_targets $i
259 if (( i == nb_chaps )); then : # we have finished temporary tools
260 # Add the save target, if needed
261 [[ "$SAVE_CH5" = "y" ]] && wrt_save_target $Makefile_target
262 fi
263 if (( i == 1+nb_chaps )); then : # we have finished final system
264 # Add the iterations targets, if needed
265 [[ "$COMPARE" = "y" ]] && wrt_compare_targets $i
266 fi
267 done
268 # Add the CUSTOM_TOOLS targets, if needed
269 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
270
271 # Add a header, some variables and include the function file
272 # to the top of the real Makefile.
273 wrt_Makefile_header
274
275 # Add chroot commands
276 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
277 i=1
278 for file in ../chroot-scripts/*chroot* ; do
279 chroot=`cat $file | \
280 perl -pe 's|\\\\\n||g' | \
281 tr -s [:space:] | \
282 grep chroot | \
283 sed -e "s|chroot|$CHROOT_LOC|" \
284 -e 's|\\$|&&|g' \
285 -e 's|"$$LFS"|$(MOUNT_PT)|'`
286 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
287 i=`expr $i + 1`
288 done
289
290 # Store virtual kernel file systems commands:
291 devices=`cat ../kernfs-scripts/devices.sh | \
292 sed -e 's|^| |' \
293 -e 's|mount|sudo &|' \
294 -e 's|mkdir|sudo &|' \
295 -e 's|\\$|&&|g' \
296 -e 's|\$|; \\\\|' \
297 -e 's|then|& :|' \
298 -e 's|\$\$LFS|$(MOUNT_PT)|g'`
299 teardown=`cat ../kernfs-scripts/teardown.sh | \
300 sed -e 's|^| |' \
301 -e 's|umount|-sudo &|' \
302 -e 's|\$LFS|$(MOUNT_PT)|'`
303 teardownat=`cat ../kernfs-scripts/teardown.sh | \
304 sed -e 's|^| |' \
305 -e 's|umount|@-sudo &|' \
306 -e 's|\$LFS|$(MOUNT_PT)|'`
307 # Drop in the main target 'all:' and the chapter targets with each sub-target
308 # as a dependency.
309(
310 cat << EOF
311
312all: ck_UID ck_terminal mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_BLFS_TOOL mk_CUSTOM_TOOLS
313$teardownat
314 @sudo make do_housekeeping
315 @echo $VERSION > lfs-release && \\
316 sudo mv lfs-release \$(MOUNT_PT)/etc && \\
317 sudo chown root:root \$(MOUNT_PT)/etc/lfs-release
318 @/bin/echo -e -n \\
319 DISTRIB_ID=\\"Linux From Scratch\\"\\\\n\\
320 DISTRIB_RELEASE=\\"$VERSION\\"\\\\n\\
321 DISTRIB_CODENAME=\\"$(whoami)-jhalfs\\"\\\\n\\
322 DISTRIB_DESCRIPTION=\\"Linux From Scratch\\"\\\\n\\
323 > lsb-release && \\
324 sudo mv lsb-release \$(MOUNT_PT)/etc && \\
325 sudo chown root:root \$(MOUNT_PT)/etc/lsb-release
326 @/bin/echo -e -n \\
327 NAME=\\"Linux From Scratch\\"\\\\n\\
328 VERSION=\\"$VERSION\\"\\\\n\\
329 ID=lfs\\\\n\\
330 PRETTY_NAME=\\"Linux From Scratch $VERSION\\"\\\\n\\
331 VERSION_CODENAME=\\"$(whoami)-jhalfs\\"\\\\n\\
332 > os-release && \\
333 sudo mv os-release \$(MOUNT_PT)/etc && \\
334 sudo chown root:root \$(MOUNT_PT)/etc/os-release
335 @\$(call echo_finished,$VERSION)
336
337ck_UID:
338 @if [ \`id -u\` = "0" ]; then \\
339 echo "--------------------------------------------------"; \\
340 echo "You cannot run this makefile from the root account"; \\
341 echo "--------------------------------------------------"; \\
342 exit 1; \\
343 fi
344
345ck_terminal:
346 @stty size | ( read L C; \\
347 if (( L < 24 )) || (( C < 80 )) ; then \\
348 echo "--------------------------------------------------"; \\
349 echo "Terminal too small: \$\$C columns x \$\$L lines";\\
350 echo "Minimum: 80 columns x 24 lines";\\
351 echo "--------------------------------------------------"; \\
352 exit 1; \\
353 fi )
354
355mk_SETUP:
356 @\$(call echo_SU_request)
357 @sudo make save-luser
358 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
359 @touch \$@
360
361mk_LUSER: mk_SETUP
362 @\$(call echo_SULUSER_request)
363 @\$(SU_LUSER) "make -C \$(MOUNT_PT)/\$(SCRIPT_ROOT) BREAKPOINT=\$(BREAKPOINT) LUSER"
364 @sudo make restore-luser
365 @touch \$@
366
367mk_SUDO: mk_LUSER
368 @sudo rm -f envars
369 @sudo make BREAKPOINT=\$(BREAKPOINT) SUDO
370 @touch \$@
371
372mk_CHROOT: mk_SUDO
373 @\$(call echo_CHROOT_request)
374 @( sudo \$(CHROOT1) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
375 @touch \$@
376
377mk_BOOT: mk_CHROOT
378 @\$(call echo_CHROOT_request)
379 @( sudo \$(CHROOT1) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
380 @touch \$@
381
382mk_BLFS_TOOL: create-sbu_du-report
383 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
384 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
385 (sudo \$(CHROOT1) -c "make -C $BLFS_ROOT/work"); \\
386 fi;
387 @touch \$@
388
389mk_CUSTOM_TOOLS: mk_BLFS_TOOL
390 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
391 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
392 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
393 (sudo \$(CHROOT1) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
394 fi;
395 @touch \$@
396
397devices: ck_UID
398$devices
399EOF
400) >> $MKFILE
401if [ "$INITSYS" = systemd ]; then
402(
403 cat << EOF
404 sudo mkdir -pv \$(MOUNT_PT)/run/systemd/resolve
405 sudo cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
406EOF
407) >> $MKFILE
408fi
409(
410 cat << EOF
411
412teardown:
413$teardown
414
415chroot1: devices
416 sudo \$(CHROOT1)
417 \$(MAKE) teardown
418
419chroot: devices
420 sudo \$(CHROOT1)
421 \$(MAKE) teardown
422
423SETUP: $SETUP_TGT
424LUSER: $LUSER_TGT
425SUDO: $SUDO_TGT
426EOF
427) >> $MKFILE
428if [ "$INITSYS" = systemd ]; then
429(
430 cat << EOF
431 mkdir -pv \$(MOUNT_PT)/run/systemd/resolve
432 cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
433
434EOF
435) >> $MKFILE
436fi
437(
438 cat << EOF
439CHROOT: SHELL=\$(filter %bash,\$(CHROOT1))
440CHROOT: $CHROOT_TGT
441BOOT: $BOOT_TGT
442CUSTOM_TOOLS: $custom_list
443
444create-sbu_du-report: mk_BOOT
445 @\$(call echo_message, Building)
446 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
447 sudo ./create-sbu_du-report.sh logs $VERSION $(date --iso-8601); \\
448 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
449 fi
450 @touch \$@
451
452save-luser:
453 @\$(call echo_message, Building)
454 @LUSER_ID=\$\$(grep '^\$(LUSER):' /etc/passwd | cut -d: -f3); \\
455 if [ -n "\$\$LUSER_ID" ]; then \\
456 if [ ! -d \$(LUSER_HOME).XXX ]; then \\
457 mv \$(LUSER_HOME){,.XXX}; \\
458 mkdir \$(LUSER_HOME); \\
459 chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME); \\
460 fi; \\
461 echo "\$\$LUSER_ID" > luser-id; \\
462 echo User \$(LUSER) exists with ID \$\$LUSER_ID; \\
463 else \\
464 rm -f luser-id; \\
465 echo User \$(LUSER) does not exist; \\
466 echo It will be created with book instructions.; \\
467 fi
468 @\$(call housekeeping)
469
470restore-luser:
471 @\$(call echo_message, Building)
472 @if [ -f luser-id ]; then \\
473 rm -rf \$(LUSER_HOME); \\
474 mv \$(LUSER_HOME){.XXX,}; \\
475 rm luser-id; \\
476 else \\
477 userdel \$(LUSER); \\
478 groupdel \$(LGROUP); \\
479 rm -rf \$(LUSER_HOME); \\
480 fi
481 @\$(call housekeeping)
482
483do_housekeeping:
484 @-rm -f /tools
485
486EOF
487) >> $MKFILE
488
489 # Bring over the items from the Makefile.tmp
490 cat $MKFILE.tmp >> $MKFILE
491 rm $MKFILE.tmp
492 echo "Creating Makefile... ${BOLD}DONE${OFF}"
493}
Note: See TracBrowser for help on using the repository browser.