Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
0
        /// <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");
        }
Ejemplo n.º 3
0
        //[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);
            }
        }
Ejemplo n.º 4
0
        /// <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");
                }
        }