oe-buildenv/init.sh

32 lines
826 B
Bash
Raw Normal View History

#!/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 "$@"