2022-04-03 04:07:16 +00:00
|
|
|
package product
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
|
|
|
"regexp"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-version"
|
|
|
|
"github.com/hashicorp/hc-install/internal/build"
|
|
|
|
)
|
|
|
|
|
|
|
|
var consulVersionOutputRe = regexp.MustCompile(`Consul ` + simpleVersionRe)
|
|
|
|
|
|
|
|
var (
|
2022-08-06 14:21:18 +00:00
|
|
|
v1_18 = version.Must(version.NewVersion("1.18"))
|
2022-04-03 04:07:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var Consul = Product{
|
|
|
|
Name: "consul",
|
|
|
|
BinaryName: func() string {
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
return "consul.exe"
|
|
|
|
}
|
|
|
|
return "consul"
|
|
|
|
},
|
|
|
|
GetVersion: func(ctx context.Context, path string) (*version.Version, error) {
|
|
|
|
cmd := exec.CommandContext(ctx, path, "version")
|
|
|
|
|
|
|
|
out, err := cmd.Output()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
stdout := strings.TrimSpace(string(out))
|
|
|
|
|
|
|
|
submatches := consulVersionOutputRe.FindStringSubmatch(stdout)
|
|
|
|
if len(submatches) != 2 {
|
|
|
|
return nil, fmt.Errorf("unexpected number of version matches %d for %s", len(submatches), stdout)
|
|
|
|
}
|
|
|
|
v, err := version.NewVersion(submatches[1])
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("unable to parse version %q: %w", submatches[1], err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return v, err
|
|
|
|
},
|
|
|
|
BuildInstructions: &BuildInstructions{
|
|
|
|
GitRepoURL: "https://github.com/hashicorp/consul.git",
|
|
|
|
PreCloneCheck: &build.GoIsInstalled{},
|
2023-03-20 20:25:53 +00:00
|
|
|
Build: &build.GoBuild{},
|
2022-04-03 04:07:16 +00:00
|
|
|
},
|
|
|
|
}
|