-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdateserver.sh
89 lines (81 loc) · 2.76 KB
/
updateserver.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
#!/bin/bash
#Configuration
## Download locations for different architectures.
X86LOC="http://builds.cuberite.org/job/Cuberite%20Linux%20x86%20Master/lastSuccessfulBuild/artifact/Cuberite.tar.gz"
X64LOC="http://builds.cuberite.org/job/Cuberite%20Linux%20x64%20Master/lastSuccessfulBuild/artifact/Cuberite.tar.gz"
ARMLOC="http://builds.cuberite.org/job/Cuberite%20Linux%20raspi-armhf%20Master/lastSuccessfulBuild/artifact/Cuberite.tar.gz"
X86LOCSHA="http://builds.cuberite.org/job/Cuberite%20Linux%20x86%20Master/lastSuccessfulBuild/artifact/Cuberite.tar.gz.sha1"
X64LOCSHA="http://builds.cuberite.org/job/Cuberite%20Linux%20x64%20Master/lastSuccessfulBuild/artifact/Cuberite.tar.gz.sha1"
ARMLOCSHA="http://builds.cuberite.org/job/Cuberite%20Linux%20raspi-armhf%20Master/lastSuccessfulBuild/artifact/Cuberite.tar.gz.sha1"
## Cuberite Directory
CUBERITEDIR="cuberite/"
## Cache Directory
CACHEDIR=".cuberiteupdate/"
# Define the download and extract function.
download() {
# Download the current archive.
echo "Downloading Cuberite..."
wget --quiet $ARCHLOC -O $CACHEDIR"Cuberite.tar.gz"
# Find out the current Cuberite process and kill it.
pid=`pgrep -o -x Cuberite`
kill -s 15 $pid 2>/dev/null
# Extract the archive, clean up, and start the server.
echo "Extracting downloaded archive..."
tar -xf $CACHEDIR"Cuberite.tar.gz"
echo "Copying new files..."
cp -r "Cuberite/Plugins" $CUBERITEDIR
cp -r "Cuberite/webadmin" $CUBERITEDIR
cp "Cuberite/monsters.ini" $CUBERITEDIR
cp "Cuberite/items.ini" $CUBERITEDIR
cp "Cuberite/crafting.txt" $CUBERITEDIR
cp "Cuberite/furnace.txt" $CUBERITEDIR
cp "Cuberite/Cuberite" $CUBERITEDIR
rm -r "Cuberite"
cd $CUBERITEDIR
screen ./Cuberite
# Nothing more is needed from the script, exit.
echo "Updated successfully!"
exit
}
# Work out the current architecture and store it.
CURRENTARCH=`uname -m`
if [ $CURRENTARCH == "i686" ]
then
ARCHLOC=$X86LOC
ARCHLOCSHA=$X86LOCSHA
elif [ $CURRENTARCH == "x86_64" ]
then
ARCHLOC=$X64LOC
ARCHLOCSHA=$X64LOCSHA
elif [ $CURRENTARCH == "armv6l" ]
then
ARCHLOC=$ARMLOC
ARCHLOCSHA=$ARMLOCSHA
else
echo "Arch not recognised. Please file a bug report with the output from uname -m and your machine type."
exit
fi
# Make sure the specified Cuberite directory exists.
if [ ! -d $CUBERITEDIR ]
then
# Make the directory.
mkdir $CUBERITEDIR
fi
# Check if the cache directory exists.
if [ ! -d $CACHEDIR ]
then
mkdir $CACHEDIR
download
fi
# Donwload thesha1 sum from the buildserver and check it against the current tar.
wget --quiet $ARCHLOCSHA -O $CACHEDIR"Cuberite.tar.gz.sha1"
cd $CACHEDIR
sha1sum -c --status "Cuberite.tar.gz.sha1"
rc=$?
if [ $rc != 0 ]
then
cd ..
# We don't have the most updated Cuberite version, update now.
download
fi
echo "Cuberite up to date, quitting!"