From 261f13a7c5c262f7411ed1e6f8dd8ae3622369f8 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Wed, 6 Jul 2022 00:42:42 +0530 Subject: [PATCH] Add composer plugins to allow list before installing --- src/scripts/tools/add_tools.ps1 | 17 ++++++++--------- src/scripts/tools/add_tools.sh | 18 ++++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/scripts/tools/add_tools.ps1 b/src/scripts/tools/add_tools.ps1 index 23d5b1f3..1daa1dad 100644 --- a/src/scripts/tools/add_tools.ps1 +++ b/src/scripts/tools/add_tools.ps1 @@ -182,28 +182,27 @@ Function Add-ComposertoolHelper() { if(Test-Path $composer_lock) { Remove-Item -Path $composer_lock -Force } - composer global require $prefix$release $composer_args >$null 2>&1 - composer global show $prefix$tool 2>&1 | Out-File -FilePath $env:TEMP\composer.log - if(findstr '^type *: *composer-plugin' $env:TEMP\composer.log) { - composer global config --no-plugins allow-plugins."$prefix$release" true >$null 2>&1 + if(composer global show $prefix$tool -a 2>&1 | findstr '^type *: *composer-plugin') { + composer global config --no-plugins allow-plugins."$prefix$tool" true >$null 2>&1 } + composer global require $prefix$release $composer_args >$null 2>&1 + return composer global show $prefix$tool 2>&1 | findstr '^versions' } else { $release_stream = [System.IO.MemoryStream]::New([System.Text.Encoding]::ASCII.GetBytes($release)) $scoped_dir_suffix = (Get-FileHash -InputStream $release_stream -Algorithm sha256).Hash $scoped_dir = "$composer_bin\_tools\$tool-$scoped_dir_suffix" $unix_scoped_dir = $scoped_dir.replace('\', '/') + if(composer show $prefix$tool -d $unix_scoped_dir -a 2>&1 | findstr '^type *: *composer-plugin') { + composer config -d $unix_scoped_dir --no-plugins allow-plugins."$prefix$release" true >$null 2>&1 + } if(-not(Test-Path $scoped_dir)) { New-Item -ItemType Directory -Force -Path $scoped_dir > $null 2>&1 composer require $prefix$release -d $unix_scoped_dir $composer_args >$null 2>&1 } [System.Environment]::SetEnvironmentVariable(($tool.replace('-', '_') + '_bin'), "$scoped_dir\vendor\bin") Add-Path $scoped_dir\vendor\bin - composer show $prefix$tool -d $unix_scoped_dir 2>&1 | Out-File -FilePath $env:TEMP\composer.log - if(findstr '^type *: *composer-plugin' $env:TEMP\composer.log) { - composer config -d $unix_scoped_dir --no-plugins allow-plugins."$prefix$release" true >$null 2>&1 - } + return composer show $prefix$tool -d $unix_scoped_dir 2>&1 | findstr '^versions' } - return findstr '^versions' $env:TEMP\composer.log } # Function to setup a tool using composer. diff --git a/src/scripts/tools/add_tools.sh b/src/scripts/tools/add_tools.sh index 5463d392..fd1d1a14 100644 --- a/src/scripts/tools/add_tools.sh +++ b/src/scripts/tools/add_tools.sh @@ -143,23 +143,21 @@ add_composertool_helper() { enable_extensions curl mbstring openssl if [ "$scope" = "global" ]; then sudo rm -f "$composer_lock" >/dev/null 2>&1 || true - composer global require "$prefix$release" "$composer_args" >/dev/null 2>&1 - composer global show "$prefix$tool" 2>&1 | sudo tee /tmp/composer_show.log >/dev/null 2>&1 - grep -E ^versions /tmp/composer_show.log | sudo tee /tmp/composer.log >/dev/null 2>&1 - if grep -qE '^type *: *composer-plugin' /tmp/composer_show.log; then - composer global config --no-plugins allow-plugins."$prefix$release" true >/dev/null 2>&1 + if composer global show "$prefix$tool" -a 2>&1 | grep -qE '^type *: *composer-plugin'; then + composer global config --no-plugins allow-plugins."$prefix$tool" true >/dev/null 2>&1 fi + composer global require "$prefix$release" "$composer_args" >/dev/null 2>&1 + composer global show "$prefix$tool" 2>&1 | grep -E ^versions | sudo tee /tmp/composer_show.log >/dev/null 2>&1 else scoped_dir="$composer_bin/_tools/$tool-$(echo -n "$release" | shasum -a 256 | cut -d ' ' -f 1)" if ! [ -d "$scoped_dir" ]; then mkdir -p "$scoped_dir" echo '{}' | tee "$scoped_dir/composer.json" >/dev/null - composer require "$prefix$release" -d "$scoped_dir" "$composer_args" >/dev/null 2>&1 - composer show "$prefix$tool" -d "$scoped_dir" 2>&1 | sudo tee /tmp/composer_show.log >/dev/null 2>&1 - grep -E ^versions /tmp/composer_show.log | sudo tee /tmp/composer.log >/dev/null 2>&1 - if grep -qE '^type *: *composer-plugin' /tmp/composer_show.log; then - composer config -d "$scoped_dir" --no-plugins allow-plugins."$prefix$release" true >/dev/null 2>&1 + if composer show "$prefix$tool" -d "$scoped_dir" -a 2>&1 | grep -qE '^type *: *composer-plugin'; then + composer config -d "$scoped_dir" --no-plugins allow-plugins."$prefix$tool" true >/dev/null 2>&1 fi + composer require "$prefix$release" -d "$scoped_dir" "$composer_args" >/dev/null 2>&1 + composer show "$prefix$tool" -d "$scoped_dir" 2>&1 | grep -E ^versions | sudo tee /tmp/composer.log >/dev/null 2>&1 fi add_path "$scoped_dir"/vendor/bin fi