oe-buildenv/init.sh
Thomas Klaehn d64c9e41b1 Yocto build container: initial commit
Signed-off-by: Thomas Klaehn <thomas.klaehn@u-blox.com>
2017-11-17 12:03:32 +01:00

32 lines
826 B
Bash
Executable File

#!/bin/bash
username=builduser
usergroup=buildgroup
builddir=/var/build
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)
# create a group
groupadd --gid ${BUILD_GID} --non-unique ${usergroup}
# add user
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}
exec "$@"