-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_bedrock.sh
executable file
·68 lines (56 loc) · 2.06 KB
/
update_bedrock.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
#!/bin/bash
# (c) 2020 Leif Sawyer
# License: GPL 3.0 (see https://github.com/akhepcat/)
# Permanent home: https://github.com/akhepcat/Miscellaneous/
# Direct download: https://raw.githubusercontent.com/akhepcat/Miscellaneous/master/update_bedrock.sh
#
#
# Simple in-dir minecraft server updater.
SOURCE="${BASH_SOURCE[0]}"
while [[ -h "$SOURCE" ]]
do
# resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
# if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
PDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd -P )"
## end
UA="Mozilla/5.0 (X11; Linux x86_64)"
echo "Grabbing URL..."
URL=$(curl -A "${UA}" --silent https://www.minecraft.net/en-us/download/server/bedrock | grep -i linux/bedrock-server | sed 's/.*href=//g;' | cut -f2 -d\")
FN=${URL##*/}
echo "File: ${FN}"
# make sure the requisite directories exist
mkdir -p "${PDIR}/updates/" "${PDIR}/CONFIG/"
if [ -r "${PDIR}/updates/${FN}" ]
then
echo "running at current version, no update needed"
else
if [ -n "$1" -a "$1" != "check" ]
then
echo "$0 - updates the minecraft server"
echo "$0 check - only checks for updates, does not apply them"
echo " no other args are accepted or required"
exit 1
elif [ "$1" = "check" ]
then
echo "Update check-only complete, please manually update"
exit 0
fi
echo "Fetching update: ${FN}"
wget --referer=https://www.minecraft.net/en-us/download/server/bedrock/ -O "${PDIR}/updates/${FN}" "${URL}"
if [ -z "$(pgrep bedrock_server)" ]
then
echo "backing up config files for ${server}"
cp permissions.json valid_known_packs.json whitelist.json server.properties "${PDIR}/CONFIGS/"
echo "unpacking update"
unzip "${PDIR}/updates/${FN}" -x permissions.json valid_known_packs.json whitelist.json server.properties
cp "${PDIR}/CONFIGS"/* .
chmod +x bedrock_server
else
echo "Stop the existing bedrock server before updating"
exit 1
fi
fi