using System.Diagnostics; using System.IO.Compression; using System.Reflection; namespace AttackTracerNinjaServerBootstrapper; internal static class Program { private static int Main() { string tempRoot = Path.Combine(Path.GetTempPath(), "AttackTracerNinjaServerSetup", Guid.NewGuid().ToString("N")); Directory.CreateDirectory(tempRoot); try { Assembly assembly = Assembly.GetExecutingAssembly(); string resourceName = assembly.GetManifestResourceNames() .First(name => name.EndsWith("payload.zip", StringComparison.OrdinalIgnoreCase)); string zipPath = Path.Combine(tempRoot, "payload.zip"); using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName) ?? throw new InvalidOperationException("Embedded payload.zip was not found.")) using (FileStream output = File.Create(zipPath)) { resourceStream.CopyTo(output); } string extractRoot = Path.Combine(tempRoot, "payload"); ZipFile.ExtractToDirectory(zipPath, extractRoot); string installScript = Path.Combine(extractRoot, "install-attacktracer-ninja-server.ps1"); if (!File.Exists(installScript)) { throw new FileNotFoundException("Installer script missing from payload.", installScript); } var startInfo = new ProcessStartInfo { FileName = "powershell.exe", Arguments = $"-ExecutionPolicy Bypass -File \"{installScript}\"", WorkingDirectory = extractRoot, UseShellExecute = true }; using Process process = Process.Start(startInfo) ?? throw new InvalidOperationException("Failed to launch installer process."); process.WaitForExit(); return process.ExitCode; } catch (Exception ex) { Console.Error.WriteLine($"AttackTracerNinjaServer installer failed: {ex}"); return 1; } finally { try { if (Directory.Exists(tempRoot)) { Directory.Delete(tempRoot, recursive: true); } } catch { } } } }