# bootstrap.ps1 # --- [ Elevation Check & Self-Relaunch ] --- # If not running as administrator, re-run the remote script with elevated privileges. $elevated = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole( [Security.Principal.WindowsBuiltinRole]::Administrator) if (-not $elevated) { Write-Host "Elevation required. Restarting script as administrator..." $scriptURL = "https://setup.xn--zn8h.fm" # Adjust the URL if needed # Build an argument array to re-run the remote script $arguments = @( "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", "iwr '$scriptURL' | iex" ) Start-Process -FilePath "powershell.exe" -Verb RunAs -ArgumentList $arguments exit } # --- [ Main Logic (Elevated) ] --- $sharePath = "\\xn--zn8h.fm\Share" $driveLetter = "Z" Write-Host "Checking if ${driveLetter}: is already mapped..." # Attempt to remove any existing mapping via net use first $null = net use ${driveLetter}: /delete /yes 2>$null # If a PSDrive exists with the same letter, remove it if (Get-PSDrive -Name $driveLetter -ErrorAction SilentlyContinue) { try { Write-Host "Cleaning up PSDrive ${driveLetter}..." Remove-PSDrive -Name $driveLetter -Force -ErrorAction Stop } catch { Write-Warning "Could not remove PSDrive, continuing..." } } Write-Host "Enter credentials to access the SMB share (leave blank for anonymous)" $credential = Get-Credential try { Write-Host "Mounting SMB share at ${driveLetter}:..." New-PSDrive -Name $driveLetter -PSProvider FileSystem -Root $sharePath -Credential $credential -Persist -ErrorAction Stop Write-Host "Successfully mounted $sharePath to ${driveLetter}:" } catch { Write-Error "Failed to mount $sharePath. $_" Read-Host "`nPress Enter to exit..." exit 1 } $setupPath = "${driveLetter}:\setup.bat" if (Test-Path $setupPath) { Write-Host "Running setup.bat..." Start-Process -FilePath $setupPath -WorkingDirectory (Split-Path $setupPath) -Wait } else { Write-Error "setup.bat not found at $setupPath" Read-Host "`nPress Enter to exit..." exit 1 } Write-Host "`nAll done! Press Enter to exit..." Read-Host