-# handle root's homedir and tweak root prompt
-echo "* myplc-devel: root's homedir and prompt"
-roothome=devel/data/root
-mkdir -p $roothome
-cat << EOF > $roothome/.profile
-export PS1="<plc-devel> \$PS1"
+# Add a build user with the same ID as the current build user, who can
+# then cross-mount their home directory into the image and build MyPLC
+# in their home directory.
+echo "* myplc-devel: Adding build user"
+uid=${SUDO_UID:-2000}
+gid=${SUDO_GID:-2000}
+if ! grep -q "Automated Build" devel/root/etc/passwd ; then
+ chroot devel/root <<EOF
+groupadd -g $gid build
+useradd -c "Automated Build" -u $uid -g $gid -n -d /data/build -M -s /bin/bash build
+EOF
+fi
+
+# Copy build scripts to build home directory
+mkdir -p devel/data/build
+rsync -a $srcdir/build/ devel/data/build/
+
+# Allow build user to build certain RPMs as root
+cat >devel/root/etc/sudoers <<EOF
+root ALL=(ALL) ALL
+build ALL=(root) NOPASSWD: /usr/bin/rpmbuild