Refactor installation scripts

This commit is contained in:
Shivam Mathur
2019-10-11 04:41:25 +05:30
parent 3087ceb811
commit e755fb7a69
25 changed files with 345 additions and 520 deletions

View File

@ -1,3 +1,4 @@
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
brew link icu4c gettext --force >/dev/null 2>&1
@ -48,12 +49,36 @@ export PHPBREW_HOME=/opt/phpbrew
echo "[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc" >> ~/.bashrc
source ~/.bash_profile >/dev/null 2>&1
source ~/.bashrc >/dev/null 2>&1
phpbrew install -j 6 7.4.0RC3 +dev >/dev/null 2>&1
phpbrew switch 7.4.0RC3
sudo ln -sf /opt/phpbrew/php/php-7.4.0RC3/bin/* /usr/local/bin/
sudo ln -sf /opt/phpbrew/php/php-7.4.0RC3/etc/php.ini /etc/php.ini
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"
sudo chmod 777 "$ini_file"
brew install composer
brew install composer
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";
elif php -m | grep -i -q "$extension"; then
echo "\033[33;1m$log_prefix: $extension was already enabled\033[0m";
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";
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";
fi
fi
fi
}

View File

@ -1,3 +1,4 @@
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
@ -10,4 +11,28 @@ 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
composer -V
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";
elif php -m | grep -i -q "$extension"; then
echo "\033[33;1m$log_prefix: $extension was already enabled\033[0m";
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";
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";
fi
fi
fi
}

View File

@ -1,5 +1,6 @@
version=$(php-config --version | cut -c 1-3)
if [ "$version" != "$1" ]; then
existing_version=$(php-config --version | cut -c 1-3)
version=$1
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
sudo DEBIAN_FRONTEND=noninteractive apt update -y >/dev/null 2>&1
@ -37,3 +38,20 @@ sudo chmod 777 "$ini_file"
sudo mkdir -p /run/php
php -v
composer -V
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";
elif php -m | grep -i -q "$extension"; then
echo "\033[33;1m$log_prefix: $extension was already enabled\033[0m";
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";
fi
}

View File

@ -40,4 +40,41 @@ if($version -lt '7.4') {
Write-Host "Installing Composer" -ForegroundColor Blue
Install-Composer -Scope System -Path C:\tools\php
php -v
composer -V
composer -V
Function Add-Extension($extension, $install_command, $prefix, $log_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
} elseif(php -m | findstr -i $extension) {
Write-Host "$log_prefix`: $extension was already enabled" -ForegroundColor yellow
}
} catch [Exception] {
Write-Host "$log_prefix`: $extension could not be enabled" -ForegroundColor red
}
$status = 404
try {
$status = (Invoke-WebRequest -Uri "https://pecl.php.net/json.php?package=$extension" -UseBasicParsing -DisableKeepAlive).StatusCode
} catch [Exception] {
$status = 500
}
if($status -eq 200) {
if(!(php -m | findstr -i $extension)) {
try {
Invoke-Expression $install_command
Write-Host "$log_prefix`: Installed and enabled $extension" -ForegroundColor green
} catch [Exception] {
Write-Host "$log_prefix`: Could not install $extension on PHP $version" -ForegroundColor red
}
}
} else {
if(!(php -m | findstr -i $extension)) {
Write-Host "$log_prefix`: Could not find $extension for PHP$version on PECL" -ForegroundColor red
}
}
}