From 294f03454a1a38dbf189c508a2a9136b56bd40a0 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 30 Oct 2020 11:28:54 +0530 Subject: [PATCH] Install VcRedist from GitHub --- README.md | 1 + src/scripts/win32.ps1 | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a978909f..e4160e86 100644 --- a/README.md +++ b/README.md @@ -769,6 +769,7 @@ Examples of using `setup-php` with various PHP Frameworks and Packages. ## :package: Dependencies - [Node.js dependencies](https://github.com/shivammathur/setup-php/network/dependencies "Node.js dependencies") +- [aaronparker/VcRedist](https://github.com/aaronparker/VcRedist "VcRedist PowerShell package") - [gplessis/dotdeb-php](https://github.com/gplessis/dotdeb-php "Packaging for end of life PHP versions") - [mlocati/powershell-phpmanager](https://github.com/mlocati/powershell-phpmanager "Package to handle PHP on windows") - [ppa:ondrej/php](https://launchpad.net/~ondrej/+archive/ubuntu/php "Packaging active PHP packages") diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index e95a527e..2ccf30dc 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -79,7 +79,7 @@ Function Add-Printf { if(Test-Path "C:\msys64\usr\bin\printf.exe") { New-Item -Path $bin_dir\printf.exe -ItemType SymbolicLink -Value C:\msys64\usr\bin\printf.exe } else { - Invoke-WebRequest -UseBasicParsing -Uri "https://github.com/shivammathur/printf/releases/latest/download/printf-x64.zip" -OutFile "$bin_dir\printf.zip" + Invoke-WebRequest -UseBasicParsing -Uri "$github/shivammathur/printf/releases/latest/download/printf-x64.zip" -OutFile "$bin_dir\printf.zip" Expand-Archive -Path $bin_dir\printf.zip -DestinationPath $bin_dir -Force } } else { @@ -96,16 +96,24 @@ Function Get-CleanPSProfile { Add-ToProfile $profile $current_profile.replace('\', '\\') ". $current_profile" } -# Function to install PhpManager. -Function Install-PhpManager() { - $module_path = "$bin_dir\PhpManager\PhpManager.psm1" +# Function to install a powershell package from GitHub. +Function Install-GitHubPackage() { + param( + [Parameter(Position = 0, Mandatory = $true)] + $package, + [Parameter(Position = 1, Mandatory = $true)] + $psm1_path, + [Parameter(Position = 2, Mandatory = $true)] + $url + ) + $module_path = "$bin_dir\$psm1_path.psm1" if(-not (Test-Path $module_path -PathType Leaf)) { - $zip_file = "$bin_dir\PhpManager.zip" - Invoke-WebRequest -UseBasicParsing -Uri 'https://github.com/mlocati/powershell-phpmanager/releases/latest/download/PhpManager.zip' -OutFile $zip_file + $zip_file = "$bin_dir\$package.zip" + Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $zip_file Expand-Archive -Path $zip_file -DestinationPath $bin_dir -Force } Import-Module $module_path - Add-ToProfile $current_profile 'powershell-phpmanager' "Import-Module $module_path" + Add-ToProfile $current_profile "$package-search" "Import-Module $module_path" } # Function to add PHP extensions. @@ -319,6 +327,7 @@ $cross = ([char]10007) $php_dir = 'C:\tools\php' $ext_dir = "$php_dir\ext" $bin_dir = $php_dir +$github = 'https://github.com' $composer_bin = "$env:APPDATA\Composer\vendor\bin" $current_profile = "$env:TEMP\setup-php.ps1" $ProgressPreference = 'SilentlyContinue' @@ -362,7 +371,7 @@ if($env:RUNNER -eq 'self-hosted') { Add-Printf >$null 2>&1 Step-Log "Setup PhpManager" -Install-PhpManager >$null 2>&1 +Install-GitHubPackage PhpManager PhpManager\PhpManager "$github/mlocati/powershell-phpmanager/releases/latest/download/PhpManager.zip" >$null 2>&1 Add-Log $tick "PhpManager" "Installed" Step-Log "Setup PHP" @@ -375,7 +384,7 @@ if (Test-Path -LiteralPath $php_dir -PathType Container) { $status = "Installed" if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.'))) -or $ts -ne $installed.ThreadSafe) { if ($version -lt '7.0' -and (Get-InstalledModule).Name -notcontains 'VcRedist') { - Install-Module -Name VcRedist -Force + Install-GitHubPackage VcRedist VcRedist-main\VcRedist\VcRedist "$github/aaronparker/VcRedist/archive/main.zip" >$null 2>&1 } if ($version -match $nightly_version) { Invoke-WebRequest -UseBasicParsing -Uri https://dl.bintray.com/shivammathur/php/Install-PhpNightly.ps1 -OutFile $php_dir\Install-PhpNightly.ps1 > $null 2>&1