Skip to content

Instantly share code, notes, and snippets.

@garnetsunset
Last active April 24, 2025 16:10
Show Gist options
  • Save garnetsunset/02236a759a0ada79662f56edccd58b4a to your computer and use it in GitHub Desktop.
Save garnetsunset/02236a759a0ada79662f56edccd58b4a to your computer and use it in GitHub Desktop.
startup.ps1
# This part checks for internet connectivity before proceeding
function WaitForInternetConnection {
$isConnected = $false
while (-not $isConnected) {
try {
Write-Output "Trying to connect..."
Test-Connection -ComputerName "google.com" -Count 1 -ErrorAction Stop
$isConnected = $true
Write-Output "Connection successful."
} catch {
Write-Output "Failed to connect. Retrying in 5 seconds..."
Start-Sleep -Seconds 5
}
}
}
# Function to perform git pull and restart the script if it was updated
function UpdateScriptFromGit {
Write-Output "Checking for script updates..."
$gitOutput = git pull
Write-Output "Update output: $gitOutput"
if ($gitOutput -notlike "*Already up to date.*") {
Write-Output "Updates were applied, restarting the script..."
& $PSCommandPath
exit
}
}
# Log beginning of the script
Write-Output "Starting script..."
# Wait for an active internet connection
Write-Output "Waiting for an internet connection..."
WaitForInternetConnection
Write-Output "Internet connection established."
# Perform the update check
UpdateScriptFromGit
# Set the location to the script's root directory
Set-Location $PSScriptRoot
Write-Output "Set location to script's root directory."
# List of directories to remove
$pathsToRemove = @(
"$env:TEMP\*",
"C:\AMD",
"C:\Intel",
"C:\Nvidia",
"C:\Temp",
"C:\vol0\Cache"
)
# Directories to skip when deleting the entire directory
$skipFullDelete = @(
"$env:TEMP",
"C:\Temp",
"C:\vol0"
)
# Create an empty directory for the robocopy mirroring technique
$emptyDir = "C:\EmptyTempDir"
New-Item -Path $emptyDir -ItemType Directory -ErrorAction SilentlyContinue
foreach ($path in $pathsToRemove) {
Write-Output "Processing directory: $path..."
# Remove wildcard from path for robocopy
$adjustedPath = $path -replace '\\\*$', ''
if (Test-Path $adjustedPath) {
# Use robocopy to mirror the empty directory over the target path, effectively deleting its contents
robocopy $emptyDir $adjustedPath /MIR /W:1 /R:1
# Delete the directory itself if it's not in the skip list
if ($skipFullDelete -notcontains $adjustedPath) {
Remove-Item $adjustedPath -Force -Recurse -ErrorAction SilentlyContinue
}
}
}
# Clean up the temporary empty directory
Remove-Item $emptyDir -Force -Confirm:$false
Write-Output "Removal of specified directories completed."
# Clear Blackmagic Resolve cache
Write-Output "Clearing Blackmagic Resolve cache..."
$resolveCachePath = "C:\vol0"
if (Test-Path $resolveCachePath) {
Remove-Item "$resolveCachePath\*" -Force -Recurse -ErrorAction SilentlyContinue
Write-Output "Blackmagic Resolve cache cleared."
} else {
Write-Output "No Blackmagic Resolve cache found to clear."
}
# Remove registry key
Write-Output "Removing registry key..."
reg delete "HKEY_CURRENT_USER\SOFTWARE\SweetScape\010 Editor" /f
Write-Output "Registry key removed."
# Remove items from the Desktop
Write-Output "Removing items from the Desktop..."
Remove-Item "$env:USERPROFILE\Desktop\*" -Recurse -Force -ErrorAction SilentlyContinue -Confirm:$false
Write-Output "Items from the Desktop removed."
# Shutdown WSL
Write-Output "Shutting down WSL..."
wsl --shutdown
Write-Output "WSL shutdown completed."
# Compact WSL2 Disk
Write-Output "Compacting WSL2 Disk..."
wslcompact -c -y
Write-Output "WSL2 Disk compacted."
Write-Output "Install JQ"
winget install jqlang.jq
# Spicetify
spicetify backup apply
# System scans and repairs
Write-Output "Starting system scans and repairs..."
sfc /scannow | Out-Null
DISM /Online /Cleanup-Image /RestoreHealth | Out-Null
Write-Output "System scans and repairs completed."
# Define the path to the SteamVR settings file
$steamvrSettingsPath = "C:\Program Files (x86)\Steam\config\steamvr.vrsettings"
if (Test-Path $steamvrSettingsPath) {
Write-Output "Modifying SteamVR settings file at $steamvrSettingsPath with jq..."
# Check if jq is available
if (-not (Get-Command jq -ErrorAction SilentlyContinue)) {
Write-Output "jq is not installed or not found in PATH. Please install jq from https://stedolan.github.io/jq/."
}
else {
# Create a temporary file name for the updated JSON
$tempFile = [System.IO.Path]::GetTempFileName()
# The jq filter explained:
# - (.power.autoLaunchSteamVROnButtonPress // false) ensures that if the key doesn't exist, it is treated as false.
# - Then we use an if/else to set it to false if it is true (or leave it as false if already false).
# This effectively forces the value to false.
$jqFilter = '.power.autoLaunchSteamVROnButtonPress = ((.power.autoLaunchSteamVROnButtonPress // false) | if . == true then false else . end)'
# Run jq to process the JSON file and output to the temporary file
& jq $jqFilter $steamvrSettingsPath | Out-File -FilePath $tempFile -Encoding UTF8
# Overwrite the original file with the updated file
Move-Item -Path $tempFile -Destination $steamvrSettingsPath -Force
Write-Output "SteamVR settings updated successfully with jq."
}
} else {
Write-Output "SteamVR settings file not found at $steamvrSettingsPath."
}
# Exit the script
Write-Output "Script completed."
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment