public async Task InstallLatestVersion() { try { await _installLatestVersionLock.WaitAsync(); var connectionInfo = _configService.GetConnectionInfo(); var serverUrl = connectionInfo.Host; Logger.Write("Service Updater: Downloading install package."); var downloadId = Guid.NewGuid().ToString(); var zipPath = Path.Combine(Path.GetTempPath(), "RemotelyUpdate.zip"); var installerPath = Path.Combine(Path.GetTempPath(), "Remotely_Installer.exe"); var platform = Environment.Is64BitOperatingSystem ? "x64" : "x86"; await _webClientEx.DownloadFileTaskAsync( serverUrl + $"/Content/Remotely_Installer.exe", installerPath); await _webClientEx.DownloadFileTaskAsync( serverUrl + $"/api/AgentUpdate/DownloadPackage/win-{platform}/{downloadId}", zipPath); (await WebRequest.CreateHttp(serverUrl + $"/api/AgentUpdate/ClearDownload/{downloadId}").GetResponseAsync()).Dispose(); foreach (var proc in Process.GetProcessesByName("Remotely_Installer")) { proc.Kill(); } Logger.Write("Launching installer to perform update."); Process.Start(installerPath, $"-install -quiet -path {zipPath} -serverurl {serverUrl} -organizationid {connectionInfo.OrganizationID}"); } catch (WebException ex) when(ex.Status == WebExceptionStatus.Timeout) { Logger.Write("Timed out while waiting to download update.", Shared.Enums.EventType.Warning); _lastUpdateFailure = DateTimeOffset.Now; } catch (Exception ex) { Logger.Write(ex); _lastUpdateFailure = DateTimeOffset.Now; } finally { _installLatestVersionLock.Release(); } }
public async Task InstallLatestVersion() { try { await _installLatestVersionLock.WaitAsync(); var connectionInfo = _configService.GetConnectionInfo(); var serverUrl = connectionInfo.Host; Logger.Write("Service Updater: Downloading install package."); var downloadId = Guid.NewGuid().ToString(); var zipPath = Path.Combine(Path.GetTempPath(), "RemotelyUpdate.zip"); var installerPath = Path.Combine(Path.GetTempPath(), "RemotelyUpdate.sh"); await _webClientEx.DownloadFileTaskAsync( serverUrl + $"/API/ClientDownloads/{connectionInfo.OrganizationID}/MacOSInstaller-{_achitecture}", installerPath); await _webClientEx.DownloadFileTaskAsync( serverUrl + $"/API/AgentUpdate/DownloadPackage/macos-{_achitecture}/{downloadId}", zipPath); (await WebRequest.CreateHttp(serverUrl + $"/api/AgentUpdate/ClearDownload/{downloadId}").GetResponseAsync()).Dispose(); Logger.Write("Launching installer to perform update."); Process.Start("sudo", $"chmod +x {installerPath}").WaitForExit(); Process.Start("sudo", $"{installerPath} --path {zipPath}"); } catch (WebException ex) when(ex.Status == WebExceptionStatus.Timeout) { Logger.Write("Timed out while waiting to download update.", Shared.Enums.EventType.Warning); _lastUpdateFailure = DateTimeOffset.Now; } catch (Exception ex) { Logger.Write(ex); _lastUpdateFailure = DateTimeOffset.Now; } finally { _installLatestVersionLock.Release(); } }
public async Task InstallLatestVersion() { try { await _installLatestVersionLock.WaitAsync(); var connectionInfo = _configService.GetConnectionInfo(); var serverUrl = connectionInfo.Host; Logger.Write("Service Updater: Downloading install package."); var downloadId = Guid.NewGuid().ToString(); var zipPath = Path.Combine(Path.GetTempPath(), "RemotelyUpdate.zip"); var installerPath = Path.Combine(Path.GetTempPath(), "RemotelyUpdate.sh"); string platform; if (RuntimeInformation.OSDescription.Contains("Ubuntu", StringComparison.OrdinalIgnoreCase)) { platform = "UbuntuInstaller-x64"; } else if (RuntimeInformation.OSDescription.Contains("Manjaro", StringComparison.OrdinalIgnoreCase)) { platform = "ManjaroInstaller-x64"; } else { throw new PlatformNotSupportedException(); } await _webClientEx.DownloadFileTaskAsync( serverUrl + $"/API/ClientDownloads/{connectionInfo.OrganizationID}/{platform}", installerPath); await _webClientEx.DownloadFileTaskAsync( serverUrl + $"/API/AgentUpdate/DownloadPackage/linux/{downloadId}", zipPath); (await WebRequest.CreateHttp(serverUrl + $"/api/AgentUpdate/ClearDownload/{downloadId}").GetResponseAsync()).Dispose(); Logger.Write("Launching installer to perform update."); Process.Start("sudo", $"chmod +x {installerPath}").WaitForExit(); Process.Start("sudo", $"{installerPath} --path {zipPath}"); } catch (WebException ex) when(ex.Status == WebExceptionStatus.Timeout) { Logger.Write("Timed out while waiting to download update.", Shared.Enums.EventType.Warning); _lastUpdateFailure = DateTimeOffset.Now; } catch (Exception ex) { Logger.Write(ex); _lastUpdateFailure = DateTimeOffset.Now; } finally { _installLatestVersionLock.Release(); } }