windows is bs
This commit is contained in:
parent
8d6f46c4ca
commit
3a36e4dda5
2 changed files with 26 additions and 23 deletions
6
main.go
6
main.go
|
@ -67,6 +67,12 @@ func printHelp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
if flag.Lookup("h").Value.(flag.Getter).Get().(bool) {
|
if flag.Lookup("h").Value.(flag.Getter).Get().(bool) {
|
||||||
|
|
|
@ -11,31 +11,28 @@ import (
|
||||||
// Array to store errors
|
// Array to store errors
|
||||||
var errors []string
|
var errors []string
|
||||||
|
|
||||||
// Check and Set MOZILLABUILD environment variable automatically
|
// SetGlobalEnv sets the MOZILLABUILD environment variable globally for the user (or system)
|
||||||
func setMozillaBuildEnv() error {
|
func SetGlobalEnv(variable, value string, scope string) error {
|
||||||
// Check if MOZILLABUILD is already set
|
if runtime.GOOS == "windows" {
|
||||||
if os.Getenv("MOZILLABUILD") != "" {
|
var cmd *exec.Cmd
|
||||||
fmt.Println("MOZILLABUILD environment variable is already set.")
|
if scope == "user" {
|
||||||
return nil
|
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)
|
||||||
// Try to detect the MozillaBuild installation directory
|
} else {
|
||||||
defaultPaths := []string{
|
return fmt.Errorf("unknown scope: %s", scope)
|
||||||
"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)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If no directory was found, return an error
|
// Run the command
|
||||||
return fmt.Errorf("MozillaBuild directory not found. Please install MozillaBuild or set the MOZILLABUILD environment variable manually.")
|
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
|
// Run an external command like scp or rsync
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue