Improve cURL use

This commit is contained in:
Shivam Mathur 2020-07-23 05:47:11 +05:30
parent 90b6355bf0
commit 8b218279a3
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
6 changed files with 59 additions and 71 deletions

View File

@ -28,7 +28,7 @@ read_env() {
self_hosted_setup() { self_hosted_setup() {
if [[ $(command -v brew) == "" ]]; then if [[ $(command -v brew) == "" ]]; then
step_log "Setup Brew" step_log "Setup Brew"
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh | bash -s >/dev/null 2>&1 curl "${curl_opts[@]}" https://raw.githubusercontent.com/Homebrew/install/master/install.sh | bash -s >/dev/null 2>&1
add_log "$tick" "Brew" "Installed Homebrew" add_log "$tick" "Brew" "Installed Homebrew"
fi fi
} }
@ -62,7 +62,7 @@ get_pecl_version() {
extension=$1 extension=$1
stability="$(echo "$2" | grep -m 1 -Eio "(alpha|beta|rc|snapshot)")" stability="$(echo "$2" | grep -m 1 -Eio "(alpha|beta|rc|snapshot)")"
pecl_rest='https://pecl.php.net/rest/r/' pecl_rest='https://pecl.php.net/rest/r/'
response=$(curl -q -sSL "$pecl_rest$extension"/allreleases.xml) response=$(curl "${curl_opts[@]}" "$pecl_rest$extension"/allreleases.xml)
pecl_version=$(echo "$response" | grep -m 1 -Eio "(\d*\.\d*\.\d*$stability\d*)") pecl_version=$(echo "$response" | grep -m 1 -Eio "(\d*\.\d*\.\d*$stability\d*)")
if [ ! "$pecl_version" ]; then if [ ! "$pecl_version" ]; then
pecl_version=$(echo "$response" | grep -m 1 -Eo "(\d*\.\d*\.\d*)") pecl_version=$(echo "$response" | grep -m 1 -Eo "(\d*\.\d*\.\d*)")
@ -155,7 +155,7 @@ add_tool() {
rm -rf "$tool_path" rm -rf "$tool_path"
fi fi
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" -L "$url") status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
if [ "$status_code" = "200" ]; then if [ "$status_code" = "200" ]; then
sudo chmod a+x "$tool_path" sudo chmod a+x "$tool_path"
if [ "$tool" = "composer" ]; then if [ "$tool" = "composer" ]; then
@ -239,6 +239,7 @@ version=$1
nodot_version=${1/./} nodot_version=${1/./}
old_versions="5.[3-5]" old_versions="5.[3-5]"
tool_path_dir="/usr/local/bin" tool_path_dir="/usr/local/bin"
curl_opts=(-sSL --retry 5 --retry-delay 1)
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3) existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
read_env read_env
@ -254,7 +255,7 @@ fi
# Setup PHP # Setup PHP
step_log "Setup PHP" step_log "Setup PHP"
if [[ "$version" =~ $old_versions ]]; then if [[ "$version" =~ $old_versions ]]; then
curl -sSL https://github.com/shivammathur/php5-darwin/releases/latest/download/install.sh | bash -s "$nodot_version" >/dev/null 2>&1 && curl "${curl_opts[@]}" https://github.com/shivammathur/php5-darwin/releases/latest/download/install.sh | bash -s "$nodot_version" >/dev/null 2>&1 &&
status="Installed" status="Installed"
elif [ "$existing_version" != "$version" ]; then elif [ "$existing_version" != "$version" ]; then
setup_php "install" >/dev/null 2>&1 setup_php "install" >/dev/null 2>&1

View File

@ -1,11 +1,17 @@
version=${1/./} # Function to install blackfire extension.
extension=${2} add_blackfire() {
extension_version=$(echo "$extension" | cut -d '-' -f 2) extension=$1
if [ "$extension_version" = "blackfire" ]; then version=${version:?}
extension_version=$(curl -sSL https://blackfire.io/docs/up-and-running/update | grep 'class="version"' | sed -e 's/<[^>]*>\| //g' | sed -n '3,3p') no_dot_version=${version/./}
fi platform=$(uname -s | tr '[:upper:]' '[:lower:]')
ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||") extension_version=$(echo "$extension" | cut -d '-' -f 2)
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||") blackfire_ini_file="${scan_dir:?}/50-blackfire.ini"
ini_file="$scan_dir/50-blackfire.ini" if [ ! -e "${ext_dir:?}/blackfire.so" ]; then
sudo curl -o $ext_dir/blackfire.so -SL https://packages.blackfire.io/binaries/blackfire-php/$extension_version/blackfire-php-linux_amd64-php-$version.so if [ "$extension_version" = "blackfire" ]; then
echo "extension=blackfire.so" | sudo tee -a "$ini_file" extension_version=$(curl "${curl_opts[@]:?}" https://blackfire.io/docs/up-and-running/update | grep 'class="version"' | sed -e "s/ //g" | sed -n '3,3p' | cut -d '>' -f 2 | cut -d '<' -f 1)
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
fi
echo "extension=blackfire.so" | sudo tee -a "$blackfire_ini_file" >/dev/null 2>&1
add_extension_log "$extension-$extension_version" "Installed and enabled"
}

View File

@ -4,8 +4,9 @@ extension_version=$(echo "$extension" | cut -d '-' -f 2)
if [ "$extension_version" = "blackfire" ]; then if [ "$extension_version" = "blackfire" ]; then
extension_version=$(curl -sSL https://blackfire.io/docs/up-and-running/update | grep 'class="version"' | sed -e "s/ //g" | sed -n '3,3p' | cut -d '>' -f 2 | cut -d '<' -f 1) extension_version=$(curl -sSL https://blackfire.io/docs/up-and-running/update | grep 'class="version"' | sed -e "s/ //g" | sed -n '3,3p' | cut -d '>' -f 2 | cut -d '<' -f 1)
fi fi
curl_opts=(-sSL --retry 5 --retry-delay 1)
ext_dir=$(php -i | grep -Ei "extension_dir => /usr" | sed -e "s|.*=> s*||") ext_dir=$(php -i | grep -Ei "extension_dir => /usr" | sed -e "s|.*=> s*||")
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||") scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
ini_file="$scan_dir/50-blackfire.ini" ini_file="$scan_dir/50-blackfire.ini"
sudo curl -o $ext_dir/blackfire.so -SL https://packages.blackfire.io/binaries/blackfire-php/$extension_version/blackfire-php-darwin_amd64-php-$version.so sudo curl -o $ext_dir/blackfire.so "${curl_opts[@]}" "https://packages.blackfire.io/binaries/blackfire-php/$extension_version/blackfire-php-darwin_amd64-php-$version.so"
echo "extension=blackfire.so" | sudo tee -a "$ini_file" echo "extension=blackfire.so" | sudo tee -a "$ini_file"

View File

@ -1,41 +1,19 @@
# Function to log result of a operation. # Function to log result of a operation.
add_log() { add_license_log() {
mark=$1
subject=$2
message=$3
if [ "$mark" = "$tick" ]; then
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "ioncube" "Click to read the ioncube loader license information" printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "ioncube" "Click to read the ioncube loader license information"
cat /tmp/ioncube/LICENSE.txt cat /tmp/ioncube/LICENSE.txt
echo "::endgroup::" echo "::endgroup::"
else
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
fi
}
# Function to test if extension is loaded.
check_extension() {
extension=$1
php -m | grep -i -q -w "$extension"
} }
# Function to install ioncube. # Function to install ioncube.
install_ioncube() { add_ioncube() {
if [ ! -e "$ext_dir/ioncube.so" ]; then if [ ! -e "${ext_dir:?}/ioncube.so" ]; then
os_name='lin'
status='Installed and enabled' status='Installed and enabled'
[ "$(uname -s)" = "Darwin" ] && os_name='mac' os_name='lin' && [ "$(uname -s)" = "Darwin" ] && os_name='mac'
curl -sSL https://downloads.ioncube.com/loader_downloads/ioncube_loaders_"$os_name"_x86-64.tar.gz | tar -xzf - -C /tmp curl "${curl_opts[@]:?}" 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" sudo mv /tmp/ioncube/ioncube_loader_"$os_name"_"${version:?}".so "$ext_dir/ioncube.so"
fi fi
echo "zend_extension=$ext_dir/ioncube.so" | sudo tee "$scan_dir/00-ioncube.ini" echo "zend_extension=$ext_dir/ioncube.so" | sudo tee "${scan_dir:?}/00-ioncube.ini" >/dev/null 2>&1
add_extension_log "ioncube" "$status"
check_extension "ioncube" && add_license_log
} }
version=$1
tick='✓'
cross='✗'
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||")
status='Enabled'
install_ioncube >/dev/null 2>&1
(check_extension "ioncube" && add_log "$tick" "ioncube" "$status") || add_log "$cross" "ioncube" "Could not install ioncube"

View File

@ -47,7 +47,7 @@ install_client() {
arch='macos' arch='macos'
lib_ext='dylib' lib_ext='dylib'
fi fi
curl -o "/opt/oracle/$package.zip" -sSL "https://download.oracle.com/otn_software/$os_name/instantclient/instantclient-$package-$arch.zip" curl -o "/opt/oracle/$package.zip" "${curl_opts[@]}" "https://download.oracle.com/otn_software/$os_name/instantclient/instantclient-$package-$arch.zip"
unzip "/opt/oracle/$package.zip" -d "$oracle_home" unzip "/opt/oracle/$package.zip" -d "$oracle_home"
done done
sudo ln -sf /opt/oracle/instantclient*/*.$lib_ext* $libs sudo ln -sf /opt/oracle/instantclient*/*.$lib_ext* $libs
@ -57,7 +57,7 @@ install_client() {
# Function to get PHP source. # Function to get PHP source.
get_php() { get_php() {
[ ! -d "/opt/oracle/php-src-$tag" ] && curl -sSL "https://github.com/php/php-src/archive/$tag.tar.gz" | tar xzf - -C "$oracle_home/" [ ! -d "/opt/oracle/php-src-$tag" ] && curl "${curl_opts[@]}" "https://github.com/php/php-src/archive/$tag.tar.gz" | tar xzf - -C "$oracle_home/"
} }
# Function to get phpize location on darwin. # Function to get phpize location on darwin.
@ -86,7 +86,7 @@ restore_phpize() {
# Function to patch pdo_oci. # Function to patch pdo_oci.
patch_pdo_oci_config() { patch_pdo_oci_config() {
curl -sSLO https://raw.githubusercontent.com/php/php-src/master/ext/pdo_oci/config.m4 curl -O "${curl_opts[@]}" https://raw.githubusercontent.com/php/php-src/master/ext/pdo_oci/config.m4
sudo sed -i '' "/PHP_CHECK_PDO_INCLUDES/d" config.m4 || sudo sed -i "/PHP_CHECK_PDO_INCLUDES/d" config.m4 sudo sed -i '' "/PHP_CHECK_PDO_INCLUDES/d" config.m4 || sudo sed -i "/PHP_CHECK_PDO_INCLUDES/d" config.m4
} }
@ -132,6 +132,7 @@ oracle_home='/opt/oracle'
oracle_client=$oracle_home/instantclient oracle_client=$oracle_home/instantclient
runner="${runner:-github}" && RUNNER="${RUNNER:-github}" runner="${runner:-github}" && RUNNER="${RUNNER:-github}"
os=$(uname -s) os=$(uname -s)
curl_opts=(-sSL --retry 5 --retry-delay 1)
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||") scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||") ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||")
install_client >/dev/null 2>&1 install_client >/dev/null 2>&1

View File

@ -35,16 +35,6 @@ cleanup_lists() {
fi fi
} }
# Function to update the package lists.
update_lists() {
if [ ! -e /tmp/setup_php ]; then
[ "$DISTRIB_RELEASE" = "20.04" ] && add_ppa >/dev/null 2>&1
cleanup_lists
sudo "$debconf_fix" apt-get update >/dev/null 2>&1
echo '' | sudo tee "/tmp/setup_php" >/dev/null 2>&1
fi
}
# Function to add ppa:ondrej/php. # Function to add ppa:ondrej/php.
add_ppa() { add_ppa() {
if ! apt-cache policy | grep -q ondrej/php; then if ! apt-cache policy | grep -q ondrej/php; then
@ -56,6 +46,16 @@ add_ppa() {
fi fi
} }
# Function to update the package lists.
update_lists() {
if [ ! -e /tmp/setup_php ]; then
[ "$DISTRIB_RELEASE" = "20.04" ] && add_ppa >/dev/null 2>&1
cleanup_lists
sudo "$debconf_fix" apt-get update >/dev/null 2>&1
echo '' | sudo tee "/tmp/setup_php" >/dev/null 2>&1
fi
}
# Function to setup environment for self-hosted runners. # Function to setup environment for self-hosted runners.
self_hosted_setup() { self_hosted_setup() {
echo "Set disable_coredump false" | sudo tee -a /etc/sudo.conf echo "Set disable_coredump false" | sudo tee -a /etc/sudo.conf
@ -83,7 +83,7 @@ get_pecl_version() {
extension=$1 extension=$1
stability="$(echo "$2" | grep -m 1 -Eio "(alpha|beta|rc|snapshot)")" stability="$(echo "$2" | grep -m 1 -Eio "(alpha|beta|rc|snapshot)")"
pecl_rest='https://pecl.php.net/rest/r/' pecl_rest='https://pecl.php.net/rest/r/'
response=$(curl -q -sSL "$pecl_rest$extension"/allreleases.xml) response=$(curl "${curl_opts[@]}" "$pecl_rest$extension"/allreleases.xml)
pecl_version=$(echo "$response" | grep -m 1 -Pio "(\d*\.\d*\.\d*$stability\d*)") pecl_version=$(echo "$response" | grep -m 1 -Pio "(\d*\.\d*\.\d*$stability\d*)")
if [ ! "$pecl_version" ]; then if [ ! "$pecl_version" ]; then
pecl_version=$(echo "$response" | grep -m 1 -Po "(\d*\.\d*\.\d*)") pecl_version=$(echo "$response" | grep -m 1 -Po "(\d*\.\d*\.\d*)")
@ -218,7 +218,7 @@ add_extension_from_source() {
( (
add_devtools add_devtools
delete_extension "$extension" delete_extension "$extension"
curl -o /tmp/"$extension".tar.gz -sSL https://github.com/"$repo"/archive/"$release".tar.gz curl -o /tmp/"$extension".tar.gz "${curl_opts[@]}" https://github.com/"$repo"/archive/"$release".tar.gz
tar xf /tmp/"$extension".tar.gz -C /tmp tar xf /tmp/"$extension".tar.gz -C /tmp
cd /tmp/"$extension-$release" || exit 1 cd /tmp/"$extension-$release" || exit 1
phpize && ./configure "$args" && make && sudo make install phpize && ./configure "$args" && make && sudo make install
@ -253,7 +253,7 @@ add_tool() {
if [ ! -e "$tool_path" ]; then if [ ! -e "$tool_path" ]; then
rm -rf "$tool_path" rm -rf "$tool_path"
fi fi
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" -L "$url") status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
if [ "$status_code" = "200" ]; then if [ "$status_code" = "200" ]; then
sudo chmod a+x "$tool_path" sudo chmod a+x "$tool_path"
if [ "$tool" = "composer" ]; then if [ "$tool" = "composer" ]; then
@ -300,7 +300,7 @@ add_devtools() {
# Function to add blackfire and blackfire-agent. # Function to add blackfire and blackfire-agent.
add_blackfire() { add_blackfire() {
sudo mkdir -p /var/run/blackfire sudo mkdir -p /var/run/blackfire
sudo curl -sSL https://packages.blackfire.io/gpg.key | sudo apt-key add - >/dev/null 2>&1 sudo curl "${curl_opts[@]}" https://packages.blackfire.io/gpg.key | sudo apt-key add - >/dev/null 2>&1
echo "deb http://packages.blackfire.io/debian any main" | sudo tee /etc/apt/sources.list.d/blackfire.list >/dev/null 2>&1 echo "deb http://packages.blackfire.io/debian any main" | sudo tee /etc/apt/sources.list.d/blackfire.list >/dev/null 2>&1
sudo "$debconf_fix" apt-get update >/dev/null 2>&1 sudo "$debconf_fix" apt-get update >/dev/null 2>&1
$apt_install blackfire-agent >/dev/null 2>&1 $apt_install blackfire-agent >/dev/null 2>&1
@ -317,12 +317,12 @@ add_blackfire() {
# Function to setup the nightly build from master branch. # Function to setup the nightly build from master branch.
setup_master() { setup_master() {
curl -sSL "$github"/php-builder/releases/latest/download/install.sh | bash -s "$runner" curl "${curl_opts[@]}" "$github"/php-builder/releases/latest/download/install.sh | bash -s "$runner"
} }
# Function to setup PHP 5.3, PHP 5.4 and PHP 5.5. # Function to setup PHP 5.3, PHP 5.4 and PHP 5.5.
setup_old_versions() { setup_old_versions() {
curl -sSL "$github"/php5-ubuntu/releases/latest/download/install.sh | bash -s "$version" curl "${curl_opts[@]}" "$github"/php5-ubuntu/releases/latest/download/install.sh | bash -s "$version"
configure_pecl configure_pecl
release_version=$(php -v | head -n 1 | cut -d' ' -f 2) release_version=$(php -v | head -n 1 | cut -d' ' -f 2)
} }
@ -362,7 +362,7 @@ add_packaged_php() {
IFS=' ' read -r -a packages <<< "$(echo "cli curl mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")" IFS=' ' read -r -a packages <<< "$(echo "cli curl mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")"
$apt_install "${packages[@]}" $apt_install "${packages[@]}"
else else
curl -sSL "$github"/php-ubuntu/releases/latest/download/install.sh | bash -s "$version" curl "${curl_opts[@]}" "$github"/php-ubuntu/releases/latest/download/install.sh | bash -s "$version"
fi fi
} }
@ -402,6 +402,7 @@ debconf_fix="DEBIAN_FRONTEND=noninteractive"
github="https://github.com/shivammathur" github="https://github.com/shivammathur"
apt_install="sudo $debconf_fix apt-fast install -y" apt_install="sudo $debconf_fix apt-fast install -y"
tool_path_dir="/usr/local/bin" tool_path_dir="/usr/local/bin"
curl_opts=(-sSL --retry 5 --retry-delay 1)
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3) existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
read_env read_env