-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set env variables to execute commands
before executing any action we need to update the environment variables PODMAN_CONNECTIONS_CONF, PODMAN_DATA_DIR and PODMAN_RUNTIME_DIR to define a specific location where to store macadam data. This way we prevent to write macadam stuff within podman-related folders Signed-off-by: lstocchi <[email protected]>
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//go:build !windows | ||
|
||
package config | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/containers/storage/pkg/unshare" | ||
) | ||
|
||
// _configPath is the path to the macadam/machines.conf | ||
// inside a given config directory. | ||
const _configPath = "macadam/machines.conf" | ||
|
||
// userConfigPath returns the path to the users local config that is | ||
// not shared with other users. It uses $XDG_CONFIG_HOME/containers... | ||
// if set or $HOME/.config/containers... if not. | ||
func UserConfigPath() (string, error) { | ||
if configHome := os.Getenv("XDG_CONFIG_HOME"); configHome != "" { | ||
return filepath.Join(configHome, _configPath), nil | ||
} | ||
home, err := unshare.HomeDir() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return filepath.Join(home, _configPath), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//go:build windows | ||
|
||
package config | ||
|
||
import "os" | ||
|
||
const ( | ||
// _configPath is the path to the macadam/machines.conf | ||
// inside a given config directory. | ||
_configPath = "\\macadam\\machines.conf" | ||
) | ||
|
||
// userConfigPath returns the path to the users local config that is | ||
// not shared with other users. It uses $APPDATA/containers... | ||
func UserConfigPath() (string, error) { | ||
return os.Getenv("APPDATA") + _configPath, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package env | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/cfergeau/macadam/pkg/config" | ||
) | ||
|
||
const connectionsFile = "macadam-connections.json" | ||
|
||
func SetupEnvironment() error { | ||
path, err := config.UserConfigPath() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
connsFile := filepath.Join(filepath.Dir(path), connectionsFile) | ||
// set the path used for storing connection of macadam vms | ||
err = os.Setenv("PODMAN_CONNECTIONS_CONF", connsFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// set the directory used when calculating the data and config paths | ||
// config -> <configHome>/containers/macadam/machine (configHome changes based on the OS used e.g. configHome == /home/user/.config) | ||
// data -> <dataHome>/containers/macadam/machine (dataHome changes based on the OS used e.g. dataHome == /home/user/.local/share) | ||
err = os.Setenv("PODMAN_DATA_DIR", filepath.Join("macadam", "machine")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// set the directory to be used when calculating runtime path | ||
// run -> <runHome>/macadam (runHome changes based on the OS used e.g. runHome == /run) | ||
err = os.Setenv("PODMAN_RUNTIME_DIR", "macadam") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |