-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-forge.ps1
170 lines (131 loc) · 5.47 KB
/
install-forge.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Stop script on error
$ErrorActionPreference = "Stop"
# Usage: .\install-forge.ps1 <forge-jar-file> <Monifactory-server-zip>
# Check if the correct number of arguments are provided
if ($args.Count -ne 2) {
Write-Host "Usage: .\install-forge.ps1 <forge-jar-file> <Monifactory-server-zip>"
exit 1
}
$forgeJarFile = $args[0]
$serverZipFile = $args[1]
# Check if the destination directory exists
if (Test-Path -Path "server") {
# Remove the existing directory
Remove-Item -Path "server" -Recurse -Force
}
# Create "server" directory if it doesn't exist
if (-Not (Test-Path -Path "server")) {
New-Item -ItemType Directory -Path "server"
}
# Copy the forge jar file into the server directory
Copy-Item -Path $forgeJarFile -Destination "server/forge.jar"
Set-Location -Path "server"
# Execute java -jar TheForgeInstallerName.jar --installServer
& java -jar forge.jar --installServer
Set-Location -Path ".."
# Check if the temp directory exists
if (Test-Path -Path "temp") {
# Remove the existing directory
Remove-Item -Path "temp" -Recurse -Force
}
# Create temp directory
if (-Not (Test-Path -Path "temp")) {
New-Item -ItemType Directory -Path "temp"
}
# Unzip the server zip file to the temp directory
Expand-Archive -Path $serverZipFile -DestinationPath "temp" -Force
# Move the contents of the overrides folder to the server directory
$subFolderList = Get-ChildItem -Path "temp/overrides" -Directory
for ($i = 0; $i -lt $subFolderList.Count; $i++) {
$subFolder = $subFolderList[$i]
Move-Item -Path "temp/overrides/$($subFolder.Name)/" -Destination "server" -Force
}
# Move-Item -Path "temp/overrides/*" -Destination "server" -Recurse -Force
# Remove temp directory
Remove-Item -Path "temp" -Recurse -Force
# Change to the server directory
Set-Location -Path "server"
# Accept the EULA
"eula=true" | Out-File -FilePath "eula.txt" -Encoding ASCII
Set-Location -Path ".."
# Check if the temp directory exists
if (Test-Path -Path "temp") {
# Remove the existing directory
Remove-Item -Path "temp" -Recurse -Force
}
# Create temp directory
if (-Not (Test-Path -Path "temp")) {
New-Item -ItemType Directory -Path "temp"
}
# Find zip file in files-to-add/world
$worldZip = Get-ChildItem -Path "files-to-add/world-zip" -Filter "*.zip" -Recurse
# Check if a zip file was found
if ($worldZip) {
# Unzip the world zip file to the temp directory
Expand-Archive -Path $worldZip.FullName -DestinationPath "temp/world" -Force
} else {
Write-Host "No zip file found in files-to-add/world-zip"
}
# Move the contents of the world folder to the server directory
$subFolderList = Get-ChildItem -Path "temp/world" -Directory
for ($i = 0; $i -lt $subFolderList.Count; $i++) {
$subFolder = $subFolderList[$i]
Move-Item -Path "temp/world/$($subFolder.Name)/" -Destination "server/world" -Force
}
# Remove temp directory
Remove-Item -Path "temp" -Recurse -Force
# Copy files from files-to-add/mods into server/mods
$mods = Get-ChildItem -Path "files-to-add/mods" -Recurse
foreach ($mod in $mods) {
Copy-Item -Path $mod.FullName -Destination "server/mods" -Force
}
# Copy files from files-to-add/config into server/config
$configs = Get-ChildItem -Path "files-to-add/config" -Recurse
foreach ($config in $configs) {
Copy-Item -Path $config.FullName -Destination "server/config" -Force
}
# Get name of original zip
$zipName = $serverZipFile | Split-Path -Leaf
$craftyZipName = $zipName -replace ".zip", "-crafty.zip"
# Remove $craftyZipName if it exists
if (Test-Path -Path $craftyZipName) {
Remove-Item -Path $craftyZipName -Force
}
# Compress the contents of the temporary folder
Compress-Archive -Path server/* -DestinationPath $craftyZipName -CompressionLevel Optimal
# Print Import table in crafty4-table.txt, use tabs to separate columns
# Server Name\tForge Test
# Server path\t<path to zip>/forge.zip
# Select root dir Select 'forge' or whatever the parent directory of /libraries is
# Server Executable file libraries/net/minecraftforge/forge/[your-forge-version-do-not-copy]/[your-forge-version-do-not-copy]-server.jar
# Min Memory 4GB (or whatever)
# Max Memory 4GB (or whatever)
# Server Port <Your choice, I left as default 25565>
# if fiel already exists, remove it
if (Test-Path -Path "crafty4-table.txt") {
Remove-Item -Path "crafty4-table.txt" -Force
}
# Create crafty4-table.txt
# Find our
$serverExecutableFile = Get-ChildItem -Path "server" -Recurse -Filter "*-server.jar"
# serverExecutableFile should start with libraries/
$serverExecutableFile = $serverExecutableFile.FullName -replace "server\\", ""
# crop string to libraries*
$serverExecutableFile = $serverExecutableFile -replace ".*libraries", "libraries"
$serverExecutableFile = $serverExecutableFile -replace "\\", "/"
# Like java -Xms6000M -Xmx6000M @libraries/net/minecraftforge/forge/[your-forge-version-do-not-copy]/unix_args.txt nogui
$serverExecutionCommand = "java -Xms6000M -Xmx6000M @$serverExecutableFile/unix_args.txt nogui"
$craftyTable = @"
Server Name Name for Crafty
Server path $craftyZipName
Select root dir <parent directory of /libraries, should be none for this script>
Server Executable File $serverExecutableFile
Min Memory 6GB
Max Memory 6GB
Server Execution Command $serverExecutionCommand
"@
$craftyTable | Out-File -FilePath "crafty4-table.txt" -Encoding ASCII
# Print Finished
Write-Host "<] Crafty zip created: $craftyZipName"
Write-Host "<] Crafty table created: crafty4-table.txt"
Write-Host "<] Finished 💅"