forked from simylein/minecraft-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
102 lines (81 loc) · 2.74 KB
/
update.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
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
#!/bin/bash
# minecraft server update script
# read server files
source server.settings
source server.functions
# parse arguments
ParseArgs "$@"
ArgHelp
# safety checks
RootSafety
ScriptSafety
# debug
Debug "executing $0 script"
# change to server directory
ChangeServerDirectory
# check for existence of executable
CheckExecutable
# look if server is running
CheckScreen
# prints countdown to screen
Countdown "updating"
# server stop
Stop
# awaits server stop
AwaitStop
# force quit server if not stopped
ForceQuit
# output confirmed stop
Log "ok" "server successfully stopped" "${screenLog}"
Print "ok" "server successfully stopped"
# create backup
CachedBackup "update"
# update from url
url="https://launcher.mojang.com/v1/objects/c9df48efed58511cdd0213c56b9013a7b5c9ac1f/server.jar"
version="1.19.3"
# Test internet connectivity and update on success
wget --spider --quiet "${url}"
if [ "$?" != 0 ]; then
Log "warn" "unable to connect to mojang api skipping update..." "${screenLog}"
Print "warn" "unable to connect to mojang api skipping update..."
else
Log "action" "downloading newest server version..." "${screenLog}"
Print "action" "downloading newest server version..."
# check if already on newest version
if [[ "${executableServerFile}" = *"minecraft-server.${version}.jar" ]]; then
Log "info" "you are running the newest server version - skipping update" "${screenLog}"
Print "info" "you are running the newest server version - skipping update"
else
wget -q -O "minecraft-server.${version}.jar" "${url}"
# update server-file variable in server.settings
newExecutableServerFile="${serverDirectory}/minecraft-server.${version}.jar"
# if new server-file exists remove old server-file
if [ -s "${newExecutableServerFile}" ]; then
Log "ok" "download successful"
Print "ok" "download successful"
Log "info" "updating server.settings for startup with new server version ${version}" "${screenLog}"
Print "info" "updating server.settings for startup with new server version ${version}"
sed -i "s|${executableServerFile}|${newExecutableServerFile}|g" "server.settings"
# remove old server-file if it exists
if [ -s "${executableServerFile}" ]; then
rm "${executableServerFile}"
fi
else
Print "warn" "could not remove old server-file ${executableServerFile} because new server-file ${newExecutableServerFile} is missing"
Print "info" "server will startup with old server-file ${executableServerFile}"
fi
fi
fi
# remove scripts from server-directory
RemoveScripts
# downloading scripts from github
DownloadScripts
# make selected scripts executable
ExecutableScripts
# restart the server
Print "action" "restarting server..."
./start.sh --force "$@"
# log to debug if true
Debug "executed $0 script"
# exit with code 0
exit 0