Add support for update and extension versions

This commit is contained in:
Shivam Mathur
2020-02-13 22:39:00 +05:30
parent ca33d01e9f
commit 17241e2689
8 changed files with 79 additions and 108 deletions

View File

@ -1,79 +0,0 @@
linux_extension_dir() {
apiv=$1
if [ "$version" = "5.3" ]; then
echo "/home/runner/php/5.3.29/lib/php/extensions/no-debug-non-zts-$apiv"
elif [[ "$version" =~ $old_versions_linux ]]; then
echo "/usr/lib/php5/$apiv"
elif [ "$version" = "8.0" ]; then
echo "/home/runner/php/8.0/lib/php/extensions/no-debug-non-zts-$apiv"
else
echo "/usr/lib/php/$apiv"
fi
}
darwin_extension_dir() {
apiv=$1
if [[ "$version" =~ $old_versions_darwin ]]; then
echo "/opt/local/lib/php${version/./}/extensions/no-debug-non-zts-$apiv"
else
echo "/usr/local/lib/php/pecl/$apiv"
fi
}
get_apiv() {
case $version in
5.3)
echo "20090626"
;;
5.4)
echo "20100525"
;;
5.5)
echo "20121212"
;;
5.6)
echo "20131226"
;;
7.0)
echo "20151012"
;;
7.1)
echo "20160303"
;;
7.2)
echo "20170718"
;;
7.3)
echo "20180731"
;;
*)
if [ "$version" = "8.0" ]; then
php_h="https://raw.githubusercontent.com/php/php-src/master/main/php.h"
else
semver=$(curl -sSL --retry 5 https://github.com/php/php-src/releases | grep "$flags" "(php-$version.[0-9]+)".zip | head -n 1 | grep "$flags" '[0-9]+\.[0-9]+\.[0-9]+')
php_h="https://raw.githubusercontent.com/php/php-src/PHP-$semver/main/php.h"
fi
curl -sSL --retry 5 "$php_h" | grep "PHP_API_VERSION" | cut -d' ' -f 3
;;
esac
}
version=$2
old_versions_linux="5.[4-5]"
old_versions_darwin="5.[3-5]"
os=$(uname -s)
if [ "$os" = "Linux" ]; then
flags='-Po'
apiv=$(get_apiv)
dir=$(linux_extension_dir "$apiv")
sudo mkdir -p "$dir" && sudo chown -R "$USER":"$(id -g -n)" $(dirname "$dir")
elif [ "$os" = "Darwin" ]; then
flags='-Eo'
apiv=$(get_apiv)
dir=$(darwin_extension_dir "$apiv")
else
dir='C:\\tools\\php\\ext'
fi
hash=$(echo -n "$1" | openssl dgst -sha256 | cut -d ' ' -f 2)
echo "::set-output name=ext_dir::$dir"
echo "::set-output name=ext_hash::$hash"

View File

@ -24,11 +24,12 @@ update_ppa() {
else
ppa="ondrej-ubuntu-php*.list"
fi
find /etc/apt/sources.list.d -type f -name "$ppa" -exec sudo DEBIAN_FRONTEND=noninteractive apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1
find /etc/apt/sources.list.d -type f -name "$ppa" -exec sudo "$debconf_fix" apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1
echo "true"
fi
}
# Function to configure PECL
configure_pecl() {
if [ "$pecl_config" = "false" ] && [ -e /usr/bin/pecl ]; then
for tool in pear pecl; do
@ -247,7 +248,8 @@ ppa_updated="false"
pecl_config="false"
version=$1
old_versions="5.[4-5]"
apt_install="sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y"
debconf_fix="DEBIAN_FRONTEND=noninteractive"
apt_install="sudo $debconf_fix apt-fast install -y"
existing_version=$(php-config --version | cut -c 1-3)
# Setup PHP
@ -267,33 +269,37 @@ if [ "$existing_version" != "$version" ]; then
fi
$apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml >/dev/null 2>&1
fi
status="installed"
status="Installed"
else
status="switched"
if [ "$update" = "true" ]; then
$apt_install php"$version" >/dev/null 2>&1
status="Updated to"
else
status="Switched to"
fi
fi
# PHP 5.3 is switched by install script, for rest switch_version
if [ "$version" != "5.3" ]; then
switch_version
fi
if [ "$version" = "8.0" ]; then
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
else
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
fi
if [ "$status" != "switched" ]; then
status="Installed PHP $semver"
else
status="Switched to PHP $semver"
fi
else
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
status="PHP $semver Found"
if [ "$update" = "true" ]; then
$apt_install php"$version" >/dev/null 2>&1
status="Updated to"
else
status="Found"
fi
fi
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
if [ ! "$version" = "8.0" ]; then
semver=$(echo "$semver" | cut -f 1 -d '-')
fi
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||")
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
sudo chmod 777 "$ini_file"
add_log "$tick" "PHP" "$status"
add_log "$tick" "PHP" "$status PHP $semver"

View File

@ -31,7 +31,12 @@ Function Add-Extension {
[ValidateNotNull()]
[ValidateSet('stable', 'beta', 'alpha', 'devel', 'snapshot')]
[string]
$mininum_stability = 'stable'
$mininum_stability = 'stable',
[Parameter(Position = 2, Mandatory = $false)]
[ValidateNotNull()]
[ValidatePattern('^\d+(\.\d+){0,2}$')]
[string]
$extension_version = ''
)
try {
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
@ -50,7 +55,7 @@ Function Add-Extension {
}
}
else {
Install-PhpExtension -Extension $extension -MinimumStability $mininum_stability -Path $php_dir
Install-PhpExtension -Extension $extension -MinimumStability $mininum_stability -Version $extension_version -Path $php_dir
Add-Log $tick $extension "Installed and enabled"
}
}
@ -192,8 +197,10 @@ if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version
Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1
} else {
$updated = Update-Php $php_dir >$null 2>&1
if($updated -eq $False) {
if((Test-Path env:update) -and $env:update -eq 'true') {
Update-Php $php_dir > $null 2>&1
$status = "Updated to"
} else {
$status = "Found"
}
}