-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStart-Server.ps1
66 lines (56 loc) · 2.32 KB
/
Start-Server.ps1
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
Write-Host "---------------------------------------------"
Write-Host " Server Launcher - v0.2"
Write-Host "---------------------------------------------"
Write-Host "This script runs the latest snapshot/release."
Write-Host "When the server is shutdown, the script will "
Write-Host "update the server, and start it back up asap."
Write-Host "This script also can be used to install a new"
Write-Host "server instance."
Write-Host "---------------------------------------------"
Write-Host " https://github.com/demon2749"
Write-Host "---------------------------------------------"
while (1 -eq 1)
{
if (Test-Path server.jar)
{
Write-Host "Starting the minecraft server..."
java -Xmx2G -jar server.jar -nogui
}else{
Write-Host "The server will be installed. Press Ctrl+C to Cancel."
timeout /t 8
}
$versions =
Invoke-WebRequest https://launchermeta.mojang.com/mc/game/version_manifest.json |
Select-Object -ExpandProperty Content |
ConvertFrom-Json | Select-Object -ExpandProperty versions
$newest = $versions[0]
$link = $newest | Select-Object -ExpandProperty url | Out-String
$newVer =
Invoke-WebRequest $link | Select-Object -ExpandProperty Content |
ConvertFrom-Json | Select-Object -ExpandProperty downloads |
Select-Object -ExpandProperty server
$sha = $newVer | Select-Object -ExpandProperty sha1 | Out-String
$download = $newVer | Select-Object -ExpandProperty url | Out-String
if (Test-Path server.jar)
{
$currentSHA = Get-FileHash -Algorithm SHA1 -Path server.jar |
Select-Object -ExpandProperty Hash | Out-String
$sha = $sha.ToUpper()
if ($sha -eq $currentSHA)
{
Write-Host "No need for an update!"
}else{
Remove-Item -Path server.jar
Write-Host "Downloading server update..."
Invoke-WebRequest $download -OutFile server.jar
}
}else{
Write-Host "Downloading server files..."
Invoke-WebRequest $download -OutFile server.jar
Write-Host "Creating Eula.txt..."
Remove-Item -Path eula.txt
New-Item -Name eula.txt -Value "eula=true"
}
Write-Host "Server will start shortly. Press Ctrl+C to stop, or any key to skip the wait."
timeout /t 5
}