-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.sh
83 lines (70 loc) · 2.71 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
set -e
# These variables can be overridden by docker environment variables
USER_UID=${USER_UID:-1000}
USER_GID=${USER_GID:-1000}
USERNAME=${USERNAME:-docker}
create_user() {
# If the home folder exists, set a flag.
# Creating the user during container initialization often is anticipated
# by the mount of a docker volume. In this case the home directory is already
# present in the file system and adduser skips by default the copy of the
# configuration files.
HOME_FOLDER_EXISTS=0
if [ -d /home/$USERNAME ] ; then HOME_FOLDER_EXISTS=1 ; fi
# Create a group with USER_GID
if ! getent group ${USERNAME} >/dev/null; then
echo "Creating ${USERNAME} group"
groupadd -f -g ${USER_GID} ${USERNAME} 2> /dev/null
fi
# Create a user with USER_UID
if ! getent passwd ${USERNAME} >/dev/null; then
echo "Creating ${USERNAME} user"
adduser --quiet \
--disabled-login \
--uid ${USER_UID} \
--gid ${USER_GID} \
--gecos 'Workspace' \
${USERNAME}
fi
# If configuration files have not been copied, do it manually
if [ ! $HOME_FOLDER_EXISTS -eq 0 ] ; then
chown ${USER_UID}:${USER_GID} /home/${USERNAME}
install -m 644 -g ${USERNAME} -o ${USERNAME} /etc/skel/.bashrc /home/${USERNAME}
install -m 644 -g ${USERNAME} -o ${USERNAME} /etc/skel/.bash_logout /home/${USERNAME}
install -m 644 -g ${USERNAME} -o ${USERNAME} /etc/skel/.profile /home/${USERNAME}
fi
# Assign the user to the runtimeusers group
gpasswd -a ${USERNAME} runtimeusers
}
# Create the user
echo "==> Creating the runtime user"
create_user
# Set a default root password
echo "==> Setting the default root password"
ROOT_PASSWORD="root"
echo "root:${ROOT_PASSWORD}" | chpasswd
# Set a default password
echo "==> Setting the default user password"
USER_PASSWORD=${USERNAME}
echo "${USERNAME}:${USER_PASSWORD}" | chpasswd
echo "${USERNAME} ALL=(ALL:ALL) ALL" >> /etc/sudoers
# Add the user to video group for HW acceleration (Intel GPUs)
usermod -aG video ${USERNAME}
# Configure git
if [[ ! -z ${GIT_USER_NAME:+x} && ! -z ${GIT_USER_EMAIL:+x} ]] ; then
echo "==> Setting up git"
su -c "git config --global user.name ${GIT_USER_NAME}" $USERNAME
su -c "git config --global user.email ${GIT_USER_EMAIL}" $USERNAME
su -c "git config --global color.pager true" $USERNAME
su -c "git config --global color.ui auto" $USERNAME
su -c "git config --global push.default upstream" $USERNAME
su -c "git config --global core.autocrlf input" $USERNAME
fi
echo "==> Configuring the support of extending PATH system-wide"
echo 'PATH=$DEVENV_PATH:$PATH' >> /etc/bash.bashrc
# Adding matlab to PATH
if [[ ! -z ${Matlab_ROOT_DIR:+x} ]] ; then
echo "==> Setting up matlab"
echo 'PATH=$PATH:$Matlab_ROOT_DIR/bin' >> /etc/bash.bashrc
fi