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 (
|
2024-05-10 10:32:48 -04:00
|
|
|
"fmt"
|
2021-02-02 18:05:04 +01:00
|
|
|
"log"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
2024-05-10 10:32:48 -04:00
|
|
|
"strings"
|
2021-02-02 18:05:04 +01:00
|
|
|
|
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/pathing"
|
|
|
|
|
)
|
|
|
|
|
|
2024-05-15 19:13:34 -04:00
|
|
|
var pathSep = fmt.Sprintf("%c", os.PathListSeparator)
|
|
|
|
|
|
2024-01-15 14:31:04 -05:00
|
|
|
// PluginFolder returns the known plugin folder based on system.
|
|
|
|
|
func PluginFolder() (string, error) {
|
2023-05-23 21:05:35 -04:00
|
|
|
if packerPluginPath := os.Getenv("PACKER_PLUGIN_PATH"); packerPluginPath != "" {
|
2024-05-15 19:13:34 -04:00
|
|
|
if strings.Contains(packerPluginPath, pathSep) {
|
2024-05-10 10:32:48 -04:00
|
|
|
return "", fmt.Errorf("Multiple paths are no longer supported for PACKER_PLUGIN_PATH.\n"+
|
|
|
|
|
"This should be defined as one of the following options for your environment:"+
|
2024-05-15 19:13:34 -04:00
|
|
|
"\n* PACKER_PLUGIN_PATH=%v", strings.Join(strings.Split(packerPluginPath, pathSep), "\n* PACKER_PLUGIN_PATH="))
|
2024-05-10 10:32:48 -04:00
|
|
|
}
|
|
|
|
|
|
2024-01-15 14:31:04 -05:00
|
|
|
return packerPluginPath, nil
|
2023-05-23 21:05:35 -04:00
|
|
|
}
|
|
|
|
|
|
2024-01-15 14:31:04 -05:00
|
|
|
cd, err := pathing.ConfigDir()
|
|
|
|
|
if err != nil {
|
2021-02-02 18:05:04 +01:00
|
|
|
log.Printf("[ERR] Error loading config directory: %v", err)
|
2024-01-15 14:31:04 -05:00
|
|
|
return "", err
|
2021-02-02 18:05:04 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-15 14:31:04 -05:00
|
|
|
return filepath.Join(cd, "plugins"), nil
|
2021-02-02 18:05:04 +01:00
|
|
|
}
|