コード例 #1
0
        public static string installation_type = "";                                                   //installation type

        /// <summary>
        ///  public static void download_repo()
        ///  Downloading nesessary files from kurjun(gorjun) repository accorfing to download list
        /// </summary>
        public static void download_repo()
        {
            Deploy.StageReporter("Downloading prerequisites", "");

            logger.Info("Downloading repo_descriptor");
            download_description_file("repo_descriptor");
            installation_type = _arguments["type"];

            Deploy.StageReporter("", $"Creating download list for installation type: {installation_type}");

            rows = FD.repo_rows($"{Program.inst_Dir}{_arguments["repo_descriptor"]}", _arguments["peer"], installation_type);
            string regfile = Path.Combine(FD.logDir(), "subutai-clean-registry.reg");

            Deploy.HideMarquee();
            download_file(regfile, download_prerequisites);
        }
コード例 #2
0
ファイル: Inst.cs プロジェクト: nibircse/installers
        /// <summary>
        /// public static void inst_ssh(string instDir)
        /// Create home folder (soft link) for ssh to create .ssh directory
        /// to keep ssh files - known_hosts, keys etc
        /// </summary>
        /// <param name="instDir">Installation directory</param>
        public static void inst_ssh(string instDir)
        {
            string path_t = Path.Combine(FD.sysDrive(), "Users");
            string path_l = Path.Combine(instDir, "home");

            path_l = FD.path_with_commas(path_l);
            if (!Directory.Exists(path_l))
            {
                string res = Deploy.LaunchCommandLineApp("cmd.exe", $"/C mklink /d {path_l} {path_t}", 300000);
                logger.Info("ssh - creating home: {0}", res);
            }
            else
            {
                logger.Info("link {0} already exists", path_l);
            }
        }
コード例 #3
0
ファイル: Deploy.cs プロジェクト: nibircse/installers
        /// <summary>
        /// Launches the command line application.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns></returns>
        public static string LaunchCommandLineApp(string filename, string arguments)
        {
            // Use ProcessStartInfo class
            string fname = FD.path_with_commas(filename);

            var startInfo = new ProcessStartInfo
            {
                CreateNoWindow         = true,
                UseShellExecute        = false,
                FileName               = fname,
                WindowStyle            = ProcessWindowStyle.Hidden,
                Arguments              = arguments,
                RedirectStandardOutput = true,
                RedirectStandardError  = true
            };
            string output;
            string err;

            logger.Info("trying to exe {0} {1}", filename, arguments);
            try
            {
                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                using (var exeProcess = Process.Start(startInfo))
                {
                    output = exeProcess.StandardOutput.ReadToEnd();
                    err    = exeProcess.StandardError.ReadToEnd();
                    exeProcess?.WaitForExit();
                    return($"executing: \"{filename} {arguments}\"|{output}|{err}");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, "can not run process {0}", filename); //try to repeat, counting
                Thread.Sleep(10000);                                           //uncomment if need repeated tries
                //LaunchCommandLineApp(filename, arguments, 0);//will try 3 times
            }
            return($"1|{filename} was not executed|Error");
        }
コード例 #4
0
        /// <summary>
        /// private void f_install_Load(object sender, EventArgs e)
        /// On form load: Changes environment variables - %Path% and %Subutai%
        /// updates uninstall string (in Windows Registry)
        /// and starts downloading
        /// </summary>
        private void f_install_Load(object sender, EventArgs e)
        {
            _deploy.SetEnvironmentVariables();
            Inst.remove_repo_desc(Program.inst_Dir, _arguments["repo_descriptor"]);

            string strUninstall = "";

            if (!FD.copy_uninstall())
            {
                strUninstall = Path.Combine(Program.inst_Dir, "bin", "uninstall-clean.exe");
            }
            else
            {
                strUninstall = Path.Combine(FD.logDir(), "uninstall-clean.exe");
            };

            Inst.update_uninstallString(strUninstall);

            string res = FD.delete_dir_bin(Program.inst_Dir);

            if (!res.Contains("Deleted"))
            {
                MessageBox.Show(res, "Delete bin folder", MessageBoxButtons.OK);
                res = FD.delete_dir_bin(Program.inst_Dir);
                if (!res.Contains("Deleted"))
                {
                    Program.ShowError("Can not delete bin folder.\nPlease, close running applications (Subutay tray, cmd sessions, file explorer) that can lock files \nand install again", "Delete bin folder");
                    Program.form1.Visible = false;
                }
            }

            if (_arguments["network-installation"].ToLower() == "true")
            {
                // DOWNLOAD REPO
                Deploy.StageReporter("Downloading prerequisites", "");
                Deploy.HideMarquee();
                TC.download_repo();
            }
        }
コード例 #5
0
ファイル: Deploy.cs プロジェクト: nibircse/installers
        /// <summary>
        /// public void SetEnvironmentVariables()
        /// Set environment variables %Path% and %Subutai%
        /// </summary>
        public void SetEnvironmentVariables()
        {
            string sysDrive = FD.sysDrive();
            //string path_orig = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
            string path_orig = Environment.GetEnvironmentVariable("Path");

            logger.Info("Orig: {0}", path_orig);
            if (!path_orig.Contains("VirtualBox"))
            {
                path_orig += $";{sysDrive}Program Files\\Oracle\\VirtualBox";
                //logger.Info("VirtualBox: {0}", path_orig);
            }

            if (!path_orig.Contains("TAP-Windows"))
            {
                path_orig += $";{sysDrive}Program Files\\TAP-Windows\\bin";
                //logger.Info("TAP-Windows: {0}", path_orig);
            }

            if (!path_orig.Contains("Subutai"))
            {
                path_orig += $";{Program.inst_Dir}bin";
                path_orig += $";{Program.inst_Dir}bin\\tray";
            }

            //            logger.Info("Path changed: {0}", Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine));
            path_orig = path_orig.Replace(";;", ";");
            Environment.SetEnvironmentVariable("Path", path_orig, EnvironmentVariableTarget.Machine);
            Environment.SetEnvironmentVariable("Path", path_orig, EnvironmentVariableTarget.Process);//comment to test Sirmen's issue
            logger.Info("Path machine: {0}", Environment.GetEnvironmentVariable("Path"), EnvironmentVariableTarget.Machine);
            logger.Info("Path Process: {0}", Environment.GetEnvironmentVariable("Path"), EnvironmentVariableTarget.Process);

            Environment.SetEnvironmentVariable("Subutai", Program.inst_Dir, EnvironmentVariableTarget.Machine);
            Environment.SetEnvironmentVariable("Subutai", Program.inst_Dir, EnvironmentVariableTarget.Process);

            logger.Info("Subutai machine: {0}", Environment.GetEnvironmentVariable("Subutai"), EnvironmentVariableTarget.Machine);
            logger.Info("Subutai Process: {0}", Environment.GetEnvironmentVariable("Subutai"), EnvironmentVariableTarget.Process);
        }
コード例 #6
0
 /// <summary>
 /// Runs uninstall application
 /// </summary>
 /// <param name="appdir">The appdir - installation folder</param>
 private void clean(string appdir)
 {
     Process.Start($"{FD.logDir()}\\{Deploy.SubutaiUninstallName}", "Silent false NoAll");
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: nibircse/installers
        //[STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            AppDomain current_domain = AppDomain.CurrentDomain;

            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //Add installation type command line parameter to parameter string
            inst_type = InstType(cmd_args[1]);
            string repo_desc        = cmd_args[2];
            string if_installer_run = cmd_args[3];
            string kurjunURL        = cmd_args[4];

            inst_args = $"type={inst_type} network-installation=true kurjunUrl={kurjunURL} repo_descriptor={repo_desc}";

            logger.Info("Argument string: {0}", inst_args);
            //Check if_installer_run - if "Installer", will run application in new process - to close installer

            if (if_installer_run.Equals("Installer"))
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.UseShellExecute  = true;
                startInfo.WorkingDirectory = Environment.CurrentDirectory;
                startInfo.FileName         = Application.ExecutablePath;
                startInfo.Arguments        = $"{cmd_args[1]} {cmd_args[2]} Run {kurjunURL}";
                startInfo.Verb             = "runas";
                try
                {
                    Thread.Sleep(3000);
                    Process p = Process.Start(startInfo);
                    Environment.Exit(0);
                }
                catch (System.ComponentModel.Win32Exception)
                {
                    MessageBox.Show("This utility requires elevated priviledges to complete correctly.", "Error: UAC Authorisation Required", MessageBoxButtons.OK);
                    return;
                }
            }
            inst_Dir = Inst.subutai_path();
            form_    = new f_confirm();
            form_.ShowDialog();
            if (stRun)
            {
                form1 = new f_install(inst_args);
                form2 = new InstallationFinished("complete", "");

                Application.Run(form1);
            }
            else
            {
                if (inst_Dir.Equals("") || inst_Dir.Equals("\"\""))
                {
                    inst_Dir = Inst.subutai_path();
                }

                string cmd = $"{inst_Dir}bin\\uninstall-clean.exe";
                cmd = FD.path_with_commas(cmd);
                var startInfo = new ProcessStartInfo
                {
                    CreateNoWindow  = true,
                    UseShellExecute = false,
                    FileName        = cmd,
                    WindowStyle     = ProcessWindowStyle.Hidden,
                    Arguments       = "Silent NoAll"
                };
                var exeProcess = Process.Start(startInfo);
                Environment.Exit(1);
            }
        }
コード例 #8
0
ファイル: Deploy.cs プロジェクト: nibircse/installers
        /// <summary>
        /// Creates all shortcuts needed.
        /// </summary>
        public void createAppShortCuts(bool forAll)
        {
            logger.Info("Creating shortcuts");
            var    binPath  = "";
            var    destPath = "";
            string iconPath = "";

            if (forAll)
            {
                //Creating tray shortcuts
                binPath  = Path.Combine(Program.inst_Dir, "bin\\tray", SubutaiTrayName);
                destPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory),
                                        "Subutai.lnk");


                //Desktop
                iconPath = Path.Combine(Program.inst_Dir, SubutaiIconName);
                Deploy.CreateShortcut(
                    binPath,
                    destPath,
                    "",
                    iconPath,
                    false);

                //StartMenu/Programs
                destPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu),
                                        "Programs",
                                        "Subutai.lnk");
                Deploy.CreateShortcut(
                    binPath,
                    destPath,
                    "",
                    iconPath,
                    false);
            }

            //Create App folder in Programs
            string folderpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms), "Subutai");

            try
            {
                if (!Directory.Exists(folderpath))
                {
                    Directory.CreateDirectory(folderpath);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }

            if (forAll)
            {
                //Shortcut in Subutai folder for SubutaiTray
                destPath = Path.Combine(folderpath, "Subutai.lnk");
                Deploy.CreateShortcut(
                    binPath,
                    destPath,
                    "",
                    iconPath,
                    false);
            }

            //Shortcut in Subutai folder for Uninstall
            destPath = Path.Combine(folderpath, "Uninstall.lnk");
            binPath  = Path.Combine(FD.logDir(), SubutaiUninstallName);
            iconPath = Path.Combine(Program.inst_Dir, SubutaiUninstallIconName);
            Deploy.CreateShortcut(
                binPath,
                destPath,
                "",
                iconPath,
                false);
        }
コード例 #9
0
ファイル: Deploy.cs プロジェクト: nibircse/installers
        /// <summary>
        /// Launches the command line application with timeout.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <param name="arguments">The arguments.</param>
        /// <param name="timeout">The timeout for command in ms.</param>
        /// <returns></returns>
        public static string LaunchCommandLineApp(string filename, string arguments, int timeout)
        {
            // Use ProcessStartInfo class
            string fname = FD.path_with_commas(filename);

            var startInfo = new ProcessStartInfo
            {
                CreateNoWindow         = true,
                UseShellExecute        = false,
                FileName               = fname,
                WindowStyle            = ProcessWindowStyle.Hidden,
                Arguments              = arguments,
                RedirectStandardOutput = true,
                RedirectStandardError  = true
            };
            //string output;
            //string err;
            Process process = new Process();

            process.StartInfo = startInfo;

            StringBuilder output = new StringBuilder();
            StringBuilder error  = new StringBuilder();

            using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
                using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
                {
                    process.OutputDataReceived += (sender, e) =>
                    {
                        if (e.Data == null)
                        {
                            outputWaitHandle.Set();
                        }
                        else
                        {
                            output.AppendLine(e.Data);
                        }
                    };
                    process.ErrorDataReceived += (sender, e) =>
                    {
                        if (e.Data == null)
                        {
                            errorWaitHandle.Set();
                        }
                        else
                        {
                            error.AppendLine(e.Data);
                        }
                    };

                    logger.Info("trying to exe {0} {1}", filename, arguments);
                    try
                    {
                        // Start the process with the info we specified.
                        // Call WaitForExit and then the using statement will close.
                        process.Start();

                        process.BeginOutputReadLine();
                        process.BeginErrorReadLine();

                        if (process.WaitForExit(timeout) &&
                            outputWaitHandle.WaitOne(timeout) &&
                            errorWaitHandle.WaitOne(timeout))
                        {
                            // Process completed. Check process.ExitCode here.
                            return($"executing: \"{filename} {arguments}\"|{output}|{error}");
                        }
                        else
                        {
                            // Timed out.
                            return($"1|{filename} was timed out|Error");
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message, "can not run process {0}", filename);
                        //try to repeat, counting
                        //uncomment if need repeated tries
                        //LaunchCommandLineApp(filename, arguments, 0);//will try 3 times
                        //Thread.Sleep(10000);
                    }
                    return($"1|{filename} was not executed|Error");
                }
        }
コード例 #10
0
ファイル: Inst.cs プロジェクト: nibircse/installers
        /// <summary>
        /// public static void install_mh_nw()
        /// Installing management host, ssh using name-password
        /// </summary>
        public static void install_mh_nw()
        {
            //installing master template

            bool b_res = import_templ_task("master");

            // installing management template
            b_res = import_templ_task("management");
            string ssh_res = "";

            if (!b_res)
            {
                logger.Info("trying import management again");
                //need to remove previouis import
                string killcmd = "sudo kill `ps -ef | grep import | grep -v grep | awk '{print $2}'`";
                ssh_res = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu",
                                                killcmd, 7);
                logger.Info("Importing stuck first time, killing processes: {0}", ssh_res);

                if (ssh_res.Contains("Connection Error"))
                {
                    string kh_path = Path.Combine($"{ Program.inst_Dir}home", Environment.UserName, ".ssh", "known_hosts");
                    FD.edit_known_hosts(kh_path);

                    //restarting VM
                    if (!VMs.restart_vm(TC._cloneName))
                    {
                        //can not restart VM
                        Program.ShowError("Can not restart VM, please check VM state and try to install later", "Can not start VM");
                        Program.form1.Visible = false;
                    }
                    ;
                }
                //remove previously installed master
                ssh_res = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu",
                                                "sudo subutai destroy master", 7);
                logger.Info("Destroying master to import second time: {0}", ssh_res);

                ssh_res = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu",
                                                "sudo subutai destroy management", 7);
                logger.Info("Destroying management to import second time: {0}", ssh_res);

                b_res = import_templ_task("master");

                b_res = import_templ_task("management");
                if (!b_res)
                {
                    logger.Info("import management failed second time");
                    Program.form1.Invoke((MethodInvoker) delegate
                    {
                        Program.ShowError("Management template was not installed, installation failed, please try to install later", "Management template was not imported");
                        Program.form1.Visible = false;
                    });
                }
            }

            ssh_res = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu",
                                            "sudo bash subutai info ipaddr", 7);
            //todo: delete old
            logger.Info("Import management address returned by subutai info: {0}", ssh_res);

            string rhIP = Deploy.com_out(ssh_res, 1);

            if (!is_ip_address(rhIP))
            {
                logger.Error("import management failed ", "Management template was not installed");
                Program.ShowError("Management template was not installed, installation failed, removing", "Management template was not imported");
                Program.form1.Visible = false;
            }
        }