-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·59 lines (47 loc) · 2.01 KB
/
entrypoint.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
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# If a remote file server has been specified.
if [[ ! -z "$REMOTE_FILE_SERVER" ]]; then
# If a remote file server has not been set in the default apache conf file.
if ! grep -q remote-file-server.conf /etc/apache2/sites-available/000-default.conf; then
# Include the remote file server configuration file.
sed -i '/<\/VirtualHost>/i \
\tInclude conf-available/remote-file-server.conf' /etc/apache2/sites-available/000-default.conf
fi
# If a remote file server has not been set in the default-ssl apache conf
# file.
if ! grep -q remote-file-server.conf /etc/apache2/sites-available/default-ssl.conf; then
# Include the remote file server configuration file.
sed -i '/<\/VirtualHost>/i \
\t\tInclude conf-available/remote-file-server.conf' /etc/apache2/sites-available/default-ssl.conf
fi
fi
# If required environment variables are not set.
if [[ -z "$HOST_USER" || -z "$HOST_UID" ]]; then
if [[ -z "$HOST_USER" ]]; then
echo "Need to set the HOST_USER environment variable"
fi
if [[ -z "$HOST_UID" ]]; then
echo "Need to set the HOST_UID environment variable"
fi
exit 1
fi
# If the user has not already been created.
if [[ ! $(id -u $HOST_USER) =~ ^-?[0-9]+$ ]]; then
# If a folder for the user already exists, i.e. a host folder was bind mounted
# inside the user folder, manually copy files from the /etc/skel directory.
if [[ -d /home/$HOST_USER ]]; then
# Copy files from the /etc/skel directory into the user's home directory.
cp -a /etc/skel/. /home/$HOST_USER/
fi
# Create the user.
adduser --disabled-password --gecos GECOS --uid $HOST_UID $HOST_USER
# Ensure the users home directory is owned by them.
chown -R $HOST_USER:$HOST_USER /home/$HOST_USER
# Add the user to the sudo group.
usermod -aG sudo $HOST_USER
# Allow the user to use sudo to run all commands without a password.
echo $HOST_USER' ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/$HOST_USER
fi
exec "$@"