@@ -6,30 +6,24 @@ set -eo pipefail
6
6
: " ${PREVIEW:= false} "
7
7
8
8
function isTrue() {
9
- case " ${1,,} " in
10
- true | on | 1)
11
- return 0
12
- ;;
13
- * )
14
- return 1
15
- ;;
16
- esac
9
+ [[ " ${1,,} " =~ ^(true| on| 1)$ ]] && return 0
10
+ return 1
17
11
}
18
12
19
13
function lookupVersion() {
20
14
platform=${1:? Missing required platform indicator}
21
15
16
+ # shellcheck disable=SC2034
22
17
for i in {1..3}; do
23
18
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 ' ' )
24
- if [[ ${DOWNLOAD_URL} ]]; then
25
- break 2
26
- fi
19
+ [[ -n " ${DOWNLOAD_URL} " ]] && break
27
20
sleep 1
28
21
done
29
22
if [[ -z ${DOWNLOAD_URL} ]]; then
30
23
DOWNLOAD_URL=$( curl -s https://mc-bds-helper.vercel.app/api/latest)
31
24
fi
32
25
26
+ # shellcheck disable=SC2012
33
27
if [[ ${DOWNLOAD_URL} =~ http.* /.* -(.* )\. zip ]]; then
34
28
VERSION=${BASH_REMATCH[1]}
35
29
elif [[ $( ls -rv bedrock_server-* 2> /dev/null| head -1) =~ bedrock_server-(.* ) ]]; then
@@ -49,7 +43,7 @@ function lookupVersion() {
49
43
rm -f restify.err
50
44
}
51
45
52
- if [[ ${DEBUG^^} = TRUE ]]; then
46
+ if [[ ${DEBUG^^} == TRUE ]]; then
53
47
set -x
54
48
curlArgs=(-v)
55
49
echo " DEBUG: running as $( id -a) with $( ls -ld /data) "
@@ -103,64 +97,63 @@ case ${VERSION^^} in
103
97
;;
104
98
esac
105
99
106
- if [ ! -f " bedrock_server-${VERSION} " ]; then
100
+ if [[ ! -f " bedrock_server-${VERSION} " ] ]; then
107
101
108
- if [[ ! ${DOWNLOAD_URL} ]]; then
102
+ if [[ -z " ${DOWNLOAD_URL} " ]]; then
109
103
binPath=bin-linux
110
- if isTrue " ${PREVIEW} " ; then
111
- binPath=bin-linux-preview
112
- fi
104
+ isTrue " ${PREVIEW} " && binPath+=" -preview"
113
105
DOWNLOAD_URL=" https://minecraft.azureedge.net/${binPath} /bedrock-server-${VERSION} .zip"
114
106
fi
115
107
116
108
[[ $TMP_DIR != /tmp ]] && mkdir -p " $TMP_DIR "
117
109
TMP_ZIP=" $TMP_DIR /$( basename " ${DOWNLOAD_URL} " ) "
118
110
119
111
echo " Downloading Bedrock server version ${VERSION} ..."
120
- if ! curl " ${curlArgs[@]} " -o " ${TMP_ZIP} " -fsSL ${DOWNLOAD_URL} ; then
112
+ if ! curl " ${curlArgs[@]} " -o " ${TMP_ZIP} " -fsSL " ${DOWNLOAD_URL} " ; then
121
113
echo " ERROR failed to download from ${DOWNLOAD_URL} "
122
114
echo " Double check that the given VERSION is valid"
123
115
exit 2
124
116
fi
125
117
126
118
# remove only binaries and some docs, to allow for an upgrade of those
127
- rm -rf bedrock_server bedrock_server-* * .so release-notes.txt bedrock_server_how_to.html valid_known_packs.json premium_cache 2> /dev/null
119
+ rm -rf -- bedrock_server bedrock_server-* * .so release-notes.txt bedrock_server_how_to.html valid_known_packs.json premium_cache 2> /dev/null
128
120
129
121
bkupDir=backup-pre-${VERSION}
130
122
# fixup any previous interrupted upgrades
131
123
rm -rf " ${bkupDir} "
132
124
for d in behavior_packs definitions minecraftpe resource_packs structures treatments world_templates; do
133
125
if [[ -d $d && -n " $( ls $d ) " ]]; then
134
- mkdir -p $ bkupDir /$d
126
+ mkdir -p " ${ bkupDir} /$d "
135
127
echo " Backing up $d into $bkupDir "
136
128
if [[ " $d " == " resource_packs" ]]; then
137
- mv $d /{chemistry,vanilla} $ bkupDir/
138
- [[ -n " $( ls $d ) " ]] && cp -a $d /* $ bkupDir/
129
+ mv $d /{chemistry,vanilla} " ${ bkupDir} / "
130
+ [[ -n " $( ls $d ) " ]] && cp -a $d /* " ${ bkupDir} / "
139
131
else
140
- mv $d /* $ bkupDir/
132
+ mv $d /* " ${ bkupDir} / "
141
133
fi
142
134
fi
143
135
done
144
136
145
137
# remove old package backups, but keep PACKAGE_BACKUP_KEEP
146
138
if (( ${PACKAGE_BACKUP_KEEP:= 2} >= 0 )) ; then
147
139
shopt -s nullglob
140
+ # shellcheck disable=SC2012
148
141
for d in $( ls -td1 backup-pre-* | tail +$(( PACKAGE_BACKUP_KEEP + 1 )) ) ; do
149
- echo " Pruning $d "
150
- rm -rf $d
142
+ echo " Pruning backup directory: $d "
143
+ rm -rf " $d "
151
144
done
152
145
fi
153
146
154
147
# Do not overwrite existing files, which means the cleanup above needs to account for things
155
148
# that MUST be replaced on upgrade
156
- unzip -q -n ${TMP_ZIP}
149
+ unzip -q -n " ${TMP_ZIP} "
157
150
[[ $TMP_DIR != /tmp ]] && rm -rf " $TMP_DIR "
158
151
159
152
chmod +x bedrock_server
160
- mv bedrock_server bedrock_server-${VERSION}
153
+ mv bedrock_server " bedrock_server-${VERSION} "
161
154
fi
162
155
163
- if [ -n " $OPS " ] || [ -n " $MEMBERS " ] || [ -n " $VISITORS " ]; then
156
+ if [[ -n " $OPS " || -n " $MEMBERS " || -n " $VISITORS " ] ]; then
164
157
echo " Updating permissions"
165
158
jq -n --arg ops " $OPS " --arg members " $MEMBERS " --arg visitors " $VISITORS " ' [
166
159
[$ops | split(",") | map({permission: "operator", xuid:.})],
@@ -185,16 +178,20 @@ else
185
178
ALLOW_LIST=false
186
179
rm -f allowlist.json
187
180
fi
188
- sed -i ' /^white-list=.*/d' server.properties # Removes white-list= line from server.properties
181
+
182
+ # prevent issue with bind mounted server.properties which can not be moved (sed tries to move the file when '-i' is used)
183
+ _SERVER_PROPERTIES=$( sed ' /^white-list=.*/d' server.properties) # Removes white-list= line from server.properties
184
+ echo " ${_SERVER_PROPERTIES} " > server.properties
189
185
export ALLOW_LIST
190
186
187
+ # update server.properties with environment settings
191
188
set-property --file server.properties --bulk /etc/bds-property-definitions.json
192
189
193
190
export LD_LIBRARY_PATH=.
194
191
195
192
echo " Starting Bedrock server..."
196
- if [ -f /usr/local/bin/box64 ] ; then
197
- exec box64 ./bedrock_server-${VERSION}
193
+ if [[ -f /usr/local/bin/box64 ] ] ; then
194
+ exec box64 ./" bedrock_server-${VERSION} "
198
195
else
199
- exec ./bedrock_server-${VERSION}
196
+ exec ./" bedrock_server-${VERSION} "
200
197
fi
0 commit comments