forked from TapeWerm/MCscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcbe_getzip.sh
executable file
·59 lines (53 loc) · 1.78 KB
/
mcbe_getzip.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
#!/usr/bin/env bash
# Exit if error
set -e
clobber=true
syntax='Usage: mcbe_getzip.sh [OPTION]...'
args=$(getopt -l help,no-clobber -o hn -- "$@")
eval set -- "$args"
while [ "$1" != -- ]; do
case $1 in
--help|-h)
echo "$syntax"
echo "If the ZIP of the current version isn't in ~, download it, and remove outdated ZIPs in ~."
echo
echo Mandatory arguments to long options are mandatory for short options too.
echo "-n, --no-clobber don't remove outdated ZIPs in ~"
exit
;;
--no-clobber|-n)
clobber=false
shift
;;
esac
done
shift
if [ "$#" -gt 0 ]; then
>&2 echo Too much arguments
>&2 echo "$syntax"
exit 1
fi
webpage=$(curl -A 'Mozilla/5.0 (X11; Linux x86_64)' -H 'Accept-Language: en-US' --compressed -LsS https://www.minecraft.net/en-us/download/server/bedrock)
url=$(echo "$webpage" | grep -Eo 'https://[^ ]+bin-linux/bedrock-server-[^ ]+\.zip' | head -n 1)
current_ver=$(basename "$url")
# ls fails if there's no match
installed_ver=$(ls ~/bedrock-server-*.zip 2> /dev/null || true)
# There might be more than one ZIP in ~
if ! echo "$installed_ver" | grep -q "$current_ver"; then
echo Enter Y if you agree to the Minecraft End User License Agreement and Privacy Policy
# Does prompting the EULA seem so official that it violates the EULA?
echo Minecraft End User License Agreement: https://minecraft.net/terms
echo Privacy Policy: https://go.microsoft.com/fwlink/?LinkId=521839
read -r input
input=$(echo "$input" | tr '[:upper:]' '[:lower:]')
if [ "$input" != y ]; then
>&2 echo "$input != y"
exit 1
fi
curl -A 'Mozilla/5.0 (X11; Linux x86_64)' -H 'Accept-Language: en-US' --compressed -LsS "$url" -o ~/"$current_ver".part
trap '' SIGTERM
mv ~/"$current_ver".part ~/"$current_ver"
if [ "$clobber" = true ]; then
echo "$installed_ver" | xargs -d '\n' rm -f
fi
fi