Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add go install support as fallback #194

Merged
merged 5 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,21 @@ func (r *Runner) Run() error {
continue
}
if i, ok := utils.Contains(toolList, toolName); ok {
tool := getTool(toolName, toolList)
if err := pkg.Install(r.options.Path, toolList[i]); err != nil {
if err == types.ErrIsInstalled {
dogancanbakir marked this conversation as resolved.
Show resolved Hide resolved
gologger.Info().Msgf("%s: %s", toolName, err)
} else {
gologger.Error().Msgf("error while installing %s: %s", toolName, err)
}

gologger.Info().Msgf("trying to install %s using go install", toolName)
if err := fallbackGoInstall(tool); err != nil {
gologger.Error().Msgf("error while installing %s using go install: %s", toolName, err)
} else {
gologger.Info().Msgf("successfully installed %s using go install", toolName)
}
}
tool := getTool(toolName, toolList)
printRequirementInfo(tool)
} else {
gologger.Error().Msgf("error while installing %s: %s not found in the list", toolName, toolName)
Expand Down Expand Up @@ -152,6 +159,18 @@ func (r *Runner) Run() error {
return nil
}

func fallbackGoInstall(tool *types.Tool) error {
err := os.Setenv("GOBIN", defaultPath)
if err != nil {
return fmt.Errorf("failed to set GOBIN: %s", err)
}
cmd := exec.Command("go", "install", "-v", fmt.Sprintf("github.com/projectdiscovery/%s/%s", tool.Name, tool.GoInstallPath))
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("go install failed for %s: %s", tool.Name, string(output))
}
return nil
}

func printRequirementInfo(tool *types.Tool) {
specs := getSpecs(tool)

Expand Down
11 changes: 6 additions & 5 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ var (
)

type Tool struct {
Name string `json:"name"`
Repo string `json:"repo"`
Version string `json:"version"`
Requirements []ToolRequirement `json:"requirements"`
Assets map[string]string `json:"assets"`
Name string `json:"name"`
Repo string `json:"repo"`
Version string `json:"version"`
GoInstallPath string `json:"go_install_path" yaml:"go_install_path"`
Requirements []ToolRequirement `json:"requirements"`
Assets map[string]string `json:"assets"`
}

type ToolRequirement struct {
Expand Down
Loading