2023-03-02 15:37:05 -05:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-10 15:53:29 -07:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-02 15:37:05 -05:00
|
|
|
|
2021-02-02 18:05:04 +01:00
|
|
|
package packer
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"log"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/pathing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// PluginFolders returns the list of known plugin folders based on system.
|
|
|
|
|
func PluginFolders(dirs ...string) []string {
|
|
|
|
|
res := []string{}
|
|
|
|
|
|
2023-05-23 21:05:35 -04:00
|
|
|
if packerPluginPath := os.Getenv("PACKER_PLUGIN_PATH"); packerPluginPath != "" {
|
|
|
|
|
res = append(res, strings.Split(packerPluginPath, string(os.PathListSeparator))...)
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 18:05:04 +01:00
|
|
|
if path, err := os.Executable(); err != nil {
|
|
|
|
|
log.Printf("[ERR] Error finding executable: %v", err)
|
|
|
|
|
} else {
|
2023-05-11 16:48:30 -04:00
|
|
|
res = append(res, filepath.Dir(path))
|
2021-02-02 18:05:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res = append(res, dirs...)
|
|
|
|
|
|
|
|
|
|
if cd, err := pathing.ConfigDir(); err != nil {
|
|
|
|
|
log.Printf("[ERR] Error loading config directory: %v", err)
|
|
|
|
|
} else {
|
|
|
|
|
res = append(res, filepath.Join(cd, "plugins"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
}
|