forked from hexparrot/mineos-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·116 lines (101 loc) · 3.43 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
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
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
set -eo pipefail
if [[ ! -f /root/password ]]; then
if [ -z "$USER_PASSWORD" ] || [ "$USER_PASSWORD" = "random_see_log" ]; then
echo >&2 'USER_PASSWORD not specified, generating random password.'
USER_PASSWORD=$(date +%s | sha256sum | base64 | head -c 20 ; echo)
echo >&2 '*******************************************************'
echo >&2 'Password set to: ' $USER_PASSWORD
echo >&2 '*******************************************************'
echo 'Password set to: ' $USER_PASSWORD > /root/password
fi
else
echo >&2 "Password already set by entrypoint.sh, at /root/password"
cat /root/password
fi
if [ "$USER_NAME" ]; then
# username specifically provided, will overwrite 'mc'
if [[ "$USER_NAME" =~ [^a-zA-Z0-9] ]]; then
echo >&2 'USER_NAME must contain only alphanumerics [a-zA-Z0-9]'
exit 1
fi
else
echo >&2 'USER_NAME not provided; defaulting to "mc"'
USER_NAME=mc
fi
if [ "$GROUP_NAME" ]; then
# group name specifically provided, will overwrite 'mc'
if [[ "$GROUP_NAME" =~ [^a-zA-Z0-9] ]]; then
echo >&2 'GROUP_NAME must contain only alphanumerics [a-zA-Z0-9]'
exit 1
fi
else
echo >&2 'GROUP_NAME not provided; defaulting to "mc"'
GROUP_NAME=mc
fi
if [ "$USER_UID" ]; then
# uid specifically provided, will overwrite 1000 default
if [[ "$USER_UID" =~ [^0-9] ]]; then
echo >&2 'USER_UID must contain only numerics [0-9]'
exit 1
fi
else
USER_UID=1000
fi
if [ "$GROUP_GID" ]; then
# gid specifically provided, will overwrite 1000 default
if [[ "$GROUP_GID" =~ [^0-9] ]]; then
echo >&2 'GROUP_GID must contain only numerics [0-9]'
exit 1
fi
else
GROUP_GID=1000
fi
if getent group $GROUP_NAME >/dev/null 2>&1; then
echo "a group named $GROUP_NAME already exists."
else
groupadd -og $GROUP_GID $GROUP_NAME
echo >&2 "Created group: $GROUP_NAME (gid: $GROUP_GID)"
fi
if id -u $USER_NAME >/dev/null 2>&1; then
echo "a user named $USER_NAME already exists."
else
useradd -Mos /bin/false -u $USER_UID -g $GROUP_GID $USER_NAME
echo >&2 "Created user: $USER_NAME (uid: $USER_UID, gid: $GROUP_GID)"
fi
echo >&2 "Setting user password for '$USER_NAME'"
echo "$USER_NAME:$USER_PASSWORD" | chpasswd --crypt-method SHA512
if [ ! -z "$USE_HTTPS" ]; then
# update mineos.conf from environment
sed -i 's/use_https = .*/use_https = '${USE_HTTPS}'/g' /etc/mineos.conf
echo >&2 "Setting use_https to: " $USE_HTTPS
if [[ -z $SERVER_PORT ]] && [ "$USE_HTTPS" = "true" ]; then
Port=8443
elif [[ -z $SERVER_PORT ]] && [ "$USE_HTTPS" = "false" ]; then
Port=8080
else
Port=$SERVER_PORT
fi
sed -i 's/socket_port = .*/socket_port = '${Port}'/g' /etc/mineos.conf
echo >&2 "Setting server port to: "$Port
fi
if [[ ! -f /etc/ssl/certs/mineos.crt ]] && [[ ! -z $( grep 'use_https = true' /etc/mineos.conf) ]]; then
# generate the cert if it is missing and enabled in the config
echo >&2 "Generating Self-Signed SSL..."
sh /usr/games/minecraft/generate-sslcert.sh
else
echo >&2 "Skipping Self-Signed SSL, it either exists or is disabled."
fi
if [ "$USE_HTTPS" ]; then
if [ "$USE_HTTPS" == "true" ]; then
echo "Setting https to true"
sed -i 's/use_https = false/use_https = true/' /etc/mineos.conf
else
echo "Setting https to false"
sed -i 's/use_https = true/use_https = false/' /etc/mineos.conf
fi
else
echo "Falling back to https true"
sed -i 's/use_https = false/use_https = true/' /etc/mineos.conf
fi
exec "$@"