Beispiel #1
0
        public async Task InstallLatestVersion()
        {
            try
            {
                await InstallLatestVersionLock.WaitAsync();

                var connectionInfo = ConfigService.GetConnectionInfo();
                var serverUrl      = connectionInfo.Host;

                Logger.Write("Service Updater: Downloading install package.");

                using var wc = new WebClientEx((int)UpdateTimer.Interval);
                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 wc.DownloadFileTaskAsync(
                    serverUrl + $"/Downloads/Remotely_Installer.exe",
                    installerPath);

                await wc.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);
                PreviousUpdateFailed = true;
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                PreviousUpdateFailed = true;
            }
            finally
            {
                InstallLatestVersionLock.Release();
            }
        }
        public async Task InstallLatestVersion()
        {
            try
            {
                var connectionInfo = ConfigService.GetConnectionInfo();
                var serverUrl      = connectionInfo.Host;

                Logger.Write("Service Updater: Downloading install package.");

                using var wc = new WebClientEx((int)UpdateTimer.Interval);
                var downloadId = Guid.NewGuid().ToString();
                var zipPath    = Path.Combine(Path.GetTempPath(), "RemotelyUpdate.zip");

                if (EnvironmentHelper.IsWindows)
                {
                    var installerPath = Path.Combine(Path.GetTempPath(), "Remotely_Installer.exe");
                    var platform      = Environment.Is64BitOperatingSystem ? "x64" : "x86";

                    await wc.DownloadFileTaskAsync(
                        serverUrl + $"/Downloads/Remotely_Installer.exe",
                        installerPath);

                    await wc.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}");
                }
                else if (EnvironmentHelper.IsLinux)
                {
                    var installerPath = Path.Combine(Path.GetTempPath(), "RemotelyUpdate.sh");

                    string platform;

                    if (RuntimeInformation.OSDescription.Contains("Ubuntu", StringComparison.OrdinalIgnoreCase))
                    {
                        platform = "Ubuntu-x64";
                    }
                    else if (RuntimeInformation.OSDescription.Contains("Manjaro", StringComparison.OrdinalIgnoreCase))
                    {
                        platform = "Manjaro-x64";
                    }
                    else
                    {
                        throw new PlatformNotSupportedException();
                    }

                    await wc.DownloadFileTaskAsync(
                        serverUrl + $"/API/ClientDownloads/{connectionInfo.OrganizationID}/{platform}",
                        installerPath);

                    await wc.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} & disown");
                }
            }
            catch (WebException ex) when(ex.Status == WebExceptionStatus.Timeout)
            {
                Logger.Write("Timed out while waiting to downloaod update.", Shared.Enums.EventType.Warning);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
            }
        }
Beispiel #3
0
        public async Task InstallLatestVersion()
        {
            try
            {
                await InstallLatestVersionLock.WaitAsync();

                var connectionInfo = ConfigService.GetConnectionInfo();
                var serverUrl      = connectionInfo.Host;

                Logger.Write("Service Updater: Downloading install package.");

                using var wc = new WebClientEx((int)UpdateTimer.Interval);
                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 = "Ubuntu-x64";
                }
                else if (RuntimeInformation.OSDescription.Contains("Manjaro", StringComparison.OrdinalIgnoreCase))
                {
                    platform = "Manjaro-x64";
                }
                else
                {
                    throw new PlatformNotSupportedException();
                }

                await wc.DownloadFileTaskAsync(
                    serverUrl + $"/API/ClientDownloads/{connectionInfo.OrganizationID}/{platform}",
                    installerPath);

                await wc.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} & disown");
            }
            catch (WebException ex) when(ex.Status == WebExceptionStatus.Timeout)
            {
                Logger.Write("Timed out while waiting to download update.", Shared.Enums.EventType.Warning);
                PreviousUpdateFailed = true;
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                PreviousUpdateFailed = true;
            }
            finally
            {
                InstallLatestVersionLock.Release();
            }
        }