protected async Task Download (Context context, Uri url, string destinationFilePath, string descriptiveName, string fileName, DownloadStatus downloadStatus) { bool fancyLogging = context.InteractiveSession; Log.DebugLine ($"{descriptiveName} URL: {url}"); if (!context.InteractiveSession) LogStatus ($"downloading {fileName} ", 4, ConsoleColor.Gray); bool success; Exception downloadEx = null; try { Log.DebugLine ("About to start downloading"); success = await Utilities.Download (url, destinationFilePath, downloadStatus); } catch (Exception ex) { Log.DebugLine ($"Caught exception: {ex}"); downloadEx = ex; success = false; } Log.Debug ($"success == {success}"); if (success) return; string message = $"Failed to download {url}"; if (downloadEx != null) throw new InvalidOperationException ($"{message}: {downloadEx.Message}", downloadEx); throw new InvalidOperationException (message); }
public override async Task <bool> Install() { Context context = Context.Instance; if (!context.AutoProvisionUsesSudo) { Log.ErrorLine("Installation of macOS packages requires sudo to be enabled (pass `--auto-provision-uses-sudo=yes` to the bootstrapper)"); return(false); } if (PackageUrl == null) { Log.ErrorLine($"{Name} is not installed but no URL is provided to download it from. Please make sure to install it before continuing"); return(false); } (bool success, ulong size) = await Utilities.GetDownloadSize(PackageUrl); if (!success) { Log.ErrorLine($"Failed to get download size of {PackageUrl}"); return(false); } DownloadStatus downloadStatus = Utilities.SetupDownloadStatus(context, size, context.InteractiveSession); Log.StatusLine($" {context.Characters.Link} {PackageUrl}", ConsoleColor.White); string localPath = Path.Combine(context.Properties.GetRequiredValue(KnownProperties.AndroidToolchainCacheDirectory), Path.GetFileName(PackageUrl.LocalPath)); success = await Utilities.Download(PackageUrl, localPath, downloadStatus); if (!success) { Log.ErrorLine($"Failed to download {PackageUrl}"); return(false); } var runner = new ProcessRunner("sudo") { EchoStandardError = true, EchoStandardOutput = true, ProcessTimeout = TimeSpan.FromMinutes(10) }; runner.AddArgument("/usr/sbin/installer"); runner.AddArgument("-verbose"); runner.AddArgument("-pkg"); runner.AddQuotedArgument(localPath); runner.AddArgument("-target"); runner.AddArgument("/"); return(await Task.Run(() => runner.Run())); }