improves bedrock-entry.sh to pass shellcheck (#365)
This commit is contained in:
1 parent
0110314e64
commit
4631a42bbb
1 file changed
+29
-32
+29
-32
@@ -6,30 +6,24 @@ set -eo pipefail
|
|||||||
: "${PREVIEW:=false}"
|
: "${PREVIEW:=false}"
|
||||||
|
|
||||||
function isTrue() {
|
function isTrue() {
|
||||||
case "${1,,}" in
|
[[ "${1,,}" =~ ^(true|on|1)$ ]] && return 0
|
||||||
true | on | 1)
|
return 1
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function lookupVersion() {
|
function lookupVersion() {
|
||||||
platform=${1:?Missing required platform indicator}
|
platform=${1:?Missing required platform indicator}
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
for i in {1..3}; do
|
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 '')
|
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
|
[[ -n "${DOWNLOAD_URL}" ]] && break
|
||||||
break 2
|
|
||||||
fi
|
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
if [[ -z ${DOWNLOAD_URL} ]]; then
|
if [[ -z ${DOWNLOAD_URL} ]]; then
|
||||||
DOWNLOAD_URL=$(curl -s https://mc-bds-helper.vercel.app/api/latest)
|
DOWNLOAD_URL=$(curl -s https://mc-bds-helper.vercel.app/api/latest)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# shellcheck disable=SC2012
|
||||||
if [[ ${DOWNLOAD_URL} =~ http.*/.*-(.*)\.zip ]]; then
|
if [[ ${DOWNLOAD_URL} =~ http.*/.*-(.*)\.zip ]]; then
|
||||||
VERSION=${BASH_REMATCH[1]}
|
VERSION=${BASH_REMATCH[1]}
|
||||||
elif [[ $(ls -rv bedrock_server-* 2> /dev/null|head -1) =~ bedrock_server-(.*) ]]; then
|
elif [[ $(ls -rv bedrock_server-* 2> /dev/null|head -1) =~ bedrock_server-(.*) ]]; then
|
||||||
@@ -49,7 +43,7 @@ function lookupVersion() {
|
|||||||
rm -f restify.err
|
rm -f restify.err
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ ${DEBUG^^} = TRUE ]]; then
|
if [[ ${DEBUG^^} == TRUE ]]; then
|
||||||
set -x
|
set -x
|
||||||
curlArgs=(-v)
|
curlArgs=(-v)
|
||||||
echo "DEBUG: running as $(id -a) with $(ls -ld /data)"
|
echo "DEBUG: running as $(id -a) with $(ls -ld /data)"
|
||||||
@@ -103,13 +97,11 @@ case ${VERSION^^} in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ ! -f "bedrock_server-${VERSION}" ]; then
|
if [[ ! -f "bedrock_server-${VERSION}" ]]; then
|
||||||
|
|
||||||
if [[ ! ${DOWNLOAD_URL} ]]; then
|
if [[ -z "${DOWNLOAD_URL}" ]]; then
|
||||||
binPath=bin-linux
|
binPath=bin-linux
|
||||||
if isTrue "${PREVIEW}"; then
|
isTrue "${PREVIEW}" && binPath+="-preview"
|
||||||
binPath=bin-linux-preview
|
|
||||||
fi
|
|
||||||
DOWNLOAD_URL="https://minecraft.azureedge.net/${binPath}/bedrock-server-${VERSION}.zip"
|
DOWNLOAD_URL="https://minecraft.azureedge.net/${binPath}/bedrock-server-${VERSION}.zip"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -117,27 +109,27 @@ if [ ! -f "bedrock_server-${VERSION}" ]; then
|
|||||||
TMP_ZIP="$TMP_DIR/$(basename "${DOWNLOAD_URL}")"
|
TMP_ZIP="$TMP_DIR/$(basename "${DOWNLOAD_URL}")"
|
||||||
|
|
||||||
echo "Downloading Bedrock server version ${VERSION} ..."
|
echo "Downloading Bedrock server version ${VERSION} ..."
|
||||||
if ! curl "${curlArgs[@]}" -o "${TMP_ZIP}" -fsSL ${DOWNLOAD_URL}; then
|
if ! curl "${curlArgs[@]}" -o "${TMP_ZIP}" -fsSL "${DOWNLOAD_URL}"; then
|
||||||
echo "ERROR failed to download from ${DOWNLOAD_URL}"
|
echo "ERROR failed to download from ${DOWNLOAD_URL}"
|
||||||
echo " Double check that the given VERSION is valid"
|
echo " Double check that the given VERSION is valid"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# remove only binaries and some docs, to allow for an upgrade of those
|
# 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
|
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}
|
bkupDir=backup-pre-${VERSION}
|
||||||
# fixup any previous interrupted upgrades
|
# fixup any previous interrupted upgrades
|
||||||
rm -rf "${bkupDir}"
|
rm -rf "${bkupDir}"
|
||||||
for d in behavior_packs definitions minecraftpe resource_packs structures treatments world_templates; do
|
for d in behavior_packs definitions minecraftpe resource_packs structures treatments world_templates; do
|
||||||
if [[ -d $d && -n "$(ls $d)" ]]; then
|
if [[ -d $d && -n "$(ls $d)" ]]; then
|
||||||
mkdir -p $bkupDir/$d
|
mkdir -p "${bkupDir}/$d"
|
||||||
echo "Backing up $d into $bkupDir"
|
echo "Backing up $d into $bkupDir"
|
||||||
if [[ "$d" == "resource_packs" ]]; then
|
if [[ "$d" == "resource_packs" ]]; then
|
||||||
mv $d/{chemistry,vanilla} $bkupDir/
|
mv $d/{chemistry,vanilla} "${bkupDir}/"
|
||||||
[[ -n "$(ls $d)" ]] && cp -a $d/* $bkupDir/
|
[[ -n "$(ls $d)" ]] && cp -a $d/* "${bkupDir}/"
|
||||||
else
|
else
|
||||||
mv $d/* $bkupDir/
|
mv $d/* "${bkupDir}/"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -145,22 +137,23 @@ if [ ! -f "bedrock_server-${VERSION}" ]; then
|
|||||||
# remove old package backups, but keep PACKAGE_BACKUP_KEEP
|
# remove old package backups, but keep PACKAGE_BACKUP_KEEP
|
||||||
if (( ${PACKAGE_BACKUP_KEEP:=2} >= 0 )); then
|
if (( ${PACKAGE_BACKUP_KEEP:=2} >= 0 )); then
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
# shellcheck disable=SC2012
|
||||||
for d in $( ls -td1 backup-pre-* | tail +$(( PACKAGE_BACKUP_KEEP + 1 )) ); do
|
for d in $( ls -td1 backup-pre-* | tail +$(( PACKAGE_BACKUP_KEEP + 1 )) ); do
|
||||||
echo "Pruning $d"
|
echo "Pruning backup directory: $d"
|
||||||
rm -rf $d
|
rm -rf "$d"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Do not overwrite existing files, which means the cleanup above needs to account for things
|
# Do not overwrite existing files, which means the cleanup above needs to account for things
|
||||||
# that MUST be replaced on upgrade
|
# that MUST be replaced on upgrade
|
||||||
unzip -q -n ${TMP_ZIP}
|
unzip -q -n "${TMP_ZIP}"
|
||||||
[[ $TMP_DIR != /tmp ]] && rm -rf "$TMP_DIR"
|
[[ $TMP_DIR != /tmp ]] && rm -rf "$TMP_DIR"
|
||||||
|
|
||||||
chmod +x bedrock_server
|
chmod +x bedrock_server
|
||||||
mv bedrock_server bedrock_server-${VERSION}
|
mv bedrock_server "bedrock_server-${VERSION}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$OPS" ] || [ -n "$MEMBERS" ] || [ -n "$VISITORS" ]; then
|
if [[ -n "$OPS" || -n "$MEMBERS" || -n "$VISITORS" ]]; then
|
||||||
echo "Updating permissions"
|
echo "Updating permissions"
|
||||||
jq -n --arg ops "$OPS" --arg members "$MEMBERS" --arg visitors "$VISITORS" '[
|
jq -n --arg ops "$OPS" --arg members "$MEMBERS" --arg visitors "$VISITORS" '[
|
||||||
[$ops | split(",") | map({permission: "operator", xuid:.})],
|
[$ops | split(",") | map({permission: "operator", xuid:.})],
|
||||||
@@ -185,16 +178,20 @@ else
|
|||||||
ALLOW_LIST=false
|
ALLOW_LIST=false
|
||||||
rm -f allowlist.json
|
rm -f allowlist.json
|
||||||
fi
|
fi
|
||||||
sed -i '/^white-list=.*/d' server.properties #Removes white-list= line from server.properties
|
|
||||||
|
# prevent issue with bind mounted server.properties which can not be moved (sed tries to move the file when '-i' is used)
|
||||||
|
_SERVER_PROPERTIES=$(sed '/^white-list=.*/d' server.properties) #Removes white-list= line from server.properties
|
||||||
|
echo "${_SERVER_PROPERTIES}" > server.properties
|
||||||
export ALLOW_LIST
|
export ALLOW_LIST
|
||||||
|
|
||||||
|
# update server.properties with environment settings
|
||||||
set-property --file server.properties --bulk /etc/bds-property-definitions.json
|
set-property --file server.properties --bulk /etc/bds-property-definitions.json
|
||||||
|
|
||||||
export LD_LIBRARY_PATH=.
|
export LD_LIBRARY_PATH=.
|
||||||
|
|
||||||
echo "Starting Bedrock server..."
|
echo "Starting Bedrock server..."
|
||||||
if [ -f /usr/local/bin/box64 ] ; then
|
if [[ -f /usr/local/bin/box64 ]] ; then
|
||||||
exec box64 ./bedrock_server-${VERSION}
|
exec box64 ./"bedrock_server-${VERSION}"
|
||||||
else
|
else
|
||||||
exec ./bedrock_server-${VERSION}
|
exec ./"bedrock_server-${VERSION}"
|
||||||
fi
|
fi
|
||||||
Reference in new issue
Block a user