示例#1
0
        public async Task PerformInstall(CliParams cliParams)
        {
            var latestBuild = await _githubApi.GetLatestBuildArtifact(cliParams);

            var latestBuildId = latestBuild?.id;

            if (cliParams.CreateNew == true)
            {
                var dispatchResult = await _githubApi.TriggerDispatch(cliParams);

                if (!dispatchResult)
                {
                    ConsoleHelper.WriteError("GitHub API call to trigger build action failed.  Do you have " +
                                             "Actions enabled on your forked Remotely repo on the Actions tab?  If not, enable them and try again. " +
                                             "Otherwise, please check your input parameters.");
                    return;
                }

                ConsoleHelper.WriteLine("Build action triggered successfully.  Waiting for build completion.");

                while (latestBuild?.id == latestBuildId)
                {
                    await Task.Delay(TimeSpan.FromMinutes(1));

                    ConsoleHelper.WriteLine("Waiting for GitHub build completion.");
                    latestBuild = await _githubApi.GetLatestBuildArtifact(cliParams);
                }
            }
            else if (latestBuild is null)
            {
                ConsoleHelper.WriteError("There are no existing build artifacts, and --create-new was not specified.  Exiting.");
                return;
            }

            var filePath = Path.Combine(Path.GetTempPath(), "Remotely_Artifact.zip");

            var downloadResult = await _githubApi.DownloadArtifact(cliParams, latestBuild.archive_download_url, filePath);

            if (!downloadResult)
            {
                ConsoleHelper.WriteError("Downloading the build artifact was not successful.");
                return;
            }


            ConsoleHelper.WriteLine("Extracting artifact files.");
            if (Directory.Exists(cliParams.InstallDirectory))
            {
                Directory.Delete(cliParams.InstallDirectory, true);
            }
            Directory.CreateDirectory(cliParams.InstallDirectory);
            ZipFile.ExtractToDirectory(filePath, cliParams.InstallDirectory);

            await LaunchExternalInstaller(cliParams);
        }
示例#2
0
        public async Task PerformInstall(CliParams cliParams)
        {
            var zipPath = Path.Combine(Path.GetTempPath(), "Remotely_Server.zip");

            if (cliParams.UsePrebuiltPackage == true)
            {
                ConsoleHelper.WriteLine("Downloading pre-built server package.");

                int progress = 0;

                var releaseFile = cliParams.WebServer == WebServerType.IisWindows ?
                                  "https://github.com/lucent-sea/Remotely/releases/latest/download/Remotely_Server_Win-x64.zip" :
                                  "https://github.com/lucent-sea/Remotely/releases/latest/download/Remotely_Server_Linux-x64.zip";

                using var webClient = new WebClient();
                webClient.DownloadProgressChanged += (sender, args) =>
                {
                    var newProgress = args.ProgressPercentage / 5 * 5;
                    if (newProgress != progress)
                    {
                        progress = newProgress;
                        ConsoleHelper.WriteLine($"Progress: {progress}%");
                    }
                };
                await webClient.DownloadFileTaskAsync(releaseFile, zipPath);
            }
            else
            {
                var latestBuild = await _githubApi.GetLatestBuildArtifact(cliParams);

                var latestBuildId = latestBuild?.id;

                if (cliParams.CreateNew == true)
                {
                    var dispatchResult = await _githubApi.TriggerDispatch(cliParams);

                    if (!dispatchResult)
                    {
                        ConsoleHelper.WriteError("GitHub API call to trigger build action failed.  Do you have " +
                                                 "Actions enabled on your forked Remotely repo on the Actions tab?  If not, enable them and try again. " +
                                                 "Otherwise, please check your input parameters.");
                        return;
                    }

                    ConsoleHelper.WriteLine("Build action triggered successfully.  Waiting for build completion.");

                    while (latestBuild?.id == latestBuildId)
                    {
                        await Task.Delay(TimeSpan.FromMinutes(1));

                        ConsoleHelper.WriteLine("Waiting for GitHub build completion.");
                        latestBuild = await _githubApi.GetLatestBuildArtifact(cliParams);
                    }
                }
                else if (latestBuild is null)
                {
                    ConsoleHelper.WriteError("There are no existing build artifacts, and --create-new was not specified.  Exiting.");
                    return;
                }

                var downloadResult = await _githubApi.DownloadArtifact(cliParams, latestBuild.archive_download_url, zipPath);

                if (!downloadResult)
                {
                    ConsoleHelper.WriteError("Downloading the build artifact was not successful.");
                    return;
                }
            }

            // Files in use can't be overwritten in Windows.  Stop the
            // website process first.
            if (cliParams.WebServer == WebServerType.IisWindows)
            {
                var initialW3wpCount = Process.GetProcessesByName("w3wp").Length;
                Process.Start("powershell.exe", "-Command & \"{ Stop-WebAppPool -Name Remotely -ErrorAction SilentlyContinue }\"").WaitForExit();
                Process.Start("powershell.exe", "-Command & \"{ Stop-Website -Name Remotely -ErrorAction SilentlyContinue }\"").WaitForExit();
                ConsoleHelper.WriteLine("Waiting for w3wp processes to close...");
                TaskHelper.DelayUntil(() => Process.GetProcessesByName("w3wp").Length < initialW3wpCount, TimeSpan.FromMinutes(5), 100);
            }

            ConsoleHelper.WriteLine("Extracting files.");
            Directory.CreateDirectory(cliParams.InstallDirectory);
            ZipFile.ExtractToDirectory(zipPath, cliParams.InstallDirectory, true);

            await LaunchExternalInstaller(cliParams);
        }
示例#3
0
        public async Task PerformInstall(CliParams cliParams)
        {
            var filePath = Path.Combine(Path.GetTempPath(), "Remotely_Server.zip");

            if (cliParams.UsePrebuiltPackage == true)
            {
                ConsoleHelper.WriteLine("Downloading pre-built server package.");

                var progress    = 0;
                var releaseFile = "https://github.com/lucent-sea/Remotely/releases/latest/download/Remotely_Server_Linux-x64.zip";
                using var webClient = new WebClient();
                webClient.DownloadProgressChanged += (sender, arg) =>
                {
                    var newProgress = arg.ProgressPercentage / 5 * 5;
                    if (newProgress != progress)
                    {
                        progress = newProgress;
                        ConsoleHelper.WriteLine($"Progress: {progress}%");
                    }
                };
                await webClient.DownloadFileTaskAsync(releaseFile, filePath);
            }
            else
            {
                var latestBuild = await _githubApi.GetLatestBuildArtifact(cliParams);

                var latestBuildId = latestBuild?.id;

                if (cliParams.CreateNew == true)
                {
                    var dispatchResult = await _githubApi.TriggerDispatch(cliParams);

                    if (!dispatchResult)
                    {
                        ConsoleHelper.WriteError("GitHub API call to trigger build action failed.  Do you have " +
                                                 "Actions enabled on your forked Remotely repo on the Actions tab?  If not, enable them and try again. " +
                                                 "Otherwise, please check your input parameters.");
                        return;
                    }

                    ConsoleHelper.WriteLine("Build action triggered successfully.  Waiting for build completion.");

                    while (latestBuild?.id == latestBuildId)
                    {
                        await Task.Delay(TimeSpan.FromMinutes(1));

                        ConsoleHelper.WriteLine("Waiting for GitHub build completion.");
                        latestBuild = await _githubApi.GetLatestBuildArtifact(cliParams);
                    }
                }
                else if (latestBuild is null)
                {
                    ConsoleHelper.WriteError("There are no existing build artifacts, and --create-new was not specified.  Exiting.");
                    return;
                }

                var downloadResult = await _githubApi.DownloadArtifact(cliParams, latestBuild.archive_download_url, filePath);

                if (!downloadResult)
                {
                    ConsoleHelper.WriteError("Downloading the build artifact was not successful.");
                    return;
                }
            }


            ConsoleHelper.WriteLine("Extracting files.");
            if (Directory.Exists(cliParams.InstallDirectory))
            {
                Directory.Delete(cliParams.InstallDirectory, true);
            }
            Directory.CreateDirectory(cliParams.InstallDirectory);
            ZipFile.ExtractToDirectory(filePath, cliParams.InstallDirectory);

            await LaunchExternalInstaller(cliParams);
        }