Changeset 903eefd for LFS


Ignore:
Timestamp:
03/29/2020 02:06:41 PM (4 years ago)
Author:
Pierre Labastie <pierre@…>
Branches:
ablfs-more, legacy, trunk
Children:
4762fb9
Parents:
939731a
Message:

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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • LFS/master.sh

    r939731a r903eefd  
    1515#----------------------------#
    1616  echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4     ( SETUP ) ${R_arrow}"
    17 
    18 # If $LUSER_HOME 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
    23 020-creatingtoolsdir:
    24         @\$(call echo_message, Building)
    25         @mkdir \$(MOUNT_PT)/tools && \\
    26         rm -f /tools && \\
    27         ln -s \$(MOUNT_PT)/tools /
    28         @\$(call housekeeping)
    29 
    30 021-addinguser:  020-creatingtoolsdir
    31         @\$(call echo_message, Building)
    32         @-if [ ! -d \$(LUSER_HOME) ]; then \\
    33                 groupadd \$(LGROUP); \\
    34                 useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
    35         else \\
    36                 touch luser-exist; \\
    37         fi;
    38         @chown \$(LUSER) \$(MOUNT_PT)/tools && \\
    39         chmod -R a+wt \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
    40         chmod a+wt \$(SRCSDIR)
    41         @\$(call housekeeping)
    42 
    43 022-settingenvironment:  021-addinguser
    44         @\$(call echo_message, Building)
    45         @if [ -f \$(LUSER_HOME)/.bashrc -a ! -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
    46                 mv \$(LUSER_HOME)/.bashrc \$(LUSER_HOME)/.bashrc.XXX; \\
    47         fi;
    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; \\
    50         fi;
    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 "LFS_TGT=`uname -m`-lfs-linux-gnu" >> \$(LUSER_HOME)/.bashrc && \\
    56         echo "PATH=/tools/bin:/bin:/usr/bin" >> \$(LUSER_HOME)/.bashrc && \\
    57         echo "export LFS LC_ALL LFS_TGT PATH" >> \$(LUSER_HOME)/.bashrc && \\
    58         echo "source $JHALFSDIR/envars" >> \$(LUSER_HOME)/.bashrc && \\
    59         chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bashrc && \\
    60         touch envars && \\
    61         chown \$(LUSER) envars
    62         @\$(call housekeeping)
    63 EOF
    64 ) > $MKFILE.tmp
    65 
    66   chapter4=" 020-creatingtoolsdir 021-addinguser 022-settingenvironment"
     17  # Ensure the first dependency is empty
     18  unset PREV
     19
     20  for file in chapter04/* ; do
     21    # Keep the script file name
     22    this_script=`basename $file`
     23
     24    # First append each name of the script files to a list (this will become
     25    # the names of the targets in the Makefile
     26    # DO NOT append the settingenvironment script, it need be run as luser.
     27    # A hack is necessary: create script in chap4 BUT run as a dependency for
     28    # LUSER target
     29    case "${this_script}" in
     30      *settingenvironment) chapter5="$chapter5 ${this_script}" ;;
     31                        *) chapter4="$chapter4 ${this_script}" ;;
     32    esac
     33
     34    # Grab the name of the target
     35    name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
     36
     37    #--------------------------------------------------------------------#
     38    #         >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<<          #
     39    #--------------------------------------------------------------------#
     40    #
     41
     42    # Drop in the name of the target on a new line, and the previous target
     43    # as a dependency. Also call the echo_message function.
     44    LUSER_wrt_target "${this_script}" "$PREV"
     45
     46    case "${this_script}" in
     47      *settingenvironment)
     48(
     49cat << EOF
     50        @cd && \\
     51        function source() { true; } && \\
     52        export -f source && \\
     53        \$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@ 2>&1 && \\
     54        sed 's|/mnt/lfs|\$(MOUNT_PT)|' -i .bashrc && \\
     55        echo source $JHALFSDIR/envars >> .bashrc
     56        @\$(PRT_DU) >>logs/\$@
     57EOF
     58) >> $MKFILE.tmp
     59              ;;
     60      *addinguser)
     61(
     62cat << EOF
     63        @if [ -f luser-id ]; then \\
     64          function useradd() { true; }; \\
     65          function groupadd() { true; }; \\
     66          export -f useradd groupadd; \\
     67        fi; \\
     68        export LFS=\$(MOUNT_PT) && \\
     69        \$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@ 2>&1; \\
     70        \$(PRT_DU) >>logs/\$@
     71        @chown \$(LUSER):\$(LGROUP) envars
     72        @chmod -R a+wt $JHALFSDIR
     73        @chmod a+wt \$(SRCSDIR)
     74EOF
     75) >> $MKFILE.tmp
     76              ;;
     77      *)                   wrt_RunAsRoot "$file" ;;
     78    esac
     79
     80    # Include a touch of the target name so make can check
     81    # if it's already been made.
     82    wrt_touch
     83    #
     84    #--------------------------------------------------------------------#
     85    #              >>>>>>>> END OF Makefile ENTRY <<<<<<<<               #
     86    #--------------------------------------------------------------------#
     87
     88    # Keep the script file name for Makefile dependencies.
     89    PREV=${this_script}
     90  done  # end for file in chapter04/*
    6791}
    6892
     
    108132                                    -e 's@-pass[0-9]\{1\}@@' \
    109133                                    -e 's@-libstdc++@@'`
    110 
    111     # Set the dependency for the first target.
    112     if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
    113134
    114135    #--------------------------------------------------------------------#
     
    481502
    482503mk_SETUP:
     504        @sudo make save-luser
    483505        @\$(call echo_SU_request)
    484506        @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
     
    487509mk_LUSER: mk_SETUP
    488510        @\$(call echo_SULUSER_request)
    489         @( \$(SU_LUSER) "make -C \$(MOUNT_PT)/\$(SCRIPT_ROOT) BREAKPOINT=\$(BREAKPOINT) LUSER" )
    490         @sudo make restore-luser-env
     511        @\$(SU_LUSER) "make -C \$(MOUNT_PT)/\$(SCRIPT_ROOT) BREAKPOINT=\$(BREAKPOINT) LUSER"
     512        @sudo make restore-luser
    491513        @touch \$@
    492514
     
    574596          sudo ./create-sbu_du-report.sh logs $VERSION $(date --iso-8601); \\
    575597          \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
    576         fi;
     598        fi
    577599        @touch  \$@
    578600
    579 restore-luser-env:
     601save-luser:
    580602        @\$(call echo_message, Building)
    581         @if [ -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
    582                 mv -f \$(LUSER_HOME)/.bashrc.XXX \$(LUSER_HOME)/.bashrc; \\
    583         fi;
    584         @if [ -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
    585                 mv \$(LUSER_HOME)/.bash_profile.XXX \$(LUSER_HOME)/.bash_profile; \\
    586         fi;
    587         @chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bash*
     603        @if lslogins \$(LUSER) > luser-id 2>/dev/null; then  \\
     604            if [ ! -d \$(LUSER_HOME).XXX ]; then \\
     605                mv \$(LUSER_HOME){,.XXX}; \\
     606                mkdir \$(LUSER_HOME); \\
     607                chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME); \\
     608            fi; \\
     609        else \\
     610                rm luser-id; \\
     611        fi
     612        @\$(call housekeeping)
     613
     614restore-luser:
     615        @\$(call echo_message, Building)
     616        @if [ -f luser-id ]; then \\
     617                rm -rf \$(LUSER_HOME); \\
     618                mv \$(LUSER_HOME){.XXX,}; \\
     619                rm luser-id; \\
     620        else \\
     621                userdel \$(LUSER); \\
     622                groupdel \$(LGROUP); \\
     623                rm -rf \$(LUSER_HOME); \\
     624        fi
    588625        @\$(call housekeeping)
    589626
    590627do_housekeeping:
    591628        @-rm /tools
    592         @-if [ ! -f luser-exist ]; then \\
    593                 userdel \$(LUSER); \\
    594                 rm -rf \$(LUSER_HOME); \\
    595         fi;
    596629
    597630EOF
Note: See TracChangeset for help on using the changeset viewer.