package linux import ( "errors" "fmt" cmd2 "git.shadowhosting.xyz/Eggactyl/shell/cmd" "golang.org/x/sys/unix" "io/fs" "os" "os/exec" ) func (cmd *LinuxCommand) isCommandExecutable(command string) (bool, error) { fmt.Println(command) whichOut, err := cmd2.Which(command, cmd2.BasicOptions{ Env: cmd.Options.Env, Sources: cmd.Options.Sources, Cwd: cmd.Options.Cwd, }) if err != nil { if errors.Is(err, cmd2.ErrNotFound) { if _, err := os.Stat(command); errors.Is(err, fs.ErrNotExist) { return false, err } } else { return false, err } } fmt.Println(whichOut) if len(whichOut) == 0 { return false, nil } fmt.Println("which:", whichOut) if err := unix.Access(whichOut, unix.X_OK); err != nil { if err == unix.EACCES { return false, nil } else { fmt.Println(err) return false, err } } return true, nil } func (cmd *LinuxCommand) doesCommandExist(command string) (bool, error) { shellCmd := exec.Command(cmd.Options.Shell, "-c", fmt.Sprintf("command -v %s", command)) if err := shellCmd.Start(); err != nil { var exitErr *exec.ExitError if errors.As(err, &exitErr) { if exitErr.ExitCode() == 1 { return false, nil } else { return false, ErrRunningCmd } } } if err := shellCmd.Wait(); err != nil { var exitErr *exec.ExitError if errors.As(err, &exitErr) { if exitErr.ExitCode() == 1 { return false, nil } else { return false, ErrRunningCmd } } } return true, nil }