source: LFS/master.sh@ 4c32ca8

ablfs-more legacy trunk
Last change on this file since 4c32ca8 was 33a4e41, checked in by DJ Lucas <dj@…>, 3 years ago

Fix package management and put back optional stripping again for backwards compatibility.

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