oe-buildenv/init.sh
Thomas Klaehn 6691814ab4 Yocto build container: start as builduser
Signed-off-by: Thomas Klaehn <thomas.klaehn@u-blox.com>
2017-11-17 12:03:33 +01:00

46 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
now="$(date +%s >&1)"
username=builduser_${now}
usergroup=buildgroup_${now}
builddir=$(pwd)
homedir=/home/${username}
sshdir=${homedir}/.ssh
# Figure out the uid/gid we need to use by integrating the path that has
# been bind mounted in. This is then used for the builduser.
BUILD_UID=$(stat --printf=%u ${builddir} 2> /dev/null)
BUILD_GID=$(stat --printf=%g ${builddir} 2> /dev/null)
# Add docker container group/user.
groupadd --gid ${BUILD_GID} --non-unique ${usergroup}
useradd -s /bin/bash --home ${homedir} --non-unique --uid ${BUILD_UID} \
--gid ${BUILD_GID} --groups sudo ${username}
# Give users in the sudo group sudo access in the container.
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# Copy ssh key files.
mkdir -p ${homedir}
mkdir -p ${sshdir}
cp /var/ssh/* ${sshdir}/
chown -R ${username}:${usergroup} ${homedir}
# Determine parallel build capabilities.
parallel_build="$(nproc >&1)"
if [ ${parallel_build} -gt 20 ]
then
BB_NUMBER_THREADS=20
PARALLEL_MAKE=20
else
BB_NUMBER_THREADS=${parallel_build}
PARALLEL_MAKE=${parallel_build}
fi
export BB_NUMBER_THREADS
export PARALLEL_MAKE
# Execute CMD
su ${username} -c "$@"