2017-07-24 17:15:45 +02:00
|
|
|
#!/usr/bin/env bash
|
2017-06-21 09:30:31 +02:00
|
|
|
|
2017-09-02 21:51:46 +02:00
|
|
|
# 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}
|
2017-06-21 09:30:31 +02:00
|
|
|
|
2017-09-02 21:51:46 +02:00
|
|
|
groupadd --non-unique --gid $RUN_GID $USER_NAME
|
|
|
|
useradd --non-unique --create-home --uid $RUN_UID --gid $USER_NAME --groups sudo $USER_NAME
|
2017-06-21 09:30:31 +02:00
|
|
|
|
2017-09-02 21:51:46 +02:00
|
|
|
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
|
2017-07-24 17:15:45 +02:00
|
|
|
echo -e "\033[01;38;5;155mChanging user id:group to ${RUN_UID}:${RUN_GID}. Please wait...\033[0m"
|
2017-09-02 21:51:46 +02:00
|
|
|
chown $RUN_UID:$RUN_GID -R $CARGO_HOME $RUSTUP_HOME
|
2017-07-24 17:15:45 +02:00
|
|
|
fi
|
2017-06-21 09:30:31 +02:00
|
|
|
|
2017-09-02 21:51:46 +02:00
|
|
|
exec gosu $USER_NAME "$@"
|