File: core.go

package info (click to toggle)
bettercap 2.33.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,668 kB
  • sloc: sh: 154; makefile: 76; python: 52; ansic: 9
file content (48 lines) | stat: -rw-r--r-- 789 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package core

import (
	"os/exec"
	"sort"

	"github.com/evilsocket/islazy/str"
)

func UniqueInts(a []int, sorted bool) []int {
	tmp := make(map[int]bool, len(a))
	uniq := make([]int, 0, len(a))

	for _, n := range a {
		tmp[n] = true
	}

	for n := range tmp {
		uniq = append(uniq, n)
	}

	if sorted {
		sort.Ints(uniq)
	}

	return uniq
}

func HasBinary(executable string) bool {
	if path, err := exec.LookPath(executable); err != nil || path == "" {
		return false
	}
	return true
}

func Exec(executable string, args []string) (string, error) {
	path, err := exec.LookPath(executable)
	if err != nil {
		return "", err
	}

	raw, err := exec.Command(path, args...).CombinedOutput()
	if err != nil {
		return str.Trim(string(raw)), err
	} else {
		return str.Trim(string(raw)), nil
	}
}