Skip to content

Instantly share code, notes, and snippets.

@comerford
Created March 22, 2023 19:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save comerford/e507c90eae696ae4c06d729e10994a61 to your computer and use it in GitHub Desktop.
Save comerford/e507c90eae696ae4c06d729e10994a61 to your computer and use it in GitHub Desktop.
Public rclone wrapper
param(
[Parameter(Mandatory=$true)]
[string]$access_key,
[Parameter(Mandatory=$true)]
[string]$secret_key,
[string]$path="c:\unreal-5.0"
)
# this asssumes that the custom UE5 that you want to download is in an S3 bucket and is in a self-extracting archive (7zip or similar)
# for the last version built, 225GB is needed at least, but we might be re-running, so need to get the current amount downloaded and subtract if present
$driveInfo = Get-PSDrive -PSProvider 'FileSystem' | Where-Object { $_.Name -eq $path[0] }
$requiredSpace = 225GB
if (Test-Path $path) {
$currentSpace = (Get-ChildItem $path -Recurse | Measure-Object -Property Length -Sum).Sum
} else {
$currentSpace = 0
}
$freeSpace = $driveInfo.Free
$requiredSpace -= $currentSpace / 1GB
if ($freeSpace -lt $requiredSpace) {
Write-Host "Insufficient disk space. Required space: $([math]::Round($requiredSpace, 2)) GB. Free space: $freeSpace GB."
exit
}
$tempDir = "$env:TEMP\rclone"
if (Test-Path $tempDir) {
Remove-Item $tempDir -Recurse -Force
}
# (re)Create temp directory
$tempdir = New-Item -ItemType Directory -Path $env:TEMP\rclone -Force
# Download and extract latest rclone
$rclonezipurl = "https://downloads.rclone.org/rclone-current-windows-amd64.zip"
$rclonezippath = Join-Path $tempdir.FullName "rclone.zip"
Invoke-WebRequest -Uri $rclonezipurl -OutFile $rclonezippath
Expand-Archive -LiteralPath $rclonezippath -DestinationPath $tempdir.FullName
# Rename extracted rclone folder
$rclonefolder = Get-ChildItem -Path $tempdir.FullName -Filter "rclone-*" -Directory | Select-Object -First 1
$strippedname = $rclonefolder.Name -replace "-.*$"
Rename-Item -LiteralPath $rclonefolder.FullName -NewName $strippedname
# Create rclone.conf
$configfile = Join-Path $tempdir.FullName "rclone.conf"
$configcontent = @"
[ue5customS3]
type = s3
provider = AWS
env_auth = false
region = us-east-1
location_constraint = "us-east-1"
acl = private
access_key_id = $access_key
secret_access_key = $secret_key
"@
$configcontent | Out-File -FilePath $configfile -Encoding utf8
# Sync with S3 using rclone
$rcloneexe = Join-Path $tempdir.FullName "rclone\rclone.exe"
$syncpath = "ue5customS3:ue5-custom"
$arguments = @("-vv", "sync", $syncpath, $path, "--config", $configfile)
Start-Process -FilePath $rcloneexe -ArgumentList $arguments -Wait
# check that all files have been synced completely
$remoteFiles = Invoke-Expression "& $rcloneexe ls ue5customS3:ue5-custom --config $configfile"
$localFiles = Get-ChildItem $path -Recurse -File
$remoteCount = ($remoteFiles | Measure-Object).Count
$localCount = ($localFiles | Measure-Object).Count
if ($remoteCount -ne $localCount) {
Write-Host "Not all files have been synced yet. Not extracting, please re-run..."
} else {
Write-Host "Looks like we have all the files, extracting"
$exeFile = Get-ChildItem $path -Recurse -File -Filter "*.exe" | Select-Object -First 1
cd $path
Start-Process -FilePath $exeFile -ArgumentList "-y" -Wait
}
# Remove temp directory and files
Remove-Item -LiteralPath $tempdir.FullName -Recurse -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment