Skip to content

Instantly share code, notes, and snippets.

@michele-tn
Created March 21, 2024 10:14
Show Gist options
  • Save michele-tn/0d2cd5c0196a711dcfc127ada6af9559 to your computer and use it in GitHub Desktop.
Save michele-tn/0d2cd5c0196a711dcfc127ada6af9559 to your computer and use it in GitHub Desktop.
Downloads the latest version of Rustdesk (Nightly or Latest) using the GitHub API web service, configures application by setting the IP and keys of your self-hosted server. Finally, it runs the application you just downloaded. That's all. ;-)
<#
.AUTHOR : MICHELE-TN
.CLIENT DEPLOYMENT : https://rustdesk.com/docs/en/self-host/client-configuration/
: https://rustdesk.com/docs/en/self-host/client-deployment/
.SERVER DEPLOYMENT : https://rustdesk.com/docs/en/self-host/
.Techahold/rustdeskinstall : Easy install Script for Rustdesk
: https://github.com/techahold/rustdeskinstall
.Note : Downloads the latest version of Rustdesk (Nightly or Latest) using
the GitHub API web service, configures application by setting the IP and
keys of your self-hosted server.
Finally, it runs the application you just downloaded.
That's all. ;-)
#>
Function GetRustdesk([bool]$PreRelease, [string]$FileName){
$repo = "rustdesk/rustdesk"
$filenamePattern = "*x86_64.exe"
$UriPattern = "*/nightly/*"
if ($PreRelease) {
$releasesUri = "https://api.github.com/repos/$repo/releases" # Nightly version!!!
[Net.ServicePointManager]::SecurityProtocol = "Tls, Tls11, Tls12, Ssl3"
$downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object { $_.name -like $filenamePattern -and $_.browser_download_url -like $UriPattern}).browser_download_url
} else {
$releasesUri = "https://api.github.com/repos/$repo/releases/latest" # Latest version!!!
[Net.ServicePointManager]::SecurityProtocol = "Tls, Tls11, Tls12, Ssl3"
$downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).browser_download_url
}
Invoke-WebRequest -Uri $downloadUri -Out $FileName
}
Function ConfigSelfHostedServer([string]$pUsername){
$IP_SelfHosted_Server = "'YOUR_SELF_HOSTED_SERVER_IP'"
$KEY_SelfHosted_Server = "'YOUR_SELF_HOSTED_SERVER_KEY'"
$nl = [Environment]::NewLine
$n2 = $nl + $nl
$CustomConfig = 'rendezvous_server = ' + $IP_SelfHosted_Server + $nl +
'nat_type = 1' + $nl +
'serial = 0' + $n2 +
'[options]' + $nl +
'custom-rendezvous-server = ' + $IP_SelfHosted_Server + $nl +
'key = ' + $KEY_SelfHosted_Server + $nl +
'relay-server = '''' ' + $nl +
'api-server = '''' '
Set-Content C:\Users\$pUsername\AppData\Roaming\RustDesk\config\RustDesk2.toml $CustomConfig
}
function GetNconfigRustdesk([bool]$PreRelease){
[Net.ServicePointManager]::SecurityProtocol = "Tls, Tls11, Tls12, Ssl3"
if ($PreRelease){
GetRustdesk 1 'rustdesk_nightly.exe'
#Invoke-WebRequest "https://github.com/rustdesk/rustdesk/releases/download/nightly/rustdesk-1.2.4-x86_64.exe" -Outfile "rustdesk.exe"
Start-Process .\rustdesk_nightly.exe
} else{
GetRustdesk 0 'rustdesk_latest.exe'
Start-Process .\rustdesk_latest.exe
}
$username = ((Get-WMIObject -ClassName Win32_ComputerSystem).Username).Split('\')[1]
$FilePath = "C:\Users\$username\AppData\Roaming\RustDesk\config\RustDesk2.toml"
while (!(Test-Path -path $FilePath -PathType Leaf)){
Write-Host "RustDesk2.toml does not exist" -f Yellow
}
if (Test-Path -path $FilePath -PathType Leaf) {
Write-Host "RustDesk2.toml FOUND!!" -f Yellow
if ($PreRelease){
taskkill /im rustdesk_nightly.exe /f
} else{
taskkill /im rustdesk_latest.exe /f
}
Remove-Item C:\Users\$username\AppData\Roaming\RustDesk\config\RustDesk2.toml
New-Item C:\Users\$username\AppData\Roaming\RustDesk\config\RustDesk2.toml
ConfigSelfHostedServer($username)
if ($PreRelease){
Start-Process .\rustdesk_nightly.exe
} else{
Start-Process .\rustdesk_latest.exe
}
}
}
cls
# Run as administrator and stays in the current directory
if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
Start-Process PowerShell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
}
}
GetNconfigRustdesk 1 #NIGHTLY
#GetNconfigRustdesk 0 #LATEST RELEASE!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment