private OsInfo GetOsInfo(FileMap script)
        {
            InstallationProgress.Step = InstallationProgressStep.GetOsInfo;
            CacheHelper.SetInstallationProgress(UserId, InstallationProgress);

            using (var stream = SshClient.CreateShellStream("terminal", 150, 24, 800, 600, 1024))
            {
                stream.WriteLine(string.Format("sudo bash {0}", script.RemotePath));

                var output = stream.Expect(Settings.InstallationStopPattern);

                if (output.Contains(Settings.InstallationSuccessPattern))
                {
                    InstallationProgress.ProgressText += output;
                }

                if (output.Contains(Settings.InstallationErrorPattern))
                {
                    throw new Exception(output);
                }
            }

            var osInfo = new OsInfo
            {
                Dist   = GetTerminalParam(InstallationProgress.ProgressText, "DIST"),
                Ver    = GetTerminalParam(InstallationProgress.ProgressText, "REV"),
                Type   = GetTerminalParam(InstallationProgress.ProgressText, "MACH"),
                Kernel = GetTerminalParam(InstallationProgress.ProgressText, "KERNEL")
            };

            return(osInfo);
        }
        private void InstallDocker(OsInfo osInfo, bool afterReboot = false)
        {
            if (afterReboot)
            {
                CheckPorts();
            }

            var needReboot = false;

            InstallationProgress.Step = InstallationProgressStep.InstallDocker;
            CacheHelper.SetInstallationProgress(UserId, InstallationProgress);

            var command = string.Format("sudo bash {0} \"{1}\" \"{2}\" \"{3}\" \"{4}\" {5}",
                                        FileMap.RunDockerScript.RemotePath,
                                        osInfo.Dist,
                                        osInfo.Ver,
                                        osInfo.Type,
                                        osInfo.Kernel,
                                        afterReboot ? true.ToString().ToLower() : string.Empty);

            using (var stream = SshClient.CreateShellStream("terminal", 150, 24, 800, 600, 1024))
            {
                stream.WriteLine(command);

                var output = stream.Expect(Settings.InstallationStopPattern);

                if (output.Contains(Settings.InstallationRebootPattern))
                {
                    InstallationProgress.ProgressText += output;
                    InstallationProgress.Step          = InstallationProgressStep.RebootServer;
                    CacheHelper.SetInstallationProgress(UserId, InstallationProgress);

                    needReboot = true;

                    stream.WriteLine("sudo reboot");

                    System.Threading.Thread.Sleep(10000);
                }
                else
                {
                    if (output.Contains(Settings.InstallationSuccessPattern))
                    {
                        InstallationProgress.ProgressText += output;
                    }

                    if (output.Contains(Settings.InstallationErrorPattern))
                    {
                        throw new Exception(output);
                    }
                }
            }

            if (needReboot)
            {
                InstallDocker(osInfo, true);
            }
        }
Пример #3
0
 private void InstallDocker(OsInfo osInfo)
 {
     RunScript(InstallationProgressStep.InstallDocker,
               FileMap.RunDockerScript,
               true,
               osInfo.Dist,
               osInfo.Ver,
               osInfo.Kernel,
               osInfo.Type);
 }
Пример #4
0
        private OsInfo GetOsInfo(FileMap script, InstallationProgressStep?progressStep)
        {
            var output = RunScript(progressStep, script);

            var osInfo = new OsInfo
            {
                Dist   = GetTerminalParam(output, "DIST"),
                Ver    = GetTerminalParam(output, "REV"),
                Type   = GetTerminalParam(output, "MACH"),
                Kernel = GetTerminalParam(output, "KERNEL")
            };

            CacheHelper.SetOsInfo(UserId, osInfo);

            return(osInfo);
        }
        private void InstallDocker(OsInfo osInfo, bool afterReboot = false)
        {
            if(afterReboot)
                CheckPorts();

            var needReboot = false;

            InstallationProgress.Step = InstallationProgressStep.InstallDocker;
            CacheHelper.SetInstallationProgress(UserId, InstallationProgress);

            var command = string.Format("sudo bash {0} \"{1}\" \"{2}\" \"{3}\" \"{4}\" {5}",
                                        FileMap.RunDockerScript.RemotePath,
                                        osInfo.Dist,
                                        osInfo.Ver,
                                        osInfo.Type,
                                        osInfo.Kernel,
                                        afterReboot ? true.ToString().ToLower() : string.Empty);

            using (var stream = SshClient.CreateShellStream("terminal", 150, 24, 800, 600, 1024))
            {
                stream.WriteLine(command);

                var output = stream.Expect(Settings.InstallationStopPattern);

                if (output.Contains(Settings.InstallationRebootPattern))
                {
                    InstallationProgress.ProgressText += output;
                    InstallationProgress.Step = InstallationProgressStep.RebootServer;
                    CacheHelper.SetInstallationProgress(UserId, InstallationProgress);

                    needReboot = true;

                    stream.WriteLine("sudo reboot");

                    System.Threading.Thread.Sleep(10000);
                }
                else
                {
                    if (output.Contains(Settings.InstallationSuccessPattern))
                        InstallationProgress.ProgressText += output;

                    if (output.Contains(Settings.InstallationErrorPattern))
                        throw new Exception(output);
                }
            }

            if (needReboot)
            {
                InstallDocker(osInfo, true);
            }
        }
        private OsInfo GetOsInfo(FileMap script)
        {
            InstallationProgress.Step = InstallationProgressStep.GetOsInfo;
            CacheHelper.SetInstallationProgress(UserId, InstallationProgress);

            using (var stream = SshClient.CreateShellStream("terminal", 150, 24, 800, 600, 1024))
            {
                stream.WriteLine(string.Format("sudo bash {0}", script.RemotePath));

                var output = stream.Expect(Settings.InstallationStopPattern);

                if (output.Contains(Settings.InstallationSuccessPattern))
                    InstallationProgress.ProgressText += output;

                if (output.Contains(Settings.InstallationErrorPattern))
                    throw new Exception(output);
            }

            var osInfo = new OsInfo
                                {
                                    Dist = GetTerminalParam(InstallationProgress.ProgressText, "DIST"),
                                    Ver = GetTerminalParam(InstallationProgress.ProgressText, "REV"),
                                    Type = GetTerminalParam(InstallationProgress.ProgressText, "MACH"),
                                    Kernel = GetTerminalParam(InstallationProgress.ProgressText, "KERNEL")
                                };

            return osInfo;
        }