Index: HLFS/config
===================================================================
--- HLFS/config	(revision 28f47563a6de72ad88cb4d9ecc5a461b863dff22)
+++ HLFS/config	(revision 6ad5a2fbb71942d230be4bf47110dd71c89b0d55)
@@ -12,4 +12,8 @@
 #--- The host system has grsecurity options enabled? 0(no)/1(yes)
 GRSECURITY_HOST=0
+
+#--- Unprivileged user and group name
+LUSER=hlfs
+LGROUP=hlfs
 
 #--- Location of fstab file (if empty, a template is created)
Index: HLFS/master.sh
===================================================================
--- HLFS/master.sh	(revision 28f47563a6de72ad88cb4d9ecc5a461b863dff22)
+++ HLFS/master.sh	(revision 6ad5a2fbb71942d230be4bf47110dd71c89b0d55)
@@ -7,56 +7,4 @@
 ###          FUNCTIONS          ###
 ###################################
-
-#----------------------------------#
-wrt_ExecuteAsUser() {              # Execute the file ($3) under the users account ($1), log in $2
-#----------------------------------#
-  local this_user=$1
-  local this_script=$2
-  local file=$3
-
-(
-cat << EOF
-	@( time { su - ${this_user} -c "source /home/${this_user}/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
-	echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
-EOF
-) >> $MKFILE.tmp
-}
-
-
-#----------------------------------#
-wrt_Unpack_SetOwner() {            # Unpack and set owner. Assign 'ROOT' var
-#----------------------------------#
-  local USER_ACCT=$1
-  local FILE=$2
-  local optSAVE_PREVIOUS=$3
-
-  if [ "${optSAVE_PREVIOUS}" != "1" ]; then
-    wrt_remove_existing_dirs "$FILE"
-  fi
-(
-cat << EOF
-	@\$(call unpack,$FILE)
-	@ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
-	echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
-	chown -R ${USER_ACCT} \$(MOUNT_PT)\$(SRC)/\$\$ROOT
-EOF
-) >> $MKFILE.tmp
-}
-
-#----------------------------------#
-wrt_RunAsRoot() {                  # Some scripts must be run as root..
-#----------------------------------#
-  local user_ACCT=$(echo $1 | tr [a-z] [A-Z])
-  local this_script=$2
-  local file=$3
-
-(
-cat << EOF
-	@( time { export ${user_ACCT}=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
-	echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
-EOF
-) >> $MKFILE.tmp
-}
-
 
 #----------------------------#
@@ -102,9 +50,9 @@
 EOF
 ) >> $MKFILE.tmp
-      wrt_ExecuteAsUser "hlfs" "$toolchain" "$this_script"
+      wrt_RunAsUser "$toolchain" "$this_script"
       ;;
   esac
   #
-  # Safe method to remove packages unpacked outside the toolchain
+  # Safe method to remove packages unpacked while inside the toolchain script
   pkg_tarball=$(get_package_tarball_name "binutils")
   wrt_remove_existing_dirs  "$pkg_tarball"
@@ -137,5 +85,5 @@
   fi
 
-  # If /home/hlfs is already present in the host, we asume that the
+  # If /home/$LUSER is already present in the host, we asume that the
   # hlfs user and group are also presents in the host, and a backup
   # of their bash init files is made.
@@ -157,12 +105,12 @@
 021-addinguser:  020-creatingtoolsdir
 	@\$(call echo_message, Building)
-	@if [ ! -d /home/hlfs ]; then \\
-		groupadd hlfs; \\
-		useradd -s /bin/bash -g hlfs -m -k /dev/null hlfs; \\
+	@if [ ! -d /home/\$(LUSER) ]; then \\
+		groupadd \$(LGROUP); \\
+		useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
 	else \\
-		touch user-hlfs-exist; \\
-	fi;
-	@chown hlfs \$(MOUNT_PT)/tools && \\
-	chown hlfs \$(MOUNT_PT)/sources && \\
+		touch luser-exist; \\
+	fi;
+	@chown \$(LUSER) \$(MOUNT_PT)/tools && \\
+	chown \$(LUSER) \$(MOUNT_PT)/sources && \\
 	touch \$@ && \\
 	echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
@@ -171,22 +119,22 @@
 022-settingenvironment:  021-addinguser
 	@\$(call echo_message, Building)
-	@if [ -f /home/hlfs/.bashrc -a ! -f /home/hlfs/.bashrc.XXX ]; then \\
-		mv /home/hlfs/.bashrc /home/hlfs/.bashrc.XXX; \\
-	fi;
-	@if [ -f /home/hlfs/.bash_profile  -a ! -f /home/hlfs/.bash_profile.XXX ]; then \\
-		mv /home/hlfs/.bash_profile /home/hlfs/.bash_profile.XXX; \\
-	fi;
-	@echo "set +h" > /home/hlfs/.bashrc && \\
-	echo "umask 022" >> /home/hlfs/.bashrc && \\
-	echo "HLFS=\$(MOUNT_PT)" >> /home/hlfs/.bashrc && \\
-	echo "LC_ALL=POSIX" >> /home/hlfs/.bashrc && \\
-	echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/hlfs/.bashrc && \\
-	echo "export HLFS LC_ALL PATH" >> /home/hlfs/.bashrc && \\
-	echo "" >> /home/hlfs/.bashrc && \\
-	echo "target=$(uname -m)-${TARGET}" >> /home/lfs/.bashrc && \\
-	echo "ldso=/tools/lib/${LOADER}" >> /home/lfs/.bashrc && \\
-	echo "export target ldso" >> /home/lfs/.bashrc && \\
-	echo "source $JHALFSDIR/envars" >> /home/hlfs/.bashrc && \\
-	chown hlfs:hlfs /home/hlfs/.bashrc && \\
+	@if [ -f /home/\$(LUSER)/.bashrc -a ! -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
+		mv /home/\$(LUSER)/.bashrc /home/\$(LUSER)/.bashrc.XXX; \\
+	fi;
+	@if [ -f /home/\$(LUSER)/.bash_profile  -a ! -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
+		mv /home/\$(LUSER)/.bash_profile /home/\$(LUSER)/.bash_profile.XXX; \\
+	fi;
+	@echo "set +h" > /home/\$(LUSER)/.bashrc && \\
+	echo "umask 022" >> /home/\$(LUSER)/.bashrc && \\
+	echo "HLFS=\$(MOUNT_PT)" >> /home/\$(LUSER)/.bashrc && \\
+	echo "LC_ALL=POSIX" >> /home/\$(LUSER)/.bashrc && \\
+	echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/\$(LUSER)/.bashrc && \\
+	echo "export HLFS LC_ALL PATH" >> /home/\$(LUSER)/.bashrc && \\
+	echo "" >> /home/\$(LUSER)/.bashrc && \\
+	echo "target=$(uname -m)-${TARGET}" >> /home/\$(LUSER)/.bashrc && \\
+	echo "ldso=/tools/lib/${LOADER}" >> /home/\$(LUSER)/.bashrc && \\
+	echo "export target ldso" >> /home/\$(LUSER)/.bashrc && \\
+	echo "source $JHALFSDIR/envars" >> /home/\$(LUSER)/.bashrc && \\
+	chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bashrc && \\
 	touch envars && \\
 	touch \$@ && \\
@@ -263,5 +211,5 @@
     if [ "$pkg_tarball" != "" ] ; then
       # Insert instructions for unpacking the package and to set the PKGDIR variable.
-      wrt_Unpack_SetOwner "hlfs" "$pkg_tarball"
+      wrt_unpack "$pkg_tarball"
       # If using optimizations, write the instructions
       [[ "$OPTIMIZE" = "2" ]] &&  wrt_optimize "$name" && wrt_makeflags "$name"
@@ -269,5 +217,5 @@
     # Insert date and disk usage at the top of the log file, the script run
     # and date and disk usage again at the bottom of the log file.
-    wrt_ExecuteAsUser "hlfs" "$this_script" "${file}"
+    wrt_RunAsUser "$this_script" "${file}"
 
     # Remove the build directory(ies) except if the package build fails
@@ -396,5 +344,5 @@
     case "${this_script}" in
       *kernfs*)
-        wrt_RunAsRoot "hlfs" "${this_script}" "${file}"
+        wrt_RunAsRoot "${this_script}" "${file}"
         ;;
       *)   # The rest of Chapter06
@@ -538,4 +486,6 @@
 MOUNT_PT= $BUILDDIR
 PKG_LST= $PKG_LST
+LUSER= $LUSER
+LGROUP= $LGROUP
 
 include makefile-functions
@@ -546,15 +496,20 @@
 
   # Add chroot commands
+  CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
   i=1
   for file in chapter06/*chroot* ; do
-    chroot=`cat $file | sed -e '/#!\/bin\/sh/d' \
-          -e '/^export/d' \
-          -e '/^logout/d' \
-          -e 's@ \\\@ @g' | tr -d '\n' |  sed -e 's/  */ /g' \
-                                              -e 's|\\$|&&|g' \
-                                              -e 's|exit||g' \
-                                              -e 's|$| -c|' \
-                                              -e 's|"$$HLFS"|$(MOUNT_PT)|'\
-                                              -e 's|set -e||'`
+    chroot=`cat $file | \
+            sed -e "s@chroot@$CHROOT_LOC@" \
+                -e '/#!\/bin\/sh/d' \
+                -e '/^export/d' \
+                -e '/^logout/d' \
+                -e 's@ \\\@ @g' | \
+            tr -d '\n' |  \
+            sed -e 's/  */ /g' \
+                -e 's|\\$|&&|g' \
+                -e 's|exit||g' \
+                -e 's|$| -c|' \
+                -e 's|"$$HLFS"|$(MOUNT_PT)|'\
+                -e 's|set -e||'`
     echo -e "CHROOT$i= $chroot\n" >> $MKFILE
     i=`expr $i + 1`
@@ -570,5 +525,5 @@
 chapter3:  020-creatingtoolsdir 021-addinguser 022-settingenvironment
 
-chapter5:  chapter3 $chapter5 restore-hlfs-env
+chapter5:  chapter3 $chapter5 restore-luser-env
 
 chapter6:  chapter5 $chapter6
@@ -584,16 +539,16 @@
 
 clean-chapter3:
-	-if [ ! -f user-hlfs-exist ]; then \\
-		userdel hlfs; \\
-		rm -rf /home/hlfs; \\
+	-if [ ! -f luser-exist ]; then \\
+		userdel \$(LUSER); \\
+		rm -rf /home/\$(LUSER); \\
 	fi;
 	rm -rf \$(MOUNT_PT)/tools
 	rm -f /tools
-	rm -f envars user-hlfs-exist
+	rm -f envars luser-exist
 	rm -f 02* logs/02*.log
 
 clean-chapter5:
 	rm -rf \$(MOUNT_PT)/tools/*
-	rm -f $chapter5 restore-hlfs-env sources-dir
+	rm -f $chapter5 restore-luser-env sources-dir
 	cd logs && rm -f $chapter5 && cd ..
 
@@ -612,13 +567,13 @@
 	cd logs && rm -f $chapter7 && cd ..
 
-restore-hlfs-env:
+restore-luser-env:
 	@\$(call echo_message, Building)
-	@if [ -f /home/hlfs/.bashrc.XXX ]; then \\
-		mv -f /home/hlfs/.bashrc.XXX /home/hlfs/.bashrc; \\
-	fi;
-	@if [ -f /home/hlfs/.bash_profile.XXX ]; then \\
-		mv /home/hlfs/.bash_profile.XXX /home/hlfs/.bash_profile; \\
-	fi;
-	@chown hlfs:hlfs /home/hlfs/.bash* && \\
+	@if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
+		mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
+	fi;
+	@if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
+		mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
+	fi;
+	@chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
 	touch \$@ && \\
 	echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
@@ -631,7 +586,7 @@
 	@-umount \$(MOUNT_PT)/sys
 	@-umount \$(MOUNT_PT)/proc
-	@-if [ ! -f user-hlfs-exist ]; then \\
-		userdel hlfs; \\
-		rm -rf /home/hlfs; \\
+	@-if [ ! -f luser-exist ]; then \\
+		userdel \$(LUSER); \\
+		rm -rf /home/\$(LUSER); \\
 	fi;
 
