Merge pull request #194004 from Homebrew/bump-binance-1.54.4
[Homebrew/homebrew-cask.git] / Casks / m / minecraft-server.rb
blob5987776857d2b805bc8739fff8b847ee323c6f6b
1 cask "minecraft-server" do
2   version "1.21.3,45810d238246d90e811d896f87b14695b7fb6839"
3   sha256 "e153b89b02c0839cdf5e8c1d57c80dd42a3fffb80c60817632080c041bf8afb5"
5   url "https://launcher.mojang.com/v#{version.major}/objects/#{version.csv.second}/server.jar",
6       verified: "launcher.mojang.com/"
7   name "Minecraft Server"
8   desc "Run a Minecraft multiplayer server"
9   homepage "https://www.minecraft.net/en-us/"
11   livecheck do
12     url "https://www.minecraft.net/en-us/download/server"
13     regex(%r{href=.*?/objects/(\h+)/server\.jar[^>]*>minecraft[_-]server[._-]v?(\d+(?:\.\d+)*)\.jar}i)
14     strategy :page_match do |page, regex|
15       page.scan(regex).map { |match| "#{match[1]},#{match[0]}" }
16     end
17   end
19   container type: :naked
21   # shim script (https://github.com/Homebrew/homebrew-cask/issues/18809)
22   shimscript = "#{staged_path}/minecraft-server.wrapper.sh"
23   binary shimscript, target: "minecraft-server"
25   config_dir = HOMEBREW_PREFIX.join("etc", "minecraft-server")
27   preflight do
28     FileUtils.mkdir_p config_dir
30     File.write shimscript, <<~EOS
31       #!/bin/sh
32       cd '#{config_dir}' && \
33         exec /usr/bin/java ${@:--Xms1024M -Xmx1024M} -jar '#{staged_path}/server.jar' nogui
34     EOS
35   end
37   eula_file = config_dir.join("eula.txt")
39   postflight do
40     system_command shimscript
41     File.write(eula_file, File.read(eula_file).sub("eula=false", "eula=TRUE"))
42   end
44   uninstall_preflight do
45     FileUtils.rm(eula_file) if eula_file.exist?
46   end
48   zap trash: config_dir
50   caveats do
51     depends_on_java "16+"
52     <<~EOS
53       Configuration files are located in
55         #{config_dir}
56     EOS
57   end
58 end