windows is bs
This commit is contained in:
parent
8d6f46c4ca
commit
3a36e4dda5
2 changed files with 26 additions and 23 deletions
|
@ -11,31 +11,28 @@ import (
|
|||
// Array to store errors
|
||||
var errors []string
|
||||
|
||||
// Check and Set MOZILLABUILD environment variable automatically
|
||||
func setMozillaBuildEnv() error {
|
||||
// Check if MOZILLABUILD is already set
|
||||
if os.Getenv("MOZILLABUILD") != "" {
|
||||
fmt.Println("MOZILLABUILD environment variable is already set.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Try to detect the MozillaBuild installation directory
|
||||
defaultPaths := []string{
|
||||
"C:\\mozilla-build",
|
||||
"C:\\Program Files\\mozilla-build",
|
||||
"C:\\Program Files (x86)\\mozilla-build",
|
||||
}
|
||||
|
||||
for _, path := range defaultPaths {
|
||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||
// Set the MOZILLABUILD environment variable
|
||||
fmt.Printf("Setting MOZILLABUILD environment variable to: %s\n", path)
|
||||
return os.Setenv("MOZILLABUILD", path)
|
||||
// SetGlobalEnv sets the MOZILLABUILD environment variable globally for the user (or system)
|
||||
func SetGlobalEnv(variable, value string, scope string) error {
|
||||
if runtime.GOOS == "windows" {
|
||||
var cmd *exec.Cmd
|
||||
if scope == "user" {
|
||||
cmd = exec.Command("setx", variable, value) // Set for current user
|
||||
} else if scope == "system" {
|
||||
cmd = exec.Command("setx", variable, value, "/M") // Set for system (requires admin privileges)
|
||||
} else {
|
||||
return fmt.Errorf("unknown scope: %s", scope)
|
||||
}
|
||||
}
|
||||
|
||||
// If no directory was found, return an error
|
||||
return fmt.Errorf("MozillaBuild directory not found. Please install MozillaBuild or set the MOZILLABUILD environment variable manually.")
|
||||
// Run the command
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set environment variable %s=%s: %v\nOutput: %s", variable, value, err, string(out))
|
||||
}
|
||||
fmt.Printf("Successfully set %s=%s\n", variable, value)
|
||||
return nil
|
||||
} else {
|
||||
return fmt.Errorf("global environment variable setting is not supported on non-Windows systems")
|
||||
}
|
||||
}
|
||||
|
||||
// Run an external command like scp or rsync
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue