mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-08-11 08:04:39 +07:00
Add tools support
This commit is contained in:
@ -47,11 +47,27 @@ remove_extension() {
|
||||
sudo rm -rf "$ext_dir"/"$1".so >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Function to setup a remote tool
|
||||
add_tool() {
|
||||
url=$1
|
||||
tool=$2
|
||||
if [ ! -e /usr/local/bin/"$tool" ]; then
|
||||
rm -rf /usr/local/bin/"${tool:?}"
|
||||
fi
|
||||
sudo curl -o /usr/local/bin/"$tool" -L "$url" >/dev/null 2>&1
|
||||
sudo chmod a+x /usr/local/bin/"$tool"
|
||||
add_log "$tick" "$tool" "Added"
|
||||
}
|
||||
|
||||
add_pecl() {
|
||||
add_log "$tick" "PECL" "Added"
|
||||
}
|
||||
|
||||
# Function to setup PHP and composer
|
||||
setup_php_and_composer() {
|
||||
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE
|
||||
brew tap shivammathur/homebrew-php >/dev/null 2>&1
|
||||
brew install shivammathur/php/php@"$version" composer >/dev/null 2>&1
|
||||
brew install shivammathur/php/php@"$version" >/dev/null 2>&1
|
||||
brew link --force --overwrite php@"$version" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
@ -61,7 +77,7 @@ cross="✗"
|
||||
version=$1
|
||||
|
||||
# Setup PHP and composer
|
||||
step_log "Setup PHP and Composer"
|
||||
step_log "Setup PHP"
|
||||
setup_php_and_composer
|
||||
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
|
||||
echo "date.timezone=UTC" >> "$ini_file"
|
||||
@ -70,4 +86,3 @@ sudo chmod 777 "$ini_file"
|
||||
mkdir -p "$(pecl config-get ext_dir)"
|
||||
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
|
||||
add_log "$tick" "PHP" "Installed PHP $semver"
|
||||
add_log "$tick" "Composer" "Installed"
|
||||
|
@ -43,11 +43,23 @@ add_extension() {
|
||||
# Function to remove extensions
|
||||
remove_extension() {
|
||||
extension=$1
|
||||
if [ -e /etc/php/"$version"/mods-available/$1.ini ]; then
|
||||
sudo phpdismod -v "$version" $1
|
||||
if [ -e /etc/php/"$version"/mods-available/"$extension".ini ]; then
|
||||
sudo phpdismod -v "$version" "$extension"
|
||||
fi
|
||||
sudo sed -i "/$1/d" "$ini_file"
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get remove php-$1 -y >/dev/null 2>&1
|
||||
sudo sed -i "/$extension/d" "$ini_file"
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get remove php-"$extension" -y >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Function to setup a remote tool
|
||||
add_tool() {
|
||||
url=$1
|
||||
tool=$2
|
||||
if [ ! -e /usr/local/bin/"$tool" ]; then
|
||||
rm -rf /usr/local/bin/"${tool:?}"
|
||||
fi
|
||||
sudo curl -o /usr/local/bin/"$tool" -L "$url" >/dev/null 2>&1
|
||||
sudo chmod a+x /usr/local/bin/"$tool"
|
||||
add_log "$tick" "$tool" "Added"
|
||||
}
|
||||
|
||||
# Function to setup the nightly build from master branch
|
||||
@ -64,30 +76,18 @@ setup_master() {
|
||||
}
|
||||
|
||||
# Function to setup PECL
|
||||
setup_pecl() {
|
||||
add_pecl() {
|
||||
update_ppa
|
||||
$apt_install php"$version"-dev php"$version"-xml >/dev/null 2>&1
|
||||
sudo update-alternatives --set php-config /usr/bin/php-config"$version" >/dev/null 2>&1
|
||||
sudo update-alternatives --set phpize /usr/bin/phpize"$version" >/dev/null 2>&1
|
||||
wget https://github.com/pear/pearweb_phars/raw/master/install-pear-nozlib.phar >/dev/null 2>&1
|
||||
sudo php install-pear-nozlib.phar >/dev/null 2>&1
|
||||
sudo rm -rf install-pear-nozlib.phar >/dev/null 2>&1
|
||||
sudo pear config-set php_ini "$ini_file" >/dev/null 2>&1
|
||||
sudo pear config-set auto_discover 1 >/dev/null 2>&1
|
||||
sudo pear channel-update pear.php.net >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Function to setup composer
|
||||
setup_composer() {
|
||||
if [ ! -e "/usr/bin/composer" ]; then
|
||||
curl -s -L https://getcomposer.org/installer >composer-setup.php
|
||||
if [ "$(curl -s https://composer.github.io/installer.sig)" != "$(php -r "echo hash_file('sha384', 'composer-setup.php');")" ]; then
|
||||
echo >&2 'ERROR: Invalid installer signature'
|
||||
else
|
||||
export COMPOSER_ALLOW_SUPERUSER=1
|
||||
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
|
||||
fi
|
||||
rm composer-setup.php
|
||||
fi
|
||||
add_log "$tick" "Composer" "Installed"
|
||||
add_log "$tick" "PECL" "Added"
|
||||
}
|
||||
|
||||
# Function to switch versions of PHP binaries
|
||||
@ -104,13 +104,12 @@ tick="✓"
|
||||
cross="✗"
|
||||
ppa_updated="false"
|
||||
version=$1
|
||||
pecl=$2
|
||||
apt_install="sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y"
|
||||
existing_version=$(php-config --version | cut -c 1-3)
|
||||
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
|
||||
|
||||
# Setup PHP
|
||||
step_log "Setup PHP and Composer"
|
||||
step_log "Setup PHP"
|
||||
sudo mkdir -p /var/run
|
||||
sudo mkdir -p /run/php
|
||||
|
||||
@ -150,13 +149,3 @@ ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s
|
||||
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
|
||||
sudo chmod 777 "$ini_file"
|
||||
add_log "$tick" "PHP" "$status"
|
||||
|
||||
# Setup PECL
|
||||
if [ "$pecl" = "true" ]; then
|
||||
update_ppa
|
||||
setup_pecl
|
||||
add_log "$tick" "PECL" "Installed"
|
||||
fi
|
||||
|
||||
# Setup composer
|
||||
setup_composer
|
||||
|
@ -75,6 +75,38 @@ Function Remove-Extension() {
|
||||
}
|
||||
}
|
||||
|
||||
# Function to setup a remote tool
|
||||
Function Add-Tool() {
|
||||
Param (
|
||||
[Parameter(Position = 0, Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[ValidateLength(1, [int]::MaxValue)]
|
||||
[string]
|
||||
$url,
|
||||
[Parameter(Position = 1, Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[ValidateLength(1, [int]::MaxValue)]
|
||||
[string]
|
||||
$tool
|
||||
)
|
||||
if (Test-Path $php_dir\$tool) {
|
||||
Remove-Item $php_dir\$tool
|
||||
}
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool > $null 2>&1
|
||||
$bat_content = @()
|
||||
$bat_content += "@ECHO off"
|
||||
$bat_content += "setlocal DISABLEDELAYEDEXPANSION"
|
||||
$bat_content += "SET BIN_TARGET=%~dp0/" + $tool
|
||||
$bat_content += "php %BIN_TARGET% %*"
|
||||
Set-Content -Path $php_dir\$tool.bat -Value $bat_content
|
||||
Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.bat"
|
||||
Add-Log $tick $tool "Added"
|
||||
}
|
||||
|
||||
Function Add-PECL() {
|
||||
Add-Log $tick "PECL" "Use extensions input or Install-PhpExtension to setup PECL extensions on windows"
|
||||
}
|
||||
|
||||
# Variables
|
||||
$tick = ([char]8730)
|
||||
$cross = ([char]10007)
|
||||
@ -96,7 +128,7 @@ if (Test-Path -LiteralPath $php_dir -PathType Container) {
|
||||
catch {
|
||||
}
|
||||
}
|
||||
Step-Log "Setup PHP and Composer"
|
||||
Step-Log "Setup PHP"
|
||||
if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) {
|
||||
if ($version -lt '7.0') {
|
||||
Install-Module -Name VcRedist -Force
|
||||
@ -123,6 +155,3 @@ if ($version -eq 'master') {
|
||||
Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir
|
||||
}
|
||||
Add-Log $tick "PHP" $status
|
||||
|
||||
Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir
|
||||
Add-Log $tick "Composer" "Installed"
|
||||
|
Reference in New Issue
Block a user