2022-07-05 01:21:42 +00:00
|
|
|
# Get ci parameter to check if running with ci
|
|
|
|
param(
|
|
|
|
[Parameter()]
|
|
|
|
[Switch]$ci
|
|
|
|
)
|
|
|
|
|
2022-06-30 01:44:14 +00:00
|
|
|
# Get temp folder
|
|
|
|
$temp = [System.IO.Path]::GetTempPath()
|
|
|
|
|
|
|
|
# Get current running dir
|
|
|
|
$currentLocation = $((Get-Location).path)
|
|
|
|
|
|
|
|
# Check to see if a command exists (eg if an app is installed)
|
|
|
|
Function CheckCommand {
|
|
|
|
|
|
|
|
Param ($command)
|
|
|
|
|
|
|
|
$oldPreference = $ErrorActionPreference
|
|
|
|
|
|
|
|
$ErrorActionPreference = 'stop'
|
|
|
|
|
|
|
|
try { if (Get-Command $command) { RETURN $true } }
|
|
|
|
|
|
|
|
Catch { RETURN $false }
|
|
|
|
|
|
|
|
Finally { $ErrorActionPreference = $oldPreference }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host "Spacedrive Development Environment Setup" -ForegroundColor Magenta
|
|
|
|
Write-Host @"
|
|
|
|
|
|
|
|
To set up your machine for Spacedrive development, this script will do the following:
|
|
|
|
|
|
|
|
1) Check for Rust and Cargo
|
|
|
|
|
|
|
|
2) Install pnpm (if not installed)
|
|
|
|
|
|
|
|
3) Install the latest version of Node.js using pnpm
|
|
|
|
|
|
|
|
4) Install LLVM (compiler for ffmpeg-rust)
|
|
|
|
|
|
|
|
4) Download ffmpeg and set as an environment variable
|
|
|
|
|
|
|
|
"@
|
|
|
|
|
|
|
|
Write-Host "Checking for Rust and Cargo..." -ForegroundColor Yellow
|
|
|
|
Start-Sleep -Milliseconds 150
|
|
|
|
|
|
|
|
$cargoCheck = CheckCommand cargo
|
|
|
|
|
|
|
|
if ($cargoCheck -eq $false) {
|
|
|
|
Write-Host @"
|
|
|
|
Cargo is not installed.
|
|
|
|
|
|
|
|
To use Spacedrive on Windows, Cargo needs to be installed.
|
|
|
|
The Visual Studio C++ Build tools are also required.
|
|
|
|
Instructions can be found here:
|
|
|
|
|
|
|
|
https://tauri.app/v1/guides/getting-started/prerequisites/#setting-up-windows
|
|
|
|
|
|
|
|
Once you have installed Cargo, re-run this script.
|
|
|
|
|
|
|
|
"@
|
|
|
|
Exit
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Host "Cargo is installed."
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host
|
|
|
|
Write-Host "Checking for pnpm..." -ForegroundColor Yellow
|
|
|
|
Start-Sleep -Milliseconds 150
|
|
|
|
|
|
|
|
$pnpmCheck = CheckCommand pnpm
|
|
|
|
if ($pnpmCheck -eq $false) {
|
|
|
|
|
|
|
|
Write-Host "pnpm is not installed. Installing now."
|
|
|
|
Write-Host "Running the pnpm installer..."
|
|
|
|
|
|
|
|
#pnpm installer taken from https://pnpm.io
|
|
|
|
Invoke-WebRequest https://get.pnpm.io/install.ps1 -useb | Invoke-Expression
|
|
|
|
|
2022-07-05 01:21:42 +00:00
|
|
|
# Reset the PATH env variables to make sure pnpm is accessible
|
2022-06-30 01:44:14 +00:00
|
|
|
$env:PNPM_HOME = [System.Environment]::GetEnvironmentVariable("PNPM_HOME", "User")
|
|
|
|
$env:Path = [System.Environment]::ExpandEnvironmentVariables([System.Environment]::GetEnvironmentVariable("Path", "User"))
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Host "pnpm is installed."
|
|
|
|
}
|
|
|
|
|
2022-07-05 01:21:42 +00:00
|
|
|
# A GitHub Action takes care of installing node, so this isn't necessary if running in the ci.
|
|
|
|
if ($ci -eq $True) {
|
|
|
|
Write-Host
|
|
|
|
Write-Host "Running with Ci, skipping Node install." -ForegroundColor Yellow
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Host
|
|
|
|
Write-Host "Using pnpm to install the latest version of Node..." -ForegroundColor Yellow
|
|
|
|
Write-Host "This will set your global Node version to the latest!"
|
|
|
|
Start-Sleep -Milliseconds 150
|
2022-06-30 01:44:14 +00:00
|
|
|
|
2022-07-05 01:21:42 +00:00
|
|
|
# Runs the pnpm command to use the latest version of node, which also installs it
|
|
|
|
Start-Process -Wait -FilePath "pnpm" -ArgumentList "env use --global latest" -PassThru -Verb runAs
|
|
|
|
}
|
2022-06-30 01:44:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-07-05 01:21:42 +00:00
|
|
|
# We can't run the installer if running in ci, so we install LLVM through a GitHub Action instead.
|
|
|
|
if ($ci -eq $True) {
|
|
|
|
Write-Host
|
|
|
|
Write-Host "Running with Ci, skipping LLVM install." -ForegroundColor Yellow
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Host
|
|
|
|
Write-Host "Downloading the LLVM installer..." -ForegroundColor Yellow
|
|
|
|
# Downloads latest installer for LLVM
|
|
|
|
$filenamePattern = "*-win64.exe"
|
|
|
|
$releasesUri = "https://api.github.com/repos/llvm/llvm-project/releases/latest"
|
|
|
|
$downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).browser_download_url
|
|
|
|
|
|
|
|
Start-BitsTransfer -Source $downloadUri -Destination "$temp\llvm.exe"
|
|
|
|
|
|
|
|
Write-Host
|
|
|
|
Write-Host "Running the LLVM installer..." -ForegroundColor Yellow
|
|
|
|
Write-Host "Please follow the instructions to install LLVM."
|
|
|
|
Write-Host "Ensure you add LLVM to your PATH."
|
|
|
|
|
|
|
|
Start-Process "$temp\llvm.exe" -Wait
|
|
|
|
}
|
|
|
|
|
2022-06-30 01:44:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
Write-Host
|
|
|
|
Write-Host "Downloading the latest ffmpeg build..." -ForegroundColor Yellow
|
|
|
|
|
|
|
|
# Downloads the latest shared build of ffmpeg from GitHub
|
|
|
|
$filenamePattern = "*-full_build-shared.zip"
|
|
|
|
$releasesUri = "https://api.github.com/repos/GyanD/codexffmpeg/releases/latest"
|
|
|
|
$downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).browser_download_url
|
|
|
|
$filename = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).name
|
|
|
|
$remove = ".zip"
|
|
|
|
$foldername = $filename.Substring(0, ($filename.Length - $remove.Length))
|
|
|
|
|
|
|
|
Start-BitsTransfer -Source $downloadUri -Destination "$temp\ffmpeg.zip"
|
|
|
|
|
|
|
|
Write-Host
|
|
|
|
Write-Host "Expanding ffmpeg zip..." -ForegroundColor Yellow
|
|
|
|
|
|
|
|
Expand-Archive "$temp\ffmpeg.zip" $HOME -ErrorAction SilentlyContinue
|
|
|
|
|
|
|
|
Remove-Item "$temp\ffmpeg.zip"
|
|
|
|
|
|
|
|
Write-Host
|
|
|
|
Write-Host "Setting environment variables..." -ForegroundColor Yellow
|
|
|
|
|
|
|
|
# Sets environment variable for ffmpeg
|
|
|
|
[System.Environment]::SetEnvironmentVariable('FFMPEG_DIR', "$HOME\$foldername", [System.EnvironmentVariableTarget]::User)
|
|
|
|
|
|
|
|
Write-Host
|
|
|
|
Write-Host "Copying Required .dll files..." -ForegroundColor Yellow
|
|
|
|
|
|
|
|
# Create target\debug folder, continue if already exists
|
|
|
|
New-Item -Path $currentLocation\target\debug -ItemType Directory -ErrorAction SilentlyContinue
|
|
|
|
|
|
|
|
# Copies all .dll required for rust-ffmpeg to target\debug folder
|
|
|
|
Get-ChildItem "$HOME\$foldername\bin" -recurse -filter *.dll | Copy-Item -Destination "$currentLocation\target\debug"
|
|
|
|
|
|
|
|
Write-Host
|
|
|
|
Write-Host "Your machine has been setup for Spacedrive development!"
|