diff --git a/internal/native/native.go b/internal/native/native.go index 0d94ca8..3856bab 100644 --- a/internal/native/native.go +++ b/internal/native/native.go @@ -65,7 +65,7 @@ connector: return fmt.Errorf("write config: %w", err) } - // 3. Ensure NGINX is installed (Wallarm node requires it) + // 3. Install NGINX (Wallarm node requires it as proxy layer) installNginx() // 4. Download installer if missing @@ -100,22 +100,19 @@ WALLARM_CONFIG_PATH=%s return fmt.Errorf("extract installer: %w\n%s", err, string(out)) } - // 6. Run the embedded setup.sh with our configuration + // 6. Run setup.sh in batch mode (non-interactive) setupScript := filepath.Join(workDir, "setup.sh") if _, err := os.Stat(setupScript); err != nil { return fmt.Errorf("setup.sh not found after extraction: %w", err) } - fmt.Printf("[%s] Running setup...\n", node.Name) - setupCmd := exec.Command("bash", setupScript) - setupCmd.Dir = workDir - setupCmd.Env = append(os.Environ(), - "WALLARM_API_TOKEN="+apiToken, - "WALLARM_API_HOST="+apiHost, - "WALLARM_LABELS="+labels, - "WALLARM_ACCEPT_EULA=true", + fmt.Printf("[%s] Running setup (batch mode)...\n", node.Name) + setupCmd := exec.Command("bash", setupScript, + "--batch", + "--token", apiToken, + "--cloud", cloudFromHost(apiHost), + "--host", apiHost, ) - // Pipe token + host to handle interactive prompts - setupCmd.Stdin = strings.NewReader(apiToken + "\n" + apiHost + "\n") + setupCmd.Dir = workDir logFile, err := os.Create(filepath.Join(workDir, "install.log")) if err == nil { @@ -247,3 +244,14 @@ func installNginx() { exec.Command("apt-get", "update", "-qq").Run() exec.Command("apt-get", "install", "-y", "-qq", "nginx").Run() } + +// cloudFromHost maps API host to cloud region code (US/EU/ME). +func cloudFromHost(host string) string { + if strings.Contains(host, "us1") { + return "US" + } + if strings.Contains(host, "me1") { + return "ME" + } + return "EU" +}