From 314aa521ebff5d897bddce96a98f38e18174c218 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Wed, 11 Nov 2020 02:23:45 +0530 Subject: [PATCH] Improve web requests --- src/scripts/common.sh | 50 +++++++++++++++++++++------- src/scripts/darwin.sh | 6 ++-- src/scripts/ext/blackfire.ps1 | 2 +- src/scripts/ext/blackfire.sh | 4 +-- src/scripts/ext/intl.sh | 6 ++-- src/scripts/ext/ioncube.ps1 | 2 +- src/scripts/ext/ioncube.sh | 2 +- src/scripts/ext/oci.ps1 | 4 +-- src/scripts/ext/oci.sh | 6 ++-- src/scripts/ext/phalcon.ps1 | 4 +-- src/scripts/linux.sh | 8 ++--- src/scripts/tools/blackfire.ps1 | 2 +- src/scripts/tools/blackfire.sh | 2 +- src/scripts/tools/grpc_php_plugin.sh | 10 +++--- src/scripts/tools/protoc.ps1 | 2 +- src/scripts/tools/protoc.sh | 8 ++--- src/scripts/win32.ps1 | 17 +++++----- 17 files changed, 80 insertions(+), 55 deletions(-) diff --git a/src/scripts/common.sh b/src/scripts/common.sh index c5f383f4c..e92a47f4a 100644 --- a/src/scripts/common.sh +++ b/src/scripts/common.sh @@ -7,7 +7,9 @@ export old_versions="5.[3-5]" export tool_path_dir="/usr/local/bin" export composer_bin="$HOME/.composer/vendor/bin" export composer_json="$HOME/.composer/composer.json" +export latest="releases/latest/download" export github="https://github.com/shivammathur" +export bintray="https://dl.bintray/shivammathur" # Function to log start of a operation. step_log() { @@ -47,6 +49,36 @@ read_env() { [[ -z "${fail_fast}" ]] && fail_fast='false' || fail_fast="${fail_fast}" } +# Function to download a file using cURL. +# mode: -s pipe to stdout, -v save file and return status code +# execute: -e save file as executable +get() { + mode=$1 + execute=$2 + file_path=$3 + shift 3 + links=("$@") + if [ "$mode" = "-s" ]; then + sudo curl "${curl_opts[@]}" "${links[0]}" + else + for link in "${links[@]}"; do + status_code=$(sudo curl -w "%{http_code}" -o "$file_path" "${curl_opts[@]}" "$link") + [ "$status_code" = "200" ] && break + done + [ "$execute" = "-e" ] && sudo chmod a+x "$file_path" + [ "$mode" = "-v" ] && echo "$status_code" + fi +} + +# Function to download and run scripts from GitHub releases with bintray fallback. +run_script() { + repo=$1 + shift + args=("$@") + get -q -e /tmp/install.sh "$github/$repo/$latest/install.sh" "$bintray/php/$repo.sh" + bash /tmp/install.sh "${args[@]}" +} + # Function to install required packages on self-hosted runners. self_hosted_setup() { if [ "$runner" = "self-hosted" ]; then @@ -92,7 +124,7 @@ get_pecl_version() { extension=$1 stability="$(echo "$2" | grep -m 1 -Eio "(alpha|beta|rc|snapshot|preview)")" pecl_rest='https://pecl.php.net/rest/r/' - response=$(curl "${curl_opts[@]}" "$pecl_rest$extension"/allreleases.xml) + response=$(get -s -n "" "$pecl_rest$extension"/allreleases.xml) pecl_version=$(echo "$response" | grep -m 1 -Pio "(\d*\.\d*\.\d*$stability\d*)") if [ ! "$pecl_version" ]; then pecl_version=$(echo "$response" | grep -m 1 -Po "(\d*\.\d*\.\d*)") @@ -158,19 +190,13 @@ add_tool() { if [ ! -e "$tool_path" ]; then rm -rf "$tool_path" fi - if [ "$tool" = "composer" ]; then - IFS="," read -r -a urls <<< "$url" - status_code=$(sudo curl -f -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "${urls[0]}") || - status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "${urls[1]}") - else - status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url") - if [ "$status_code" != "200" ] && [[ "$url" =~ .*github.com.*releases.*latest.* ]]; then - url="${url//releases\/latest\/download/releases\/download/$(curl "${curl_opts[@]}" "$(echo "$url" | cut -d '/' -f '1-5')/releases" | grep -Eo -m 1 "([0-9]+\.[0-9]+\.[0-9]+)/$(echo "$url" | sed -e "s/.*\///")" | cut -d '/' -f 1)}"url="${url//releases\/latest\/download/releases\/download/$(curl "${curl_opts[@]}" "$(echo "$url" | cut -d '/' -f '1-5')/releases" | grep -Eo -m 1 "([0-9]+\.[0-9]+\.[0-9]+)/$(echo "$url" | sed -e "s/.*\///")" | cut -d '/' -f 1)}" - status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url") - fi + IFS="," read -r -a url <<< "$url" + status_code=$(get -v -e "$tool_path" "${url[@]}") + if [ "$status_code" != "200" ] && [[ "${url[0]}" =~ .*github.com.*releases.*latest.* ]]; then + url[0]="${url//releases\/latest\/download/releases\/download/$(get -s -n "$(echo "${url[0]}" | cut -d '/' -f '1-5')/releases" | grep -Eo -m 1 "([0-9]+\.[0-9]+\.[0-9]+)/$(echo "${url[0]}" | sed -e "s/.*\///")" | cut -d '/' -f 1)}" + status_code=$(get -v -e "$tool_path" "${url[0]}") fi if [ "$status_code" = "200" ]; then - sudo chmod a+x "$tool_path" if [ "$tool" = "composer" ]; then configure_composer "$tool_path" elif [ "$tool" = "cs2pr" ]; then diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 2f3d56b78..b0d143bd9 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -2,7 +2,7 @@ self_hosted_helper() { if ! command -v brew >/dev/null; then step_log "Setup Brew" - curl "${curl_opts[@]:?}" https://raw.githubusercontent.com/Homebrew/install/master/install.sh | bash -s >/dev/null 2>&1 + get -q -e "/tmp/install.sh" "https://raw.githubusercontent.com/Homebrew/install/master/install.sh" && /tmp/install.sh >/dev/null 2>&1 add_log "${tick:?}" "Brew" "Installed Homebrew" fi } @@ -88,7 +88,7 @@ update_dependencies() { if [[ "$version" =~ ${nightly_versions:?} ]] && [ "${runner:?}" != "self-hosted" ]; then tap_dir="$(brew --prefix)/Homebrew/Library/Taps" while read -r formula; do - curl -o "$tap_dir/homebrew/homebrew-core/Formula/$formula.rb" "${curl_opts[@]:?}" "https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/$formula.rb" & + get -q -n "$tap_dir/homebrew/homebrew-core/Formula/$formula.rb" "https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/$formula.rb" & to_wait+=($!) done <"$tap_dir/shivammathur/homebrew-php/.github/deps/${ImageOS:?}_${ImageVersion:?}" wait "${to_wait[@]}" @@ -115,7 +115,7 @@ setup_php() { step_log "Setup PHP" existing_version=$(php-config --version 2>/dev/null | cut -c 1-3) if [[ "$version" =~ ${old_versions:?} ]]; then - curl "${curl_opts[@]:?}" "${github:?}/php5-darwin/releases/latest/download/install.sh" | bash -s "${version/./}" >/dev/null 2>&1 + run_script "php5-darwin" "${version/./}" >/dev/null 2>&1 status="Installed" elif [ "$existing_version" != "$version" ]; then add_php "install" >/dev/null 2>&1 diff --git a/src/scripts/ext/blackfire.ps1 b/src/scripts/ext/blackfire.ps1 index f889881df..cca3e4c62 100644 --- a/src/scripts/ext/blackfire.ps1 +++ b/src/scripts/ext/blackfire.ps1 @@ -17,7 +17,7 @@ Function Add-Blackfire() { $status="Enabled" } else { $nts = if (!$installed.ThreadSafe) { "_nts" } else { "" } - Invoke-WebRequest -UseBasicParsing -Uri "https://packages.blackfire.io/binaries/blackfire-php/${extension_version}/blackfire-php-windows_${arch}-php-${no_dot_version}${nts}.dll" -OutFile $ext_dir\blackfire.dll > $null 2>&1 + Invoke-WebRequest -Uri "https://packages.blackfire.io/binaries/blackfire-php/${extension_version}/blackfire-php-windows_${arch}-php-${no_dot_version}${nts}.dll" -OutFile $ext_dir\blackfire.dll > $null 2>&1 Enable-PhpExtension -Extension blackfire -Path $php_dir $status="Installed and enabled" } diff --git a/src/scripts/ext/blackfire.sh b/src/scripts/ext/blackfire.sh index 31ebbdb35..58d11139e 100644 --- a/src/scripts/ext/blackfire.sh +++ b/src/scripts/ext/blackfire.sh @@ -8,9 +8,9 @@ add_blackfire() { blackfire_ini_file="${scan_dir:?}/50-blackfire.ini" if [ ! -e "${ext_dir:?}/blackfire.so" ]; then if [ "$extension_version" = "blackfire" ]; then - extension_version=$(curl -sSL https://blackfire.io/api/v1/releases | grep -Eo 'php":"([0-9]+.[0-9]+.[0-9]+)' | cut -d '"' -f 3) + extension_version=$(get -s -n "" https://blackfire.io/api/v1/releases | grep -Eo 'php":"([0-9]+.[0-9]+.[0-9]+)' | cut -d '"' -f 3) fi - sudo curl -o "${ext_dir:?}/blackfire.so" "${curl_opts[@]:?}" https://packages.blackfire.io/binaries/blackfire-php/"$extension_version"/blackfire-php-"$platform"_amd64-php-"$no_dot_version".so >/dev/null 2>&1 + get -q -n "${ext_dir:?}/blackfire.so" https://packages.blackfire.io/binaries/blackfire-php/"$extension_version"/blackfire-php-"$platform"_amd64-php-"$no_dot_version".so >/dev/null 2>&1 fi echo "extension=blackfire.so" | sudo tee -a "$blackfire_ini_file" >/dev/null 2>&1 add_extension_log "$extension-$extension_version" "Installed and enabled" diff --git a/src/scripts/ext/intl.sh b/src/scripts/ext/intl.sh index ce32d7cb2..44da20f84 100644 --- a/src/scripts/ext/intl.sh +++ b/src/scripts/ext/intl.sh @@ -2,7 +2,7 @@ install_icu() { icu=$1 if [ "$(php -i | grep "ICU version =>" | sed -e "s|.*=> s*||")" != "$icu" ]; then - sudo curl -o /tmp/icu.tar.zst -sL "https://dl.bintray.com/shivammathur/icu4c/icu4c-$icu.tar.zst" + get -q -n /tmp/icu.tar.zst "https://dl.bintray.com/shivammathur/icu4c/icu4c-$icu.tar.zst" sudo tar -I zstd -xf /tmp/icu.tar.zst -C /usr/local sudo cp -r /usr/local/icu/lib/* /usr/lib/x86_64-linux-gnu/ fi @@ -11,12 +11,12 @@ install_icu() { # Function to add ext-intl with the given version of ICU add_intl() { icu=$(echo "$1" | cut -d'-' -f 2) - supported_version=$(curl "${curl_opts[@]:?}" https://api.bintray.com/packages/shivammathur/icu4c/icu4c | grep -Po "$icu" | head -n 1) + supported_version=$(get -s -n "" https://api.bintray.com/packages/shivammathur/icu4c/icu4c | grep -Po "$icu" | head -n 1) if [ "$icu" != "$supported_version" ]; then add_log "${cross:?}" "intl" "ICU $icu is not supported" else install_icu "$icu" >/dev/null 2>&1 - sudo curl "${curl_opts[@]:?}" -o "${ext_dir:?}/intl.so" "https://dl.bintray.com/shivammathur/icu4c/php${version:?}-intl-$icu.so" + get -q -n "${ext_dir:?}/intl.so" "https://dl.bintray.com/shivammathur/icu4c/php${version:?}-intl-$icu.so" enable_extension intl extension add_extension_log intl "Installed and enabled with ICU $icu" fi diff --git a/src/scripts/ext/ioncube.ps1 b/src/scripts/ext/ioncube.ps1 index f2af1329c..1bd7ae963 100644 --- a/src/scripts/ext/ioncube.ps1 +++ b/src/scripts/ext/ioncube.ps1 @@ -19,7 +19,7 @@ Function Add-Ioncube() { if (-not($installed.ThreadSafe)) { $ts_part = "_nonts" } - Invoke-WebRequest -UseBasicParsing -Uri "https://downloads.ioncube.com/loader_downloads/ioncube_loaders_win$ts_part`_vc$vc`_$arch_part.zip" -OutFile $ext_dir\ioncube.zip + Invoke-WebRequest -Uri "https://downloads.ioncube.com/loader_downloads/ioncube_loaders_win$ts_part`_vc$vc`_$arch_part.zip" -OutFile $ext_dir\ioncube.zip Expand-Archive -Path $ext_dir\ioncube.zip -DestinationPath $ext_dir -Force Copy-Item $ext_dir\ioncube\ioncube_loader_win_$version.dll $ext_dir\php_ioncube.dll } diff --git a/src/scripts/ext/ioncube.sh b/src/scripts/ext/ioncube.sh index 67e3773e1..07bbdf0bd 100644 --- a/src/scripts/ext/ioncube.sh +++ b/src/scripts/ext/ioncube.sh @@ -10,7 +10,7 @@ add_ioncube() { if [ ! -e "${ext_dir:?}/ioncube.so" ]; then status='Installed and enabled' os_name='lin' && [ "$(uname -s)" = "Darwin" ] && os_name='mac' - curl "${curl_opts[@]:?}" https://downloads.ioncube.com/loader_downloads/ioncube_loaders_"$os_name"_x86-64.tar.gz | tar -xzf - -C /tmp + get -s -n "" https://downloads.ioncube.com/loader_downloads/ioncube_loaders_"$os_name"_x86-64.tar.gz | tar -xzf - -C /tmp sudo mv /tmp/ioncube/ioncube_loader_"$os_name"_"${version:?}".so "$ext_dir/ioncube.so" fi echo "zend_extension=$ext_dir/ioncube.so" | sudo tee "${scan_dir:?}/00-ioncube.ini" >/dev/null 2>&1 diff --git a/src/scripts/ext/oci.ps1 b/src/scripts/ext/oci.ps1 index b5e3ab504..1da4acb3b 100644 --- a/src/scripts/ext/oci.ps1 +++ b/src/scripts/ext/oci.ps1 @@ -14,7 +14,7 @@ Function Add-InstantClient() { if ($arch -eq 'x86') { $suffix = 'nt' } - Invoke-WebRequest -UseBasicParsing -Uri https://download.oracle.com/otn_software/nt/instantclient/instantclient-basiclite-$suffix.zip -OutFile $php_dir\instantclient.zip + Invoke-WebRequest -Uri https://download.oracle.com/otn_software/nt/instantclient/instantclient-basiclite-$suffix.zip -OutFile $php_dir\instantclient.zip Expand-Archive -Path $php_dir\instantclient.zip -DestinationPath $php_dir -Force Copy-Item $php_dir\instantclient*\* $php_dir } @@ -44,7 +44,7 @@ Function Add-Oci() { $ociVersion = '2.0.12' } $ociUrl = Get-PeclArchiveUrl oci8 $ociVersion $installed - Invoke-WebRequest -UseBasicParsing -Uri $ociUrl -OutFile $php_dir\oci8.zip + Invoke-WebRequest -Uri $ociUrl -OutFile $php_dir\oci8.zip Expand-Archive -Path $php_dir\oci8.zip -DestinationPath $ext_dir -Force } diff --git a/src/scripts/ext/oci.sh b/src/scripts/ext/oci.sh index dce1c16c7..79b312b45 100644 --- a/src/scripts/ext/oci.sh +++ b/src/scripts/ext/oci.sh @@ -34,7 +34,7 @@ add_client() { arch='macos' lib_ext='dylib' fi - curl -o "/opt/oracle/$package.zip" "${curl_opts[@]:?}" "https://download.oracle.com/otn_software/$os_name/instantclient/instantclient-$package-$arch.zip" + get -q -n "/opt/oracle/$package.zip" "https://download.oracle.com/otn_software/$os_name/instantclient/instantclient-$package-$arch.zip" unzip "/opt/oracle/$package.zip" -d "$oracle_home" done sudo ln -sf /opt/oracle/instantclient*/*.$lib_ext* $libs @@ -44,7 +44,7 @@ add_client() { # Function to get PHP source. get_php() { - [ ! -d "/opt/oracle/php-src-$tag" ] && curl "${curl_opts[@]}" "https://github.com/php/php-src/archive/$tag.tar.gz" | tar xzf - -C "$oracle_home/" + [ ! -d "/opt/oracle/php-src-$tag" ] && get -s -n "" "https://github.com/php/php-src/archive/$tag.tar.gz" | tar xzf - -C "$oracle_home/" } # Function to get phpize location on darwin. @@ -73,7 +73,7 @@ restore_phpize() { # Function to patch pdo_oci. patch_pdo_oci_config() { - curl -O "${curl_opts[@]}" https://raw.githubusercontent.com/php/php-src/PHP-8.0/ext/pdo_oci/config.m4 + get -q -n config.m4 https://raw.githubusercontent.com/php/php-src/PHP-8.0/ext/pdo_oci/config.m4 if [[ ${version:?} =~ 5.[3-6] ]]; then sudo sed -i '' "/PHP_CHECK_PDO_INCLUDES/d" config.m4 2>/dev/null || sudo sed -i "/PHP_CHECK_PDO_INCLUDES/d" config.m4 fi diff --git a/src/scripts/ext/phalcon.ps1 b/src/scripts/ext/phalcon.ps1 index e4980436d..ce38d0f1f 100644 --- a/src/scripts/ext/phalcon.ps1 +++ b/src/scripts/ext/phalcon.ps1 @@ -5,9 +5,9 @@ Function Add-PhalconHelper() { } else { $domain = 'https://github.com' $nts = if (!$installed.ThreadSafe) { "_nts" } else { "" } - $match = Invoke-WebRequest -UseBasicParsing -Uri $domain/phalcon/cphalcon/releases | Select-String -Pattern "href=`"(.*phalcon_x64_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`"" + $match = Invoke-WebRequest -Uri $domain/phalcon/cphalcon/releases | Select-String -Pattern "href=`"(.*phalcon_x64_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`"" $zip_file = $match.Matches[0].Groups[1].Value - Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip > $null 2>&1 + Invoke-WebRequest -Uri $domain/$zip_file -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip > $null 2>&1 Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\phalcon.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\phalcon -Force > $null 2>&1 Copy-Item -Path "$ENV:RUNNER_TOOL_CACHE\phalcon\php_phalcon.dll" -Destination "$ext_dir\php_phalcon.dll" Enable-PhpExtension -Extension phalcon -Path $php_dir diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index fdcfa9c4f..d9650f830 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -141,7 +141,7 @@ add_extension_from_source() { ( add_devtools phpize delete_extension "$extension" - curl -o /tmp/"$extension".tar.gz "${curl_opts[@]:?}" https://github.com/"$repo"/archive/"$release".tar.gz + get -q -n "/tmp/$extension.tar.gz" "https://github.com/$repo/archive/$release.tar.gz" tar xf /tmp/"$extension".tar.gz -C /tmp cd /tmp/"$extension-$release" || exit 1 phpize && ./configure "$args" && make -j"$(nproc)" && sudo make install @@ -166,12 +166,12 @@ add_devtools() { # Function to setup the nightly build from shivammathur/php-builder setup_nightly() { - curl "${curl_opts[@]:?}" "${github:?}"/php-builder/releases/latest/download/install.sh | bash -s "$runner" "$version" + run_script "php-builder" "$runner" "$version" } # Function to setup PHP 5.3, PHP 5.4 and PHP 5.5. setup_old_versions() { - curl "${curl_opts[@]:?}" "${github:?}"/php5-ubuntu/releases/latest/download/install.sh | bash -s "$version" + run_script "php5-ubuntu" "$version" configure_pecl release_version=$(php -v | head -n 1 | cut -d' ' -f 2) } @@ -205,7 +205,7 @@ add_packaged_php() { IFS=' ' read -r -a packages <<<"$(echo "cli curl mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")" $apt_install "${packages[@]}" else - curl "${curl_opts[@]:?}" "${github:?}"/php-ubuntu/releases/latest/download/install.sh | bash -s "$version" + run_script "php-ubuntu" "$version" fi } diff --git a/src/scripts/tools/blackfire.ps1 b/src/scripts/tools/blackfire.ps1 index c1d6c0df4..49f24eee6 100644 --- a/src/scripts/tools/blackfire.ps1 +++ b/src/scripts/tools/blackfire.ps1 @@ -6,7 +6,7 @@ Function Add-Blackfire() { } $agent_version = (Invoke-RestMethod https://blackfire.io/api/v1/releases).agent $url = "https://packages.blackfire.io/binaries/blackfire-agent/${agent_version}/blackfire-agent-windows_${arch_name}.zip" - Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $bin_dir\blackfire.zip >$null 2>&1 + Invoke-WebRequest -Uri $url -OutFile $bin_dir\blackfire.zip >$null 2>&1 Expand-Archive -Path $bin_dir\blackfire.zip -DestinationPath $bin_dir -Force >$null 2>&1 Add-ToProfile $current_profile 'blackfire' "New-Alias blackfire $bin_dir\blackfire.exe" Add-ToProfile $current_profile 'blackfire-agent' "New-Alias blackfire-agent $bin_dir\blackfire-agent.exe" diff --git a/src/scripts/tools/blackfire.sh b/src/scripts/tools/blackfire.sh index 2f689c9c9..bbae531f4 100644 --- a/src/scripts/tools/blackfire.sh +++ b/src/scripts/tools/blackfire.sh @@ -1,6 +1,6 @@ add_blackfire_linux() { sudo mkdir -p /var/run/blackfire - sudo curl "${curl_opts[@]:?}" https://packages.blackfire.io/gpg.key | sudo apt-key add - + get -s -n "" https://packages.blackfire.io/gpg.key | sudo apt-key add - echo "deb http://packages.blackfire.io/debian any main" | sudo tee /etc/apt/sources.list.d/blackfire.list sudo "${debconf_fix:?}" apt-get update ${apt_install:?} blackfire-agent diff --git a/src/scripts/tools/grpc_php_plugin.sh b/src/scripts/tools/grpc_php_plugin.sh index a0c13b837..552d1d0bb 100644 --- a/src/scripts/tools/grpc_php_plugin.sh +++ b/src/scripts/tools/grpc_php_plugin.sh @@ -3,7 +3,7 @@ add_bazel() { os=$(uname -s) if [ "$os" = "Linux" ]; then ${apt_install:?} curl gnupg - curl "${curl_opts[@]:?}" https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - + get -s -n "" https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list sudo "${debconf_fix:?}" apt-get update -y ${apt_install:?} bazel @@ -15,13 +15,13 @@ add_bazel() { get_grpc_tag() { if [ "$grpc_tag" = "latest" ]; then - grpc_tag=$(curl "${curl_opts[@]:?}" https://grpc.io/release) + grpc_tag=$(get -s -n "" https://grpc.io/release) else - status_code=$(sudo curl -s -w "%{http_code}" -o /tmp/grpc.tmp "${curl_opts[@]:?}" "https://github.com/grpc/grpc/releases/tag/v$grpc_tag") + status_code=$(get -v -n /tmp/grpc.tmp "https://github.com/grpc/grpc/releases/tag/v$grpc_tag") if [ "$status_code" = "200" ]; then grpc_tag="v$grpc_tag" else - grpc_tag=$(curl "${curl_opts[@]:?}" https://grpc.io/release) + grpc_tag=$(get -s -n "" https://grpc.io/release) fi fi } @@ -30,7 +30,7 @@ add_grpc_php_plugin() { grpc_tag=$1 get_grpc_tag ( - curl "${curl_opts[@]:?}" "https://github.com/grpc/grpc/archive/$grpc_tag.tar.gz" | tar -xz -C /tmp + get -s -n "" "https://github.com/grpc/grpc/archive/$grpc_tag.tar.gz" | tar -xz -C /tmp cd "/tmp/grpc-${grpc_tag:1}" || exit add_bazel echo "os: $os" diff --git a/src/scripts/tools/protoc.ps1 b/src/scripts/tools/protoc.ps1 index d3b2e55dd..b5416caf1 100644 --- a/src/scripts/tools/protoc.ps1 +++ b/src/scripts/tools/protoc.ps1 @@ -27,7 +27,7 @@ Function Add-Protoc() { $arch_num = '32' } $url = "https://github.com/protocolbuffers/protobuf/releases/download/$protobuf_tag/protoc-$($protobuf_tag -replace 'v', '')-win$arch_num.zip" - Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $bin_dir\protoc.zip >$null 2>&1 + Invoke-WebRequest -Uri $url -OutFile $bin_dir\protoc.zip >$null 2>&1 Expand-Archive -Path $bin_dir\protoc.zip -DestinationPath $bin_dir\protoc -Force >$null 2>&1 Move-Item -Path $bin_dir\protoc\bin\protoc.exe -Destination $bin_dir\protoc.exe Add-ToProfile $current_profile 'protoc' "New-Alias protoc $bin_dir\protoc.exe" diff --git a/src/scripts/tools/protoc.sh b/src/scripts/tools/protoc.sh index ad357abfc..ca2478f9f 100644 --- a/src/scripts/tools/protoc.sh +++ b/src/scripts/tools/protoc.sh @@ -1,12 +1,12 @@ get_protobuf_tag() { if [ "$protobuf_tag" = "latest" ]; then - protobuf_tag=$(curl "${curl_opts[@]:?}" https://github.com/protocolbuffers/protobuf/releases/latest 2<&1 | grep -m 1 -Eo "(v[0-9]+\.[0-9]+\.[0-9]+)" | head -n 1) + protobuf_tag=$(get -s -n "" https://github.com/protocolbuffers/protobuf/releases/latest 2<&1 | grep -m 1 -Eo "(v[0-9]+\.[0-9]+\.[0-9]+)" | head -n 1) else - status_code=$(sudo curl -s -w "%{http_code}" -o /tmp/protobuf.tmp "${curl_opts[@]:?}" "https://github.com/protocolbuffers/protobuf/releases/tag/v$protobuf_tag") + status_code=$(get -v -n /tmp/protobuf.tmp "https://github.com/protocolbuffers/protobuf/releases/tag/v$protobuf_tag") if [ "$status_code" = "200" ]; then protobuf_tag="v$protobuf_tag" else - protobuf_tag=$(curl "${curl_opts[@]:?}" https://github.com/protocolbuffers/protobuf/releases/latest 2<&1 | grep -m 1 -Eo "(v[0-9]+\.[0-9]+\.[0-9]+)" | head -n 1) + protobuf_tag=$(get -s -n "" https://github.com/protocolbuffers/protobuf/releases/latest 2<&1 | grep -m 1 -Eo "(v[0-9]+\.[0-9]+\.[0-9]+)" | head -n 1) fi fi } @@ -17,7 +17,7 @@ add_protoc() { ( platform='linux' [ "$(uname -s)" = "Darwin" ] && platform='osx' - curl -o /tmp/protobuf.zip "${curl_opts[@]:?}" "https://github.com/protocolbuffers/protobuf/releases/download/$protobuf_tag/protoc-${protobuf_tag:1}-$platform-x86_64.zip" + get -q -n /tmp/protobuf.zip "https://github.com/protocolbuffers/protobuf/releases/download/$protobuf_tag/protoc-${protobuf_tag:1}-$platform-x86_64.zip" sudo unzip /tmp/protobuf.zip -d /usr/local/ sudo chmod 777 /usr/local/bin/protoc -R /usr/local/include/google ) >/dev/null 2>&1 diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 1e7b9e8ba..5611ec6b7 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 "$github/shivammathur/printf/releases/latest/download/printf-x64.zip" -OutFile "$bin_dir\printf.zip" + Invoke-WebRequest -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 { @@ -109,7 +109,7 @@ Function Install-PSPackage() { $module_path = "$bin_dir\$psm1_path.psm1" if(-not (Test-Path $module_path -PathType Leaf)) { $zip_file = "$bin_dir\$package.zip" - Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $zip_file + Invoke-WebRequest -Uri $url -OutFile $zip_file Expand-Archive -Path $zip_file -DestinationPath $bin_dir -Force } Import-Module $module_path @@ -250,16 +250,16 @@ Function Add-Tool() { } if($url.Count -gt 1) { $url = $url[0] } if ($tool -eq "symfony") { - Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $bin_dir\$tool.exe + Invoke-WebRequest -Uri $url -OutFile $bin_dir\$tool.exe Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.exe" >$null 2>&1 } else { try { - Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $bin_dir\$tool + Invoke-WebRequest -Uri $url -OutFile $bin_dir\$tool } catch { if($url -match '.*github.com.*releases.*latest.*') { try { - $url = $url.replace("releases/latest/download", "releases/download/" + ([regex]::match((Invoke-WebRequest -UseBasicParsing -Uri ($url.split('/release')[0] + "/releases")).Content, "([0-9]+\.[0-9]+\.[0-9]+)/" + ($url.Substring($url.LastIndexOf("/") + 1))).Groups[0].Value).split('/')[0]) - Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $bin_dir\$tool + $url = $url.replace("releases/latest/download", "releases/download/" + ([regex]::match((Invoke-WebRequest -Uri ($url.split('/release')[0] + "/releases")).Content, "([0-9]+\.[0-9]+\.[0-9]+)/" + ($url.Substring($url.LastIndexOf("/") + 1))).Groups[0].Value).split('/')[0]) + Invoke-WebRequest -Uri $url -OutFile $bin_dir\$tool } catch { } } } @@ -342,7 +342,6 @@ $ProgressPreference = 'SilentlyContinue' $nightly_version = '8.[0-9]' $cert_source='CurrentUser' $enable_extensions = ('openssl', 'curl', 'mbstring') -$wc = New-Object System.Net.WebClient $arch = 'x64' if(-not([Environment]::Is64BitOperatingSystem) -or $version -lt '7.0') { @@ -397,7 +396,7 @@ if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version Install-PSPackage VcRedist VcRedist-main\VcRedist\VcRedist "$github/aaronparker/VcRedist/archive/main.zip" >$null 2>&1 } if ($version -match $nightly_version) { - $wc.DownloadFile("$bintray/Get-PhpNightly.ps1", "$php_dir\Get-PhpNightly.ps1") > $null 2>&1 + Invoke-WebRequest -Uri $bintray/Get-PhpNightly.ps1 -OutFile $php_dir\Get-PhpNightly.ps1 > $null 2>&1 & $php_dir\Get-PhpNightly.ps1 -Architecture $arch -ThreadSafe $ts -Path $php_dir -Version $version > $null 2>&1 } else { Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force > $null 2>&1 @@ -414,7 +413,7 @@ if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version $installed = Get-Php -Path $php_dir ('date.timezone=UTC', 'memory_limit=-1') | foreach { $p=$_.split('='); Set-PhpIniKey -Key $p[0] -Value $p[1] -Path $php_dir } if($version -lt "5.5") { - ('libeay32.dll', 'ssleay32.dll') | ForEach { $wc.DownloadFile("$bintray/$_", "$php_dir\$_") >$null 2>&1 } + ('libeay32.dll', 'ssleay32.dll') | ForEach { Invoke-WebRequest -Uri $bintray/$_ -OutFile $php_dir\$_ >$null 2>&1 } } else { $enable_extensions += ('opcache') }