2021-09-09 11:12:25 -07:00
|
|
|
//go:build !windows
|
2019-03-13 04:14:30 -07:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-11-04 23:56:12 -08:00
|
|
|
"errors"
|
2019-03-13 04:14:30 -07:00
|
|
|
"os"
|
2021-08-01 06:25:15 -07:00
|
|
|
"time"
|
2021-05-22 07:50:34 -07:00
|
|
|
|
2021-11-13 14:46:06 -08:00
|
|
|
"github.com/shirou/gopsutil/v3/host"
|
2021-05-22 07:50:34 -07:00
|
|
|
terminal "github.com/wayneashleyberry/terminal-dimensions"
|
2019-03-13 04:14:30 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func (env *environment) isRunningAsRoot() bool {
|
2021-11-16 22:16:43 -08:00
|
|
|
defer env.trace(time.Now(), "isRunningAsRoot")
|
2019-03-13 04:14:30 -07:00
|
|
|
return os.Geteuid() == 0
|
|
|
|
}
|
2020-10-12 07:01:08 -07:00
|
|
|
|
|
|
|
func (env *environment) homeDir() string {
|
|
|
|
return os.Getenv("HOME")
|
|
|
|
}
|
2020-11-04 23:56:12 -08:00
|
|
|
|
2020-11-12 00:43:32 -08:00
|
|
|
func (env *environment) getWindowTitle(imageName, windowTitleRegex string) (string, error) {
|
2020-11-04 23:56:12 -08:00
|
|
|
return "", errors.New("not implemented")
|
|
|
|
}
|
2021-02-14 23:26:52 -08:00
|
|
|
|
|
|
|
func (env *environment) isWsl() bool {
|
2021-11-16 22:16:43 -08:00
|
|
|
defer env.trace(time.Now(), "isWsl")
|
2021-02-14 23:26:52 -08:00
|
|
|
// one way to check
|
|
|
|
// version := env.getFileContent("/proc/version")
|
|
|
|
// return strings.Contains(version, "microsoft")
|
|
|
|
// using env variable
|
|
|
|
return env.getenv("WSL_DISTRO_NAME") != ""
|
|
|
|
}
|
2021-05-22 07:50:34 -07:00
|
|
|
|
|
|
|
func (env *environment) getTerminalWidth() (int, error) {
|
2021-11-16 22:16:43 -08:00
|
|
|
defer env.trace(time.Now(), "getTerminalWidth")
|
2021-05-22 07:50:34 -07:00
|
|
|
width, err := terminal.Width()
|
2021-10-20 02:55:53 -07:00
|
|
|
if err != nil {
|
2021-11-16 22:16:43 -08:00
|
|
|
env.log(Error, "runCommand", err.Error())
|
2021-10-20 02:55:53 -07:00
|
|
|
}
|
2021-05-22 07:50:34 -07:00
|
|
|
return int(width), err
|
|
|
|
}
|
2021-09-09 22:25:12 -07:00
|
|
|
|
|
|
|
func (env *environment) getPlatform() string {
|
|
|
|
p, _, _, _ := host.PlatformInformation()
|
|
|
|
return p
|
|
|
|
}
|
2021-10-02 22:27:18 -07:00
|
|
|
|
|
|
|
func (env *environment) getCachePath() string {
|
2021-11-16 22:16:43 -08:00
|
|
|
defer env.trace(time.Now(), "getCachePath")
|
2021-10-02 22:27:18 -07:00
|
|
|
// get XDG_CACHE_HOME if present
|
|
|
|
if cachePath := returnOrBuildCachePath(env.getenv("XDG_CACHE_HOME")); len(cachePath) != 0 {
|
|
|
|
return cachePath
|
|
|
|
}
|
|
|
|
// HOME cache folder
|
|
|
|
if cachePath := returnOrBuildCachePath(env.homeDir() + "/.cache"); len(cachePath) != 0 {
|
|
|
|
return cachePath
|
|
|
|
}
|
|
|
|
return env.homeDir()
|
|
|
|
}
|
2021-11-24 04:47:30 -08:00
|
|
|
|
2021-12-04 13:11:25 -08:00
|
|
|
func (env *environment) getWindowsRegistryKeyValue(path string) (*windowsRegistryValue, error) {
|
|
|
|
return nil, errors.New("not implemented")
|
2021-11-24 04:47:30 -08:00
|
|
|
}
|