Working on Linux auto-updating.

This commit is contained in:
Jared Goodwin 2019-03-11 17:55:34 -07:00
parent 892b346772
commit 571f176c67
15 changed files with 56112 additions and 45012 deletions

View File

@ -16,7 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Utilities", "Utilities", "{
Utilities\Register-TURNServer.ps1 = Utilities\Register-TURNServer.ps1
Utilities\Remotely_Server_Install.sh = Utilities\Remotely_Server_Install.sh
Utilities\Setup_Ubuntu_Builder.sh = Utilities\Setup_Ubuntu_Builder.sh
Utilities\TURN_Install.sh = Utilities\TURN_Install.sh
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assets", "Assets", "{D96B47F6-EF3E-4AF6-A1BE-006D531DDBA4}"

View File

@ -33,7 +33,6 @@ namespace Remotely_Agent
return settings;
};
if (argDict.ContainsKey("update"))
{
Updater.CoreUpdate();

View File

@ -9,6 +9,7 @@ using System.Management.Automation;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Linq;
namespace Remotely_Agent.Services
{
@ -68,22 +69,33 @@ namespace Remotely_Agent.Services
Logger.Write($"Service Updater: Extracting files.");
ZipFile.ExtractToDirectory(tempFile, Path.Combine(Path.GetTempPath(), "Remotely_Update"), true);
if (OSUtils.IsLinux)
if (OSUtils.IsWindows)
{
ZipFile.ExtractToDirectory(tempFile, Path.Combine(Path.GetTempPath(), "Remotely_Update"), true);
}
else if (OSUtils.IsLinux)
{
Process.Start("sudo", "apt-get install unzip").WaitForExit();
Process.Start("sudo", $"unzip -o {tempFile} -d {Path.Combine(Path.GetTempPath(), "Remotely_Update")}").WaitForExit();
Process.Start("sudo", $"chmod -R 777 {Path.Combine(Path.GetTempPath(), "Remotely_Update")}").WaitForExit();
Process.Start("sudo", $"chmod +x {Path.Combine(Path.GetTempPath(), "Remotely_Update", "Remotely_Agent")}").WaitForExit();
}
var psi = new ProcessStartInfo()
{
FileName = Path.Combine(Path.GetTempPath(), "Remotely_Update", OSUtils.ClientExecutableFileName),
Arguments = "-update true",
Verb = "RunAs"
};
Logger.Write($"Service Updater: Launching new process.");
Process.Start(psi);
Environment.Exit(0);
Logger.Write($"Service Updater: Launching extracted process to perform update.");
if (OSUtils.IsWindows)
{
var psi = new ProcessStartInfo()
{
FileName = Path.Combine(Path.GetTempPath(), "Remotely_Update", OSUtils.ClientExecutableFileName),
Arguments = "-update true",
Verb = "RunAs"
};
Process.Start(psi);
}
else if (OSUtils.IsLinux)
{
Process.Start("sudo", $"{Path.Combine(Path.GetTempPath(), "Remotely_Update", "Remotely_Agent")} -update true");
}
}
}
catch (Exception ex)
@ -105,36 +117,59 @@ namespace Remotely_Agent.Services
}
else if (OSUtils.IsLinux)
{
Process.Start("sudo", "systemctl stop remotely_service");
Process.Start("sudo", "systemctl stop remotely-agent");
}
ps.AddScript(@"
Get-Process | Where-Object {
$_.Name -like ""Remotely_Agent"" -and
$_.Id -ne [System.Diagnostics.Process]::GetCurrentProcess().Id
} | Stop-Process -Force");
ps.Invoke();
ps.Commands.Clear();
foreach (var proc in Process.GetProcesses().Where(x =>
x.ProcessName.Contains("Remotely_Agent") &&
x.Id != Process.GetCurrentProcess().Id))
{
proc.Kill();
}
Logger.Write("Service Updater: Gathering files.");
var targetDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Remotely");
string targetDir = "";
if (OSUtils.IsWindows)
{
targetDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Remotely");
}
else if (OSUtils.IsLinux)
{
targetDir = "/usr/local/bin/Remotely";
}
var itemList = Directory.GetFileSystemEntries(Path.Combine(Path.GetTempPath(), "Remotely_Update"));
var subdirList = Directory.GetDirectories(Path.Combine(Path.GetTempPath(), "Remotely_Update"));
var fileList = Directory.GetFiles(Path.Combine(Path.GetTempPath(), "Remotely_Update"));
Logger.Write("Service Updater: Copying new files.");
foreach (var item in itemList)
foreach (var subdir in subdirList)
{
try
{
var targetPath = Path.Combine(targetDir, Path.GetFileName(item));
var targetPath = Path.Combine(targetDir, Path.GetDirectoryName(subdir));
if (Directory.Exists(targetPath))
{
Directory.Delete(targetPath, true);
}
Directory.Move(subdir, targetPath);
}
catch (Exception ex)
{
Logger.Write(ex);
}
}
foreach (var file in fileList)
{
try
{
var targetPath = Path.Combine(targetDir, Path.GetFileName(file));
if (File.Exists(targetPath))
{
File.Delete(targetPath);
}
else if (Directory.Exists(targetPath))
{
Directory.Delete(targetPath, true);
}
Directory.Move(item, targetPath);
File.Move(file, targetPath);
}
catch (Exception ex)
{
@ -145,7 +180,7 @@ namespace Remotely_Agent.Services
}
catch (Exception ex)
{
Logger.Write(ex);
Logger.Write(ex);
}
finally
{

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,10 @@
function Append-Command($Command){
$Global:Commands = ""
function Append-Command($Command){
$Params = ""
if ($Command.HelpFile.Length -gt 0) {
$Help = Get-Help $Command.Name
$Synopsis = $Help.Synopsis.Trim().Replace("\", "\\")
$Syntax = ($Help.syntax | Out-String).Trim()
$Synopsis = $Help.Synopsis.Trim().Replace("\", "\\").Replace("``", "")
$Syntax = ($Help.syntax | Out-String).Trim().Replace("``", "")
foreach ($param in $Help.parameters.parameter) {
$Params += "new Parameter(``$(($param.name | Out-String).Trim())``, ``$(($param.description | Out-String).Trim().Replace('`', '"').Replace('${}',''))``, ``$($param.type.name.Trim().Replace('`', '^'))``),`r`n"
}
@ -17,7 +18,7 @@
}
@"
$Global:Commands += @"
new ConsoleCommand(
``$($Command.Name.Replace("\", "\\"))``,
[
@ -29,8 +30,8 @@
(parameters, paramDictionary) => {
}
),
"@ | Out-File -FilePath "$env:USERPROFILE\Downloads\PS.txt" -Append
),`r`n
"@
}
Update-Help
@ -47,4 +48,6 @@ $Cmdlets = Get-Command -All | Where-Object {
$Cmdlets | ForEach-Object {
Append-Command -Command $_
$Error.Clear()
}
}
$Global:Commands | Out-File -FilePath "$env:USERPROFILE\Downloads\PS.txt"

View File

@ -1,2 +1,2 @@
Start-Process -FilePath "powershell.exe" -ArgumentList "-f C:\Users\Typic\Source\Repos\DoXM\Utilities\Get-PSCommands.ps1"
Start-Process -FilePath "C:\Program Files\PowerShell\6.0.4\pwsh.exe" -ArgumentList "-f C:\Users\Typic\Source\Repos\DoXM\Utilities\Get-PSCommands.ps1"
Start-Process -FilePath "C:\Program Files\PowerShell\6\pwsh.exe" -ArgumentList "-f C:\Users\Typic\Source\Repos\DoXM\Utilities\Get-PSCommands.ps1"

View File

@ -56,13 +56,6 @@ Set-Location -Path (Get-Item -Path $PSScriptRoot).Parent.FullName
if ($ArgList.Contains("c")) {
# Try to build the .NET Framework ScreenCaster.
try {
dotnet build ".\Remotely_ScreenCast\" /p:Version=$CurrentVersion /p:FileVersion=$CurrentVersion --configuration Release
}
catch {
Write-Host "Unable to build ScreenCaster. The most recent pre-compiled binaries will be used."
}
# Copy .NET Framework ScreenCaster to Agent resources for embedding.
if ((Test-Path -Path ".\Remotely_Agent\Resources") -eq $false) {
New-Item -Path ".\Remotely_Agent\Resources" -ItemType Directory

View File

@ -1,8 +0,0 @@
$Trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:30
Register-ScheduledJob -Trigger $Trigger -Name "TURNServer" -RunNow -ScriptBlock {
$env:USERS = "user=password"
$env:REALM = "myserver.example.com"
$env:UDP_PORT = 3478
&"C:\path\to\simple-turn-windows-amd64.exe"
}

View File

@ -33,6 +33,40 @@ nginxConfig="server {
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
location /BrowserHub {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection \"upgrade\";
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
}
location /DeviceHub {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection \"upgrade\";
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
}
location /RCBrowserHub {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection \"upgrade\";
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
}
location /RCDeviceHub {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection \"upgrade\";
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
}
}"
echo "$nginxConfig" > /etc/nginx/sites-available/remotely
@ -77,6 +111,6 @@ systemctl start remotely.service
# Install Certbot and get SSL cert.
apt-get install certbot
apt-get install certbot python-certbot-nginx
certbot --nginx

View File

@ -1,14 +0,0 @@
# Arguments are username, password, realm.
apt-get update
apt-get upgrade
apt-get install -y coturn
echo "TURNSERVER_ENABLED=1" | tee /etc/default/coturn
echo "listening-port=3478
realm=$3
server-name=$3
lt-cred-mech
" | tee /etc/turnserver.conf
turnadmin -a -u $1 -p $2 -r $3