windows is bs

This commit is contained in:
partisan 2024-09-10 23:30:34 +02:00
parent 67ca7555ae
commit d5c37b42ec
2 changed files with 26 additions and 23 deletions

View file

@ -67,6 +67,12 @@ func printHelp() {
}
func main() {
// Check and set the MOZILLABUILD environment variable globally
err2 := spitfire.SetGlobalEnv("MOZILLABUILD", "C:\\mozilla-build", "user") // For user
if err2 != nil {
log.Fatalf("Error setting global environment variable: %v", err2)
}
flag.Parse()
if flag.Lookup("h").Value.(flag.Getter).Get().(bool) {

View file

@ -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