示例#1
0
        public override bool AutorunSetup()
        {
            log.Trace("()");

            bool res = false;

            if (SystemInfo.CurrentRuntime.IsLinux())
            {
                Dictionary <string, string> templateReplacements = new Dictionary <string, string>(StringComparer.Ordinal)
                {
                    { "{USER}", Program.UserName },
                    { "{PATH}", GeneralConfiguration.SharedValues["PsDir"] },
                    { "{BIN}", GeneralConfiguration.SharedValues[Name + "-executable"] },
                    { "{SHUTDOWN}", GeneralConfiguration.SharedValues["Ps-ShutdownFile"] },
                };

                res = InstallationFile.InstallInitdScript(InitdScriptTemplateFile, templateReplacements, "start 99 2 3 4 5 . stop 1 0 1 6 .");
            }
            else if (SystemInfo.CurrentRuntime.IsWindows())
            {
                string bin  = GeneralConfiguration.SharedValues[Name + "-executable"];
                string args = "";
                string user = GeneralConfiguration.SharedValues["WinTask-User"];
                string pass = GeneralConfiguration.SharedValues["WinTask-Pass"];
                res = InstallationFile.SchtasksCreate(WinTaskName, bin, args, user, pass);
            }


            if (res)
            {
                Status |= InstallableComponentStatus.AutorunInstalled;
                log.Trace("AutorunInstalled status set for '{0}'.", Name);
            }

            log.Trace("(-):{0}", res);
            return(res);
        }
示例#2
0
        public override bool AutorunSetup()
        {
            log.Trace("()");

            bool res = false;

            if (SystemInfo.CurrentRuntime.IsLinux())
            {
                CUI.WriteRich("Creating init.d script <white>{0}</white>... ", InitdScriptTemplateFile);

                bool   error       = true;
                string content     = null;
                string initdScript = Path.Combine("init.d", InitdScriptTemplateFile);
                string destFile    = string.Format("/etc/init.d/{0}", InitdScriptTemplateFile);
                try
                {
                    content = File.ReadAllText(initdScript)
                              .Replace("{USER}", Program.UserName)
                              .Replace("{BIN}", GeneralConfiguration.SharedValues[Name + "-executable"]);

                    File.WriteAllText(destFile, content);

                    if (InstallationFile.Chmod(destFile, "a+x"))
                    {
                        CUI.WriteOk();
                        error = false;
                    }
                    else
                    {
                        log.Error("chmod on '{0}' failed.", destFile);
                        CUI.WriteFailed();
                        CUI.Write("<red>ERROR:</red> Unable to set access rights of file <white>{0}</white>.\n", initdScript);
                    }
                }
                catch (Exception e)
                {
                    log.Error("Exception occurred: {0}", e.ToString());
                    CUI.WriteFailed();
                    if (content == null)
                    {
                        CUI.Write("<red>ERROR:</red> Unable to read file <white>{0}</white>: {1}\n", initdScript, e.Message);
                    }
                    else
                    {
                        CUI.Write("<red>ERROR:</red> Unable to write to file <white>{0}</white>: {1}\n", destFile, e.Message);
                    }
                }

                if (!error)
                {
                    CUI.WriteRich("Installing init script links for <white>{0}</white>... ", InitdScriptTemplateFile);
                    if (InstallationFile.UpdateRcdInstall(InitdScriptTemplateFile, "start 99 2 3 4 5 . stop 1 0 1 6 ."))
                    {
                        CUI.WriteOk();
                        res = true;
                    }
                    else
                    {
                        log.Error("update-rc.d failed for '{0}'.", InitdScriptTemplateFile);
                        CUI.WriteFailed();
                    }
                }
            }
            else if (SystemInfo.CurrentRuntime.IsWindows())
            {
                string bin  = GeneralConfiguration.SharedValues[Name + "-executable"];
                string args = "";
                string user = GeneralConfiguration.SharedValues["WinTask-User"];
                string pass = GeneralConfiguration.SharedValues["WinTask-Pass"];
                res = InstallationFile.SchtasksCreate(WinTaskName, bin, args, user, pass);
            }


            if (res)
            {
                Status |= InstallableComponentStatus.AutorunInstalled;
                log.Trace("AutorunInstalled status set for '{0}'.", Name);
            }


            log.Trace("(-):{0}", res);
            return(res);
        }