mirror of
https://github.com/gosticks/gml.git
synced 2026-08-17 07:20:23 +00:00
29 lines
964 B
Bash
29 lines
964 B
Bash
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
# If we are running docker natively, we want to create a user in the container
|
|
# with the same UID and GID as the user on the host machine, so that any files
|
|
# created are owned by that user. Without this they are all owned by root.
|
|
if [[ -n $UID ]] && [[ -n $GID ]]; then
|
|
export HOME="/home/builder"
|
|
groupadd -o -g $GID builder 2> /dev/null
|
|
useradd -d "${HOME}" -o -m -g $GID -u $UID -s /bin/bash builder 2> /dev/null
|
|
chown builder:builder /work
|
|
|
|
# Copy SSH known hosts from root if present.
|
|
if [ -f /root/.ssh/known_hosts ]; then
|
|
mkdir -p "${HOME}/.ssh"
|
|
cp /root/.ssh/known_hosts "${HOME}/.ssh/known_hosts"
|
|
chown -R builder:builder "${HOME}/.ssh"
|
|
fi
|
|
|
|
# Run the command as the specified user/group.
|
|
exec sudo -E -H -u builder \
|
|
env "PATH=$PATH" \
|
|
env "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" \
|
|
"$@"
|
|
else
|
|
# Just run the command as root.
|
|
exec "$@"
|
|
fi |