/// <summary> /// Constructor. /// </summary> /// <param name="setupHelper">The Kubernetes settup helper.</param> public WinInstallBuilder(KubeSetupHelper setupHelper) { Covenant.Requires <ArgumentNullException>(setupHelper != null, nameof(setupHelper)); this.Helper = setupHelper; }
/// <summary> /// This is the program entrypoint. /// </summary> /// <param name="args">The command line arguments.</param> public static void Main(string[] args) { string platform; KubeSetupHelper helper; commandLine = new CommandLine(args); var command = commandLine.Arguments.FirstOrDefault(); if (command != null) { command = command.ToLowerInvariant(); } if (commandLine.Arguments.Length == 0 || commandLine.HasHelpOption || command == "help") { Console.WriteLine(usage); Program.Exit(0); } try { Program.RepoRootFolder = Environment.GetEnvironmentVariable("NF_ROOT"); if (string.IsNullOrEmpty(Program.RepoRootFolder) || !Directory.Exists(Program.RepoRootFolder)) { Console.Error.WriteLine("*** ERROR: NF_ROOT environment variable does not reference the local neonKUBE repostory."); Program.Exit(1); } Program.DefaultKubernetesVersion = File.ReadAllText(Path.Combine(Program.RepoRootFolder, "kube-version.txt")).Trim(); // Handle the commands. switch (command) { case "clean": var buildFolder = Path.Combine(Program.RepoRootFolder, "Build"); if (Directory.Exists(buildFolder)) { NeonHelper.DeleteFolderContents(buildFolder); } if (commandLine.HasOption("--all")) { var buildCacheFolder = Path.Combine(Program.RepoRootFolder, "Build-cache"); if (Directory.Exists(buildCacheFolder)) { NeonHelper.DeleteFolderContents(buildCacheFolder); } } var cadenceResourcesPath = Path.Combine(Program.RepoRootFolder, "Lib", "Neon.Cadence", "Resources"); if (Directory.Exists(cadenceResourcesPath)) { NeonHelper.DeleteFolder(cadenceResourcesPath); } foreach (var folder in Directory.EnumerateDirectories(Program.RepoRootFolder, "bin", SearchOption.AllDirectories)) { if (Directory.Exists(folder)) { NeonHelper.DeleteFolder(folder); } } foreach (var folder in Directory.EnumerateDirectories(Program.RepoRootFolder, "obj", SearchOption.AllDirectories)) { if (Directory.Exists(folder)) { NeonHelper.DeleteFolder(folder); } } break; case "installer": platform = commandLine.Arguments.ElementAtOrDefault(1); if (string.IsNullOrEmpty(platform)) { Console.Error.WriteLine("*** ERROR: PLATFORM argument is required."); Program.Exit(1); } helper = new KubeSetupHelper(platform, commandLine, outputAction: text => Console.Write(text), errorAction: text => Console.Write(text)); EnsureOption("--kube-version", Program.DefaultKubernetesVersion); switch (helper.Platform) { case KubeClientPlatform.Windows: new WinInstallBuilder(helper).Run(); break; case KubeClientPlatform.Osx: throw new NotImplementedException(); } break; case "clear": platform = commandLine.Arguments.ElementAtOrDefault(1); if (string.IsNullOrEmpty(platform)) { Console.Error.WriteLine("*** ERROR: PLATFORM argument is required."); Program.Exit(1); } helper = new KubeSetupHelper(platform, commandLine, outputAction: text => Console.Write(text), errorAction: text => Console.Write(text)); helper.Clear(); break; case "download": platform = commandLine.Arguments.ElementAtOrDefault(1); if (string.IsNullOrEmpty(platform)) { Console.Error.WriteLine("*** ERROR: PLATFORM argument is required."); Program.Exit(1); } helper = new KubeSetupHelper(platform, commandLine, outputAction: text => Console.Write(text), errorAction: text => Console.Write(text)); EnsureOption("--kube-version", Program.DefaultKubernetesVersion); helper.Download(); break; case "copy": { var sourcePath = commandLine.Arguments.ElementAtOrDefault(1); var targetPath = commandLine.Arguments.ElementAtOrDefault(2); if (sourcePath == null) { Console.Error.WriteLine("*** ERROR: SOURCE argument is required."); Program.Exit(1); } if (targetPath == null) { Console.Error.WriteLine("*** ERROR: TARGET argument is required."); Program.Exit(1); } if (!File.Exists(sourcePath)) { Console.Error.WriteLine($"*** ERROR: SOURCE file [{sourcePath}] does not exist."); Program.Exit(1); } Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); if (File.Exists(targetPath) && File.GetLastWriteTimeUtc(targetPath) > File.GetLastWriteTimeUtc(sourcePath)) { Console.WriteLine($"File [{targetPath}] is up to date."); Program.Exit(0); } Console.WriteLine($"COPY: [{sourcePath}] --> [{targetPath}]."); File.Copy(sourcePath, targetPath); } break; case "gzip": Gzip(commandLine); break; case "build-version": BuildVersion(commandLine); break; case "pack-version": PackVersion(commandLine); break; case "shfb": Shfb(commandLine); break; default: Console.Error.WriteLine($"*** ERROR: Unexpected command [{command}]."); Program.Exit(1); break; } Program.Exit(0); } catch (Exception e) { Console.Error.WriteLine($"*** ERROR: {e.GetType().FullName}: {e.Message}"); Program.Exit(1); } }