2017-11-16 08:12:46 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-11-16 12:26:17 +00:00
|
|
|
now="$(date +%s >&1)"
|
|
|
|
username=builduser_${now}
|
|
|
|
usergroup=buildgroup_${now}
|
|
|
|
builddir=$(pwd)
|
2017-11-16 08:12:46 +00:00
|
|
|
homedir=/home/${username}
|
|
|
|
sshdir=${homedir}/.ssh
|
|
|
|
|
2017-11-16 12:26:17 +00:00
|
|
|
# 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.
|
2017-11-16 08:12:46 +00:00
|
|
|
BUILD_UID=$(stat --printf=%u ${builddir} 2> /dev/null)
|
|
|
|
BUILD_GID=$(stat --printf=%g ${builddir} 2> /dev/null)
|
|
|
|
|
2017-11-16 12:26:17 +00:00
|
|
|
# Add docker container group/user.
|
2017-11-16 08:12:46 +00:00
|
|
|
groupadd --gid ${BUILD_GID} --non-unique ${usergroup}
|
|
|
|
useradd -s /bin/bash --home ${homedir} --non-unique --uid ${BUILD_UID} \
|
|
|
|
--gid ${BUILD_GID} --groups sudo ${username}
|
|
|
|
|
2017-11-16 12:26:17 +00:00
|
|
|
# Give users in the sudo group sudo access in the container.
|
2017-11-16 08:12:46 +00:00
|
|
|
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
|
|
|
|
2017-11-16 12:26:17 +00:00
|
|
|
# Copy ssh key files.
|
2017-11-16 08:12:46 +00:00
|
|
|
mkdir -p ${homedir}
|
|
|
|
mkdir -p ${sshdir}
|
|
|
|
cp /var/ssh/* ${sshdir}/
|
|
|
|
chown -R ${username}:${usergroup} ${homedir}
|
|
|
|
|
2017-11-16 12:26:17 +00:00
|
|
|
# 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
|
2017-11-16 08:12:46 +00:00
|
|
|
|
2017-11-16 12:26:17 +00:00
|
|
|
# Execute CMD
|
|
|
|
su ${username} -c "$@"
|