redox/docker/entrypoint.sh
Andre Richter 6e3c76ea23
docker: Switch to official Rust image as base and rework
1. Use the official Rust nightly docker image as base
2. Remove hardcoded user
3. Use named volumes to cache .rustup and .cargo toolchain folders
    - Changing file permissions to user (chown) only needed on first launch
4. Cleanup apt folders after installing
5. Make bash the default fallback command
6. README.md: Unify workflows for Linux and MacOS
2017-09-02 21:51:46 +02:00

30 lines
1,005 B
Bash
Executable file

#!/usr/bin/env bash
# Add local user
# Either use LOCAL_UID and LOCAL_GID if passed in at runtime via
# -e LOCAL_UID="$(id -u)" -e LOCAL_GID="$(id -g)" or fallback
USER_NAME=redox
RUN_UID=${LOCAL_UID:-9001}
RUN_GID=${LOCAL_GID:-9001}
groupadd --non-unique --gid $RUN_GID $USER_NAME
useradd --non-unique --create-home --uid $RUN_UID --gid $USER_NAME --groups sudo $USER_NAME
echo "$USER_NAME ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/user-no-sudo-password
export HOME=/home/$USER_NAME
# Check current UID and GID of files in the named volume caches for
# cargo and rustup. Test only one of the top level folders to speed
# things up.
TESTFILE=$RUSTUP_HOME/settings.toml
CACHED_UID=$(stat -c "%u" $TESTFILE)
CACHED_GID=$(stat -c "%g" $TESTFILE)
if [ $CACHED_UID != $RUN_UID ] || [ $RUN_GID != $CACHED_GID ]; then
echo -e "\033[01;38;5;155mChanging user id:group to ${RUN_UID}:${RUN_GID}. Please wait...\033[0m"
chown $RUN_UID:$RUN_GID -R $CARGO_HOME $RUSTUP_HOME
fi
exec gosu $USER_NAME "$@"