-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint
More file actions
132 lines (109 loc) · 4.57 KB
/
entrypoint
File metadata and controls
132 lines (109 loc) · 4.57 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh
# Checking environments and setting defaults ----- Start ----- >
if [ -z "${HOST_UID}" ]; then
echo "Host user ID not found in environment. Using root (0)."
export HOST_UID=0
fi
if [ -z "${HOST_GID}" ]; then
echo "Host group ID not found in environment. Using root (0)."
export HOST_GID=0
fi
if [ -z "${FIVEM_LICENCE_KEY}" ]; then
echo "Licence key not found in environment, please create one at https://keymaster.fivem.net!"
export FIVEM_LICENCE_KEY=
fi
if [ -z "${FIVEM_PORT}" ]; then
echo "FiveM port not found in environment. Using default 30120"
export FIVEM_PORT=30120
fi
if [ -z "${TXADMIN_PORT}" ]; then
echo "txAdmin port not found in environment."
export TXADMIN_PORT=40120
fi
if [ -z "${SERVER_PROFILE}" ]; then
echo "txAdmin profile not found in environment. Using dev_server"
export SERVER_PROFILE="dev_server"
fi
if [ -z "${MYSQL_PASSWORD}" ]; then
echo "Databaser password not set. Using password"
export MYSQL_PASSWORD="password"
fi
if [ -z "${DATABASE_SERVICE_NAME}" ]; then
echo "Using mariadb as sql server"
export DATABASE_SERVICE_NAME="fivem"
fi
if [ -z "${MYSQL_DATABASE}" ]; then
echo "Using FiveMESX as database name"
export MYSQL_DATABASE="FiveMESX"
fi
if [ -z "${FIVEM_HOSTNAME}" ]; then
echo "FiveM Hostname not set. Using FiveM Test Server"
export FIVEM_HOSTNAME="FiveM Test Server"
fi
if [ -z "${STEAM_WEBAPIKEY}" ]; then
echo "Steam Web API key, if you want to use Steam authentication (https://steamcommunity.com/dev/apikey)"
export STEAM_WEBAPIKEY=
fi
# Checking environments and setting defaults ----- End ----- <
# Making fivem user and group to run the server -------------------
if ! getent group "${HOST_GID}" | cut -d: -f1 | read; then
addgroup fivem -g "${HOST_GID}"
HOST_GROUPNAME="fivem"
else
HOST_GROUPNAME=`getent group "${HOST_GID}" | cut -d: -f1`
fi
if ! getent passwd "${HOST_UID}" | cut -d: -f1 | read; then
adduser fivem -D -G "$HOST_GROUPNAME" --uid "$HOST_UID"
HOST_USERNAME="fivem"
else
HOST_USERNAME=`getent passwd "${HOST_UID}" | cut -d: -f1`
fi
# -----------------------------------------------------------------
# Copying and customizing server files -----------------------------------------
if ! find . -mindepth 1 | read; then
echo -e "Creating default configs...\n"
cp -r /opt/cfx-server-data/* /config
RCON_PASS="${RCON_PASSWORD-$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 16)}"
sed -i "s/{RCON_PASS}/${RCON_PASS}/g" /config/server.cfg;
sed -i "s/{FIVEM_PORT}/${FIVEM_PORT}/g" /config/server.cfg;
echo "----------------------------------------------"
echo "Your RCON password is set to: ${RCON_PASS}"
echo -e "----------------------------------------------\n"
sed -i "s/{FIVEM_HOSTNAME}/${FIVEM_HOSTNAME}/g" /config/server.cfg;
sed -i "s/{STEAM_WEBAPIKEY}/${STEAM_WEBAPIKEY}/g" /config/server.cfg;
sed -i "s/{FIVEM_LICENCE_KEY}/${FIVEM_LICENCE_KEY}/g" /config/server.cfg;
sed -i "s/{MYSQL_USER}/${MYSQL_USER}/g" /config/server.cfg;
sed -i "s/{MYSQL_PASSWORD}/${MYSQL_PASSWORD}/g" /config/server.cfg;
sed -i "s/{MYSQL_DATABASE}/${MYSQL_DATABASE}/g" /config/server.cfg;
sed -i "s/{DATABASE_SERVICE_NAME}/${DATABASE_SERVICE_NAME}/g" /config/server.cfg;
fi
# -------------------------------------------------------------------------------
# Editing and moving the sql file to the correct lacation. ----------------
FILE=/opt/cfx-server-data/database.sql
if test -f "$FILE"; then
sed -i "s/{MYSQL_DATABASE}/${MYSQL_DATABASE}/g" "$FILE";
mv "$FILE" /docker-entrypoint-initdb.d/database.sql
chown mysql:mysql -R /docker-entrypoint-initdb.d
fi
# --------------------------------------------------------------------------
# Setting permissions on config folder. (Contains resources folder)
chown "$HOST_USERNAME":"$HOST_GROUPNAME" -R /config
# ------------------------------------------------------------------
if [ -z "${FIVEM_LICENCE_KEY}" ]; then
echo "Licence key not found in environment, please create one at https://keymaster.fivem.net!"
exit 1
fi
# Making and setting permissions on txData folder ------
mkdir -p /txData
chown ${HOST_USERNAME}:${HOST_GROUPNAME} -R /txData
# -------------------------------------------------------
# Starting the sql database -----------------------------
/scripts/run.sh &
# -------------------------------------------------------
# Starting fiveM servrer --------------------------------
exec su "$HOST_USERNAME" -c "/opt/cfx-server/FXServer \
+set citizen_dir /opt/cfx-server/citizen/ \
+set serverProfile ${SERVER_PROFILE} \
+set txAdminPort ${TXADMIN_PORT} \
$@"
# -------------------------------------------------------