Adapt LFS/master.sh to use chap4 scriptlets
- take targets from scriptlet names - neutralize some commands or bash builtins so that they are not used even if they are in the scriptlets, if not needed - do not set PREV in chapter 5 anymore - Improve save and restore user, so that if the LUSER exists, its home is saved while building temporary tools, and restored afterwards
This commit is contained in:
parent
939731aa52
commit
903eefd093
1 changed files with 97 additions and 64 deletions
161
LFS/master.sh
161
LFS/master.sh
|
@ -14,56 +14,80 @@
|
||||||
chapter4_Makefiles() { #
|
chapter4_Makefiles() { #
|
||||||
#----------------------------#
|
#----------------------------#
|
||||||
echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4 ( SETUP ) ${R_arrow}"
|
echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4 ( SETUP ) ${R_arrow}"
|
||||||
|
# Ensure the first dependency is empty
|
||||||
|
unset PREV
|
||||||
|
|
||||||
# If $LUSER_HOME is already present in the host, we asume that the
|
for file in chapter04/* ; do
|
||||||
# lfs user and group are also presents in the host, and a backup
|
# Keep the script file name
|
||||||
# of their bash init files is made.
|
this_script=`basename $file`
|
||||||
|
|
||||||
|
# First append each name of the script files to a list (this will become
|
||||||
|
# the names of the targets in the Makefile
|
||||||
|
# DO NOT append the settingenvironment script, it need be run as luser.
|
||||||
|
# A hack is necessary: create script in chap4 BUT run as a dependency for
|
||||||
|
# LUSER target
|
||||||
|
case "${this_script}" in
|
||||||
|
*settingenvironment) chapter5="$chapter5 ${this_script}" ;;
|
||||||
|
*) chapter4="$chapter4 ${this_script}" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Grab the name of the target
|
||||||
|
name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------#
|
||||||
|
# >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
||||||
|
#--------------------------------------------------------------------#
|
||||||
|
#
|
||||||
|
|
||||||
|
# Drop in the name of the target on a new line, and the previous target
|
||||||
|
# as a dependency. Also call the echo_message function.
|
||||||
|
LUSER_wrt_target "${this_script}" "$PREV"
|
||||||
|
|
||||||
|
case "${this_script}" in
|
||||||
|
*settingenvironment)
|
||||||
(
|
(
|
||||||
cat << EOF
|
cat << EOF
|
||||||
020-creatingtoolsdir:
|
@cd && \\
|
||||||
@\$(call echo_message, Building)
|
function source() { true; } && \\
|
||||||
@mkdir \$(MOUNT_PT)/tools && \\
|
export -f source && \\
|
||||||
rm -f /tools && \\
|
\$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@ 2>&1 && \\
|
||||||
ln -s \$(MOUNT_PT)/tools /
|
sed 's|/mnt/lfs|\$(MOUNT_PT)|' -i .bashrc && \\
|
||||||
@\$(call housekeeping)
|
echo source $JHALFSDIR/envars >> .bashrc
|
||||||
|
@\$(PRT_DU) >>logs/\$@
|
||||||
021-addinguser: 020-creatingtoolsdir
|
|
||||||
@\$(call echo_message, Building)
|
|
||||||
@-if [ ! -d \$(LUSER_HOME) ]; then \\
|
|
||||||
groupadd \$(LGROUP); \\
|
|
||||||
useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
|
|
||||||
else \\
|
|
||||||
touch luser-exist; \\
|
|
||||||
fi;
|
|
||||||
@chown \$(LUSER) \$(MOUNT_PT)/tools && \\
|
|
||||||
chmod -R a+wt \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
|
|
||||||
chmod a+wt \$(SRCSDIR)
|
|
||||||
@\$(call housekeeping)
|
|
||||||
|
|
||||||
022-settingenvironment: 021-addinguser
|
|
||||||
@\$(call echo_message, Building)
|
|
||||||
@if [ -f \$(LUSER_HOME)/.bashrc -a ! -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
|
|
||||||
mv \$(LUSER_HOME)/.bashrc \$(LUSER_HOME)/.bashrc.XXX; \\
|
|
||||||
fi;
|
|
||||||
@if [ -f \$(LUSER_HOME)/.bash_profile -a ! -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
|
|
||||||
mv \$(LUSER_HOME)/.bash_profile \$(LUSER_HOME)/.bash_profile.XXX; \\
|
|
||||||
fi;
|
|
||||||
@echo "set +h" > \$(LUSER_HOME)/.bashrc && \\
|
|
||||||
echo "umask 022" >> \$(LUSER_HOME)/.bashrc && \\
|
|
||||||
echo "LFS=\$(MOUNT_PT)" >> \$(LUSER_HOME)/.bashrc && \\
|
|
||||||
echo "LC_ALL=POSIX" >> \$(LUSER_HOME)/.bashrc && \\
|
|
||||||
echo "LFS_TGT=`uname -m`-lfs-linux-gnu" >> \$(LUSER_HOME)/.bashrc && \\
|
|
||||||
echo "PATH=/tools/bin:/bin:/usr/bin" >> \$(LUSER_HOME)/.bashrc && \\
|
|
||||||
echo "export LFS LC_ALL LFS_TGT PATH" >> \$(LUSER_HOME)/.bashrc && \\
|
|
||||||
echo "source $JHALFSDIR/envars" >> \$(LUSER_HOME)/.bashrc && \\
|
|
||||||
chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bashrc && \\
|
|
||||||
touch envars && \\
|
|
||||||
chown \$(LUSER) envars
|
|
||||||
@\$(call housekeeping)
|
|
||||||
EOF
|
EOF
|
||||||
) > $MKFILE.tmp
|
) >> $MKFILE.tmp
|
||||||
|
;;
|
||||||
|
*addinguser)
|
||||||
|
(
|
||||||
|
cat << EOF
|
||||||
|
@if [ -f luser-id ]; then \\
|
||||||
|
function useradd() { true; }; \\
|
||||||
|
function groupadd() { true; }; \\
|
||||||
|
export -f useradd groupadd; \\
|
||||||
|
fi; \\
|
||||||
|
export LFS=\$(MOUNT_PT) && \\
|
||||||
|
\$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@ 2>&1; \\
|
||||||
|
\$(PRT_DU) >>logs/\$@
|
||||||
|
@chown \$(LUSER):\$(LGROUP) envars
|
||||||
|
@chmod -R a+wt $JHALFSDIR
|
||||||
|
@chmod a+wt \$(SRCSDIR)
|
||||||
|
EOF
|
||||||
|
) >> $MKFILE.tmp
|
||||||
|
;;
|
||||||
|
*) wrt_RunAsRoot "$file" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
chapter4=" 020-creatingtoolsdir 021-addinguser 022-settingenvironment"
|
# Include a touch of the target name so make can check
|
||||||
|
# if it's already been made.
|
||||||
|
wrt_touch
|
||||||
|
#
|
||||||
|
#--------------------------------------------------------------------#
|
||||||
|
# >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
||||||
|
#--------------------------------------------------------------------#
|
||||||
|
|
||||||
|
# Keep the script file name for Makefile dependencies.
|
||||||
|
PREV=${this_script}
|
||||||
|
done # end for file in chapter04/*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,9 +132,6 @@ chapter5_Makefiles() {
|
||||||
-e 's@-pass[0-9]\{1\}@@' \
|
-e 's@-pass[0-9]\{1\}@@' \
|
||||||
-e 's@-libstdc++@@'`
|
-e 's@-libstdc++@@'`
|
||||||
|
|
||||||
# Set the dependency for the first target.
|
|
||||||
if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
# >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
# >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
|
@ -480,14 +501,15 @@ ck_UID:
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mk_SETUP:
|
mk_SETUP:
|
||||||
|
@sudo make save-luser
|
||||||
@\$(call echo_SU_request)
|
@\$(call echo_SU_request)
|
||||||
@sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
|
@sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
|
||||||
@touch \$@
|
@touch \$@
|
||||||
|
|
||||||
mk_LUSER: mk_SETUP
|
mk_LUSER: mk_SETUP
|
||||||
@\$(call echo_SULUSER_request)
|
@\$(call echo_SULUSER_request)
|
||||||
@( \$(SU_LUSER) "make -C \$(MOUNT_PT)/\$(SCRIPT_ROOT) BREAKPOINT=\$(BREAKPOINT) LUSER" )
|
@\$(SU_LUSER) "make -C \$(MOUNT_PT)/\$(SCRIPT_ROOT) BREAKPOINT=\$(BREAKPOINT) LUSER"
|
||||||
@sudo make restore-luser-env
|
@sudo make restore-luser
|
||||||
@touch \$@
|
@touch \$@
|
||||||
|
|
||||||
mk_SUDO: mk_LUSER
|
mk_SUDO: mk_LUSER
|
||||||
|
@ -573,26 +595,37 @@ create-sbu_du-report: mk_BOOT
|
||||||
@if [ "\$(ADD_REPORT)" = "y" ]; then \\
|
@if [ "\$(ADD_REPORT)" = "y" ]; then \\
|
||||||
sudo ./create-sbu_du-report.sh logs $VERSION $(date --iso-8601); \\
|
sudo ./create-sbu_du-report.sh logs $VERSION $(date --iso-8601); \\
|
||||||
\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
|
\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
|
||||||
fi;
|
fi
|
||||||
@touch \$@
|
@touch \$@
|
||||||
|
|
||||||
restore-luser-env:
|
save-luser:
|
||||||
@\$(call echo_message, Building)
|
@\$(call echo_message, Building)
|
||||||
@if [ -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
|
@if lslogins \$(LUSER) > luser-id 2>/dev/null; then \\
|
||||||
mv -f \$(LUSER_HOME)/.bashrc.XXX \$(LUSER_HOME)/.bashrc; \\
|
if [ ! -d \$(LUSER_HOME).XXX ]; then \\
|
||||||
fi;
|
mv \$(LUSER_HOME){,.XXX}; \\
|
||||||
@if [ -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
|
mkdir \$(LUSER_HOME); \\
|
||||||
mv \$(LUSER_HOME)/.bash_profile.XXX \$(LUSER_HOME)/.bash_profile; \\
|
chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME); \\
|
||||||
fi;
|
fi; \\
|
||||||
@chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bash*
|
else \\
|
||||||
|
rm luser-id; \\
|
||||||
|
fi
|
||||||
|
@\$(call housekeeping)
|
||||||
|
|
||||||
|
restore-luser:
|
||||||
|
@\$(call echo_message, Building)
|
||||||
|
@if [ -f luser-id ]; then \\
|
||||||
|
rm -rf \$(LUSER_HOME); \\
|
||||||
|
mv \$(LUSER_HOME){.XXX,}; \\
|
||||||
|
rm luser-id; \\
|
||||||
|
else \\
|
||||||
|
userdel \$(LUSER); \\
|
||||||
|
groupdel \$(LGROUP); \\
|
||||||
|
rm -rf \$(LUSER_HOME); \\
|
||||||
|
fi
|
||||||
@\$(call housekeeping)
|
@\$(call housekeeping)
|
||||||
|
|
||||||
do_housekeeping:
|
do_housekeeping:
|
||||||
@-rm /tools
|
@-rm /tools
|
||||||
@-if [ ! -f luser-exist ]; then \\
|
|
||||||
userdel \$(LUSER); \\
|
|
||||||
rm -rf \$(LUSER_HOME); \\
|
|
||||||
fi;
|
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
) >> $MKFILE
|
) >> $MKFILE
|
||||||
|
|
Reference in a new issue