diff --git a/server/neoforge.go b/server/neoforge.go index df8f608..f0b684f 100644 --- a/server/neoforge.go +++ b/server/neoforge.go @@ -2,6 +2,7 @@ package server import ( "fmt" + "github.com/nothub/mrpack-install/maven" "github.com/nothub/mrpack-install/web" "log" ) @@ -11,18 +12,24 @@ type NeoForgeInstaller struct { NeoForgeVersion string } -// TODO maven version lookup: https://maven.neoforged.net/releases/net/neoforged/forge/maven-metadata.xml - func (inst *NeoForgeInstaller) Install(serverDir string, serverFile string) error { - // TODO: implement automatic lookup for latest version - if inst.NeoForgeVersion == "" || inst.NeoForgeVersion == "latest" { - log.Fatalln("automatic NeoForge version lookup not implemented\nplease set server version with --flavor-version flag") + version := inst.NeoForgeVersion + if version == "" || version == "latest" { + meta, err := maven.FetchMetadata("https://maven.neoforged.net/releases/net/neoforged/neoforge/maven-metadata.xml") + if err != nil { + return err + } + // TODO: instead of using the latest release, match against the latest + // non-pre-release version that matches the minecraft version + version = meta.Versioning.Release } - u := fmt.Sprintf("https://maven.neoforged.net/releases/net/neoforged/neoforge/%s/neoforge-%s-installer.jar", inst.NeoForgeVersion, inst.NeoForgeVersion) + + u := fmt.Sprintf("https://maven.neoforged.net/releases/net/neoforged/neoforge/%s/neoforge-%s-installer.jar", version, version) file, err := web.DefaultClient.DownloadFile(u, serverDir, serverFile) if err != nil { return err } + log.Println("Server jar downloaded to:", file) return nil } diff --git a/web/features.go b/web/features.go index 5bb7e92..69eb069 100644 --- a/web/features.go +++ b/web/features.go @@ -68,7 +68,7 @@ func (c *Client) DownloadFile(url string, downloadDir string, fileName string) ( // TODO: this needs to (silently?) overwrite existing files! - log.Printf("downloading: %s", url) + log.Printf("Downloading file from: %s", url) request, err := http.NewRequest(http.MethodGet, url, nil) if err != nil {