diff --git a/pkg/crc/constants/constants.go b/pkg/crc/constants/constants.go index b2e2e578e6..ca2110ac06 100644 --- a/pkg/crc/constants/constants.go +++ b/pkg/crc/constants/constants.go @@ -20,7 +20,8 @@ const ( DefaultSSHUser = "core" DefaultSSHPort = 22 - CrcEnvPrefix = "CRC" + CrcEnvPrefix = "CRC" + CrcHomeDirEnvKey = "CRC_HOME_DIR" ConfigFile = "crc.json" LogFile = "crc.log" @@ -103,7 +104,7 @@ func GetDefaultBundle(preset crcpreset.Preset) string { } var ( - CrcBaseDir = filepath.Join(GetHomeDir(), ".crc") + CrcBaseDir = getBaseDir(filepath.Join(GetHomeDir(), ".crc")) CrcBinDir = filepath.Join(CrcBaseDir, "bin") CrcOcBinDir = filepath.Join(CrcBinDir, "oc") CrcPodmanBinDir = filepath.Join(CrcBinDir, "podman") @@ -119,6 +120,17 @@ var ( PasswdFilePath = filepath.Join(MachineInstanceDir, DefaultName, "passwd") ) +func getBaseDir(defaultDir string) string { + path := os.Getenv(CrcHomeDirEnvKey) + if path == "" { + return defaultDir + } + if _, err := os.Stat(path); err != nil { + return defaultDir + } + return path +} + func GetDefaultBundlePath(preset crcpreset.Preset) string { return filepath.Join(MachineCacheDir, GetDefaultBundle(preset)) }