source: LFS/master.sh@ dd529e9

experimental
Last change on this file since dd529e9 was dd529e9, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Removed a remaining envars file reference.

  • Property mode set to 100644
File size: 14.4 KB
RevLine 
[9c9775f]1#!/bin/bash
[0170229]2
[a46ada0]3# $Id$
[0170229]4
5###################################
6### FUNCTIONS ###
7###################################
8
9
[50fb011]10#############################################################
11
12
[0170229]13#----------------------------#
[50fb011]14chapter4_Makefiles() { #
[0170229]15#----------------------------#
[50fb011]16 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4 ( SETUP ) ${R_arrow}"
[0170229]17
[9c9775f]18# If $LUSER_HOME is already present in the host, we asume that the
[0170229]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
[3b6adab]2304_02-creatingtoolsdir:
[0170229]24 @\$(call echo_message, Building)
[9199a13]25 @mkdir \$(MOUNT_PT)/tools && \\
26 rm -f /tools && \\
[9c9775f]27 ln -s \$(MOUNT_PT)/tools /
28 @\$(call housekeeping)
[0170229]29
[c5ae20a]3004_03-addinguser: 04_02-creatingtoolsdir
[0170229]31 @\$(call echo_message, Building)
[9c9775f]32 @if [ ! -d \$(LUSER_HOME) ]; then \\
[9485eba]33 groupadd \$(LGROUP); \\
34 useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
[0170229]35 else \\
[30737ea8]36 touch luser-exist; \\
[0170229]37 fi;
[9485eba]38 @chown \$(LUSER) \$(MOUNT_PT)/tools && \\
[9c9775f]39 chmod -R a+wt \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
40 chmod a+wt \$(SRCSDIR)
41 @\$(call housekeeping)
[0170229]42
[c5ae20a]4304_04-settingenvironment: 04_03-addinguser
[0170229]44 @\$(call echo_message, Building)
[9c9775f]45 @if [ -f \$(LUSER_HOME)/.bashrc -a ! -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
46 mv \$(LUSER_HOME)/.bashrc \$(LUSER_HOME)/.bashrc.XXX; \\
[0170229]47 fi;
[9c9775f]48 @if [ -f \$(LUSER_HOME)/.bash_profile -a ! -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
49 mv \$(LUSER_HOME)/.bash_profile \$(LUSER_HOME)/.bash_profile.XXX; \\
[0170229]50 fi;
[9c9775f]51 @echo "set +h" > \$(LUSER_HOME)/.bashrc && \\
52 echo "umask 022" >> \$(LUSER_HOME)/.bashrc && \\
53 echo "LFS=\$(MOUNT_PT)" >> \$(LUSER_HOME)/.bashrc && \\
54 echo "LC_ALL=POSIX" >> \$(LUSER_HOME)/.bashrc && \\
55 echo "PATH=/tools/bin:/bin:/usr/bin" >> \$(LUSER_HOME)/.bashrc && \\
56 echo "export LFS LC_ALL PATH" >> \$(LUSER_HOME)/.bashrc && \\
[f5f857d]57 chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bashrc
[9c9775f]58 @\$(call housekeeping)
[0170229]59EOF
[50fb011]60) > $MKFILE.tmp
61
[3b6adab]62 chapter4=" 04_02-creatingtoolsdir 04_03-addinguser 04_04-settingenvironment"
[0170229]63}
64
[50fb011]65
66
[0170229]67#----------------------------#
68chapter5_Makefiles() {
69#----------------------------#
[50fb011]70 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5 ( LUSER ) ${R_arrow}"
[12a5707]71
[0170229]72 for file in chapter05/* ; do
73 # Keep the script file name
74 this_script=`basename $file`
75
76 # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
[af4c7b1]77 case "${this_script}" in
78 *tcl) [[ "${TEST}" = "0" ]] && continue ;;
79 *expect) [[ "${TEST}" = "0" ]] && continue ;;
80 *dejagnu) [[ "${TEST}" = "0" ]] && continue ;;
[47fddc8]81 *stripping) [[ "${STRIP}" = "n" ]] && continue ;;
[af4c7b1]82 esac
[6b1576a]83
[0170229]84 # First append each name of the script files to a list (this will become
85 # the names of the targets in the Makefile
[9c9775f]86 # DO NOT append the changingowner script, it need be run as root.
[50fb011]87 # A hack is necessary: create script in chap5 BUT run as a dependency for
[9c9775f]88 # SUDO target
[50fb011]89 case "${this_script}" in
[9c9775f]90 *changingowner) runasroot="$runasroot ${this_script}" ;;
[50fb011]91 *) chapter5="$chapter5 ${this_script}" ;;
92 esac
[0170229]93
94 # Set the dependency for the first target.
[3b6adab]95 if [ -z $PREV ] ; then PREV=04_04-settingenvironment ; fi
[0170229]96
[3f858ca]97 #--------------------------------------------------------------------#
98 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
99 #--------------------------------------------------------------------#
100 #
[0170229]101 # Drop in the name of the target on a new line, and the previous target
102 # as a dependency. Also call the echo_message function.
[50fb011]103 LUSER_wrt_target "${this_script}" "$PREV"
[0170229]104
[3b6adab]105 # Run the script.
[fed9756]106 # The changingowner script must be run as root.
107 case "${this_script}" in
[9c9775f]108 *changingowner) wrt_RunAsRoot "$file" ;;
[50fb011]109 *) LUSER_wrt_RunAsUser "$file" ;;
[fed9756]110 esac
[0170229]111
112 # Include a touch of the target name so make can check
113 # if it's already been made.
[9199a13]114 wrt_touch
[3f858ca]115 #
116 #--------------------------------------------------------------------#
117 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
118 #--------------------------------------------------------------------#
[0170229]119
120 # Keep the script file name for Makefile dependencies.
121 PREV=${this_script}
122 done # end for file in chapter05/*
123}
124
[50fb011]125
[0170229]126#----------------------------#
127chapter6_Makefiles() {
128#----------------------------#
[50fb011]129
[615e37d]130 # Set envars and scripts for iteration targets
[b242136]131 if [[ -z "$1" ]] ; then
[aa08925]132 local N=""
133 else
134 local N=-build_$1
135 local chapter6=""
[615e37d]136 mkdir chapter06$N
137 cp chapter06/* chapter06$N
138 for script in chapter06$N/* ; do
[7aee0dd]139 # Overwrite existing symlinks, files, and dirs
[615e37d]140 sed -e 's/ln -sv/&f/g' \
141 -e 's/mv -v/&f/g' \
[7aee0dd]142 -e 's/mkdir -v/&p/g' -i ${script}
[9c9775f]143 # Rename the scripts
144 mv ${script} ${script}$N
[615e37d]145 done
[aa08925]146 fi
147
[50fb011]148 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
[af4c7b1]149
[615e37d]150 for file in chapter06$N/* ; do
[0170229]151 # Keep the script file name
152 this_script=`basename $file`
153
154 # We'll run the chroot commands differently than the others, so skip them in the
155 # dependencies and target creation.
[9c9775f]156 # Skip also linux-headers in iterative builds.
[af4c7b1]157 case "${this_script}" in
158 *chroot) continue ;;
[47fddc8]159 *stripping*) [[ "${STRIP}" = "n" ]] && continue ;;
[9c9775f]160 *linux-headers*) [[ -n "$N" ]] && continue ;;
[af4c7b1]161 esac
[0170229]162
[6bf3770]163 # If building a package, grab the phase name to be used with INSTALL_LOG
164 name=`grep "^PKG_PHASE=" ${file} | sed -e 's@PKG_PHASE=@@'`
[b242136]165
[3b6adab]166 # Skip scripts not needed for iterations rebuilds
167 if [[ "$name" = "" ]] && [[ -n "$N" ]] ; then
[b242136]168 case "${this_script}" in
169 *stripping*) ;;
170 *) continue ;;
171 esac
172 fi
173
[4edbc92]174 # Append each name of the script files to a list (this will become
175 # the names of the targets in the Makefile)
[9c9775f]176 # The kernfs script must be run as part of SUDO target.
177 case "${this_script}" in
178 *kernfs) runasroot="$runasroot ${this_script}" ;;
179 *) chapter6="$chapter6 ${this_script}" ;;
180 esac
[4edbc92]181
[3f858ca]182 #--------------------------------------------------------------------#
183 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
184 #--------------------------------------------------------------------#
185 #
[0170229]186 # Drop in the name of the target on a new line, and the previous target
187 # as a dependency. Also call the echo_message function.
[9c9775f]188 # In the mount of kernel filesystems we need to set LFS
189 # and not to use chroot.
190 case "${this_script}" in
191 *kernfs) LUSER_wrt_target "${this_script}" "$PREV" ;;
192 *) CHROOT_wrt_target "${this_script}" "$PREV" ;;
193 esac
[0170229]194
[f5f857d]195 # Touch timestamp file if installed files logs will be created.
196 # But only for the firt build when running iterative builds.
197 if [ "$name" != "" ] && [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
198 CHROOT_wrt_TouchTimestamp
[0170229]199 fi
200
201 # In the mount of kernel filesystems we need to set LFS
202 # and not to use chroot.
[af4c7b1]203 case "${this_script}" in
[9c9775f]204 *kernfs) wrt_RunAsRoot "$file" ;;
[50fb011]205 *) CHROOT_wrt_RunAsRoot "$file" ;;
[af4c7b1]206 esac
[0170229]207
[3b6adab]208 # Write installed files log
209 if [ "$name" != "" ] && [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
210 CHROOT_wrt_LogNewFiles "$name"
[0170229]211 fi
212
213 # Include a touch of the target name so make can check
214 # if it's already been made.
[9199a13]215 wrt_touch
[3f858ca]216 #
217 #--------------------------------------------------------------------#
218 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
219 #--------------------------------------------------------------------#
[0170229]220
221 # Keep the script file name for Makefile dependencies.
[9c9775f]222 PREV=${this_script}
[aa08925]223 # Set system_build envar for iteration targets
224 system_build=$chapter6
[0170229]225 done # end for file in chapter06/*
226}
227
228#----------------------------#
[9c9775f]229chapter78_Makefiles() {
[0170229]230#----------------------------#
[9c9775f]231 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8 ( BOOT ) ${R_arrow}"
[af4c7b1]232
[9c9775f]233 for file in chapter0{7,8}/* ; do
[0170229]234 # Keep the script file name
235 this_script=`basename $file`
236
237 # Grub must be configured manually.
[9c9775f]238 # Handle fstab creation.
[0170229]239 # If no .config file is supplied, the kernel build is skipped
[0271c0c]240 case ${this_script} in
241 *grub) continue ;;
[50fb011]242 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
[0271c0c]243 *kernel) [[ -z ${CONFIG} ]] && continue
244 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
245 esac
[0170229]246
247 # First append each name of the script files to a list (this will become
248 # the names of the targets in the Makefile
[9c9775f]249 chapter78="$chapter78 ${this_script}"
[0170229]250
[3f858ca]251 #--------------------------------------------------------------------#
252 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
253 #--------------------------------------------------------------------#
254 #
[0170229]255 # Drop in the name of the target on a new line, and the previous target
256 # as a dependency. Also call the echo_message function.
[50fb011]257 CHROOT_wrt_target "${this_script}" "$PREV"
[0170229]258
[3b6adab]259 # For bootscripts and kernel, start INSTALL_LOG if requested
[af4c7b1]260 case "${this_script}" in
[3b6adab]261 *bootscripts | *kernel ) if [ "${INSTALL_LOG}" = "y" ] ; then
262 CHROOT_wrt_TouchTimestamp
263 fi ;;
[af4c7b1]264 esac
[6b1576a]265
[0170229]266 # Check if we have a real /etc/fstab file
[af4c7b1]267 case "${this_script}" in
268 *fstab) if [[ -n $FSTAB ]]; then
[50fb011]269 CHROOT_wrt_CopyFstab
[af4c7b1]270 else
[50fb011]271 CHROOT_wrt_RunAsRoot "$file"
[af4c7b1]272 fi
273 ;;
[50fb011]274 *) CHROOT_wrt_RunAsRoot "$file"
[af4c7b1]275 ;;
276 esac
[0170229]277
[af4c7b1]278 case "${this_script}" in
[3b6adab]279 *bootscripts) if [ "${INSTALL_LOG}" = "y" ] ; then
280 CHROOT_wrt_LogNewFiles "lfs-bootscripts"
[9c9775f]281 fi ;;
[3b6adab]282 *kernel) if [ "${INSTALL_LOG}" = "y" ] ; then
283 CHROOT_wrt_LogNewFiles "linux"
[9c9775f]284 fi ;;
[af4c7b1]285 esac
[6b1576a]286
[0170229]287 # Include a touch of the target name so make can check
288 # if it's already been made.
[9199a13]289 wrt_touch
[3f858ca]290 #
291 #--------------------------------------------------------------------#
292 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
293 #--------------------------------------------------------------------#
[0170229]294
295 # Keep the script file name for Makefile dependencies.
296 PREV=${this_script}
[9c9775f]297 done # for file in chapter0{7,8}/*
[9e4b9a1]298
[0170229]299}
300
301
[50fb011]302
[0170229]303#----------------------------#
[50fb011]304build_Makefile() { #
[0170229]305#----------------------------#
[50fb011]306
[a702b4d]307 echo "Creating Makefile... ${BOLD}START${OFF}"
[03b3eba]308
[0170229]309 cd $JHALFSDIR/${PROGNAME}-commands
310
311 # Start with a clean Makefile.tmp file
[50fb011]312 >$MKFILE
[03b3eba]313
[0170229]314 chapter4_Makefiles
315 chapter5_Makefiles
316 chapter6_Makefiles
[4edbc92]317 # Add the iterations targets, if needed
[47fddc8]318 [[ "$COMPARE" = "y" ]] && wrt_compare_targets
[9c9775f]319 chapter78_Makefiles
320 # Add the CUSTOM_TOOLS targets, if needed
321 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
[fd7455c]322 # Add the BLFS_TOOL targets, if needed
323 [[ "$BLFS_TOOL" = "y" ]] && wrt_blfs_tool_targets
[0170229]324
325 # Add a header, some variables and include the function file
326 # to the top of the real Makefile.
[9c9775f]327 wrt_Makefile_header
[0170229]328
329 # Add chroot commands
[8381f6e]330 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
[0170229]331 i=1
332 for file in chapter06/*chroot* ; do
[3b6adab]333 chroot=`cat $file | tr -d '\n' | \
[8381f6e]334 sed -e "s@chroot@$CHROOT_LOC@" \
[3b6adab]335 -e 's@ \\\@ @g' \
[f5f857d]336 -e 's/ */ /g' \
[8381f6e]337 -e 's|\\$|&&|g' \
338 -e 's|"$$LFS"|$(MOUNT_PT)|' \
[3b6adab]339 -e 's|$| -c|'`
[0170229]340 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
341 i=`expr $i + 1`
342 done
343
344 # Drop in the main target 'all:' and the chapter targets with each sub-target
345 # as a dependency.
346(
347 cat << EOF
[50fb011]348
[9c9775f]349all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_CUSTOM_TOOLS mk_BLFS_TOOL
[4012541]350 @sudo make do_housekeeping
[9c9775f]351 @echo "$VERSION - jhalfs build" > lfs-release && \\
352 sudo mv lfs-release \$(MOUNT_PT)/etc
[0170229]353 @\$(call echo_finished,$VERSION)
354
[7d4cc81]355ck_UID:
356 @if [ \`id -u\` = "0" ]; then \\
357 echo "--------------------------------------------------"; \\
358 echo "You cannot run this makefile from the root account"; \\
359 echo "--------------------------------------------------"; \\
360 exit 1; \\
361 fi
[0167dd8]362
[50fb011]363mk_SETUP:
364 @\$(call echo_SU_request)
[9c9775f]365 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
[50fb011]366 @touch \$@
[03b3eba]367
[50fb011]368mk_LUSER: mk_SETUP
369 @\$(call echo_SULUSER_request)
[9c9775f]370 @( sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) LUSER" )
[621f01f]371 @sudo make restore-luser-env
[50fb011]372 @touch \$@
[7d4cc81]373
374mk_SUDO: mk_LUSER
[9c9775f]375 @sudo make BREAKPOINT=\$(BREAKPOINT) SUDO
376 @touch \$@
377
[496f8f3]378mk_CHROOT: mk_SUDO
[50fb011]379 @\$(call echo_CHROOT_request)
[9c9775f]380 @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
[50fb011]381 @touch \$@
382
[03b3eba]383mk_BOOT: mk_CHROOT
[50fb011]384 @\$(call echo_CHROOT_request)
[9c9775f]385 @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
[50fb011]386 @touch \$@
[03b3eba]387
[9c9775f]388mk_CUSTOM_TOOLS: create-sbu_du-report
389 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
390 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
391 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
392 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
393 fi;
394 @touch \$@
[50fb011]395
[9c9775f]396mk_BLFS_TOOL: mk_CUSTOM_TOOLS
397 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
398 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
399 sudo mkdir -p $BUILDDIR$TRACKING_DIR; \\
400 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BLFS_TOOL"); \\
401 fi;
402 @touch \$@
[50fb011]403
[7d4cc81]404
[9c9775f]405SETUP: $chapter4
406LUSER: $chapter5
407SUDO: $runasroot
408CHROOT: SHELL=/tools/bin/bash
409CHROOT: $chapter6
410BOOT: $chapter78
411CUSTOM_TOOLS: $custom_list
412BLFS_TOOL: $blfs_tool
[50fb011]413
[0170229]414
[9c9775f]415create-sbu_du-report: mk_BOOT
416 @\$(call echo_message, Building)
417 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
418 ./create-sbu_du-report.sh logs $VERSION; \\
419 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
420 fi;
421 @touch \$@
[0170229]422
[30737ea8]423restore-luser-env:
[0170229]424 @\$(call echo_message, Building)
[9c9775f]425 @if [ -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
426 mv -f \$(LUSER_HOME)/.bashrc.XXX \$(LUSER_HOME)/.bashrc; \\
[0170229]427 fi;
[9c9775f]428 @if [ -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
429 mv \$(LUSER_HOME)/.bash_profile.XXX \$(LUSER_HOME)/.bash_profile; \\
[0170229]430 fi;
[9c9775f]431 @chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bash*
432 @\$(call housekeeping)
[460ea63]433
[3a27393]434do_housekeeping:
[9199a13]435 @-umount \$(MOUNT_PT)/sys
436 @-umount \$(MOUNT_PT)/proc
437 @-umount \$(MOUNT_PT)/dev/shm
438 @-umount \$(MOUNT_PT)/dev/pts
439 @-umount \$(MOUNT_PT)/dev
[0167dd8]440 @-rm /tools
[30737ea8]441 @-if [ ! -f luser-exist ]; then \\
[9485eba]442 userdel \$(LUSER); \\
[9c9775f]443 rm -rf \$(LUSER_HOME); \\
[3a27393]444 fi;
[460ea63]445
[9199a13]446
[42346b2]447EOF
448) >> $MKFILE
449
[0170229]450 # Bring over the items from the Makefile.tmp
451 cat $MKFILE.tmp >> $MKFILE
452 rm $MKFILE.tmp
[a702b4d]453 echo "Creating Makefile... ${BOLD}DONE${OFF}"
454}
Note: See TracBrowser for help on using the repository browser.