-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateMinecraftServer.sh
More file actions
130 lines (120 loc) · 4.95 KB
/
Copy pathupdateMinecraftServer.sh
File metadata and controls
130 lines (120 loc) · 4.95 KB
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
#!/bin/bash
#######################################################
# Update Minecraft Bedrock (C++)/Java Server on Linux #
#######################################################
function usage(){
echo "Usage:"
echo "updateMinecraftServer.sh -o <old_version_tag> [-n <new_version_tag>] [-t <type>]"
echo ' -n <new_version_tag> new version tag update to (default will be newest tag)'
echo ' -t <type> type "bedrock" for bedrock, type "java" for java server (default "Java")'
exit 0
}
function update(){
url=""
# is new tag specified otherwise take newest server version
if [[ -z $newtag ]]
then
if [[ $servertype == "java" ]]
then
# extract version and sha1 from .json file
newtag=$(cat java_version_latest.json | grep version | cut -d: -f2 | xargs)
hashsha1=$(cat java_version_latest.json | grep sha1 | cut -d: -f2 | xargs)
else
url=https://net-secondary.web.minecraft-services.net/api/v1.0/download/links
newtag=$(curl $url -s -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36' | grep -Eo "bin-linux/bedrock-server-[0-9,\.]+" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
fi
fi
# main routine
echo -e "\e[33mUpdating Minecraft $servertype Server\e[0m"
echo -e "\e[33mCurrent version: $oldtag\e[0m"
echo -e "\e[33mPlanned version: $newtag\e[0m"
# Download new version
echo -e "\e[33mDownloading...\e[0m"
if [[ $servertype == "bedrock" ]]
then
download=https://www.minecraft.net/bedrockdedicatedserver/bin-linux/bedrock-server-${newtag}.zip
wget --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" -P ~/Downloads $download
else
# new variant: extract current version from .json file
download=https://piston-data.mojang.com/v1/objects/${hashsha1}/server.jar
wget --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" -P ~/Downloads ${download}
fi
# unzip it and remove the download file
echo -e "\e[33mExtracting...\e[0m"
if [[ $servertype == "bedrock" ]]
then
unzip ~/Downloads/bedrock-server-$newtag.zip -d ~/Desktop/MinecraftBedrock-$newtag/
rm ~/Downloads/bedrock-server-$newtag.zip
else
mkdir -p ~/Desktop/MinecraftJava-$newtag/
mv ~/Downloads/server.jar ~/Desktop/MinecraftJava-$newtag/
# for java one has to start the server once
echo -e "\e[33mOne time start for Minecraft Server\e[0m"
cd ~/Desktop/MinecraftJava-$newtag/
java -Xmx4G -Xms1024M -jar server.jar nogui
echo -e "\e[33mAccepting eula.txt\e[0m"
sed -i s/false/true/g eula.txt
fi
echo -e "\e[33mNew properties file:\e[0m"
diff -u --color ~/Desktop/Minecraft${servertype^}-$oldtag/server.properties ~/Desktop/Minecraft${servertype^}-$newtag/server.properties
read -p $'\e[33mAccept to merge properties file manually [y/n]?\e[0m ' SERVPROP
if [ $SERVPROP == "y" ]
then
# copy old files to new server
echo ""
echo -e "\e[33mCopying worlds and packs...\e[0m"
cp ~/Desktop/Minecraft${servertype^}-$oldtag/whitelist.json ~/Desktop/Minecraft${servertype^}-$newtag/
if [[ $servertype == "bedrock" ]]
then
cp ~/Desktop/Minecraft${servertype^}-$oldtag/permissions.json ~/Desktop/Minecraft${servertype^}-$newtag/
cp -r ~/Desktop/Minecraft${servertype^}-$oldtag/worlds ~/Desktop/Minecraft${servertype^}-$newtag/
cp -r ~/Desktop/Minecraft${servertype^}-$oldtag/resource_packs/SweetDreamsShader2.0 ~/Desktop/Minecraft${servertype^}-$newtag/resource_packs/
cp ~/Desktop/Minecraft${servertype^}-$oldtag/howto.txt ~/Desktop/Minecraft${servertype^}-$newtag/
else
cp ~/Desktop/Minecraft${servertype^}-$oldtag/ops.json ~/Desktop/Minecraft${servertype^}-$newtag/
cp ~/Desktop/Minecraft${servertype^}-$oldtag/usercache.json ~/Desktop/Minecraft${servertype^}-$newtag/
cp -r ~/Desktop/Minecraft${servertype^}-$oldtag/SandysWorld ~/Desktop/Minecraft${servertype^}-$newtag/
cp ~/Desktop/Minecraft${servertype^}-$oldtag/start.sh ~/Desktop/Minecraft${servertype^}-$newtag/
fi
### move this manually due to frequent changes
# cp ~/Desktop/Minecraft${servertype^}-$oldtag/server.properties ~/Desktop/Minecraft${servertype^}-$newtag/
echo -e "\e[33mUpdate successfull! Reminder: Change properties file manually!\e[0m"
else
echo "Update process canceled."
rm -r ~/Desktop/Minecraft${servertype^}-$newtag/
fi
}
hasOldTag=false
isH=false
while getopts 'ht:o:n:' OPTION; do
case "$OPTION" in
h)
isH=true
;;
t)
servertype="$OPTARG"
if [[ $servertype != "java" ]] && [[ $servertype != "bedrock" ]]
then
echo "Update process canceled. $servertype is not a correct server type."
exit 1
fi
;;
o)
oldtag="$OPTARG"
hasOldTag=true
;;
n)
newtag="$OPTARG"
;;
?)
usage
;;
esac
done
shift "$(($OPTIND -1))"
if ( [[ $OPTIND -eq 1 ]] && ! $isH ) || ! $hasOldTag
then
usage
else
update
fi