new: new -caplets-path argument to specify an alternative caplets base path (closes #850)

This commit is contained in:
Simone Margaritelli 2021-03-23 19:05:58 +01:00
parent 161124a3f4
commit d63122bab3
3 changed files with 27 additions and 6 deletions

View file

@ -15,7 +15,7 @@ const (
InstallArchive = "https://github.com/bettercap/caplets/archive/master.zip"
)
func getInstallBase() string {
func getDefaultInstallBase() string {
if runtime.GOOS == "windows" {
return filepath.Join(os.Getenv("ALLUSERSPROFILE"), "bettercap")
}
@ -28,10 +28,18 @@ func getUserHomeDir() string {
}
var (
InstallBase = getInstallBase()
InstallBase = ""
InstallPathArchive = ""
InstallPath = ""
ArchivePath = ""
LoadPaths = []string(nil)
)
func Setup(base string) error {
InstallBase = base
InstallPathArchive = filepath.Join(InstallBase, "caplets-master")
InstallPath = filepath.Join(InstallBase, "caplets")
ArchivePath = filepath.Join(os.TempDir(), "caplets.zip")
InstallPath = filepath.Join(InstallBase, "caplets")
ArchivePath = filepath.Join(os.TempDir(), "caplets.zip")
LoadPaths = []string{
"./",
@ -39,9 +47,7 @@ var (
InstallPath,
filepath.Join(getUserHomeDir(), "caplets"),
}
)
func init() {
for _, path := range str.SplitBy(str.Trim(os.Getenv(EnvVarName)), string(os.PathListSeparator)) {
if path = str.Trim(path); len(path) > 0 {
LoadPaths = append(LoadPaths, path)
@ -51,4 +57,11 @@ func init() {
for i, path := range LoadPaths {
LoadPaths[i], _ = filepath.Abs(path)
}
return nil
}
func init() {
// init with defaults
Setup(getDefaultInstallBase())
}

View file

@ -16,6 +16,7 @@ type Options struct {
Commands *string
CpuProfile *string
MemProfile *string
CapletsPath *string
}
func ParseOptions() (Options, error) {
@ -33,6 +34,7 @@ func ParseOptions() (Options, error) {
Commands: flag.String("eval", "", "Run one or more commands separated by ; in the interactive session, used to set variables via command line."),
CpuProfile: flag.String("cpu-profile", "", "Write cpu profile `file`."),
MemProfile: flag.String("mem-profile", "", "Write memory profile to `file`."),
CapletsPath: flag.String("caplets-path", "", "Specify an alternative base path for caplets."),
}
flag.Parse()

View file

@ -224,6 +224,12 @@ func (s *Session) Start() error {
return s.Modules[i].Name() < s.Modules[j].Name()
})
if *s.Options.CapletsPath != "" {
if err = caplets.Setup(*s.Options.CapletsPath); err != nil {
return err
}
}
if s.Interface, err = network.FindInterface(*s.Options.InterfaceName); err != nil {
return err
}