forked from itzg/docker-minecraft-bedrock-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bedrock-entry.sh
executable file
·192 lines (167 loc) · 5 KB
/
bedrock-entry.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
set -eo pipefail
: "${TMP_DIR:=/tmp}"
: "${PREVIEW:=false}"
function isTrue() {
case "${1,,}" in
true | on | 1)
return 0
;;
*)
return 1
;;
esac
}
function lookupVersion() {
platform=${1:?Missing required platform indicator}
for i in {1..3}; do
DOWNLOAD_URL=$(restify --user-agent=itzg/minecraft-bedrock-server --headers "accept-language:*" --attribute=data-platform="${platform}" "${downloadPage}" 2> restify.err | jq -r '.[0].href' || echo '')
if [[ ${DOWNLOAD_URL} ]]; then
break 2
fi
sleep 1
done
if [[ -z ${DOWNLOAD_URL} ]]; then
DOWNLOAD_URL=$(curl -s https://mc-bds-helper.vercel.app/api/latest)
fi
if [[ ${DOWNLOAD_URL} =~ http.*/.*-(.*)\.zip ]]; then
VERSION=${BASH_REMATCH[1]}
elif [[ $(ls -rv bedrock_server-* 2> /dev/null|head -1) =~ bedrock_server-(.*) ]]; then
VERSION=${BASH_REMATCH[1]}
echo "WARN Minecraft download page failed, so using existing download of $VERSION"
cat restify.err
else
if [[ -f restify.err ]]; then
echo "Failed to extract download URL '${DOWNLOAD_URL}' from ${downloadPage}"
cat restify.err
rm restify.err
else
echo "Failed to lookup download URL: ${DOWNLOAD_URL}"
fi
exit 2
fi
rm -f restify.err
}
if [[ ${DEBUG^^} = TRUE ]]; then
set -x
curlArgs=(-v)
echo "DEBUG: running as $(id -a) with $(ls -ld /data)"
echo " current directory is $(pwd)"
fi
downloadPage=https://www.minecraft.net/en-us/download/server/bedrock
if [[ ${EULA^^} != TRUE ]]; then
echo
echo "EULA must be set to TRUE to indicate agreement with the Minecraft End User License"
echo "See https://minecraft.net/terms"
echo
echo "Current value is '${EULA}'"
echo
exit 1
fi
case ${VERSION^^} in
1.12)
VERSION=1.12.0.28
;;
1.13)
VERSION=1.13.0.34
;;
1.14)
VERSION=1.14.60.5
;;
1.16)
VERSION=1.16.20.03
;;
1.17)
VERSION=1.17.41.01
;;
1.17.41)
VERSION=1.17.41.01
;;
1.18|PREVIOUS)
VERSION=1.18.33.02
;;
PREVIEW)
echo "Looking up latest preview version..."
lookupVersion serverBedrockPreviewLinux
;;
LATEST)
echo "Looking up latest version..."
lookupVersion serverBedrockLinux
;;
*)
# use the given version exactly
;;
esac
if [ ! -f "bedrock_server-${VERSION}" ]; then
if [[ ! ${DOWNLOAD_URL} ]]; then
binPath=bin-linux
if isTrue "${PREVIEW}"; then
binPath=bin-linux-preview
fi
DOWNLOAD_URL="https://minecraft.azureedge.net/${binPath}/bedrock-server-${VERSION}.zip"
fi
[[ $TMP_DIR != /tmp ]] && mkdir -p "$TMP_DIR"
TMP_ZIP="$TMP_DIR/$(basename "${DOWNLOAD_URL}")"
echo "Downloading Bedrock server version ${VERSION} ..."
if ! curl "${curlArgs[@]}" -o "${TMP_ZIP}" -fsSL ${DOWNLOAD_URL}; then
echo "ERROR failed to download from ${DOWNLOAD_URL}"
echo " Double check that the given VERSION is valid"
exit 2
fi
# remove only binaries and some docs, to allow for an upgrade of those
rm -rf bedrock_server bedrock_server-* *.so release-notes.txt bedrock_server_how_to.html valid_known_packs.json premium_cache 2> /dev/null
bkupDir=backup-pre-${VERSION}
# fixup any previous interrupted upgrades
rm -rf "${bkupDir}"
for d in behavior_packs definitions minecraftpe resource_packs structures treatments world_templates
do
if [ -d $d ]; then
mkdir -p $bkupDir
echo "Backing up $d into $bkupDir"
mv $d $bkupDir
fi
done
# remove old package backups, but keep PACKAGE_BACKUP_KEEP
if (( ${PACKAGE_BACKUP_KEEP:=2} >= 0 )); then
shopt -s nullglob
for d in $( ls -td1 backup-pre-* | tail +$(( PACKAGE_BACKUP_KEEP + 1 )) ); do
echo "Pruning $d"
rm -rf $d
done
fi
# Do not overwrite existing files, which means the cleanup above needs to account for things
# that MUST be replaced on upgrade
unzip -q -n ${TMP_ZIP}
[[ $TMP_DIR != /tmp ]] && rm -rf "$TMP_DIR"
chmod +x bedrock_server
mv bedrock_server bedrock_server-${VERSION}
fi
if [ -n "$OPS" ] || [ -n "$MEMBERS" ] || [ -n "$VISITORS" ]; then
echo "Updating permissions"
jq -n --arg ops "$OPS" --arg members "$MEMBERS" --arg visitors "$VISITORS" '[
[$ops | split(",") | map({permission: "operator", xuid:.})],
[$members | split(",") | map({permission: "member", xuid:.})],
[$visitors | split(",") | map({permission: "visitor", xuid:.})]
]| flatten' > permissions.json
fi
allowListUsers=${ALLOW_LIST_USERS:-${WHITE_LIST_USERS}}
if [ -n "$allowListUsers" ]; then
echo "Setting allow list"
for f in whitelist.json allowlist.json; do
if [ -f $f ]; then
rm -rf $f
fi
jq -n --arg users "$allowListUsers" '$users | split(",") | map({"name": .})' > $f
done
# activate server property to enable list usage
export WHITE_LIST=true
export ALLOW_LIST=true
fi
set-property --file server.properties --bulk /etc/bds-property-definitions.json
export LD_LIBRARY_PATH=.
echo "Starting Bedrock server..."
if [ -f /usr/local/bin/box64 ] ; then
exec box64 ./bedrock_server-${VERSION}
else
exec ./bedrock_server-${VERSION}
fi