Skip to content

Commit

Permalink
Fix auto-update and mac install.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Feb 22, 2024
1 parent 91daac9 commit f59b7cc
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 59 deletions.
1 change: 1 addition & 0 deletions Agent/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ private static void RegisterServices(IServiceCollection services)
services.AddSingleton<IAppLauncher, AppLauncherMac>();
services.AddSingleton<IUpdater, UpdaterMac>();
services.AddSingleton<IDeviceInformationService, DeviceInfoGeneratorMac>();
services.AddSingleton<IElevationDetector, ElevationDetectorMac>();
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions Agent/Services/MacOS/AppLauncherMac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ public class AppLauncherMac : IAppLauncher

public async Task<int> LaunchChatService(string pipeName, string userConnectionId, string requesterName, string orgName, string orgId, HubConnection hubConnection)
{
await hubConnection.SendAsync("DisplayMessage", "Feature under development.", "Feature is under development.", "bg-warning", userConnectionId);
await hubConnection.SendAsync("DisplayMessage", "Feature under development.", "Currently unsupported", "bg-warning", userConnectionId);
return 0;
}

public async Task LaunchRemoteControl(int targetSessionId, string sessionId, string accessKey, string userConnectionId, string requesterName, string orgName, string orgId, HubConnection hubConnection)
{
await hubConnection.SendAsync("DisplayMessage", "Feature under development.", "Feature is under development.", "bg-warning", userConnectionId);
await hubConnection.SendAsync("DisplayMessage", "Feature under development.", "Currently unsupported", "bg-warning", userConnectionId);
}

public async Task RestartScreenCaster(string[] viewerIds, string sessionId, string accessKey, string userConnectionId, string requesterName, string orgName, string orgId, HubConnection hubConnection, int targetSessionID = -1)
{
await hubConnection.SendAsync("DisplayMessage", "Feature under development.", "Feature is under development.", "bg-warning", userConnectionId);
await hubConnection.SendAsync("DisplayMessage", "Feature under development.", "Currently unsupported", "bg-warning", userConnectionId);
}
}
14 changes: 6 additions & 8 deletions Agent/Services/Windows/UpdaterWin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,23 @@ public async Task InstallLatestVersion()

var zipPath = Path.Combine(Path.GetTempPath(), "RemotelyUpdate.zip");

var installerPath = Path.Combine(Path.GetTempPath(), "Remotely_Installer.exe");
var installerPath = Path.Combine(Path.GetTempPath(), "Install-Remotely.ps1");
var platform = Environment.Is64BitOperatingSystem ? "x64" : "x86";

await _updateDownloader.DownloadFile(
$"{serverUrl}/Content/Remotely_Installer.exe",
$"{serverUrl}/Content/Install-Remotely.ps1",
installerPath);

await _updateDownloader.DownloadFile(
$"{serverUrl}/api/AgentUpdate/DownloadPackage/win-{platform}",
zipPath);

foreach (var proc in Process.GetProcessesByName("Remotely_Installer"))
{
proc.Kill();
}

_logger.LogInformation("Launching installer to perform update.");

Process.Start(installerPath, $"-install -quiet -path {zipPath} -serverurl {serverUrl} -organizationid {connectionInfo.OrganizationID}");
Process.Start(
"powershell.exe",
$"-ExecutionPolicy Bypass -File \"{installerPath}\" -Path \"{zipPath}\" " +
$"-OrganizationId {connectionInfo.OrganizationID} -ServerUrl {connectionInfo.Host}");
}
catch (WebException ex) when (ex.Status == WebExceptionStatus.Timeout)
{
Expand Down
4 changes: 2 additions & 2 deletions Server/API/ClientDownloadsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ private async Task<IActionResult> GetInstallFile(string organizationId, string p
return NotFound();
}

fileContents[hostIndex] = $"$HostName = \"{effectiveScheme}://{Request.Host}\"";
fileContents[orgIndex] = $"$Organization = \"{organizationId}\"";
fileContents[hostIndex] = $"[string]$HostName = \"{effectiveScheme}://{Request.Host}\"";
fileContents[orgIndex] = $"[string]$Organization = \"{organizationId}\"";
var fileBytes = Encoding.UTF8.GetBytes(string.Join("\n", fileContents));

return File(fileBytes, "application/octet-stream", "Install-Remotely.ps1");
Expand Down
32 changes: 25 additions & 7 deletions Server/Components/Pages/Downloads.razor
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,6 @@
<a target="_blank" href="/Content/Remotely-MacOS-x64.zip">macOS x64 Files Only</a>
</p>

@*<strong>macOS arm64 (11.01)</strong>
<p>
<a target="_blank" href="/API/ClientDownloads/MacOSInstaller-arm64">macOS arm64 Bash Installer</a>
<br />
<a target="_blank" href="/Content/Remotely-MacOS-arm64.zip">macOS arm64 Files Only</a>
</p>*@

<p>
<div class="small">Example Install:</div>

Expand All @@ -169,6 +162,31 @@
<code class="label label-default small">sudo [path]/Install-MacOS-x64.sh --uninstall</code>
</p>
</div>

<div class="col-sm-6 mb-3">
<strong>macOS arm64</strong>
<p>
<a target="_blank" href="/API/ClientDownloads/MacOSInstaller-arm64">macOS arm64 Bash Installer</a>
<br />
<a target="_blank" href="/Content/Remotely-MacOS-arm64.zip">macOS arm64 Files Only</a>
</p>

<p>
<div class="small">Example Install:</div>

<code class="label label-default small">sudo [path]/Install-MacOS-arm64.sh</code>
</p>
<p>
<div class="small">Example Local Install:</div>

<code class="label label-default small">sudo [path]/Install-MacOS-arm64.sh --path [path]/Remotely-MacOS-arm64.zip</code>
</p>
<p>
<div class="small">Example Uninstall:</div>

<code class="label label-default small">sudo [path]/Install-MacOS-arm64.sh --uninstall</code>
</p>
</div>
}

</div>
Expand Down
1 change: 1 addition & 0 deletions Server/Options/ApplicationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public class ApplicationOptions
{
public const string SectionKey = "ApplicationOptions";
public string DbProvider { get; set; } = "SQLite";
public string? DockerGatewayIp { get; set; }
}
15 changes: 11 additions & 4 deletions Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
services.Configure<ApplicationOptions>(
configuration.GetSection(ApplicationOptions.SectionKey));

var appOptions = configuration
.GetSection(ApplicationOptions.SectionKey)
.Get<ApplicationOptions>();

services
.AddRazorComponents()
.AddInteractiveServerComponents();
Expand All @@ -47,7 +51,7 @@
services.AddScoped<IdentityRedirectManager>();
services.AddScoped<AuthenticationStateProvider, IdentityRevalidatingAuthenticationStateProvider>();

var dbProvider = configuration["ApplicationOptions:DbProvider"]?.ToLower();
var dbProvider = appOptions?.DbProvider?.ToLower();

switch (dbProvider)
{
Expand Down Expand Up @@ -168,7 +172,10 @@
options.ForwardLimit = null;
// Default Docker host. We want to allow forwarded headers from this address.
options.KnownProxies.Add(IPAddress.Parse("172.17.0.1"));
if (IPAddress.TryParse(appOptions?.DockerGatewayIp, out var dockerGatewayIp))
{
options.KnownProxies.Add(dockerGatewayIp);
}
if (settings.KnownProxies is { Count: >0 } knownProxies)
{
Expand Down Expand Up @@ -257,15 +264,15 @@

var app = builder.Build();

app.UseForwardedHeaders();

app.UseRateLimiter();

if (settings.UseHttpLogging)
{
app.UseHttpLogging();
}

app.UseForwardedHeaders();

if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand Down
1 change: 1 addition & 0 deletions Server/Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageReference Include="QRCoder" Version="1.4.3" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
Expand Down
3 changes: 2 additions & 1 deletion Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
}
},
"ApplicationOptions": {
"DbProvider": "SQLite"
"DbProvider": "SQLite",
"DockerGatewayIp": "172.28.0.1"
}
}
18 changes: 8 additions & 10 deletions Server/wwwroot/Content/Install-MacOS-arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ArgLength=${#Args[@]}
for (( i=0; i<${ArgLength}; i+=2 ));
do
if [ "${Args[$i]}" = "--uninstall" ]; then
launchctl unload -w /Library/LaunchDaemons/remotely-agent.plist
sudo launchctl bootout system /Library/LaunchDaemons/remotely-agent.plist
rm -r -f $InstallDir/
rm -f /Library/LaunchDaemons/remotely-agent.plist
exit
Expand All @@ -41,9 +41,6 @@ Owner=$(ls -l /usr/local/bin/brew | awk '{print $3}')

su - $Owner -c "brew update"

# Install .NET Runtime
su - $Owner -c "brew install --cask dotnet"

# Install other dependencies
su - $Owner -c "brew install curl"
su - $Owner -c "brew install jq"
Expand Down Expand Up @@ -71,9 +68,10 @@ else
rm -f "$UpdatePackagePath"
fi

unzip -o $InstallDir/Remotely-MacOS-arm64.zip
unzip -o $InstallDir/Remotely-MacOS-arm64.zip -d $InstallDir
rm -f $InstallDir/Remotely-MacOS-arm64.zip

chmod +x $InstallDir/Remotely_Agent
chmod +x $InstallDir/Desktop/Remotely_Desktop

connectionInfo="{
\"DeviceID\":\"$GUID\",
Expand All @@ -95,14 +93,14 @@ plistFile="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<string>com.translucency.remotely-agent</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/dotnet</string>
<string>$InstallDir/Remotely_Agent.dll</string>
<string>$InstallDir/Remotely_Agent</string>
</array>
<key>KeepAlive</key>
<true/>
</dict>
</plist>"
echo "$plistFile" > "/Library/LaunchDaemons/remotely-agent.plist"

launchctl load -w /Library/LaunchDaemons/remotely-agent.plist
launchctl kickstart -k system/com.translucency.remotely-agent

sudo launchctl bootstrap system /Library/LaunchDaemons/remotely-agent.plist
sudo launchctl kickstart -k system/com.translucency.remotely-agent
17 changes: 7 additions & 10 deletions Server/wwwroot/Content/Install-MacOS-x64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ArgLength=${#Args[@]}
for (( i=0; i<${ArgLength}; i+=2 ));
do
if [ "${Args[$i]}" = "--uninstall" ]; then
launchctl unload -w /Library/LaunchDaemons/remotely-agent.plist
sudo launchctl bootout system /Library/LaunchDaemons/remotely-agent.plist
rm -r -f $InstallDir/
rm -f /Library/LaunchDaemons/remotely-agent.plist
exit
Expand All @@ -41,9 +41,6 @@ Owner=$(ls -l /usr/local/bin/brew | awk '{print $3}')

su - $Owner -c "brew update"

# Install .NET Runtime
su - $Owner -c "brew install --cask dotnet"

# Install other dependencies
su - $Owner -c "brew install curl"
su - $Owner -c "brew install jq"
Expand Down Expand Up @@ -71,9 +68,10 @@ else
rm -f "$UpdatePackagePath"
fi

unzip -o $InstallDir/Remotely-MacOS-x64.zip
unzip -o $InstallDir/Remotely-MacOS-x64.zip -d $InstallDir
rm -f $InstallDir/Remotely-MacOS-x64.zip

chmod +x $InstallDir/Remotely_Agent
chmod +x $InstallDir/Desktop/Remotely_Desktop

connectionInfo="{
\"DeviceID\":\"$GUID\",
Expand All @@ -95,14 +93,13 @@ plistFile="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<string>com.translucency.remotely-agent</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/dotnet</string>
<string>$InstallDir/Remotely_Agent.dll</string>
<string>$InstallDir/Remotely_Agent</string>
</array>
<key>KeepAlive</key>
<true/>
</dict>
</plist>"
echo "$plistFile" > "/Library/LaunchDaemons/remotely-agent.plist"

launchctl load -w /Library/LaunchDaemons/remotely-agent.plist
launchctl kickstart -k system/com.translucency.remotely-agent
sudo launchctl bootstrap system /Library/LaunchDaemons/remotely-agent.plist
sudo launchctl kickstart -k system/com.translucency.remotely-agent
Loading

0 comments on commit f59b7cc

Please sign in to comment.