Skip to content

Commit

Permalink
use go install path from pdtm api
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir committed Sep 25, 2023
1 parent 21b5ca7 commit d100b0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
16 changes: 6 additions & 10 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ 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 {
gologger.Info().Msgf("%s: %s", toolName, err)
Expand All @@ -109,14 +110,12 @@ func (r *Runner) Run() error {
}

gologger.Info().Msgf("trying to install %s using go install", toolName)
if err := fallbackGoInstall(toolName); err != nil {
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 @@ -160,13 +159,10 @@ func (r *Runner) Run() error {
return nil
}

func fallbackGoInstall(toolName string) error {
cmd := exec.Command("go", "install", "-v", fmt.Sprintf("github.com/projectdiscovery/%s/v2/cmd/%s@latest", toolName, toolName))
if _, err := cmd.CombinedOutput(); err != nil {
cmd = exec.Command("go", "install", "-v", fmt.Sprintf("github.com/projectdiscovery/%s/cmd/%s@latest", toolName, toolName))
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("go install failed for %s: %s", toolName, string(output))
}
func fallbackGoInstall(tool *types.Tool) error {
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
}
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

0 comments on commit d100b0b

Please sign in to comment.