2018-06-13 20:12:52 +02:00
|
|
|
#!/usr/bin/env bash
|
2015-08-18 17:46:18 +02:00
|
|
|
|
|
|
|
# This is the entrypoint script for the dockerfile. Executed in the
|
|
|
|
# container at runtime.
|
|
|
|
|
|
|
|
if [[ $# == 0 ]]; then
|
2016-07-04 06:10:36 +02:00
|
|
|
# Presumably the image has been run directly, so help the user get
|
|
|
|
# started by outputting the dockcross script
|
|
|
|
if [[ -n $DEFAULT_DOCKCROSS_IMAGE ]]; then
|
2021-08-04 11:17:08 +02:00
|
|
|
head -n 2 /dockcross/dockcross.sh
|
2016-07-04 06:10:36 +02:00
|
|
|
echo "DEFAULT_DOCKCROSS_IMAGE=$DEFAULT_DOCKCROSS_IMAGE"
|
2021-08-04 11:17:08 +02:00
|
|
|
tail -n +4 /dockcross/dockcross.sh |
|
2018-03-29 10:43:26 +02:00
|
|
|
sed -e "s@dockcross\/linux\-armv7@${DEFAULT_DOCKCROSS_IMAGE}@g" |
|
2018-03-30 03:04:52 +02:00
|
|
|
sed -e "s@dockcross\-linux\-armv7@${DEFAULT_DOCKCROSS_IMAGE//[\/:]/-}@g"
|
2016-07-04 06:10:36 +02:00
|
|
|
else
|
2021-08-04 11:17:08 +02:00
|
|
|
cat /dockcross/dockcross.sh
|
2016-07-04 06:10:36 +02:00
|
|
|
fi
|
2015-08-18 17:46:18 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
# The dockcross script sets the BUILDER_UID and BUILDER_GID vars.
|
|
|
|
if [[ -n $BUILDER_UID ]] && [[ -n $BUILDER_GID ]]; then
|
|
|
|
|
2021-08-08 20:45:36 +02:00
|
|
|
groupadd -o -g "$BUILDER_GID" "$BUILDER_GROUP" 2> /dev/null
|
|
|
|
useradd -o -m -g "$BUILDER_GID" -u "$BUILDER_UID" "$BUILDER_USER" 2> /dev/null
|
2016-07-04 07:28:47 +02:00
|
|
|
export HOME=/home/${BUILDER_USER}
|
2016-07-06 21:33:35 +02:00
|
|
|
shopt -s dotglob
|
|
|
|
cp -r /root/* $HOME/
|
2017-06-29 14:31:33 +02:00
|
|
|
chown -R $BUILDER_UID:$BUILDER_GID $HOME
|
2015-08-18 17:46:18 +02:00
|
|
|
|
2016-11-05 03:58:31 +01:00
|
|
|
# Additional updates specific to the image
|
|
|
|
if [[ -e /dockcross/pre_exec.sh ]]; then
|
|
|
|
/dockcross/pre_exec.sh
|
|
|
|
fi
|
|
|
|
|
2020-05-26 05:55:47 +02:00
|
|
|
# Enable passwordless sudo capabilities for the user
|
2021-08-08 20:45:36 +02:00
|
|
|
chown root:$BUILDER_GID "$(which gosu)"
|
|
|
|
chmod +s "$(which gosu)"; sync
|
2020-05-26 05:55:47 +02:00
|
|
|
|
2016-11-27 03:46:47 +01:00
|
|
|
# Execute project specific pre execution hook
|
|
|
|
if [[ -e /work/.dockcross ]]; then
|
2017-04-23 02:52:31 +02:00
|
|
|
gosu $BUILDER_UID:$BUILDER_GID /work/.dockcross
|
2016-11-27 03:46:47 +01:00
|
|
|
fi
|
|
|
|
|
2015-08-18 17:46:18 +02:00
|
|
|
# Run the command as the specified user/group.
|
2017-04-23 02:52:31 +02:00
|
|
|
exec gosu $BUILDER_UID:$BUILDER_GID "$@"
|
2015-08-18 17:46:18 +02:00
|
|
|
else
|
|
|
|
# Just run the command as root.
|
|
|
|
exec "$@"
|
|
|
|
fi
|