fix: use setup.sh batch mode with --batch --token --cloud

- Uses AIO installer's built-in batch mode instead of interactive prompts
- --batch --token TOKEN --cloud US|EU --host HOST for non-interactive install
- cloudFromHost() maps api.wallarm.com → EU, us1.api.wallarm.com → US
- No more stdin piping, proper CLI flags
This commit is contained in:
admin 2026-08-01 15:59:48 +00:00
parent 0ce12f4742
commit 2e6eca019d

View file

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