mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-07-19 05:13:28 +07:00
Improve Logs and tests
This commit is contained in:
@ -1,5 +1,28 @@
|
||||
tick="✓"
|
||||
cross="✗"
|
||||
|
||||
step_log() {
|
||||
message=$1
|
||||
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
|
||||
}
|
||||
|
||||
add_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"
|
||||
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
|
||||
}
|
||||
version='7.4.0RC3'
|
||||
brew install pkg-config autoconf bison re2c openssl@1.1 krb5 enchant libffi freetype intltool icu4c libiconv t1lib gd libzip gmp tidyp libxml2 libxslt postgresql curl >/dev/null 2>&1
|
||||
step_log "Setup dependencies"
|
||||
for package in pkg-config autoconf bison re2c openssl@1.1 krb5 enchant libffi freetype intltool icu4c libiconv t1lib gd libzip gmp tidyp libxml2 libxslt postgresql curl;
|
||||
do
|
||||
brew install "$package" >/dev/null 2>&1
|
||||
add_log "$tick" "$package" "Installed"
|
||||
done
|
||||
brew link icu4c gettext --force >/dev/null 2>&1
|
||||
|
||||
for package in gettext gmp krb5 icu4c bison openssl@1.1 libxml2 libffi libxslt libiconv pkgconfig enchant krb5 readline libedit freetype;
|
||||
@ -36,6 +59,8 @@ echo 'export EXTRA_LIBS="/usr/local/opt/readline/lib/libhistory.dylib
|
||||
/usr/local/opt/icu4c/lib/libicuuc.dylib"'
|
||||
} >> ~/.bash_profile
|
||||
config_file=$(pwd)/config.yaml
|
||||
|
||||
step_log "Setup PHPBrew"
|
||||
curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew >/dev/null 2>&1
|
||||
chmod +x ./phpbrew
|
||||
sudo mv phpbrew /usr/local/bin/phpbrew
|
||||
@ -47,37 +72,43 @@ sudo chmod -R 777 /opt/phpbrew
|
||||
export PHPBREW_ROOT=/opt/phpbrew
|
||||
export PHPBREW_HOME=/opt/phpbrew
|
||||
echo "[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc" >> ~/.bashrc
|
||||
add_log "$tick" "PHPBrew" "Installed"
|
||||
|
||||
source ~/.bash_profile >/dev/null 2>&1
|
||||
source ~/.bashrc >/dev/null 2>&1
|
||||
|
||||
step_log "Setup PHP and Composer"
|
||||
phpbrew install -j 6 $version +dev >/dev/null 2>&1
|
||||
phpbrew switch $version
|
||||
sudo ln -sf /opt/phpbrew/php/php-$version/bin/* /usr/local/bin/
|
||||
sudo ln -sf /opt/phpbrew/php/php-$version/etc/php.ini /etc/php.ini
|
||||
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
|
||||
ext_dir=$(php -i | grep "extension_dir => /opt" | sed -e "s|.*=> s*||")
|
||||
pecl config-set php_ini "$ini_file"
|
||||
pecl config-set php_ini "$ini_file" >/dev/null 2>&1
|
||||
sudo chmod 777 "$ini_file"
|
||||
brew install composer
|
||||
brew install composer >/dev/null 2>&1
|
||||
|
||||
add_extension()
|
||||
{
|
||||
add_log "$tick" "PHP" "Installed PHP$version"
|
||||
add_log "$tick" "Composer" "Installed"
|
||||
|
||||
add_extension() {
|
||||
extension=$1
|
||||
install_command=$2
|
||||
prefix=$3
|
||||
log_prefix=$4
|
||||
if ! php -m | grep -i -q "$extension" && [ -e "$ext_dir/$extension.so" ]; then
|
||||
echo "$prefix=$extension" >> "$ini_file" && echo "\033[32;1m$log_prefix: Enabled $extension\033[0m";
|
||||
echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled"
|
||||
elif php -m | grep -i -q "$extension"; then
|
||||
echo "\033[33;1m$log_prefix: $extension was already enabled\033[0m";
|
||||
add_log "$tick" "$extension" "Enabled"
|
||||
elif ! php -m | grep -i -q "$extension"; then
|
||||
exists=$(curl -sL https://pecl.php.net/json.php?package="$extension" -w "%{http_code}" -o /dev/null)
|
||||
if [ "$exists" = "200" ]; then
|
||||
eval "$install_command" && \
|
||||
echo "\033[32;1m$log_prefix: Installed and enabled $extension\033[0m" || \
|
||||
echo "\033[31;1m$log_prefix: Could not install $extension on PHP$version\033[0m";
|
||||
(
|
||||
eval "$install_command" && \
|
||||
add_log "$tick" "$extension" "Installed and enabled"
|
||||
) || add_log "$cross" "$extension" "Could not install $extension on PHP$version"
|
||||
else
|
||||
if ! php -m | grep -i -q "$extension"; then
|
||||
echo "\033[31;1m$log_prefix: Could not find $extension for PHP$version on PECL\033[0m";
|
||||
add_log "$cross" "$extension" "Could not find $extension for PHP$version on PECL"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
@ -1,37 +1,57 @@
|
||||
tick="✓"
|
||||
cross="✗"
|
||||
|
||||
step_log() {
|
||||
message=$1
|
||||
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
|
||||
}
|
||||
|
||||
add_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"
|
||||
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
|
||||
}
|
||||
|
||||
version=$1
|
||||
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE
|
||||
if [ "$1" = "5.6" ] || [ "$1" = "7.0" ]; then
|
||||
brew tap exolnet/homebrew-deprecated >/dev/null 2>&1
|
||||
fi
|
||||
step_log "Setup PHP and Composer"
|
||||
brew install php@"$1" composer >/dev/null 2>&1
|
||||
brew link --force --overwrite php@"$1" >/dev/null 2>&1
|
||||
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
|
||||
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
|
||||
echo "date.timezone=UTC" >> "$ini_file"
|
||||
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
|
||||
sudo chmod 777 "$ini_file"
|
||||
mkdir -p "$(pecl config-get ext_dir)"
|
||||
composer global require hirak/prestissimo >/dev/null 2>&1
|
||||
php -v
|
||||
composer -V
|
||||
add_log "$tick" "PHP" "Installed PHP$version"
|
||||
add_log "$tick" "Composer" "Installed"
|
||||
|
||||
add_extension()
|
||||
{
|
||||
add_extension() {
|
||||
extension=$1
|
||||
install_command=$2
|
||||
prefix=$3
|
||||
log_prefix=$4
|
||||
if ! php -m | grep -i -q "$extension" && [ -e "$ext_dir/$extension.so" ]; then
|
||||
echo "$prefix=$extension" >> "$ini_file" && echo "\033[32;1m$log_prefix: Enabled $extension\033[0m";
|
||||
echo "$prefix=$extension" >>"$ini_file" && add_log $tick "$extension" "Enabled"
|
||||
elif php -m | grep -i -q "$extension"; then
|
||||
echo "\033[33;1m$log_prefix: $extension was already enabled\033[0m";
|
||||
add_log "$tick" "$extension" "Enabled"
|
||||
elif ! php -m | grep -i -q "$extension"; then
|
||||
exists=$(curl -sL https://pecl.php.net/json.php?package="$extension" -w "%{http_code}" -o /dev/null)
|
||||
if [ "$exists" = "200" ]; then
|
||||
eval "$install_command" && \
|
||||
echo "\033[32;1m$log_prefix: Installed and enabled $extension\033[0m" || \
|
||||
echo "\033[31;1m$log_prefix: Could not install $extension on PHP$version\033[0m";
|
||||
(
|
||||
eval "$install_command" && \
|
||||
add_log "$tick" "$extension" "Installed and enabled"
|
||||
) || add_log "$cross" "$extension" "Could not install $extension on PHP$version"
|
||||
else
|
||||
if ! php -m | grep -i -q "$extension"; then
|
||||
echo "\033[31;1m$log_prefix: Could not find $extension for PHP$version on PECL\033[0m";
|
||||
add_log "$cross" "$extension" "Could not find $extension for PHP$version on PECL"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
@ -1,5 +1,25 @@
|
||||
tick="✓"
|
||||
cross="✗"
|
||||
|
||||
step_log() {
|
||||
message=$1
|
||||
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
|
||||
}
|
||||
|
||||
add_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"
|
||||
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
|
||||
}
|
||||
existing_version=$(php-config --version | cut -c 1-3)
|
||||
version=$1
|
||||
status="Switched to PHP$version"
|
||||
step_log "Setup PHP and Composer"
|
||||
if [ "$existing_version" != "$1" ]; then
|
||||
if [ ! -e "/usr/bin/php$1" ]; then
|
||||
sudo DEBIAN_FRONTEND=noninteractive add-apt-repository ppa:ondrej/php -y >/dev/null 2>&1
|
||||
@ -9,13 +29,22 @@ if [ "$existing_version" != "$1" ]; then
|
||||
else
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt install -y php"$1" php"$1"-dev curl php"$1"-curl >/dev/null 2>&1
|
||||
fi
|
||||
status="Installed PHP$version"
|
||||
fi
|
||||
|
||||
|
||||
for tool in php phar phar.phar php-cgi php-config phpize; do
|
||||
if [ -e "/usr/bin/$tool$1" ]; then
|
||||
sudo update-alternatives --set $tool /usr/bin/"$tool$1" &
|
||||
sudo update-alternatives --set $tool /usr/bin/"$tool$1" >/dev/null 2>&1 &
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
|
||||
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
|
||||
sudo chmod 777 "$ini_file"
|
||||
sudo mkdir -p /run/php
|
||||
add_log "$tick" "PHP" "$status"
|
||||
|
||||
if [ ! -e "/usr/bin/composer" ]; then
|
||||
curl -s -L https://getcomposer.org/installer > composer-setup.php
|
||||
@ -27,28 +56,22 @@ if [ ! -e "/usr/bin/composer" ]; then
|
||||
fi
|
||||
rm composer-setup.php
|
||||
fi
|
||||
|
||||
composer global require hirak/prestissimo >/dev/null 2>&1
|
||||
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
|
||||
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
|
||||
sudo chmod 777 "$ini_file"
|
||||
sudo mkdir -p /run/php
|
||||
php -v
|
||||
composer -V
|
||||
add_log "$tick" "Composer" "Installed"
|
||||
|
||||
add_extension()
|
||||
{
|
||||
extension=$1
|
||||
install_command=$2
|
||||
prefix=$3
|
||||
log_prefix=$4
|
||||
if ! php -m | grep -i -q "$extension" && [ -e "$ext_dir/$extension.so" ]; then
|
||||
echo "$prefix=$extension" >> "$ini_file" && echo "\033[32;1m$log_prefix: Enabled $extension\033[0m";
|
||||
echo "$prefix=$extension" >> "$ini_file" && add_log "$tick" "$extension" "Enabled"
|
||||
elif php -m | grep -i -q "$extension"; then
|
||||
echo "\033[33;1m$log_prefix: $extension was already enabled\033[0m";
|
||||
add_log "$tick" "$extension" "Enabled"
|
||||
elif ! php -m | grep -i -q "$extension"; then
|
||||
eval "$install_command" && \
|
||||
echo "\033[32;1m$log_prefix: Installed and enabled $extension\033[0m" || \
|
||||
echo "\033[31;1m$log_prefix: Could not find php$version-$extension on APT repository\033[0m";
|
||||
(
|
||||
eval "$install_command" && \
|
||||
add_log "$tick" "$extension" "Installed and enabled"
|
||||
) || add_log "$cross" "$extension" "Could not find php$version-$extension"
|
||||
fi
|
||||
}
|
||||
}
|
@ -2,58 +2,69 @@ param (
|
||||
[Parameter(Mandatory=$true)][string]$version = "7.3"
|
||||
)
|
||||
|
||||
$tick = ([char]8730)
|
||||
$cross = ([char]10007)
|
||||
|
||||
Function Step-Log($message) {
|
||||
printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m" $message
|
||||
}
|
||||
|
||||
Function Add-Log($mark, $subject, $message) {
|
||||
$code = if($mark -eq $cross) {"31"} else {"32"}
|
||||
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m" $code $mark $subject $message
|
||||
}
|
||||
|
||||
if($version -eq '7.4') {
|
||||
$version = '7.4RC'
|
||||
}
|
||||
|
||||
Write-Host "Installing PhpManager" -ForegroundColor Blue
|
||||
Step-Log "Setup PhpManager"
|
||||
Install-Module -Name PhpManager -Force -Scope CurrentUser
|
||||
printf "\n"
|
||||
Add-Log $tick "PhpManager" "Installed"
|
||||
|
||||
$installed = $($(php -v)[0] -join '')[4..6] -join ''
|
||||
Step-Log "Setup PHP and Composer"
|
||||
$status = "Switched to PHP$version"
|
||||
if($installed -ne $version) {
|
||||
if($version -lt '7.0') {
|
||||
Write-Host "Installing VcRedist"
|
||||
Install-Module -Name VcRedist -Force
|
||||
}
|
||||
Write-Host "Installing PHP" -ForegroundColor Blue
|
||||
Uninstall-Php C:\tools\php
|
||||
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -InstallVC -Path C:\tools\php$version -TimeZone UTC -InitialPhpIni Production -Force
|
||||
Write-Host "Switch PHP" -ForegroundColor Blue
|
||||
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -InstallVC -Path C:\tools\php$version -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1
|
||||
(Get-PhpSwitcher).targets
|
||||
Initialize-PhpSwitcher -Alias C:\tools\php -Scope CurrentUser -Force
|
||||
Add-PhpToSwitcher -Name $version -Path C:\tools\php$version -Force
|
||||
Switch-Php $version -Force
|
||||
$status = "Installed PHP$version"
|
||||
}
|
||||
|
||||
Write-Host "Housekeeping in PHP.ini, enabling openssl" -ForegroundColor Blue
|
||||
$ext_dir = "C:\tools\php\ext"
|
||||
Add-Content C:\tools\php\php.ini "date.timezone = 'UTC'"
|
||||
Set-PhpIniKey extension_dir $ext_dir
|
||||
|
||||
if($version -lt '7.4') {
|
||||
Enable-PhpExtension openssl
|
||||
} else {
|
||||
Add-Content C:\tools\php\php.ini "extension=php_openssl.dll"
|
||||
Copy-Item "php_pcov.dll" -Destination $ext_dir"\php_pcov.dll"
|
||||
}
|
||||
Add-Log $tick "PHP" $status
|
||||
|
||||
Write-Host "Installing Composer" -ForegroundColor Blue
|
||||
Install-Composer -Scope System -Path C:\tools\php
|
||||
php -v
|
||||
composer -V
|
||||
Add-Log $tick "Composer" "Installed"
|
||||
|
||||
Function Add-Extension($extension, $install_command, $prefix, $log_prefix)
|
||||
Function Add-Extension($extension, $install_command, $prefix)
|
||||
{
|
||||
try {
|
||||
$exist = Test-Path -Path C:\tools\php\ext\php_$extension.dll
|
||||
if(!(php -m | findstr -i ${extension}) -and $exist) {
|
||||
Add-Content C:\tools\php\php.ini "$prefix=php_$extension.dll"
|
||||
Write-Host "$log_prefix`: Enabled $extension" -ForegroundColor green
|
||||
Add-Log $tick $extension "Enabled"
|
||||
} elseif(php -m | findstr -i $extension) {
|
||||
Write-Host "$log_prefix`: $extension was already enabled" -ForegroundColor yellow
|
||||
Add-Log $tick $extension "Enabled"
|
||||
}
|
||||
} catch [Exception] {
|
||||
Write-Host "$log_prefix`: $extension could not be enabled" -ForegroundColor red
|
||||
Add-Log $cross $extension "Could not enable"
|
||||
}
|
||||
|
||||
$status = 404
|
||||
@ -67,14 +78,14 @@ Function Add-Extension($extension, $install_command, $prefix, $log_prefix)
|
||||
if(!(php -m | findstr -i $extension)) {
|
||||
try {
|
||||
Invoke-Expression $install_command
|
||||
Write-Host "$log_prefix`: Installed and enabled $extension" -ForegroundColor green
|
||||
Add-Log $tick $extension "Installed and enabled"
|
||||
} catch [Exception] {
|
||||
Write-Host "$log_prefix`: Could not install $extension on PHP $version" -ForegroundColor red
|
||||
Add-Log $cross $extension "Could not install on PHP$version"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(!(php -m | findstr -i $extension)) {
|
||||
Write-Host "$log_prefix`: Could not find $extension for PHP$version on PECL" -ForegroundColor red
|
||||
Add-Log $cross $extension "Could not find $extension for PHP$version on PECL"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user