public override bool Start() { log.Trace("()"); bool res = false; if (SystemInfo.CurrentRuntime.IsLinux()) { res = InstallationFile.RunInitdScript(InitdScriptTemplateFile, "start"); } else if (SystemInfo.CurrentRuntime.IsWindows()) { res = InstallationFile.SchtasksRun(WinTaskName); } if (res) { Status |= InstallableComponentStatus.Running; log.Trace("Running status set for '{0}'.", Name); } log.Trace("(-):{0}", res); return(res); }
public override bool AutorunSetupUninstall() { log.Trace("()"); bool res = false; if (SystemInfo.CurrentRuntime.IsLinux()) { res = InstallationFile.UpdateRcdRemove(InitdScriptTemplateFile); } else if (SystemInfo.CurrentRuntime.IsWindows()) { res = InstallationFile.SchtasksDelete(WinTaskName); } if (res) { Status &= ~InstallableComponentStatus.AutorunInstalled; } log.Trace("(-):{0}", res); return(res); }
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); }
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); }
public override bool Configure() { log.Trace("()"); bool res = false; Dictionary <string, string> conf; if (!ConfigurationByRid.TryGetValue(SystemInfo.CurrentRuntime.Rid, out conf)) { log.Trace("(-)[UNSUPPORTED]:{0}", res); return(res); } bool done = false; while (!done) { string appDataDir = Environment.ExpandEnvironmentVariables(conf["Application data directory"]); string dataDir = InstallationFile.AskForEmptyDirectory(string.Format("Where do you want <white>CAN server application data</white> to be stored? [{0}] ", appDataDir), appDataDir); conf["Application data directory"] = dataDir; GeneralConfiguration.SharedValues.Add("Can-DataDir", dataDir); string confFile = Path.Combine(dataDir, conf["Configuration file"]); int apiPort = int.Parse(conf["API port"]); while (GeneralConfiguration.UsedPorts.ContainsKey(apiPort)) { apiPort++; } conf["API port"] = apiPort.ToString(); log.Debug("Selected port {0} as CAN server's API port.", apiPort); GeneralConfiguration.UsedPorts.Add(apiPort, "CAN server API interface"); GeneralConfiguration.SharedValues.Add("CAN server API interface", apiPort.ToString()); int swarmPort = int.Parse(conf["Swarm port"]); swarmPort = AskForOpenPort(string.Format("Please enter a port number for <white>CAN server swarm interface</white>. This port will have to be open and publicly accessible from the Internet. [{0}] ", swarmPort), swarmPort, "CAN server swarm interface"); conf["Swarm port"] = swarmPort.ToString(); int gatewayPort = int.Parse(conf["Gateway port"]); gatewayPort = AskForOpenPort(string.Format("Please enter a port number for <white>CAN server gateway interface</white>. This port will have to be open and publicly accessible from the Internet. [{0}] ", gatewayPort), gatewayPort, "CAN server gateway interface"); conf["Gateway port"] = gatewayPort.ToString(); string ipfs = SystemInfo.CurrentRuntime.IsLinux() ? Path.Combine(GeneralConfiguration.SharedValues["CanDir"], "ipfs") : Path.Combine(GeneralConfiguration.SharedValues["CanDir"], "ipfs.exe"); string initIpfsScript = SystemInfo.CurrentRuntime.IsLinux() ? Path.Combine(InstallationFile.TemporaryDirectoryName, "ipfsinit.sh") : Path.Combine(InstallationFile.TemporaryDirectoryName, "ipfsinit.cmd"); string initIpfsScriptContent = SystemInfo.CurrentRuntime.IsLinux() ? string.Format("#/bin/base\n" + "\n" + "export IOPCAN_PATH=\"{0}\"\n" + "\"{1}\" init\n", dataDir, ipfs) : string.Format("@set \"IOPCAN_PATH={0}\"\n" + "\"{1}\" init\n", dataDir, ipfs); CUI.WriteRich("Creating <white>CAN server init script</white>... "); if (InstallationFile.CreateFileWriteTextChown(initIpfsScript, initIpfsScriptContent)) { CUI.WriteOk(); CUI.WriteRich("Creating <white>CAN server daemon script</white>... "); string daemonIpfsScript = SystemInfo.CurrentRuntime.IsLinux() ? Path.Combine(GeneralConfiguration.SharedValues["CanDir"], "iop-can") : Path.Combine(GeneralConfiguration.SharedValues["CanDir"], "iop-can.cmd"); GeneralConfiguration.SharedValues[Name + "-executable"] = daemonIpfsScript; GeneralConfiguration.SharedValues[Name + "-executable-args"] = string.Format("\"{0}\"", daemonIpfsScript); string daemonIpfsScriptContent = SystemInfo.CurrentRuntime.IsLinux() ? string.Format("#/bin/base\n" + "\n" + "export IOPCAN_PATH=\"{0}\"\n" + "\"{1}\" daemon &\n", dataDir, ipfs) : string.Format("@set \"IOPCAN_PATH={0}\"\n" + "\"{1}\" daemon\n", dataDir, ipfs); if (InstallationFile.CreateFileWriteTextChown(daemonIpfsScript, daemonIpfsScriptContent)) { CUI.WriteOk(); done = true; CUI.WriteRich("Starting <white>CAN server init script</white>... "); ConsoleProcess initScriptProcess = SystemInfo.CurrentRuntime.IsLinux() ? new ConsoleProcess("bash", string.Format("-x ./{0}", initIpfsScript)) : new ConsoleProcess("cmd.exe", string.Format("/C {0}", initIpfsScript)); if (initScriptProcess.RunAndWaitSuccessExit(20000)) { CUI.WriteOk(); InstallationFile.Chown(dataDir); CUI.WriteRich("Loading <white>CAN server configuration file</white>... "); try { string[] lines = File.ReadAllLines(confFile); CUI.WriteOk(); bool addressesSection = false; List <string> confLines = new List <string>(); foreach (string line in lines) { string confLine = line; if (addressesSection) { if (confLine.Contains("/ip4/0.0.0.0/tcp/14001")) { confLine = confLine.Replace("tcp/14001", string.Format("tcp/{0}", conf["Swarm port"])); } else if (confLine.Contains("ip6/::/tcp/14001")) { confLine = confLine.Replace("tcp/14001", string.Format("tcp/{0}", conf["Swarm port"])); } else if (confLine.Contains("/ip4/127.0.0.1/tcp/15001")) { confLine = confLine.Replace("tcp/15001", string.Format("tcp/{0}", conf["API port"])); } else if (confLine.Contains("/ip4/127.0.0.1/tcp/18080")) { confLine = confLine.Replace("tcp/18080", string.Format("tcp/{0}", conf["Gateway port"])); } else if (confLine.Trim().EndsWith("},")) { addressesSection = false; } } else { addressesSection = confLine.Contains("\"Addresses\":"); } confLines.Add(confLine); } CUI.WriteRich("Writing new <white>CAN server configuration file</white>... "); if (InstallationFile.CreateFileWriteTextChown(confFile, string.Join("\n", confLines))) { CUI.WriteOk(); res = true; } else { CUI.WriteFailed(); CUI.WriteRich("<red>ERROR:</red> unable to write to file <white>{0}</white>.\n", confFile); } } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); CUI.WriteFailed(); CUI.WriteRich("<red>ERROR:</red> unable to read file <white>{0}</white>.\n", confFile); } } else { CUI.WriteFailed(); } } else { CUI.WriteFailed(); CUI.WriteRich("<red>ERROR:</red> unable to write to <white>{0}</white>. Please try again.\n", daemonIpfsScript); } try { File.Delete(initIpfsScript); } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } } else { CUI.WriteFailed(); CUI.WriteRich("<red>ERROR:</red> unable to write to <white>{0}</white>. Please try again.\n", initIpfsScript); } } log.Trace("(-):{0}", res); return(res); }
/// <summary> /// Creates the installer settings file and informs user about it. /// </summary> public static void SaveInstallerSettings() { log.Trace("()"); string home = SystemInfo.CurrentRuntime.IsLinux() ? Environment.ExpandEnvironmentVariables("%HOME%") : Environment.ExpandEnvironmentVariables("%APPDATA%"); string appDataDir = SystemInfo.CurrentRuntime.IsLinux() ? Path.Combine(home, ".IoP-FullNodeInstaller") : Path.Combine(home, "IoP-FullNodeInstaller"); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("installer_version={0}", Version)); sb.AppendLine(); sb.AppendLine(string.Format("core_wallet_version={0}", IopBlockchain.Version)); sb.AppendLine(string.Format("loc_server_version={0}", LocServer.Version)); sb.AppendLine(string.Format("can_server_version={0}", CanServer.Version)); sb.AppendLine(string.Format("profile_server_version={0}", ProfileServer.Version)); sb.AppendLine(); string cwDir = GeneralConfiguration.SharedValues.ContainsKey("CoreWalletDir") ? GeneralConfiguration.SharedValues["CoreWalletDir"] : "auto/package"; sb.AppendLine(string.Format("core_wallet_dir={0}", cwDir)); string locDir = GeneralConfiguration.SharedValues.ContainsKey("LocDir") ? GeneralConfiguration.SharedValues["LocDir"] : "auto/package"; sb.AppendLine(string.Format("loc_server_dir={0}", locDir)); string canDir = GeneralConfiguration.SharedValues["CanDir"]; sb.AppendLine(string.Format("can_server_dir={0}", canDir)); string psDir = GeneralConfiguration.SharedValues["PsDir"]; sb.AppendLine(string.Format("profile_server_dir={0}", psDir)); string opensslDir = GeneralConfiguration.SharedValues.ContainsKey("OpenSslDir") ? GeneralConfiguration.SharedValues["OpenSslDir"] : "auto/package"; sb.AppendLine(string.Format("openssl_dir={0}", opensslDir)); sb.AppendLine(); string cwDataDir = GeneralConfiguration.SharedValues["CoreWallet-DataDir"]; sb.AppendLine(string.Format("core_wallet_data_dir={0}", cwDataDir)); string locDataDir = GeneralConfiguration.SharedValues["Loc-DataDir"]; sb.AppendLine(string.Format("loc_server_data_dir={0}", locDataDir)); string canDataDir = GeneralConfiguration.SharedValues["Can-DataDir"]; sb.AppendLine(string.Format("can_server_data_dir={0}", canDataDir)); string psDataDir = GeneralConfiguration.SharedValues["Ps-DataDir"]; sb.AppendLine(string.Format("profile_server_data_dir={0}", psDataDir)); CUI.WriteRich("Saving Full Node Installer configuration... "); string dir = InstallationFile.CreateDirectory(appDataDir); if (dir != null) { string confFile = Path.Combine(dir, "FullNodeInstaller.config"); if (InstallationFile.CreateFileWriteTextChown(confFile, sb.ToString())) { CUI.WriteOk(); CUI.WriteRich("\nPlease note that file <white>{0}</white> has been created and it contains information about the installed components. <yellow>You should preserve this file if you want to upgrade or uninstall the installed components later.</yellow>\n", confFile); } else { CUI.WriteFailed(); CUI.WriteRich("<red>ERROR:</red> Unable to write to file <white>{0}</white>.", confFile); log.Error("Unable to write to file '{0}'.", confFile); } } else { CUI.WriteFailed(); CUI.WriteRich("<red>ERROR:</red> Unable to create directory <white>{0}</white>.", appDataDir); log.Error("Unable to create directory '{0}'.", appDataDir); } log.Trace("(-)"); }
/// <summary> /// Program entry point. /// </summary> /// <param name="Args">Program command line arguments.</param> static void Main(string[] Args) { log.Trace("(Args:'{0}')", string.Join(" ", Args)); CUI.InitConsole(); if ((Args.Length == 1) && (Args[0] == "TestMode")) { TestMode = true; log.Info("Test mode is enabled."); CUI.WriteRich("\n<yellow>Test mode ENABLED. Note that in test mode you can skip the port check by using port values between 50001 and 65535.</yellow>\n\n"); } // Make sure the current directory is set to the directory of the main executable. string path = System.Reflection.Assembly.GetEntryAssembly().Location; path = Path.GetDirectoryName(path); Directory.SetCurrentDirectory(path); InstallationFile.Chown("./Logs"); log.Debug("Rid is {0}.", SystemInfo.CurrentRuntime.Rid); if (SystemInfo.CurrentRuntime.IsLinux()) { int sudoUid, sudoGid; if (int.TryParse(Environment.ExpandEnvironmentVariables("%SUDO_UID%"), out sudoUid) && int.TryParse(Environment.ExpandEnvironmentVariables("%SUDO_GID%"), out sudoGid)) { SudoUserGroup = string.Format("{0}:{1}", sudoUid, sudoGid); UserName = Environment.ExpandEnvironmentVariables("%SUDO_USER%"); } if (string.IsNullOrEmpty(UserName)) { UserName = "******"; } } else if (SystemInfo.CurrentRuntime.IsWindows()) { UserName = Environment.ExpandEnvironmentVariables("%USERNAME%"); } switch (SystemInfo.CurrentRuntime.Rid) { case Rid.ubuntu_14_04_x64: case Rid.ubuntu_16_04_x64: case Rid.ubuntu_16_10_x64: case Rid.win7_x64: case Rid.win8_x64: case Rid.win81_x64: case Rid.win10_x64: if (!InstallAll()) { log.Error("Installation failed."); } break; default: CUI.WriteLine(ConsoleColor.Red, "Error: Your operating system is not supported."); break; } CUI.FinitConsole(); log.Trace("(-)"); }
public override bool Configure() { log.Trace("()"); bool res = false; Dictionary <string, string> conf; if (!ConfigurationByRid.TryGetValue(SystemInfo.CurrentRuntime.Rid, out conf)) { log.Trace("(-)[UNSUPPORTED]:{0}", res); return(res); } bool rpcPublic = false; int rpcPort = int.Parse(conf["RPC port"]); string rpcUser = conf["RPC user"]; string rpcPassword = "******"; string miningLicense = ""; string miningToAddress = ""; string miningLicensePrivKey = ""; bool miningEnabled = false; bool rpcEnabled = false; string dataDir = ""; string confFile = ""; while (!res) { string appDataDir = Environment.ExpandEnvironmentVariables(conf["Application data directory"]); dataDir = InstallationFile.AskForEmptyDirectory(string.Format("Where do you want <white>IoP Blockchain Core wallet application data</white> to be stored? [{0}] ", appDataDir), appDataDir); conf["Application data directory"] = dataDir; GeneralConfiguration.SharedValues.Add("CoreWallet-DataDir", dataDir); confFile = Path.Combine(dataDir, conf["Configuration file"]); int mainPort = int.Parse(conf["Main port"]); mainPort = AskForOpenPort(string.Format("Please enter a port number for <white>Core wallet P2P interface</white>. This port will have to be open and publicly accessible from the Internet. [{0}] ", mainPort), mainPort, "Core wallet P2P interface"); conf["Main port"] = mainPort.ToString(); CUI.WriteRich("Would you like to run <white>Core wallet RPC server</white> (this is required if you want to mine)? [<white>N</white>O / <white>y</white>es] "); rpcEnabled = CUI.ReadKeyAnswer(new char[] { 'n', 'y' }) == 'y'; if (rpcEnabled) { CUI.WriteRich("Would you like the <white>RPC server</white> to be accessible from the Internet? [<white>N</white>O / <white>y</white>es] "); rpcPublic = CUI.ReadKeyAnswer(new char[] { 'n', 'y' }) == 'y'; if (rpcPublic) { rpcPort = AskForOpenPort(string.Format("Please enter a port number for <white>Core wallet RPC interface</white>. This port will have to be open and publicly accessible from the Internet. If you changed your mind and you do not want the RPC server to be accessible from the Internet, enter 0. [{0}] ", rpcPort), rpcPort, "Core wallet RPC interface", true); if (rpcPort != 0) { conf["RPC port"] = rpcPort.ToString(); } else { rpcPublic = false; } } CUI.WriteRich("Enter RPC user name: [{0}] ", rpcUser); rpcUser = CUI.ReadStringAnswer(rpcUser); conf["RPC user"] = rpcUser; CUI.WriteRich("Enter RPC password: [{0}] ", rpcPassword); rpcPassword = CUI.ReadStringAnswer(rpcPassword); CUI.WriteRich("Do you have a mining license and would you like to run a miner? [<white>N</white>O / <white>y</white>es] "); miningEnabled = CUI.ReadKeyAnswer(new char[] { 'n', 'y' }) == 'y'; if (miningEnabled) { CUI.WriteRich("Enter your mining license address (or press ENTER if you changed your mind): "); miningLicense = CUI.ReadStringAnswer(miningLicense); if (!string.IsNullOrEmpty(miningLicense)) { CUI.WriteRich("Enter the private key for your mining license. <yellow>Note that If you entered a wrong mining license or if you enter wrong private key, this installer will not recognize it, but your Core wallet may fail to start.</yellow> Private key (or press ENTER if you changed your mind): "); miningLicensePrivKey = CUI.ReadStringAnswer(miningLicensePrivKey); if (!string.IsNullOrEmpty(miningLicensePrivKey)) { CUI.WriteRich("Enter the address to which the newly minted coins should be sent (or press ENTER to generate the address automatically): "); miningToAddress = CUI.ReadStringAnswer(miningToAddress); } else { miningEnabled = false; miningLicense = ""; } } else { miningEnabled = false; } } } string confFileContents = ConfigurationFileTemplate .Replace("$MAIN_PORT", conf["Main port"]) .Replace("$ENABLE_RPC", rpcEnabled ? "1" : "0") .Replace("$RPC_USER", conf["RPC user"]) .Replace("$RPC_PASSWORD", rpcPassword) .Replace("$RPC_PORT", conf["RPC port"]) .Replace("$ENABLE_MINING", "0") .Replace("$MINING_LICENSE", miningLicense) .Replace("$MINE_TO_ADDR", miningToAddress); CUI.WriteRich("Writing <white>Core wallet's configuration</white> with mining DISABLED to <white>{0}</white>... ", confFile); if (InstallationFile.CreateFileWriteTextChown(confFile, confFileContents)) { CUI.WriteOk(); res = true; } else { CUI.WriteFailed(); CUI.WriteRich("<red>ERROR:</red> unable to write to <white>{0}</white>. Please try again.\n", confFile); } } string iopd = null; if (res) { iopd = SystemInfo.CurrentRuntime.IsLinux() ? InstallationFile.Which("IoPd") : Path.Combine(GeneralConfiguration.SharedValues["CoreWalletDir-InternalPath"], "IoPd.exe"); GeneralConfiguration.SharedValues[Name + "-executable"] = iopd; GeneralConfiguration.SharedValues[Name + "-executable-args"] = string.Format("\"{0}\" -datadir=\"{1}\"", iopd, GeneralConfiguration.SharedValues["CoreWallet-DataDir"]); } if (res && miningEnabled) { log.Trace("Configuring mining."); CUI.WriteRich("The basic configuration of <white>Core Wallet</white> is complete, but as you wanted to enable mining, some more configuration is needed. " + "Please be patient, it won't take long. If this step fails, the installation will continue and your <white>Core Wallet</white> will be fully setup except for the mining.\n"); bool miningSetupOk = false; bool saveNewConfiguration = false; string iopCli = SystemInfo.CurrentRuntime.IsLinux() ? InstallationFile.Which("IoP-cli") : Path.Combine(GeneralConfiguration.SharedValues["CoreWalletDir-InternalPath"], "IoP-cli.exe"); CUI.WriteRich("Looking for <white>IoPd</white>... "); log.Debug("IoPd location is '{0}'.", iopd); if (File.Exists(iopd)) { CUI.WriteOk(); CUI.WriteRich("Looking for <white>IoP-cli</white>... "); log.Debug("IoP-cli location is '{0}'.", iopCli); if (File.Exists(iopCli)) { CUI.WriteOk(); CUI.WriteRich("Starting <white>IoPd</white>... "); ConsoleProcess iopdProcess = new ConsoleProcess(iopd, string.Format("-datadir=\"{0}\"", dataDir)); if (iopdProcess.Run()) { Thread.Sleep(5000); CUI.WriteOk(); CUI.WriteRich("Starting <white>IoP-cli</white> to import the private key... "); ConsoleProcess iopCliProcess = new ConsoleProcess(iopCli, string.Format("-rpcconnect=127.0.0.1 -rpcport={0} -rpcuser={1} -rpcpassword={2} importprivkey {3}", rpcPort, rpcUser, rpcPassword, miningLicensePrivKey)); if (iopCliProcess.RunAndWaitSuccessExit()) { CUI.WriteOk(); if (string.IsNullOrEmpty(miningToAddress)) { CUI.WriteRich("Starting <white>IoP-cli</white> to generate mining-to address... "); iopCliProcess = new ConsoleProcess(iopCli, string.Format("-rpcconnect=127.0.0.1 -rpcport={0} -rpcuser={1} -rpcpassword={2} getnewaddress", rpcPort, rpcUser, rpcPassword)); if (iopCliProcess.RunAndWaitSuccessExit()) { List <string> outputLines = iopCliProcess.GetOutput(); if (outputLines.Count != 0) { miningToAddress = outputLines[0].Trim(); CUI.WriteOk(); CUI.WriteRich("Your newly generated mining-to address is: <white>{0}</white>\n", miningToAddress); saveNewConfiguration = true; } else { log.Error("Invalid output received from IoP-cli."); CUI.WriteFailed(); } } else { log.Error("Unable to start IoP-cli or it failed."); CUI.WriteFailed(); } } } else { log.Error("Unable to start IoP-cli or it failed."); CUI.WriteFailed(); } CUI.WriteRich("Starting <white>IoP-cli</white> to stop IoPd... "); iopCliProcess = new ConsoleProcess(iopCli, string.Format("-rpcconnect=127.0.0.1 -rpcport={0} -rpcuser={1} -rpcpassword={2} stop", rpcPort, rpcUser, rpcPassword)); if (iopCliProcess.RunAndWaitSuccessExit()) { CUI.WriteOk(); } else { CUI.WriteFailed(); } CUI.WriteRich("Waiting for <white>IoP-cli</white> to stop... "); if (iopdProcess.WaitSuccessExit(15000)) { CUI.WriteOk(); } else { CUI.WriteFailed(); CUI.WriteLine("IoPd will now be killed."); iopdProcess.KillProcess(); } } else { log.Error("Unable to start IoPd."); CUI.WriteFailed(); } } else { log.Error("Unable to find IoP-cli."); CUI.WriteFailed(); } } else { log.Error("Unable to find IoPd."); CUI.WriteFailed(); } if (saveNewConfiguration) { string confFileContents = ConfigurationFileTemplate .Replace("$MAIN_PORT", conf["Main port"]) .Replace("$ENABLE_RPC", rpcEnabled ? "1" : "0") .Replace("$RPC_USER", conf["RPC user"]) .Replace("$RPC_PASSWORD", rpcPassword) .Replace("$RPC_PORT", conf["RPC port"]) .Replace("$ENABLE_MINING", "1") .Replace("$MINING_LICENSE", miningLicense) .Replace("$MINE_TO_ADDR", miningToAddress); CUI.WriteRich("Writing <white>Core wallet's configuration</white> with mining ENABLED to <white>{0}</white>... ", confFile); if (InstallationFile.CreateFileWriteTextChown(confFile, confFileContents)) { CUI.WriteOk(); miningSetupOk = true; } else { CUI.WriteFailed(); CUI.WriteRich("<red>ERROR:</red> unable to write to <white>{0}</white>.\n", confFile); } } if (miningSetupOk) { CUI.WriteRich("Configuration of <white>Core wallet</white> for mining <green>SUCCEEDED</green>.\n"); } else { CUI.WriteRich("<red>Configuration of Core wallet for mining failed.</red>\n"); } } log.Trace("(-):{0}", res); return(res); }
public override bool Configure() { log.Trace("()"); bool res = false; Dictionary <string, string> conf; if (!ConfigurationByRid.TryGetValue(SystemInfo.CurrentRuntime.Rid, out conf)) { log.Trace("(-)[UNSUPPORTED]:{0}", res); return(res); } string appDataDir = Environment.ExpandEnvironmentVariables(conf["Application data directory"]); while (!res) { string dataDir = InstallationFile.AskForEmptyDirectory(string.Format("Where do you want <white>LOC server's application data</white> to be stored? [{0}] ", appDataDir), appDataDir); conf["Application data directory"] = dataDir; GeneralConfiguration.SharedValues.Add("Loc-DataDir", dataDir); string logFile = Path.Combine(dataDir, conf["Log file"]); string dbFile = Path.Combine(dataDir, conf["Database file"]); string confFile = Path.Combine(dataDir, conf["Configuration file"]); GeneralConfiguration.SharedValues.Add("Loc-CfgFile", confFile); string locnetd = SystemInfo.CurrentRuntime.IsLinux() ? InstallationFile.Which("iop-locnetd") : Path.Combine(GeneralConfiguration.SharedValues["LocDir"], "iop-locnetd.exe"); GeneralConfiguration.SharedValues[Name + "-executable"] = locnetd; GeneralConfiguration.SharedValues[Name + "-executable-args"] = string.Format("\"{0}\" --configfile \"{1}\"", locnetd, confFile); int localPort = int.Parse(conf["Local port"]); while (GeneralConfiguration.UsedPorts.ContainsKey(localPort)) { localPort++; } conf["Local port"] = localPort.ToString(); log.Debug("Selected port {0} as LOC server's local port.", localPort); GeneralConfiguration.UsedPorts.Add(localPort, "LOC server local interface"); GeneralConfiguration.SharedValues.Add("LOC server local interface", localPort.ToString()); int nodePort = int.Parse(conf["Node port"]); nodePort = AskForOpenPort(string.Format("Please enter a port number for <white>LOC server's node interface</white>. This port will have to be open and publicly accessible from the Internet. [{0}] ", nodePort), nodePort, "LOC server node interface"); conf["Node port"] = nodePort.ToString(); int clientPort = int.Parse(conf["Client port"]); clientPort = AskForOpenPort(string.Format("Please enter a port number for <white>LOC server's client interface</white>. This port will have to be open and publicly accessible from the Internet. [{0}] ", clientPort), clientPort, "LOC server client interface"); conf["Client port"] = clientPort.ToString(); Guid nodeId = Guid.NewGuid(); string confFileContents = ConfigurationFileTemplate .Replace("$NODE_ID", nodeId.ToString()) .Replace("$NODE_PORT", conf["Node port"]) .Replace("$CLIENT_PORT", conf["Client port"]) .Replace("$LOCAL_PORT", conf["Local port"]) .Replace("$LATITUDE", GeneralConfiguration.Location.Latitude.ToString(CultureInfo.InvariantCulture)) .Replace("$LONGITUDE", GeneralConfiguration.Location.Longitude.ToString(CultureInfo.InvariantCulture)) .Replace("$LOG_FILE", logFile) .Replace("$DB_FILE", dbFile); CUI.WriteRich("Writing <white>LOC server's configuration</white> to <white>{0}</white>... ", confFile); if (InstallationFile.CreateFileWriteTextChown(confFile, confFileContents)) { CUI.WriteOk(); res = true; } else { CUI.WriteFailed(); CUI.WriteRich("<red>ERROR:</red> unable to write to <white>{0}</white>. Please try again.\n", confFile); } } log.Trace("(-):{0}", res); return(res); }
public override bool Configure() { log.Trace("()"); bool res = false; Dictionary <string, string> conf; if (!ConfigurationByRid.TryGetValue(SystemInfo.CurrentRuntime.Rid, out conf)) { log.Trace("(-)[UNSUPPORTED]:{0}", res); return(res); } bool done = false; while (!done) { string appDataDir = Environment.ExpandEnvironmentVariables(conf["Application data directory"]); string dataDir = InstallationFile.AskForEmptyDirectory(string.Format("Where do you want <white>Profile server application data</white> to be stored? [{0}] ", appDataDir), appDataDir); conf["Application data directory"] = dataDir; GeneralConfiguration.SharedValues.Add("Ps-DataDir", dataDir); string confFile = Path.Combine(GeneralConfiguration.SharedValues["PsDir"], "ProfileServer.conf"); string shutdownFile = Path.Combine(GeneralConfiguration.SharedValues["PsDir"], "shutdown.signal"); GeneralConfiguration.SharedValues["Ps-ShutdownFile"] = shutdownFile; string exeFile = Path.Combine(GeneralConfiguration.SharedValues["PsDir"], "ProfileServer"); GeneralConfiguration.SharedValues[Name + "-executable"] = exeFile; GeneralConfiguration.SharedValues[Name + "-executable-args"] = string.Format("\"{0}\"", exeFile); int primaryPort = int.Parse(conf["Primary port"]); primaryPort = AskForOpenPort(string.Format("Please enter a port number for <white>Profile server primary interface</white>. This port will have to be open and publicly accessible from the Internet. [{0}] ", primaryPort), primaryPort, "Profile server primary interface"); conf["Primary port"] = primaryPort.ToString(); int otherPort = int.Parse(conf["Other port"]); otherPort = AskForOpenPort(string.Format("Please enter a port number for <white>other interfaces of Profile server</white>. This port will have to be open and publicly accessible from the Internet. [{0}] ", otherPort), otherPort, "Profile server other interfaces"); conf["Other port"] = otherPort.ToString(); int canApiPort = int.Parse(GeneralConfiguration.SharedValues["CAN server API interface"]); int locLocalPort = int.Parse(GeneralConfiguration.SharedValues["LOC server local interface"]); string imagesDir = Path.Combine(dataDir, "images"); string tmpDir = Path.Combine(dataDir, "tmp"); string dbFile = Path.Combine(dataDir, "ProfileServer.db"); string pfxFile = Path.Combine(dataDir, "ProfileServer.pfx"); string confFileContents = ConfigurationFileTemplate .Replace("$EXTERNAL_ADDR", GeneralConfiguration.ExternalIpAddress.ToString()) .Replace("$PRIMARY_PORT", conf["Primary port"]) .Replace("$NEIGHBOR_PORT", conf["Other port"]) .Replace("$NON_CUSTOMER_PORT", conf["Other port"]) .Replace("$CUSTOMER_PORT", conf["Other port"]) .Replace("$APP_SERVICE_PORT", conf["Other port"]) .Replace("$PFX_CERT_FILE", pfxFile) .Replace("$IMAGES_DIR", imagesDir) .Replace("$TMP_DIR", tmpDir) .Replace("$DB_FILE", dbFile) .Replace("$TMP_DIR", tmpDir) .Replace("$LOC_PORT", locLocalPort.ToString()) .Replace("$CAN_API_PORT", canApiPort.ToString()); CUI.WriteRich("Writing <white>Profile server's configuration</white> to <white>{0}</white>... ", confFile); if (InstallationFile.CreateFileWriteTextChown(confFile, confFileContents)) { CUI.WriteOk(); done = true; bool error = true; string dbSourceFile = Path.Combine(GeneralConfiguration.SharedValues["PsDir"], "ProfileServer.db"); if (string.Compare(dbFile, dbSourceFile, true) != 0) { CUI.WriteRich("Copying <white>Profile server's database file</white> to <white>{0}</white>... ", dbFile); try { File.Copy(dbSourceFile, dbFile); InstallationFile.Chown(dbFile); CUI.WriteOk(); error = false; } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); CUI.WriteFailed(); } } if (!error) { CUI.WriteRich("Loading <white>Profile server's logging configuration file</white>... "); try { string nlogConfFile = Path.Combine(GeneralConfiguration.SharedValues["PsDir"], "NLog.config"); string nlogConfFileContents = File.ReadAllText(nlogConfFile); CUI.WriteOk(); nlogConfFileContents = nlogConfFileContents.Replace("${basedir}/Logs/", Path.Combine(dataDir, "Logs") + Path.DirectorySeparatorChar); CUI.WriteRich("Updating <white>Profile server's logging configuration file</white>... "); if (InstallationFile.CreateFileWriteTextChown(nlogConfFile, nlogConfFileContents)) { CUI.WriteOk(); CUI.WriteRich("Creating <white>Profile server's TLS certificate</white>... "); string openssl = SystemInfo.CurrentRuntime.IsLinux() ? "openssl" : Path.Combine(GeneralConfiguration.SharedValues["OpenSslDir"], "openssl.exe"); if (InstallationFile.GeneratePfxCertificate(openssl, pfxFile)) { CUI.WriteOk(); res = true; } else { log.Error("Failed to generate PFX certificate '{0}'.", pfxFile); CUI.WriteFailed(); } } else { log.Error("Failed to write NLog configuration to '{0}'.", nlogConfFile); CUI.WriteFailed(); } } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); CUI.WriteFailed(); } } } else { CUI.WriteFailed(); CUI.WriteRich("<red>ERROR:</red> unable to write to <white>{0}</white>. Please try again.\n", confFile); } } log.Trace("(-):{0}", res); return(res); }