private static async Task InstallHwiAsync(string fullBaseDirectory, string hwiDir) { string hwiSoftwareDir = Path.Combine(fullBaseDirectory, "Hwi", "Software"); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { string hwiLinuxZip = Path.Combine(hwiSoftwareDir, "hwi-linux64.zip"); await IoHelpers.BetterExtractZipToDirectoryAsync(hwiLinuxZip, hwiDir); Logger.LogInfo($"Extracted {hwiLinuxZip} to {hwiDir}.", nameof(HwiProcessManager)); } else // OSX { string hwiOsxZip = Path.Combine(hwiSoftwareDir, "hwi-osx64.zip"); await IoHelpers.BetterExtractZipToDirectoryAsync(hwiOsxZip, hwiDir); Logger.LogInfo($"Extracted {hwiOsxZip} to {hwiDir}.", nameof(HwiProcessManager)); } // Make sure there's sufficient permission. string chmodHwiDirCmd = $"chmod -R 750 {hwiDir}"; EnvironmentHelpers.ShellExec(chmodHwiDirCmd); Logger.LogInfo($"Shell command executed: {chmodHwiDirCmd}.", nameof(HwiProcessManager)); }
private static void CreateDigests() { var tempDir = "DigestTempDir"; IoHelpers.DeleteRecursivelyWithMagicDustAsync(tempDir).GetAwaiter(); Directory.CreateDirectory(tempDir); var torDaemonsDir = Path.Combine(LibraryProjectDirectory, "TorDaemons"); string torWinZip = Path.Combine(torDaemonsDir, "tor-win32.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(torWinZip, tempDir).GetAwaiter(); File.Move(Path.Combine(tempDir, "Tor", "tor.exe"), Path.Combine(tempDir, "TorWin")); string torLinuxZip = Path.Combine(torDaemonsDir, "tor-linux64.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(torLinuxZip, tempDir).GetAwaiter(); File.Move(Path.Combine(tempDir, "Tor", "tor"), Path.Combine(tempDir, "TorLin")); string torOsxZip = Path.Combine(torDaemonsDir, "tor-osx64.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(torOsxZip, tempDir).GetAwaiter(); File.Move(Path.Combine(tempDir, "Tor", "tor"), Path.Combine(tempDir, "TorOsx")); string hwiSoftwareDir = Path.Combine(LibraryProjectDirectory, "Hwi", "Software"); string hwiWinZip = Path.Combine(hwiSoftwareDir, "hwi-win64.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(hwiWinZip, tempDir).GetAwaiter(); File.Move(Path.Combine(tempDir, "hwi.exe"), Path.Combine(tempDir, "HwiWin")); string hwiLinuxZip = Path.Combine(hwiSoftwareDir, "hwi-linux64.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(hwiLinuxZip, tempDir).GetAwaiter(); File.Move(Path.Combine(tempDir, "hwi"), Path.Combine(tempDir, "HwiLin")); string hwiOsxZip = Path.Combine(hwiSoftwareDir, "hwi-osx64.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(hwiOsxZip, tempDir).GetAwaiter(); File.Move(Path.Combine(tempDir, "hwi"), Path.Combine(tempDir, "HwiOsx")); var tempDirInfo = new DirectoryInfo(tempDir); var binaries = tempDirInfo.GetFiles(); Console.WriteLine("Digests:"); foreach (var file in binaries) { var filePath = file.FullName; var hash = ByteHelpers.ToHex(IoHelpers.GetHashFile(filePath)).ToLowerInvariant(); Console.WriteLine($"{file.Name} : {hash}"); } IoHelpers.DeleteRecursivelyWithMagicDustAsync(tempDir).GetAwaiter(); }
public static async Task InstallAsync(string torDir) { string torDaemonsDir = Path.Combine(EnvironmentHelpers.GetFullBaseDirectory(), "TorDaemons"); string dataZip = Path.Combine(torDaemonsDir, "data-folder.zip"); await IoHelpers.BetterExtractZipToDirectoryAsync(dataZip, torDir).ConfigureAwait(false); Logger.LogInfo($"Extracted {dataZip} to {torDir}."); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { string torWinZip = Path.Combine(torDaemonsDir, "tor-win64.zip"); await IoHelpers.BetterExtractZipToDirectoryAsync(torWinZip, torDir).ConfigureAwait(false); Logger.LogInfo($"Extracted {torWinZip} to {torDir}."); } else // Linux or OSX { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { string torLinuxZip = Path.Combine(torDaemonsDir, "tor-linux64.zip"); await IoHelpers.BetterExtractZipToDirectoryAsync(torLinuxZip, torDir).ConfigureAwait(false); Logger.LogInfo($"Extracted {torLinuxZip} to {torDir}."); } else // OSX { string torOsxZip = Path.Combine(torDaemonsDir, "tor-osx64.zip"); await IoHelpers.BetterExtractZipToDirectoryAsync(torOsxZip, torDir).ConfigureAwait(false); Logger.LogInfo($"Extracted {torOsxZip} to {torDir}."); } // Make sure there's sufficient permission. string chmodTorDirCmd = $"chmod -R 750 {torDir}"; await EnvironmentHelpers.ShellExecAsync(chmodTorDirCmd, waitForExit : true).ConfigureAwait(false); Logger.LogInfo($"Shell command executed: {chmodTorDirCmd}."); } }
private static void InstallTor(string fullBaseDirectory, string torDir) { string torDaemonsDir = Path.Combine(fullBaseDirectory, "TorDaemons"); string dataZip = Path.Combine(torDaemonsDir, "data-folder.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(dataZip, torDir).GetAwaiter().GetResult(); Logger.LogInfo <TorProcessManager>($"Extracted {dataZip} to {torDir}."); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { string torWinZip = Path.Combine(torDaemonsDir, "tor-win32.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(torWinZip, torDir).GetAwaiter().GetResult(); Logger.LogInfo <TorProcessManager>($"Extracted {torWinZip} to {torDir}."); } else // Linux or OSX { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { string torLinuxZip = Path.Combine(torDaemonsDir, "tor-linux64.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(torLinuxZip, torDir).GetAwaiter().GetResult(); Logger.LogInfo <TorProcessManager>($"Extracted {torLinuxZip} to {torDir}."); } else // OSX { string torOsxZip = Path.Combine(torDaemonsDir, "tor-osx64.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(torOsxZip, torDir).GetAwaiter().GetResult(); Logger.LogInfo <TorProcessManager>($"Extracted {torOsxZip} to {torDir}."); } // Make sure there's sufficient permission. string chmodTorDirCmd = $"chmod -R 750 {torDir}"; EnvironmentHelpers.ShellExec(chmodTorDirCmd); Logger.LogInfo <TorProcessManager>($"Shell command executed: {chmodTorDirCmd}."); } }
public void Start(bool ensureRunning, string dataDir) { new Thread(delegate() // Don't ask. This is the only way it worked on Win10/Ubuntu18.04/Manjuro(1 processor VM)/Fedora(1 processor VM) { try { // 1. Is it already running? // 2. Can I simply run it from output directory? // 3. Can I copy and unzip it from assets? // 4. Throw exception. try { if (IsTorRunningAsync(TorSocks5EndPoint).GetAwaiter().GetResult()) { Logger.LogInfo <TorProcessManager>("Tor is already running."); return; } var fullBaseDirectory = Path.GetFullPath(AppContext.BaseDirectory); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (!fullBaseDirectory.StartsWith('/')) { fullBaseDirectory.Insert(0, "/"); } } var torDir = Path.Combine(dataDir, "tor"); var torPath = ""; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { torPath = $@"{torDir}\Tor\tor.exe"; } else // Linux or OSX { torPath = $@"{torDir}/Tor/tor"; } if (!File.Exists(torPath)) { Logger.LogInfo <TorProcessManager>($"Tor instance NOT found at {torPath}. Attempting to acquire it..."); string torDaemonsDir = Path.Combine(fullBaseDirectory, "TorDaemons"); string dataZip = Path.Combine(torDaemonsDir, "data-folder.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(dataZip, torDir).GetAwaiter().GetResult(); Logger.LogInfo <TorProcessManager>($"Extracted {dataZip} to {torDir}."); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { string torWinZip = Path.Combine(torDaemonsDir, "tor-win32.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(torWinZip, torDir).GetAwaiter().GetResult(); Logger.LogInfo <TorProcessManager>($"Extracted {torWinZip} to {torDir}."); } else // Linux or OSX { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { string torLinuxZip = torLinuxZip = Path.Combine(torDaemonsDir, "tor-linux64.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(torLinuxZip, torDir).GetAwaiter().GetResult(); Logger.LogInfo <TorProcessManager>($"Extracted {torLinuxZip} to {torDir}."); } else // OSX { string torOsxZip = Path.Combine(torDaemonsDir, "tor-osx64.zip"); IoHelpers.BetterExtractZipToDirectoryAsync(torOsxZip, torDir).GetAwaiter().GetResult(); Logger.LogInfo <TorProcessManager>($"Extracted {torOsxZip} to {torDir}."); } // Make sure there's sufficient permission. string chmodTorDirCmd = $"chmod -R 777 {torDir}"; EnvironmentHelpers.ShellExec(chmodTorDirCmd); Logger.LogInfo <TorProcessManager>($"Shell command executed: {chmodTorDirCmd}."); } } else { Logger.LogInfo <TorProcessManager>($"Tor instance found at {torPath}."); } string torArguments = $"--SOCKSPort {TorSocks5EndPoint}"; if (!string.IsNullOrEmpty(LogFile)) { IoHelpers.EnsureContainingDirectoryExists(LogFile); var logFileFullPath = Path.GetFullPath(LogFile); torArguments += $" --Log \"notice file {logFileFullPath}\""; } if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var torProcessStartInfo = new ProcessStartInfo(torPath) { Arguments = torArguments, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true }; TorProcess = Process.Start(torProcessStartInfo); Logger.LogInfo <TorProcessManager>($"Starting Tor process with Process.Start."); } else // Linux and OSX { string runTorCmd = $"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:={torDir}/Tor && export LD_LIBRARY_PATH && cd {torDir}/Tor && ./tor {torArguments}"; EnvironmentHelpers.ShellExec(runTorCmd, false); Logger.LogInfo <TorProcessManager>($"Started Tor process with shell command: {runTorCmd}."); } if (ensureRunning) { Task.Delay(3000).ConfigureAwait(false).GetAwaiter().GetResult(); // dotnet brainfart, ConfigureAwait(false) IS NEEDED HERE otherwise (only on) Manjuro Linux fails, WTF?!! if (!IsTorRunningAsync(TorSocks5EndPoint).GetAwaiter().GetResult()) { throw new TorException("Attempted to start Tor, but it is not running."); } Logger.LogInfo <TorProcessManager>("Tor is running."); } } catch (Exception ex) { throw new TorException("Could not automatically start Tor. Try running Tor manually.", ex); } } catch (Exception ex) { Logger.LogError <TorProcessManager>(ex); } }).Start(); }
private async Task ExtractZipFileAsync(string zipFilePath, string destinationPath) { await IoHelpers.BetterExtractZipToDirectoryAsync(zipFilePath, destinationPath).ConfigureAwait(false); Logger.LogInfo($"Extracted '{zipFilePath}' to '{destinationPath}'."); }