This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-entrypoint.sh
executable file
·105 lines (84 loc) · 3.06 KB
/
docker-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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# Set original entrypoint
set -- tini -- start.sh ${@}
# Helper function to set time zone
_prepare_time_zone() {
echo "Setting time zone to: ${TIME_ZONE}"
ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime
}
# Helper function to prepare the steamcmd user
_prepare_steamcmd_user() {
# Fix group ID
echo "Setting steamcmd user GID to ${STEAMCMD_GID}"
groupmod -g ${STEAMCMD_GID} steamcmd
# Fix user ID
echo "Setting steamcmd user UID to ${STEAMCMD_UID}"
usermod -u ${STEAMCMD_UID} steamcmd
# Fix ownership of user home directory
echo "Fixing ownership of ${STEAMCMD_USER_HOME}"
cp -rT /etc/skel ${STEAMCMD_USER_HOME}
chown -R steamcmd:steamcmd ${STEAMCMD_USER_HOME}
}
# Helper function to fix steamcmd dumps ownership
_fix_steamcmd_dumps_ownership() {
echo "Fixing ownership of /tmp/dumps"
mkdir -p /tmp/dumps
chown -R steamcmd:steamcmd /tmp/dumps
}
# Helper function to fix session socket dir ownership
_fix_session_socket_dir_ownership() {
echo "Fixing ownership of ${STEAMCMD_SERVER_SOCKET_PATH}"
mkdir -p ${STEAMCMD_SERVER_SOCKET_PATH}
chown -R steamcmd:steamcmd ${STEAMCMD_SERVER_SOCKET_PATH}
}
# Helper function to fix host keys should they not exist
_prepare_ssh_host_key() {
local host_key_type="${1}"
local host_key_path="/opt/ssh/ssh_host_${host_key_type}_key"
if [[ ! -f ${host_key_path} ]]; then
rm -f "${host_key_path}*"
ssh-keygen -q -N "" -t ${host_key_type} -f ${host_key_path}
fi
}
# Helper function to prepare the SSH server
_prepare_ssh_server() {
local _ssh_keys="${STEAMCMD_SSH_AUTHORIZED_KEYS}"
if [[ ${_ssh_keys} != ssh-* ]]; then
_ssh_keys=$(echo -n "${STEAMCMD_SSH_AUTHORIZED_KEYS}" | base64 -d 2>&1) > /dev/null
fi
if [[ ${_ssh_keys} == ssh-* ]]; then
echo "Preparing SSH server..."
mkdir -p "${STEAMCMD_USER_HOME}/.ssh"
echo ${_ssh_keys} > "${STEAMCMD_USER_HOME}/.ssh/authorized_keys"
chown -R steamcmd:steamcmd "${STEAMCMD_USER_HOME}/.ssh"
chmod 0700 "${STEAMCMD_USER_HOME}/.ssh"
chmod 0600 "${STEAMCMD_USER_HOME}/.ssh/authorized_keys"
mkdir -p /opt/ssh
_prepare_ssh_host_key "dsa"
_prepare_ssh_host_key "rsa"
_prepare_ssh_host_key "ecdsa"
_prepare_ssh_host_key "ed25519"
# Add SSHD rundir
mkdir -p /run/sshd
# Add container environment as system environment variables to make them available in SSH sessions
env | grep STEAMCMD_ > /etc/environment
# Run the server
/usr/sbin/sshd
else
echo "Couldn't parse SSH authorized keys configuration, ignoring..."
fi
}
# Fix file and directory permissions if run as root
if [ $(id -u) -eq 0 ]; then
_prepare_time_zone
_prepare_steamcmd_user
_fix_steamcmd_dumps_ownership
_fix_session_socket_dir_ownership
if [[ "${STEAMCMD_SSH_SERVER_ENABLE}" == "1" ]]; then
_prepare_ssh_server
fi
# Call to gosu to drop from root user to steamcmd user
# when running original entrypoint
set -- gosu steamcmd $@
fi
exec ${@}