Skip to content

Instantly share code, notes, and snippets.

@AdamWorley
Created October 19, 2023 08:29
Show Gist options
  • Save AdamWorley/763d8139b87fe9c396deb7f4c9e36822 to your computer and use it in GitHub Desktop.
Save AdamWorley/763d8139b87fe9c396deb7f4c9e36822 to your computer and use it in GitHub Desktop.
Dev Drive Setup Script
# Define the Dev Drive path
$DevDrive = "D:\packages"
# Function to display progress message
function Show-Progress($message, $color) {
Write-Host -ForegroundColor $color "Progress: $message"
}
# Create npm cache directory and set environment variable
$npmCacheDir = Join-Path $DevDrive "npm"
Show-Progress "Creating npm cache directory..." Yellow
New-Item -ItemType Directory -Force -Path $npmCacheDir
[Environment]::SetEnvironmentVariable("npm_config_cache", $npmCacheDir, [System.EnvironmentVariableTarget]::Machine)
# Move existing npm cache if it exists
if (Test-Path "$env:APPDATA\npm-cache") {
Show-Progress "Moving existing npm cache..." Yellow
Move-Item "$env:APPDATA\npm-cache\*" -Destination $npmCacheDir -Force
}
# Create NuGet global-packages folder and set environment variable
$nugetPackagesDir = Join-Path $DevDrive ".nuget\packages"
Show-Progress "Creating NuGet global-packages folder..." Yellow
New-Item -ItemType Directory -Force -Path $nugetPackagesDir
[Environment]::SetEnvironmentVariable("NUGET_PACKAGES", $nugetPackagesDir, [System.EnvironmentVariableTarget]::Machine)
# Set NuGet global-packages folder for MSBuild
[Environment]::SetEnvironmentVariable("RestorePackagesPath", $nugetPackagesDir, [System.EnvironmentVariableTarget]::Machine)
# Create vcpkg cache directory and set environment variable
$vcpkgCacheDir = Join-Path $DevDrive "vcpkg"
Show-Progress "Creating vcpkg cache directory..." Yellow
New-Item -ItemType Directory -Force -Path $vcpkgCacheDir
[Environment]::SetEnvironmentVariable("VCPKG_DEFAULT_BINARY_CACHE", $vcpkgCacheDir, [System.EnvironmentVariableTarget]::Machine)
# Move existing vcpkg archives if they exist
if (Test-Path "$env:LOCALAPPDATA\vcpkg\archives" -or Test-Path "$env:APPDATA\vcpkg\archives") {
Show-Progress "Moving existing vcpkg archives..." Yellow
$sourcePath = "$env:LOCALAPPDATA\vcpkg\archives"
if (-not (Test-Path $sourcePath)) {
$sourcePath = "$env:APPDATA\vcpkg\archives"
}
Move-Item "$sourcePath\*" -Destination $vcpkgCacheDir -Force
}
# Create pip cache directory and set environment variable
$pipCacheDir = Join-Path $DevDrive "pip"
Show-Progress "Creating pip cache directory..." Yellow
New-Item -ItemType Directory -Force -Path $pipCacheDir
[Environment]::SetEnvironmentVariable("PIP_CACHE_DIR", $pipCacheDir, [System.EnvironmentVariableTarget]::Machine)
# Move existing pip cache if it exists
if (Test-Path "$env:LocalAppData\pip\Cache") {
Show-Progress "Moving existing pip cache..." Yellow
Move-Item "$env:LocalAppData\pip\Cache\*" -Destination $pipCacheDir -Force
}
# Create Cargo cache directory and set environment variable
$cargoCacheDir = Join-Path $DevDrive "cargo"
Show-Progress "Creating Cargo cache directory..." Yellow
New-Item -ItemType Directory -Force -Path $cargoCacheDir
[Environment]::SetEnvironmentVariable("CARGO_HOME", $cargoCacheDir, [System.EnvironmentVariableTarget]::Machine)
# Move existing Cargo cache if it exists
if (Test-Path "$env:USERPROFILE\.cargo") {
Show-Progress "Moving existing Cargo cache..." Yellow
Move-Item "$env:USERPROFILE\.cargo\*" -Destination $cargoCacheDir -Force
}
# Print completion message
Show-Progress "Package caches have been configured and moved to the Dev Drive." Green
@XcantloadX
Copy link

I think it's necessary to prompt users to run the script as admin.

@micsthepick
Copy link

micsthepick commented Apr 16, 2024

https://gist.github.com/AdamWorley/763d8139b87fe9c396deb7f4c9e36822#file-devdrive-ps1-L37
probably should read as follows

if ((Test-Path "$env:LOCALAPPDATA\vcpkg\archives") -or (Test-Path "$env:APPDATA\vcpkg\archives")) { 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment