Skip to content

Commit

Permalink
feat: initial feature set
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanLatimer committed Mar 10, 2021
0 parents commit 579532e
Show file tree
Hide file tree
Showing 10 changed files with 579 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .bra.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[run]
build_delay = 1500 # Minimal interval to Trigger build event
cmds = [
# Commands to run
["go", "install", "-race"],
]
env_files = [] # Load env vars from files
follow_symlinks = false # Enable/disable following symbolic links of sub directories
graceful_kill = false # Wait for exit and before directly kill
ignore = [".git", "node_modules"] # Directories to exclude from watching
ignore_files = [] # Regexps for ignoring specific notifies
init_cmds = [
# Commands run in start
["env", "CGO_ENABLED=0"],
["go", "install", "-race"],
]
interrupt_timout = 15 # Time to wait until force kill
watch_all = true # Watch all sub-directories
watch_dirs = [] # Directories to watch
watch_exts = [".go"] # Extensions to watch

[sync]
listen_addr = ":5050"
remote_addr = ":5050"
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Created by https://www.toptal.com/developers/gitignore/api/go,vscode
# Edit at https://www.toptal.com/developers/gitignore?templates=go,vscode

### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
dist

test

*.log

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

### Go Patch ###
/vendor/
/Godeps/

### vscode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# End of https://www.toptal.com/developers/gitignore/api/go,vscode
12 changes: 12 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/seanlatimer/cursepack

go 1.16

require (
github.com/klauspost/compress v1.11.12
github.com/pkg/errors v0.9.1
github.com/spf13/jwalterweatherman v1.1.0
github.com/stretchr/testify v1.4.0 // indirect
github.com/urfave/cli/v2 v2.3.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
)
30 changes: 30 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/klauspost/compress v1.11.12 h1:famVnQVu7QwryBN4jNseQdUKES71ZAOnB6UQQJPZvqk=
github.com/klauspost/compress v1.11.12/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
88 changes: 88 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package main

import (
"errors"
"os"
"strings"

"github.com/seanlatimer/cursepack/version"
jww "github.com/spf13/jwalterweatherman"
"github.com/urfave/cli/v2"
)

const TEMPDIR_NAME = "cursepack"

func main() {
app := &cli.App{
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "verbose",
Value: false,
Usage: "Enables verbose logging",
EnvVars: []string{"CP_VERBOSE"},
},
&cli.BoolFlag{
Name: "server",
Aliases: []string{"s"},
Value: false,
Usage: "Enables installing for a server, will download and install Forge automatically",
EnvVars: []string{"CP_SERVER"},
},
&cli.StringFlag{
Name: "dir",
Aliases: []string{"d"},
Value: "",
Usage: "Directory to install the pack in",
EnvVars: []string{"CP_DIR"},
},
},
Name: "cursepack",
Action: run,
Before: before,
Version: version.VERSION,
}

err := app.Run(os.Args)
if err != nil {
jww.FATAL.Fatal(err)
}
}

func before(ctx *cli.Context) error {
var err error
jww.SetStdoutThreshold(jww.LevelInfo)
if ctx.Bool("verbose") {
jww.SetStdoutThreshold(jww.LevelDebug)
}
if ctx.String("dir") == "" {
wd := ""
wd, err = os.Getwd()
ctx.Set("dir", wd)
}
return err
}

func run(ctx *cli.Context) error {
pack := ctx.Args().Get(0)
if os.Getenv("CP_PACK") != "" {
pack = os.Getenv("CP_PACK")
}
if pack == "" {
return errors.New("Must provide a pack")
}
if strings.HasSuffix(pack, ".zip") {
return handleZipPack(PackInstallOptions{
Pack: pack,
Path: ctx.String("dir"),
Server: ctx.Bool("server"),
})
}
// IMPLEMENT
return errors.New("Pack IDs are not currently supported")
}

type PackInstallOptions struct {
Pack string
Server bool
Path string
}
76 changes: 76 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package main

import (
"io"
"net/http"
"os"
"os/exec"
"path/filepath"

jww "github.com/spf13/jwalterweatherman"
)

const FORGE_DL_URL = "https://files.minecraftforge.net/maven/net/minecraftforge/forge/"

// fileExists checks if a file exists and is not a directory before we
// try using it to prevent further errors.
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}

func installForgeServer(forgeVersion string, path string) error {
jww.INFO.Println("Downloading Forge Server")
installerJar := "forge-" + forgeVersion + "-installer.jar"
installerJarPath := filepath.Join(path, "installer.jar")
if fileExists(installerJarPath) {
err := os.Remove(installerJarPath)
if err != nil {
return err
}
}

forgeFile, err := os.Create(installerJarPath)
if err != nil {
return err
}
defer os.Remove(forgeFile.Name())
defer forgeFile.Close()

forgeResp, err := http.Get(FORGE_DL_URL + forgeVersion + "/" + installerJar)
if err != nil {
return err
}
defer forgeResp.Body.Close()

_, err = io.Copy(forgeFile, forgeResp.Body)
if err != nil {
return err
}

javaPath, err := exec.LookPath("java")
if err != nil {
return err
}

cmdInstall := &exec.Cmd{
Path: javaPath,
Args: []string{javaPath, "-jar", installerJarPath, "--installServer", path},
Stdout: jww.DEBUG.Writer(),
Stderr: jww.ERROR.Writer(),
}

jww.INFO.Println("Installing Forge Server")
err = cmdInstall.Run()
if err != nil {
return err
}

src := filepath.Join(path, "forge-"+forgeVersion+".jar")
dest := filepath.Join(path, "server.jar")

return os.Rename(src, dest)
}
4 changes: 4 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package version

// VERSION current cli version
const VERSION = "0.0.0"
Loading

0 comments on commit 579532e

Please sign in to comment.