mirror of
https://github.com/timsutton/brigadier.git
synced 2024-09-19 19:18:51 -04:00
Change save locations to act more like Python
Script will now download and unpack in $env:Temp and output final result to $pwd\BootCamp-$Version like Python Script Python uses a randomly generated directory in temp, but use a predictable one to allow us to check if .pkg is already downloaded and skip if so.
This commit is contained in:
parent
344de3b871
commit
51c0e0c301
1 changed files with 27 additions and 19 deletions
|
@ -2,7 +2,7 @@
|
||||||
Param(
|
Param(
|
||||||
[string]$Model = (Get-WmiObject -Class Win32_ComputerSystem).Model,
|
[string]$Model = (Get-WmiObject -Class Win32_ComputerSystem).Model,
|
||||||
[switch]$Install,
|
[switch]$Install,
|
||||||
[string]$OutputDir = "$env:TEMP",
|
[string]$OutputDir = $PWD,
|
||||||
[switch]$KeepFiles,
|
[switch]$KeepFiles,
|
||||||
[array]$ProductId,
|
[array]$ProductId,
|
||||||
[string]$SUCATALOG_URL = 'http://swscan.apple.com/content/catalogs/others/index-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog',
|
[string]$SUCATALOG_URL = 'http://swscan.apple.com/content/catalogs/others/index-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog',
|
||||||
|
@ -20,7 +20,7 @@ $7z = "$env:ProgramFiles\7-Zip\7z.exe"
|
||||||
if (Test-Path $7z) { $7zInstalled = $true }
|
if (Test-Path $7z) { $7zInstalled = $true }
|
||||||
if ([version](Get-ItemProperty $7z).VersionInfo.FileVersion -lt 15.14) {
|
if ([version](Get-ItemProperty $7z).VersionInfo.FileVersion -lt 15.14) {
|
||||||
Write-Host "7-Zip not installed, will install and remove."
|
Write-Host "7-Zip not installed, will install and remove."
|
||||||
Invoke-WebRequest -Uri $SEVENZIP_URL -OutFile "$OutputDir\$($SEVENZIP_URL.Split('/')[-1])" -ErrorAction Stop
|
Invoke-WebRequest -Uri $SEVENZIP_URL -OutFile "$env:Temp\$($SEVENZIP_URL.Split('/')[-1])" -ErrorAction Stop
|
||||||
Start-Process -FilePath $env:SystemRoot\System32\msiexec.exe -ArgumentList "/i $OutputDir\$($SEVENZIP_URL.Split('/')[-1]) /qb- /norestart" -Wait -Verbose
|
Start-Process -FilePath $env:SystemRoot\System32\msiexec.exe -ArgumentList "/i $OutputDir\$($SEVENZIP_URL.Split('/')[-1]) /qb- /norestart" -Wait -Verbose
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,41 +56,49 @@ $package += @{'ESDVersion' = $Version}
|
||||||
Write-Host "Selected $($package.ESDVersion) as it's the most recently posted."
|
Write-Host "Selected $($package.ESDVersion) as it's the most recently posted."
|
||||||
|
|
||||||
# Download the BootCamp ESD
|
# Download the BootCamp ESD
|
||||||
|
$landingDir = Join-Path $OutputDir "BootCamp-$($package.ESDVersion)"
|
||||||
|
$workingDir = Join-Path $env:Temp "BootCamp-unpack-$($package.ESDVersion)"
|
||||||
|
$packagePath = Join-Path $workingDir 'BootCampESD.pkg'
|
||||||
|
$payloadPath = Join-Path $workingDir 'Payload~'
|
||||||
|
$dmgPath = Join-Path $workingDir 'WindowsSupport.dmg'
|
||||||
|
|
||||||
|
if (-not (Test-Path -PathType Container $landingDir)) {mkdir $landingDir > $null}
|
||||||
|
if (-not (Test-Path -PathType Container $workingDir)) {mkdir $workingDir > $null}
|
||||||
|
|
||||||
Write-Host "Starting download from $($package.URL)"
|
Write-Host "Starting download from $($package.URL)"
|
||||||
Start-BitsTransfer -Source $package.URL -Destination "$OutputDir\BootCampESD.pkg" -ErrorAction Stop
|
Start-BitsTransfer -Source $package.URL -Destination "$packagePath" -ErrorAction Stop
|
||||||
Write-Host "Download complete"
|
Write-Host "Download complete"
|
||||||
if (Test-Path -Path "$OutputDir\BootCampESD.pkg") {
|
if (Test-Path -Path "$packagePath") {
|
||||||
# Extract the bootcamp installer
|
# Extract the bootcamp installer
|
||||||
Write-Host "Extracting..."
|
Write-Host "Extracting..."
|
||||||
Invoke-Command -ScriptBlock {
|
Invoke-Command -ScriptBlock {
|
||||||
& $7z -o"$OutputDir" -y e "$OutputDir\BootCampESD.pkg"
|
& $7z -o"$workingDir" -y e "$packagePath"
|
||||||
& $7z -o"$OutputDir" -y e "$OutputDir\Payload~"
|
& $7z -o"$workingDir" -y e "$payloadPath"
|
||||||
# If just downloading, put the extracted installers on the desktop
|
& $7z -o"$landingDir" -y x "$dmgPath"
|
||||||
if ($Install) {
|
# # If just downloading, put the extracted installers on the desktop
|
||||||
& $7z -o"$OutputDir" -y x "$OutputDir\WindowsSupport.dmg"
|
# if ($Install) {
|
||||||
}
|
# & $7z -o"$OutputDir" -y x "$dmgPath"
|
||||||
else {
|
# }
|
||||||
if ($OutputDir -eq "$env:TEMP") { & $7z -o"$env:USERPROFILE\Desktop\$version" -y x "$OutputDir\WindowsSupport.dmg" } else { & $7z -o"$OutputDir" -y x "$OutputDir\WindowsSupport.dmg" }
|
# else {
|
||||||
}
|
# if ($OutputDir -eq "$env:TEMP") { & $7z -o"$env:USERPROFILE\Desktop\$version" -y x "$dmgPath" } else { & $7z -o"$OutputDir" -y x "$dmgPath" }
|
||||||
|
# }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { Write-Warning "BootCampESD.pkg could not be found"; exit }
|
else { Write-Warning "BootCampESD.pkg could not be found"; exit }
|
||||||
|
|
||||||
# Uninstall 7zip if we installed it
|
# Uninstall 7zip if we installed it
|
||||||
if ($7zInstalled -ne $true) { Start-Process -FilePath $env:SystemRoot\System32\msiexec.exe -ArgumentList "/x $OutputDir\$($SEVENZIP_URL.Split('/')[-1]) /qb- /norestart" -Wait }
|
if ($7zInstalled -ne $true) { Start-Process -FilePath $env:SystemRoot\System32\msiexec.exe -ArgumentList "/x $env:Temp\$($SEVENZIP_URL.Split('/')[-1]) /qb- /norestart" -Wait }
|
||||||
|
|
||||||
# Install Bootcamp and use MST if specified (I uploaded one that I had to use to fix the latest ESD on an iMac14,1)
|
# Install Bootcamp and use MST if specified (I uploaded one that I had to use to fix the latest ESD on an iMac14,1)
|
||||||
if ($Install) {
|
if ($Install) {
|
||||||
# Install Bootcamp
|
# Install Bootcamp
|
||||||
$scaction = New-ScheduledTaskAction -Execute "msiexec.exe" -Argument "/i $OutputDir\Bootcamp\Drivers\Apple\BootCamp.msi /qn /norestart"
|
$scaction = New-ScheduledTaskAction -Execute "msiexec.exe" -Argument "/i $landingDir\Bootcamp\Drivers\Apple\BootCamp.msi /qn /norestart"
|
||||||
$sctrigger = New-ScheduledTaskTrigger -At ((Get-Date).AddSeconds(15)) -Once
|
$sctrigger = New-ScheduledTaskTrigger -At ((Get-Date).AddSeconds(15)) -Once
|
||||||
$scprincipal = New-ScheduledTaskPrincipal "SYSTEM" -RunLevel Highest
|
$scprincipal = New-ScheduledTaskPrincipal "SYSTEM" -RunLevel Highest
|
||||||
$scsettings = New-ScheduledTaskSettingsSet
|
$scsettings = New-ScheduledTaskSettingsSet
|
||||||
$sctask = New-ScheduledTask -Action $scaction -Principal $scprincipal -Trigger $sctrigger -Settings $scsettings
|
$sctask = New-ScheduledTask -Action $scaction -Principal $scprincipal -Trigger $sctrigger -Settings $scsettings
|
||||||
Register-ScheduledTask "Install Bootcamp" -InputObject $sctask -User "SYSTEM"
|
Register-ScheduledTask "Install Bootcamp" -InputObject $sctask -User "SYSTEM"
|
||||||
do { Write-Output "Sleeping 20 seconds"; Start-Sleep -Seconds 20 } while (Get-Process -Name "msiexec" -ErrorAction SilentlyContinue)
|
do { Write-Output "Sleeping 20 seconds"; Start-Sleep -Seconds 20 } while (Get-Process -Name "msiexec" -ErrorAction SilentlyContinue)
|
||||||
|
if (-not $KeepFiles) { Remove-Item -Path "$landingDir" -Recurse -Force -ErrorAction SilentlyContinue }
|
||||||
}
|
}
|
||||||
else { exit }
|
else { exit }
|
||||||
|
|
||||||
# Clean up
|
|
||||||
if ($KeepFiles) { exit } else { Remove-Item -Path "$OutputDir\*" -Recurse -Force -ErrorAction SilentlyContinue }
|
|
||||||
|
|
Loading…
Reference in a new issue