diff --git a/cmd/server.go b/cmd/server.go index a79a1b5..5e62038 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -6,6 +6,7 @@ import ( "github.com/nothub/mrpack-install/server" "github.com/spf13/cobra" "log" + "os" ) func init() { @@ -58,6 +59,11 @@ var serverCmd = &cobra.Command{ minecraftVersion = latestMinecraftVersion } + err = os.MkdirAll(serverDir, 0755) + if err != nil { + log.Fatalln(err) + } + flavor := args[0] provider, err := server.NewProvider(flavor, minecraftVersion, flavorVersion) if err != nil { diff --git a/server/quilt.go b/server/quilt.go index 8b08f64..a03cae8 100644 --- a/server/quilt.go +++ b/server/quilt.go @@ -2,24 +2,44 @@ package server import ( "errors" + "fmt" + "github.com/nothub/mrpack-install/requester" + "github.com/nothub/mrpack-install/util" "os" + "os/exec" + "path" ) +const quiltInstallerUrl = "https://maven.quiltmc.org/repository/release/org/quiltmc/quilt-installer/latest/quilt-installer-latest.jar" + type Quilt struct { MinecraftVersion string QuiltVersion string } func (provider *Quilt) Provide(serverDir string, serverFile string) error { - return errors.New("quilt provider not implemented") + installer, err := requester.DefaultHttpClient.DownloadFile(quiltInstallerUrl, ".", "") + if err != nil { + return err + } - err := os.MkdirAll("work/quilt", 0755) + cmd := exec.Command("java", "-jar", installer, "install", "server", provider.MinecraftVersion, "--install-dir="+serverDir, "--create-scripts", "--download-server") + fmt.Println("Executing command:", cmd.String()) + err = cmd.Run() if err != nil { return err } - // TODO: download https://maven.quiltmc.org/repository/release/org/quiltmc/quilt-installer/latest/quilt-installer-latest.jar - // TODO: java -jar quilt-installer-latest.jar install server ${minecraftVersion} --download-server + if !util.PathIsFile(path.Join(serverDir, "server.jar")) { + return errors.New("server.jar not found") + } + + if serverFile != "" { + err = os.Rename(path.Join(serverDir, "server.jar"), path.Join(serverDir, serverFile)) + if err != nil { + return err + } + } return nil }