Skip to content

Commit 3ebbd23

Browse files
committed
add: linux specific binary download
1 parent d99d1a3 commit 3ebbd23

File tree

3 files changed

+63
-39
lines changed

3 files changed

+63
-39
lines changed

BrowserStackLocal/BrowserStackLocal/BrowserStackLocal.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<RootNamespace>BrowserStackRootNamespace>
44
<AssemblyName>BrowserStackLocalAssemblyName>
5-
<TargetFrameworks>net20;netstandard2.0TargetFrameworks>
5+
<TargetFrameworks>net48;netstandard2.0TargetFrameworks>
66
<GenerateAssemblyInfo>falseGenerateAssemblyInfo>
77
<Title>BrowserStackLocalTitle>
88
<Product>BrowserStackLocalProduct>
@@ -31,4 +31,4 @@
3131
3232
3333
-->
34-
Project>
34+
Project>

BrowserStackLocal/BrowserStackLocal/BrowserStackTunnel.cs

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ public enum LocalState { Idle, Connecting, Connected, Error, Disconnected };
1515

1616
public class BrowserStackTunnel : IDisposable
1717
{
18-
// Need to get rid of this variable, instead use getBinaryName()
19-
static readonly string binaryName = isDarwin() ? "BrowserStackLocal-darwin-x64" : "BrowserStackLocal.exe";
20-
static readonly string downloadURL = isDarwin() ?
21-
"https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal-darwin-x64" :
22-
"https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal.exe";
23-
static readonly string homepath = isDarwin() ?
18+
static string binaryName = GetBinaryName();
19+
static readonly string downloadURL = "https://www.browserstack.com/local-testing/downloads/binaries/" + binaryName;
20+
static readonly string homepath = IsDarwin() || IsLinux() ?
2421
Environment.GetFolderPath(Environment.SpecialFolder.Personal) :
2522
Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
2623
public static readonly string[] basePaths = new string[] {
@@ -39,79 +36,80 @@ public class BrowserStackTunnel : IDisposable
3936

4037
Process process = null;
4138

42-
static Boolean isDarwin()
39+
static bool IsDarwin()
4340
{
4441
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
4542
{
4643
return true;
4744
}
45+
return false;
4846
}
47+
4948

50-
static Boolean isWindows()
49+
static bool IsWindows()
5150
{
5251
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
5352
{
5453
return true;
5554
}
55+
return false;
5656
}
5757

58-
static Boolean isLinux()
58+
static bool IsLinux()
5959
{
60-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
60+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
6161
{
6262
return true;
6363
}
64+
return false;
6465
}
6566

66-
static Boolean isAlpine()
67+
static bool IsAlpine()
6768
{
68-
const string osReleaseFile = "/etc/os-release";
69-
70-
if (File.Exists(osReleaseFile))
69+
try
7170
{
72-
string[] lines = File.ReadAllLines(osReleaseFile);
73-
foreach (string line in lines)
71+
string[] output = Util.RunShellCommand("grep -w 'NAME' /etc/os-release");
72+
if (string.IsNullOrEmpty(output[0]) && output[0].Contains("Alpine"))
7473
{
75-
if (line.StartsWith("ID="))
76-
{
77-
string id = line.Substring(3).Trim('"'); // Remove 'ID=' and quotes
78-
if (id.Equals("alpine", StringComparison.OrdinalIgnoreCase))
79-
{
80-
return true;
81-
}
82-
}
74+
return true;
8375
}
8476
}
77+
catch (System.Exception)
78+
{
79+
return false;
80+
}
81+
return false;
8582
}
86-
static staring getBinaryName()
83+
84+
static string GetBinaryName()
8785
{
88-
if isDarwin()
86+
if (IsDarwin())
8987
{
90-
binaryName = "BrowserStackLocal-darwin-x64"
88+
return "BrowserStackLocal-darwin-x64";
9189
}
92-
else if isWindows()
90+
else if (IsWindows())
9391
{
94-
binaryName = "BrowserStackLocal.exe"
92+
return "BrowserStackLocal.exe";
9593
}
96-
else if isLinux()
94+
else if (IsLinux())
9795
{
98-
if (RuntimeInformation.OSArchitecture == Architecture.X64
99-
|| RuntimeInformation.OSArchitecture == Architecture.Arm64)
96+
if (Environment.Is64BitOperatingSystem)
10097
{
101-
if isAlpine()
98+
if (IsAlpine())
10299
{
103-
binaryName = "BrowserStackLocal-alpine"
100+
return "BrowserStackLocal-alpine";
104101
}
105102
else
106103
{
107-
binaryName = "BrowserStackLocal-linux-x64"
104+
return "BrowserStackLocal-linux-x64";
108105
}
109106
}
110107
else
111108
{
112-
binaryName = "BrowserStackLocal-linux-ia32"
109+
return "BrowserStackLocal-linux-ia32";
113110
}
114111
}
112+
return "BrowserStackLocal.exe";
115113
}
116114

117115
public virtual void addBinaryPath(string binaryAbsolute)
@@ -150,7 +148,7 @@ public virtual void fallbackPaths()
150148

151149
public void modifyBinaryPermission()
152150
{
153-
if (isDarwin())
151+
if (IsDarwin() || IsLinux())
154152
{
155153
try
156154
{
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Diagnostics;
2+
3+
namespace BrowserStack
4+
{
5+
public class Util {
6+
7+
// Only Unix Support
8+
public static string[] RunShellCommand(string command) {
9+
ProcessStartInfo psi = new ProcessStartInfo("bash", $"-c \"{command}\"") {
10+
RedirectStandardOutput = true,
11+
RedirectStandardError = true,
12+
UseShellExecute = false,
13+
CreateNoWindow = true
14+
};
15+
16+
Process process = new Process { StartInfo = psi };
17+
process.Start();
18+
string output = process.StandardOutput.ReadToEnd();
19+
string error = process.StandardError.ReadToEnd();
20+
process.WaitForExit();
21+
return new string[]{output, error};
22+
}
23+
24+
}
25+
}
26+

0 commit comments

Comments
 (0)