Changeset 6ad5a2f for HLFS


Ignore:
Timestamp:
08/08/2006 05:26:40 PM (18 years ago)
Author:
Manuel Canales Esparcia <manuel@…>
Branches:
2.3, 2.3.x, 2.4, ablfs, ablfs-more, legacy, new_features, trunk
Children:
daa9b6c
Parents:
983db9f
Message:

Ported LUSER code and last CLFS2 fix from experimental.

Location:
HLFS
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • HLFS/config

    r983db9f r6ad5a2f  
    1212#--- The host system has grsecurity options enabled? 0(no)/1(yes)
    1313GRSECURITY_HOST=0
     14
     15#--- Unprivileged user and group name
     16LUSER=hlfs
     17LGROUP=hlfs
    1418
    1519#--- Location of fstab file (if empty, a template is created)
  • HLFS/master.sh

    r983db9f r6ad5a2f  
    77###          FUNCTIONS          ###
    88###################################
    9 
    10 #----------------------------------#
    11 wrt_ExecuteAsUser() {              # Execute the file ($3) under the users account ($1), log in $2
    12 #----------------------------------#
    13   local this_user=$1
    14   local this_script=$2
    15   local file=$3
    16 
    17 (
    18 cat << EOF
    19         @( time { su - ${this_user} -c "source /home/${this_user}/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
    20         echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
    21 EOF
    22 ) >> $MKFILE.tmp
    23 }
    24 
    25 
    26 #----------------------------------#
    27 wrt_Unpack_SetOwner() {            # Unpack and set owner. Assign 'ROOT' var
    28 #----------------------------------#
    29   local USER_ACCT=$1
    30   local FILE=$2
    31   local optSAVE_PREVIOUS=$3
    32 
    33   if [ "${optSAVE_PREVIOUS}" != "1" ]; then
    34     wrt_remove_existing_dirs "$FILE"
    35   fi
    36 (
    37 cat << EOF
    38         @\$(call unpack,$FILE)
    39         @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
    40         echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
    41         chown -R ${USER_ACCT} \$(MOUNT_PT)\$(SRC)/\$\$ROOT
    42 EOF
    43 ) >> $MKFILE.tmp
    44 }
    45 
    46 #----------------------------------#
    47 wrt_RunAsRoot() {                  # Some scripts must be run as root..
    48 #----------------------------------#
    49   local user_ACCT=$(echo $1 | tr [a-z] [A-Z])
    50   local this_script=$2
    51   local file=$3
    52 
    53 (
    54 cat << EOF
    55         @( time { export ${user_ACCT}=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
    56         echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
    57 EOF
    58 ) >> $MKFILE.tmp
    59 }
    60 
    619
    6210#----------------------------#
     
    10250EOF
    10351) >> $MKFILE.tmp
    104       wrt_ExecuteAsUser "hlfs" "$toolchain" "$this_script"
     52      wrt_RunAsUser "$toolchain" "$this_script"
    10553      ;;
    10654  esac
    10755  #
    108   # Safe method to remove packages unpacked outside the toolchain
     56  # Safe method to remove packages unpacked while inside the toolchain script
    10957  pkg_tarball=$(get_package_tarball_name "binutils")
    11058  wrt_remove_existing_dirs  "$pkg_tarball"
     
    13785  fi
    13886
    139   # If /home/hlfs is already present in the host, we asume that the
     87  # If /home/$LUSER is already present in the host, we asume that the
    14088  # hlfs user and group are also presents in the host, and a backup
    14189  # of their bash init files is made.
     
    157105021-addinguser:  020-creatingtoolsdir
    158106        @\$(call echo_message, Building)
    159         @if [ ! -d /home/hlfs ]; then \\
    160                 groupadd hlfs; \\
    161                 useradd -s /bin/bash -g hlfs -m -k /dev/null hlfs; \\
     107        @if [ ! -d /home/\$(LUSER) ]; then \\
     108                groupadd \$(LGROUP); \\
     109                useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
    162110        else \\
    163                 touch user-hlfs-exist; \\
    164         fi;
    165         @chown hlfs \$(MOUNT_PT)/tools && \\
    166         chown hlfs \$(MOUNT_PT)/sources && \\
     111                touch luser-exist; \\
     112        fi;
     113        @chown \$(LUSER) \$(MOUNT_PT)/tools && \\
     114        chown \$(LUSER) \$(MOUNT_PT)/sources && \\
    167115        touch \$@ && \\
    168116        echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
     
    171119022-settingenvironment:  021-addinguser
    172120        @\$(call echo_message, Building)
    173         @if [ -f /home/hlfs/.bashrc -a ! -f /home/hlfs/.bashrc.XXX ]; then \\
    174                 mv /home/hlfs/.bashrc /home/hlfs/.bashrc.XXX; \\
    175         fi;
    176         @if [ -f /home/hlfs/.bash_profile  -a ! -f /home/hlfs/.bash_profile.XXX ]; then \\
    177                 mv /home/hlfs/.bash_profile /home/hlfs/.bash_profile.XXX; \\
    178         fi;
    179         @echo "set +h" > /home/hlfs/.bashrc && \\
    180         echo "umask 022" >> /home/hlfs/.bashrc && \\
    181         echo "HLFS=\$(MOUNT_PT)" >> /home/hlfs/.bashrc && \\
    182         echo "LC_ALL=POSIX" >> /home/hlfs/.bashrc && \\
    183         echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/hlfs/.bashrc && \\
    184         echo "export HLFS LC_ALL PATH" >> /home/hlfs/.bashrc && \\
    185         echo "" >> /home/hlfs/.bashrc && \\
    186         echo "target=$(uname -m)-${TARGET}" >> /home/lfs/.bashrc && \\
    187         echo "ldso=/tools/lib/${LOADER}" >> /home/lfs/.bashrc && \\
    188         echo "export target ldso" >> /home/lfs/.bashrc && \\
    189         echo "source $JHALFSDIR/envars" >> /home/hlfs/.bashrc && \\
    190         chown hlfs:hlfs /home/hlfs/.bashrc && \\
     121        @if [ -f /home/\$(LUSER)/.bashrc -a ! -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
     122                mv /home/\$(LUSER)/.bashrc /home/\$(LUSER)/.bashrc.XXX; \\
     123        fi;
     124        @if [ -f /home/\$(LUSER)/.bash_profile  -a ! -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
     125                mv /home/\$(LUSER)/.bash_profile /home/\$(LUSER)/.bash_profile.XXX; \\
     126        fi;
     127        @echo "set +h" > /home/\$(LUSER)/.bashrc && \\
     128        echo "umask 022" >> /home/\$(LUSER)/.bashrc && \\
     129        echo "HLFS=\$(MOUNT_PT)" >> /home/\$(LUSER)/.bashrc && \\
     130        echo "LC_ALL=POSIX" >> /home/\$(LUSER)/.bashrc && \\
     131        echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/\$(LUSER)/.bashrc && \\
     132        echo "export HLFS LC_ALL PATH" >> /home/\$(LUSER)/.bashrc && \\
     133        echo "" >> /home/\$(LUSER)/.bashrc && \\
     134        echo "target=$(uname -m)-${TARGET}" >> /home/\$(LUSER)/.bashrc && \\
     135        echo "ldso=/tools/lib/${LOADER}" >> /home/\$(LUSER)/.bashrc && \\
     136        echo "export target ldso" >> /home/\$(LUSER)/.bashrc && \\
     137        echo "source $JHALFSDIR/envars" >> /home/\$(LUSER)/.bashrc && \\
     138        chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bashrc && \\
    191139        touch envars && \\
    192140        touch \$@ && \\
     
    263211    if [ "$pkg_tarball" != "" ] ; then
    264212      # Insert instructions for unpacking the package and to set the PKGDIR variable.
    265       wrt_Unpack_SetOwner "hlfs" "$pkg_tarball"
     213      wrt_unpack "$pkg_tarball"
    266214      # If using optimizations, write the instructions
    267215      [[ "$OPTIMIZE" = "2" ]] &&  wrt_optimize "$name" && wrt_makeflags "$name"
     
    269217    # Insert date and disk usage at the top of the log file, the script run
    270218    # and date and disk usage again at the bottom of the log file.
    271     wrt_ExecuteAsUser "hlfs" "$this_script" "${file}"
     219    wrt_RunAsUser "$this_script" "${file}"
    272220
    273221    # Remove the build directory(ies) except if the package build fails
     
    396344    case "${this_script}" in
    397345      *kernfs*)
    398         wrt_RunAsRoot "hlfs" "${this_script}" "${file}"
     346        wrt_RunAsRoot "${this_script}" "${file}"
    399347        ;;
    400348      *)   # The rest of Chapter06
     
    538486MOUNT_PT= $BUILDDIR
    539487PKG_LST= $PKG_LST
     488LUSER= $LUSER
     489LGROUP= $LGROUP
    540490
    541491include makefile-functions
     
    546496
    547497  # Add chroot commands
     498  CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
    548499  i=1
    549500  for file in chapter06/*chroot* ; do
    550     chroot=`cat $file | sed -e '/#!\/bin\/sh/d' \
    551           -e '/^export/d' \
    552           -e '/^logout/d' \
    553           -e 's@ \\\@ @g' | tr -d '\n' |  sed -e 's/  */ /g' \
    554                                               -e 's|\\$|&&|g' \
    555                                               -e 's|exit||g' \
    556                                               -e 's|$| -c|' \
    557                                               -e 's|"$$HLFS"|$(MOUNT_PT)|'\
    558                                               -e 's|set -e||'`
     501    chroot=`cat $file | \
     502            sed -e "s@chroot@$CHROOT_LOC@" \
     503                -e '/#!\/bin\/sh/d' \
     504                -e '/^export/d' \
     505                -e '/^logout/d' \
     506                -e 's@ \\\@ @g' | \
     507            tr -d '\n' |  \
     508            sed -e 's/  */ /g' \
     509                -e 's|\\$|&&|g' \
     510                -e 's|exit||g' \
     511                -e 's|$| -c|' \
     512                -e 's|"$$HLFS"|$(MOUNT_PT)|'\
     513                -e 's|set -e||'`
    559514    echo -e "CHROOT$i= $chroot\n" >> $MKFILE
    560515    i=`expr $i + 1`
     
    570525chapter3:  020-creatingtoolsdir 021-addinguser 022-settingenvironment
    571526
    572 chapter5:  chapter3 $chapter5 restore-hlfs-env
     527chapter5:  chapter3 $chapter5 restore-luser-env
    573528
    574529chapter6:  chapter5 $chapter6
     
    584539
    585540clean-chapter3:
    586         -if [ ! -f user-hlfs-exist ]; then \\
    587                 userdel hlfs; \\
    588                 rm -rf /home/hlfs; \\
     541        -if [ ! -f luser-exist ]; then \\
     542                userdel \$(LUSER); \\
     543                rm -rf /home/\$(LUSER); \\
    589544        fi;
    590545        rm -rf \$(MOUNT_PT)/tools
    591546        rm -f /tools
    592         rm -f envars user-hlfs-exist
     547        rm -f envars luser-exist
    593548        rm -f 02* logs/02*.log
    594549
    595550clean-chapter5:
    596551        rm -rf \$(MOUNT_PT)/tools/*
    597         rm -f $chapter5 restore-hlfs-env sources-dir
     552        rm -f $chapter5 restore-luser-env sources-dir
    598553        cd logs && rm -f $chapter5 && cd ..
    599554
     
    612567        cd logs && rm -f $chapter7 && cd ..
    613568
    614 restore-hlfs-env:
     569restore-luser-env:
    615570        @\$(call echo_message, Building)
    616         @if [ -f /home/hlfs/.bashrc.XXX ]; then \\
    617                 mv -f /home/hlfs/.bashrc.XXX /home/hlfs/.bashrc; \\
    618         fi;
    619         @if [ -f /home/hlfs/.bash_profile.XXX ]; then \\
    620                 mv /home/hlfs/.bash_profile.XXX /home/hlfs/.bash_profile; \\
    621         fi;
    622         @chown hlfs:hlfs /home/hlfs/.bash* && \\
     571        @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
     572                mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
     573        fi;
     574        @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
     575                mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
     576        fi;
     577        @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
    623578        touch \$@ && \\
    624579        echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
     
    631586        @-umount \$(MOUNT_PT)/sys
    632587        @-umount \$(MOUNT_PT)/proc
    633         @-if [ ! -f user-hlfs-exist ]; then \\
    634                 userdel hlfs; \\
    635                 rm -rf /home/hlfs; \\
     588        @-if [ ! -f luser-exist ]; then \\
     589                userdel \$(LUSER); \\
     590                rm -rf /home/\$(LUSER); \\
    636591        fi;
    637592
Note: See TracChangeset for help on using the changeset viewer.