Skip to content

Commit

Permalink
Add macOS arm64.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed May 7, 2021
1 parent a864c01 commit a43732d
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 7 deletions.
7 changes: 4 additions & 3 deletions Agent/Services/UpdaterMac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Remotely.Agent.Services
{
public class UpdaterMac : IUpdater
{
private readonly string _achitecture = RuntimeInformation.OSArchitecture.ToString().ToLower();
private readonly SemaphoreSlim _checkForUpdatesLock = new SemaphoreSlim(1, 1);
private readonly ConfigService _configService;
private readonly IWebClientEx _webClientEx;
Expand Down Expand Up @@ -64,7 +65,7 @@ public async Task CheckForUpdates()
var connectionInfo = _configService.GetConnectionInfo();
var serverUrl = _configService.GetConnectionInfo().Host;

var fileUrl = serverUrl + $"/Content/Remotely-MacOS-x64.zip";
var fileUrl = serverUrl + $"/Content/Remotely-MacOS-{_achitecture}.zip";

var lastEtag = string.Empty;

Expand Down Expand Up @@ -128,11 +129,11 @@ public async Task InstallLatestVersion()
var installerPath = Path.Combine(Path.GetTempPath(), "RemotelyUpdate.sh");

await _webClientEx.DownloadFileTaskAsync(
serverUrl + $"/API/ClientDownloads/{connectionInfo.OrganizationID}/MacOSInstaller-x64",
serverUrl + $"/API/ClientDownloads/{connectionInfo.OrganizationID}/MacOSInstaller-{_achitecture}",
installerPath);

await _webClientEx.DownloadFileTaskAsync(
serverUrl + $"/API/AgentUpdate/DownloadPackage/macos-x64/{downloadId}",
serverUrl + $"/API/AgentUpdate/DownloadPackage/macos-{_achitecture}/{downloadId}",
zipPath);

(await WebRequest.CreateHttp(serverUrl + $"/api/AgentUpdate/ClearDownload/{downloadId}").GetResponseAsync()).Dispose();
Expand Down
16 changes: 16 additions & 0 deletions Server/API/ClientDownloadsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public async Task<IActionResult> GetDesktop(string platformID)
var filePath = Path.Combine(_hostEnv.WebRootPath, "Content", "MacOS-x64", "Remotely_Desktop");
return await GetDesktopFile(filePath);
}
case "MacOS-arm64":
{
var filePath = Path.Combine(_hostEnv.WebRootPath, "Content", "MacOS-arm64", "Remotely_Desktop");
return await GetDesktopFile(filePath);
}
default:
return NotFound();
}
Expand Down Expand Up @@ -86,6 +91,11 @@ public async Task<IActionResult> GetDesktop(string platformId, string organizati
var filePath = Path.Combine(_hostEnv.WebRootPath, "Content", "MacOS-x64", "Remotely_Desktop");
return await GetDesktopFile(filePath);
}
case "MacOS-arm64":
{
var filePath = Path.Combine(_hostEnv.WebRootPath, "Content", "MacOS-arm64", "Remotely_Desktop");
return await GetDesktopFile(filePath);
}
default:
return NotFound();
}
Expand Down Expand Up @@ -186,6 +196,12 @@ private async Task<IActionResult> GetInstallFile(string organizationId, string p
{
var fileName = "Install-MacOS-x64.sh";

return await GetBashInstaller(fileName, organizationId);
}
case "MacOSInstaller-arm64":
{
var fileName = "Install-MacOS-arm64.sh";

return await GetBashInstaller(fileName, organizationId);
}
default:
Expand Down
11 changes: 8 additions & 3 deletions Server/Pages/Downloads.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
<div class="col-sm-6 mb-3">
<strong>macOS (Catalina)</strong>
<p>
<a target="_blank" href="/api/ClientDownloads/Desktop/MacOS-x64/@_organizationId">macOS Executable</a>
<a target="_blank" href="/api/ClientDownloads/Desktop/MacOS-x64/@_organizationId">macOS x64 Executable</a>
<a target="_blank" href="/api/ClientDownloads/Desktop/MacOS-arm64/@_organizationId">macOS arm64 Executable</a>
</p>
</div>
</div>
Expand Down Expand Up @@ -175,9 +176,13 @@
<div class="col-sm-6 mb-3">
<strong>macOS x64 (Catalina)</strong>
<p>
<a target="_blank" href="/API/ClientDownloads/MacOSInstaller-x64">macOS ZSH Installer</a>
<a target="_blank" href="/API/ClientDownloads/MacOSInstaller-x64">macOS x64 Bash Installer</a>
<br />
<a target="_blank" href="/Content/Remotely-MacOS-x64.zip">macOS Files Only</a>
<a target="_blank" href="/Content/Remotely-MacOS-x64.zip">macOS x64 Files Only</a>
<br />
<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 Down
93 changes: 93 additions & 0 deletions Server/wwwroot/Content/Install-MacOS-arm64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

HostName=
Organization=
GUID="$(uuidgen)"
UpdatePackagePath=""

Args=( "$@" )
ArgLength=${#Args[@]}

for (( i=0; i<${ArgLength}; i+=2 ));
do
if [ "${Args[$i]}" = "--uninstall" ]; then
launchctl unload -w /Library/LaunchDaemons/remotely-agent.plist
rm -r -f /usr/local/bin/Remotely/
rm -f /Library/LaunchDaemons/remotely-agent.plist
exit
elif [ "${Args[$i]}" = "--path" ]; then
UpdatePackagePath="${Args[$i+1]}"
fi
done


# Install Homebrew
su - $SUDO_USER -c '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
su - $SUDO_USER -c "brew update"

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

# Install dependency for System.Drawing.Common
su - $SUDO_USER -c "brew install mono-libgdiplus"

# Install other dependencies
su - $SUDO_USER -c "brew install curl"
su - $SUDO_USER -c "brew install jq"


if [ -f "/usr/local/bin/Remotely/ConnectionInfo.json" ]; then
GUID=`cat "/usr/local/bin/Remotely/ConnectionInfo.json" | jq -r '.DeviceID'`
fi

rm -r -f /Applications/Remotely
rm -f /Library/LaunchDaemons/remotely-agent.plist

mkdir -p /usr/local/bin/Remotely/
chmod -R 755 /usr/local/bin/Remotely/
cd /usr/local/bin/Remotely/

if [ -z "$UpdatePackagePath" ]; then
echo "Downloading client..." >> /tmp/Remotely_Install.log
curl $HostName/Content/Remotely-MacOS-arm64.zip --output /usr/local/bin/Remotely/Remotely-MacOS-arm64.zip
else
echo "Copying install files..." >> /tmp/Remotely_Install.log
cp "$UpdatePackagePath" /usr/local/bin/Remotely/Remotely-MacOS-arm64.zip
rm -f "$UpdatePackagePath"
fi

unzip -o ./Remotely-MacOS-arm64.zip
rm -f ./Remotely-MacOS-arm64.zip


connectionInfo="{
\"DeviceID\":\"$GUID\",
\"Host\":\"$HostName\",
\"OrganizationID\": \"$Organization\",
\"ServerVerificationToken\":\"\"
}"

echo "$connectionInfo" > ./ConnectionInfo.json

curl --head $HostName/Content/Remotely-MacOS-arm64.zip | grep -i "etag" | cut -d' ' -f 2 > ./etag.txt


plistFile="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>Label</key>
<string>com.translucency.remotely-agent</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/dotnet</string>
<string>/usr/local/bin/Remotely/Remotely_Agent.dll</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
2 changes: 1 addition & 1 deletion Server/wwwroot/Content/Install-MacOS-x64.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/zsh
#!/bin/bash

HostName=
Organization=
Expand Down

0 comments on commit a43732d

Please sign in to comment.