Skip to content

Commit

Permalink
Improve web requests
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Nov 16, 2020
1 parent ae603e8 commit 314aa52
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 55 deletions.
50 changes: 38 additions & 12 deletions src/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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*)")
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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[@]}"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/ext/blackfire.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/ext/blackfire.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/ext/intl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/ext/ioncube.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/ext/ioncube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/ext/oci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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

}
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/ext/oci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/ext/phalcon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/tools/blackfire.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/tools/blackfire.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/scripts/tools/grpc_php_plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/tools/protoc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/tools/protoc.sh
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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
Expand Down
Loading

0 comments on commit 314aa52

Please sign in to comment.