diff --git a/internal/native/native.go b/internal/native/native.go index 00cfa12..484fa66 100644 --- a/internal/native/native.go +++ b/internal/native/native.go @@ -78,51 +78,28 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error { } }() - // 6. Run setup.sh (remove set -e to survive env.list deletion) - fmt.Printf("[%s] Running setup...\n", node.Name) - // Patch out set -e so the script doesn't exit on env.list error - exec.Command("sed", "-i", "s/^set -e/set +e/", filepath.Join(DeployTo, "setup.sh")).Run() - cmd = exec.Command("bash", filepath.Join(DeployTo, "setup.sh"), - "--batch", "--token", apiToken, "--cloud", cloudFromHost(apiHost), - "--custom-ngx-build", + // 6. Load Wallarm NGINX module + register node + fmt.Printf("[%s] Configuring NGINX module...\n", node.Name) + exec.Command("bash", filepath.Join(DeployTo, "pick-module.sh")).Run() + + fmt.Printf("[%s] Registering node...\n", node.Name) + registerCmd := exec.Command(filepath.Join(DeployTo, "register-node"), + "-token", apiToken, + "-host", apiHost, ) - cmd.Dir = DeployTo + registerCmd.Dir = DeployTo - logFile, _ := os.Create(filepath.Join(DeployTo, "install.log")) - if logFile != nil { - cmd.Stdout = logFile - cmd.Stderr = logFile - } - runErr := cmd.Run() - close(done) // stop env.list keeper - if logFile != nil { - logFile.Close() + out, regErr := registerCmd.CombinedOutput() + if regErr != nil { + return fmt.Errorf("register: %w\n%s", regErr, string(out)) } - // Success check: node.yaml exists = node registered - nodeYaml := filepath.Join(DeployTo, "etc", "wallarm", "node.yaml") - if _, err := os.Stat(nodeYaml); err == nil { - // Move /opt/wallarm → /opt/fw/{name}/wallarm - os.MkdirAll(filepath.Join(BaseDir, node.Name), 0755) - os.RemoveAll(instanceDir) - os.Rename(DeployTo, instanceDir) - fmt.Printf("[%s] Done. Installed to %s\n", node.Name, instanceDir) - return nil - } - - // Failed: show log - if runErr != nil { - if data, _ := os.ReadFile(filepath.Join(DeployTo, "install.log")); len(data) > 0 { - lines := strings.Split(string(data), "\n") - s := len(lines) - 5 - if s < 0 { - s = 0 - } - return fmt.Errorf("%s", strings.Join(lines[s:], "\n")) - } - return fmt.Errorf("setup failed: %v", runErr) - } - return fmt.Errorf("node registration failed — no node.yaml found") + // 7. Move /opt/wallarm → /opt/fw/{name}/wallarm + os.MkdirAll(filepath.Join(BaseDir, node.Name), 0755) + os.RemoveAll(instanceDir) + os.Rename(DeployTo, instanceDir) + fmt.Printf("[%s] Done. Installed to %s\n", node.Name, instanceDir) + return nil } func copyNginx(dir string) {