Skip to content

Commit

Permalink
quilt installer
Browse files Browse the repository at this point in the history
  • Loading branch information
nothub committed Sep 10, 2022
1 parent e0cc381 commit d2b88aa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
6 changes: 6 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/nothub/mrpack-install/server"
"github.com/spf13/cobra"
"log"
"os"
)

func init() {
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 24 additions & 4 deletions server/quilt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d2b88aa

Please sign in to comment.