-
Notifications
You must be signed in to change notification settings - Fork 8
/
entrypoint.sh
executable file
·108 lines (86 loc) · 4.09 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
#!/usr/bin/env bash
set -e
if ! [ -z "${MTA_DOCKER_ENTRYPOINT_DEBUG}" ]; then
set -x
fi;
readonly BASECONFIG_DIR="${MTA_SERVER_ROOT_DIR}/.default/baseconfig"
readonly DATA_DIR="${MTA_SERVER_ROOT_DIR}/mods/deathmatch"
readonly MTA_SERVER_CONFIG_FILE_PATH="${DATA_DIR}/${MTA_SERVER_CONFIG_FILE_NAME}"
DEFAULT_RESOURCES_ROOT_DIR="/resources"
if ! [ -z "${MTA_DEFAULT_RESOURCES_SUBDIRECTORY_NAME}" ]; then
DEFAULT_RESOURCES_ROOT_DIR="${DEFAULT_RESOURCES_ROOT_DIR}/${MTA_DEFAULT_RESOURCES_SUBDIRECTORY_NAME}"
fi;
main() {
if [ -L "${DATA_DIR}/resources" ]; then
unlink "${DATA_DIR}/resources"
fi;
if [ -L "${DATA_DIR}/resource-cache" ]; then
unlink "${DATA_DIR}/resource-cache"
fi;
if [ -f "${DATA_DIR}/resources" ] || [ -d "${DATA_DIR}/resources" ]; then
echo "Forbidden file or directory name (resources) in /data volume. Remove or rename it in order to run this container."
exit 1
fi;
if [ -f ${DATA_DIR}/resource-cache ] || [ -d ${DATA_DIR}/resource-cache ]; then
echo "Forbidden file or directory name (resource-cache) in /data volume. Remove or rename it in order to run this container."
exit 1
fi;
if ! [[ -f "${DATA_DIR}/acl.xml" ]]; then
cp "${BASECONFIG_DIR}/acl.xml" "${DATA_DIR}/acl.xml"
fi;
if ! [[ -f "${MTA_SERVER_CONFIG_FILE_PATH}" ]]; then
cp "${BASECONFIG_DIR}/mtaserver.conf" "${MTA_SERVER_CONFIG_FILE_PATH}"
fi;
if ! [[ -f "${DATA_DIR}/vehiclecolors.conf" ]]; then
cp "${BASECONFIG_DIR}/vehiclecolors.conf" "${DATA_DIR}/vehiclecolors.conf"
fi;
if ! [ "$(ls -A ${DEFAULT_RESOURCES_ROOT_DIR})" ]; then
echo "Downloading latest official resources package..."
wget "${MTA_DEFAULT_RESOURCES_URL}" -O /tmp/mtasa-resources-latest.zip
unzip /tmp/mtasa-resources-latest.zip -d "${DEFAULT_RESOURCES_ROOT_DIR}"
rm /tmp/mtasa-resources-latest.zip
fi;
if [ "$(ls -A /native-modules/*.so)" ]; then
echo "Copying native modules..."
cp -vf /native-modules/*.so "${MTA_SERVER_ROOT_DIR}/x64/modules"
fi;
if [ -z "${MTA_SERVER_PASSWORD_REPLACE_POLICY}" ]; then
MTA_SERVER_PASSWORD_REPLACE_POLICY="when-empty"
fi;
escaped_password="$(echo "${MTA_SERVER_PASSWORD}" | sed 's~#~\\#~g; s#&#\\\&\\;#g; s#<#\\\<\\;#g; s#>#\\\>\\;#g; s#"#\\\"\\;#g; s#'"'"'#\\\&apos\\;#g')"
checksum_before="$(md5sum "${MTA_SERVER_CONFIG_FILE_PATH}")"
echo "Password replace policy is: ${MTA_SERVER_PASSWORD_REPLACE_POLICY}"
case "${MTA_SERVER_PASSWORD_REPLACE_POLICY}" in
when-empty)
if ! [ -z "${MTA_SERVER_PASSWORD}" ]; then
sed -i 's#\(<password>\)[ ]*\(</password>\)#\1'"${escaped_password}"'\2#g' "${MTA_SERVER_CONFIG_FILE_PATH}"
else
echo "MTA_SERVER_PASSWORD is not set, skipping"
fi;
;;
unless-empty)
sed -i 's#\(<password>\)[^<]\{1,\}\(</password>\)#\1'"${escaped_password}"'\2#g' "${MTA_SERVER_CONFIG_FILE_PATH}"
;;
always)
sed -i 's#\(<password>\)[^<]*\(</password>\)#\1'"${escaped_password}"'\2#g' "${MTA_SERVER_CONFIG_FILE_PATH}"
;;
*)
echo "Unsupported password replace policy: ${MTA_SERVER_PASSWORD_REPLACE_POLICY}"
echo "Accepted values for MTA_SERVER_PASSWORD_REPLACE_POLICY are:"
echo " - 'always' (always replace password in config file)"
echo " - 'unless-empty' (replace password only if it's already set in config file)"
echo " - 'when-empty' (default - replace password only if it's not set in config file)"
exit 1
;;
esac
checksum_after="$(md5sum "${MTA_SERVER_CONFIG_FILE_PATH}")"
if [ "${checksum_before}" = "${checksum_after}" ]; then
echo "Password HAS NOT been replaced!"
else
echo "Password has been replaced!"
fi;
ln -sf /resources "${DATA_DIR}/resources"
ln -sf /resource-cache "${DATA_DIR}/resource-cache"
"${MTA_SERVER_ROOT_DIR}/mta-server64" --config "${MTA_SERVER_CONFIG_FILE_NAME}" $@
}
main $@