mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-26 13:23:05 +07:00
Refactor scripts and improve comments
This commit is contained in:
parent
0e56c0b653
commit
2df0d2b443
@ -1,10 +1,10 @@
|
|||||||
# Function to log start of a operation
|
# Function to log start of a operation.
|
||||||
step_log() {
|
step_log() {
|
||||||
message=$1
|
message=$1
|
||||||
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
|
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to log result of a operation
|
# Function to log result of a operation.
|
||||||
add_log() {
|
add_log() {
|
||||||
mark=$1
|
mark=$1
|
||||||
subject=$2
|
subject=$2
|
||||||
@ -16,7 +16,28 @@ add_log() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to remove extensions
|
# Function to read env inputs.
|
||||||
|
read_env() {
|
||||||
|
[[ -z "${update}" ]] && update='false' && UPDATE='false' || update="${update}"
|
||||||
|
[ "$update" = false ] && [[ -n ${UPDATE} ]] && update="${UPDATE}"
|
||||||
|
[[ -z "${runner}" ]] && runner='github' && RUNNER='github' || runner="${runner}"
|
||||||
|
[ "$runner" = false ] && [[ -n ${RUNNER} ]] && runner="${RUNNER}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to setup environment for self-hosted runners.
|
||||||
|
self_hosted_setup() {
|
||||||
|
if [[ "$version" =~ $old_versions ]]; then
|
||||||
|
add_log "$cross" "PHP" "PHP $version is not supported on self-hosted runner"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ $(command -v brew) == "" ]]; then
|
||||||
|
step_log "Setup Brew"
|
||||||
|
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh | bash -s >/dev/null 2>&1
|
||||||
|
add_log "$tick" "Brew" "Installed Homebrew"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to remove extensions.
|
||||||
remove_extension() {
|
remove_extension() {
|
||||||
extension=$1
|
extension=$1
|
||||||
if check_extension "$extension"; then
|
if check_extension "$extension"; then
|
||||||
@ -30,7 +51,7 @@ remove_extension() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to test if extension is loaded
|
# Function to test if extension is loaded.
|
||||||
check_extension() {
|
check_extension() {
|
||||||
extension=$1
|
extension=$1
|
||||||
if [ "$extension" != "mysql" ]; then
|
if [ "$extension" != "mysql" ]; then
|
||||||
@ -40,7 +61,7 @@ check_extension() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fuction to get the PECL version
|
# Fuction to get the PECL version.
|
||||||
get_pecl_version() {
|
get_pecl_version() {
|
||||||
extension=$1
|
extension=$1
|
||||||
stability=$2
|
stability=$2
|
||||||
@ -53,7 +74,7 @@ get_pecl_version() {
|
|||||||
echo "$pecl_version"
|
echo "$pecl_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to install a PECL version
|
# Function to install a specific version of PECL extension.
|
||||||
add_pecl_extension() {
|
add_pecl_extension() {
|
||||||
extension=$1
|
extension=$1
|
||||||
pecl_version=$2
|
pecl_version=$2
|
||||||
@ -91,7 +112,7 @@ add_extension() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to pre-release extensions using PECL
|
# Function to setup pre-release extensions using PECL.
|
||||||
add_unstable_extension() {
|
add_unstable_extension() {
|
||||||
extension=$1
|
extension=$1
|
||||||
stability=$2
|
stability=$2
|
||||||
@ -100,7 +121,7 @@ add_unstable_extension() {
|
|||||||
add_pecl_extension "$extension" "$pecl_version" "$prefix"
|
add_pecl_extension "$extension" "$pecl_version" "$prefix"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup a remote tool
|
# Function to setup a remote tool.
|
||||||
add_tool() {
|
add_tool() {
|
||||||
url=$1
|
url=$1
|
||||||
tool=$2
|
tool=$2
|
||||||
@ -138,7 +159,7 @@ add_tool() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to add a tool using composer
|
# Function to add a tool using composer.
|
||||||
add_composertool() {
|
add_composertool() {
|
||||||
tool=$1
|
tool=$1
|
||||||
release=$2
|
release=$2
|
||||||
@ -163,18 +184,17 @@ add_blackfire() {
|
|||||||
# Function to configure PECL
|
# Function to configure PECL
|
||||||
configure_pecl() {
|
configure_pecl() {
|
||||||
for tool in pear pecl; do
|
for tool in pear pecl; do
|
||||||
sudo "$tool" config-set php_ini "$ini_file" >/dev/null 2>&1
|
sudo "$tool" config-set php_ini "$ini_file"
|
||||||
sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1
|
sudo "$tool" channel-update "$tool".php.net
|
||||||
sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to log PECL, it is installed along with PHP
|
# Function to handle request to add PECL.
|
||||||
add_pecl() {
|
add_pecl() {
|
||||||
add_log "$tick" "PECL" "Added"
|
add_log "$tick" "PECL" "Added"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to fetch updated formulas
|
# Function to fetch updated formulae.
|
||||||
update_formulae() {
|
update_formulae() {
|
||||||
brew_dir=$(brew --prefix)/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
|
brew_dir=$(brew --prefix)/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
|
||||||
for formula in httpd pkg-config apr apr-util argon2 aspell autoconf bison curl-openssl freetds freetype gettext glib gmp icu4c jpeg krb5 libffi libpng libpq libsodium libzip oniguruma openldap openssl@1.1 re2c sqlite tidyp unixodbc webp; do
|
for formula in httpd pkg-config apr apr-util argon2 aspell autoconf bison curl-openssl freetds freetype gettext glib gmp icu4c jpeg krb5 libffi libpng libpq libsodium libzip oniguruma openldap openssl@1.1 re2c sqlite tidyp unixodbc webp; do
|
||||||
@ -184,7 +204,7 @@ update_formulae() {
|
|||||||
wait "${to_wait[@]}"
|
wait "${to_wait[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup PHP >=5.6
|
# Function to setup PHP 5.6 and newer.
|
||||||
setup_php() {
|
setup_php() {
|
||||||
action=$1
|
action=$1
|
||||||
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE
|
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE
|
||||||
@ -192,7 +212,7 @@ setup_php() {
|
|||||||
if brew list php@"$version" 2>/dev/null | grep -q "Error" && [ "$action" != "upgrade" ]; then
|
if brew list php@"$version" 2>/dev/null | grep -q "Error" && [ "$action" != "upgrade" ]; then
|
||||||
brew unlink php@"$version"
|
brew unlink php@"$version"
|
||||||
else
|
else
|
||||||
if [ "$version" = "8.0" ]; then update_formulae; fi
|
if [ "$version" = "$master_version" ]; then update_formulae; fi
|
||||||
brew "$action" shivammathur/php/php@"$version"
|
brew "$action" shivammathur/php/php@"$version"
|
||||||
fi
|
fi
|
||||||
brew link --force --overwrite php@"$version"
|
brew link --force --overwrite php@"$version"
|
||||||
@ -203,24 +223,14 @@ tick="✓"
|
|||||||
cross="✗"
|
cross="✗"
|
||||||
version=$1
|
version=$1
|
||||||
nodot_version=${1/./}
|
nodot_version=${1/./}
|
||||||
|
master_version="8.0"
|
||||||
old_versions="5.[3-5]"
|
old_versions="5.[3-5]"
|
||||||
tool_path_dir="/usr/local/bin"
|
tool_path_dir="/usr/local/bin"
|
||||||
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
|
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
|
||||||
[[ -z "${update}" ]] && update='false' && UPDATE='false' || update="${update}"
|
|
||||||
[ "$update" = false ] && [[ -n ${UPDATE} ]] && update="${UPDATE}"
|
|
||||||
[[ -z "${runner}" ]] && runner='github' && RUNNER='github' || runner="${runner}"
|
|
||||||
[ "$runner" = false ] && [[ -n ${RUNNER} ]] && runner="${RUNNER}"
|
|
||||||
|
|
||||||
|
read_env
|
||||||
if [ "$runner" = "self-hosted" ]; then
|
if [ "$runner" = "self-hosted" ]; then
|
||||||
if [[ "$version" =~ $old_versions ]]; then
|
self_hosted_setup >/dev/null 2>&1
|
||||||
add_log "$cross" "PHP" "PHP $version is not supported on self-hosted runner"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if [[ $(command -v brew) == "" ]]; then
|
|
||||||
step_log "Setup Brew"
|
|
||||||
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh | bash -s >/dev/null 2>&1
|
|
||||||
add_log "$tick" "Brew" "Installed Homebrew"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Setup PHP
|
# Setup PHP
|
||||||
@ -244,5 +254,5 @@ ext_dir=$(php -i | grep -Ei "extension_dir => /" | sed -e "s|.*=> s*||")
|
|||||||
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
|
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
|
||||||
sudo mkdir -p "$ext_dir"
|
sudo mkdir -p "$ext_dir"
|
||||||
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
|
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
|
||||||
if [[ ! "$version" =~ $old_versions ]]; then configure_pecl; fi
|
if [[ ! "$version" =~ $old_versions ]]; then configure_pecl >/dev/null 2>&1; fi
|
||||||
add_log "$tick" "PHP" "$status PHP $semver"
|
add_log "$tick" "PHP" "$status PHP $semver"
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
# Function to log start of a operation
|
# Function to log start of a operation.
|
||||||
step_log() {
|
step_log() {
|
||||||
message=$1
|
message=$1
|
||||||
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
|
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to log result of a operation
|
# Function to log result of a operation.
|
||||||
add_log() {
|
add_log() {
|
||||||
mark=$1
|
mark=$1
|
||||||
subject=$2
|
subject=$2
|
||||||
@ -16,54 +16,62 @@ add_log() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to update php ppa
|
# Function to read env inputs.
|
||||||
update_ppa() {
|
read_env() {
|
||||||
if [ "$ppa_updated" = "false" ]; then
|
[[ -z "${update}" ]] && update='false' && UPDATE='false' || update="${update}"
|
||||||
|
[ "$update" = false ] && [[ -n ${UPDATE} ]] && update="${UPDATE}"
|
||||||
|
[[ -z "${runner}" ]] && runner='github' && RUNNER='github' || runner="${runner}"
|
||||||
|
[ "$runner" = false ] && [[ -n ${RUNNER} ]] && runner="${RUNNER}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to dump sudo warnings instead of piping to STDOUT.
|
||||||
|
sudo_wa() {
|
||||||
|
echo "Set disable_coredump false" | sudo tee -a /etc/sudo.conf
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to update the package lists.
|
||||||
|
update_lists() {
|
||||||
|
if [ "$lists_updated" = "false" ]; then
|
||||||
sudo "$debconf_fix" apt-get update >/dev/null 2>&1
|
sudo "$debconf_fix" apt-get update >/dev/null 2>&1
|
||||||
ppa_updated="true"
|
lists_updated="true"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup environment for self-hosted runners
|
# Function to setup environment for self-hosted runners.
|
||||||
pre_setup() {
|
self_hosted_setup() {
|
||||||
sudo mkdir -p /var/run /run/php
|
if [[ "$version" =~ $old_versions ]]; then
|
||||||
echo "Set disable_coredump false" | sudo tee -a /etc/sudo.conf >/dev/null 2>&1
|
add_log "$cross" "PHP" "PHP $version is not supported on self-hosted runner"
|
||||||
if [ "$runner" = "self-hosted" ]; then
|
exit 1
|
||||||
if [[ "$version" =~ $old_versions ]] || [ "$version" = "5.3" ]; then
|
fi
|
||||||
add_log "$cross" "PHP" "PHP $version is not supported on self-hosted runner"
|
if ! command -v apt-fast >/dev/null; then
|
||||||
exit 1
|
sudo ln -sf /usr/bin/apt-get /usr/bin/apt-fast
|
||||||
fi
|
fi
|
||||||
if ! command -v apt-fast >/dev/null; then
|
update_lists && $apt_install curl make lsb-release software-properties-common unzip
|
||||||
sudo ln -sf /usr/bin/apt-get /usr/bin/apt-fast
|
if ! apt-cache policy | grep -q ondrej/php; then
|
||||||
fi
|
LC_ALL=C.UTF-8 sudo apt-add-repository ppa:ondrej/php -y
|
||||||
update_ppa && $apt_install curl make lsb-release software-properties-common unzip
|
if [ "$(lsb_release -r -s)" = "16.04" ]; then
|
||||||
if ! apt-cache policy | grep -q ondrej/php; then
|
sudo "$debconf_fix" apt-get update >/dev/null 2>&1
|
||||||
LC_ALL=C.UTF-8 sudo apt-add-repository ppa:ondrej/php -y
|
|
||||||
if [ "$(lsb_release -r -s)" = "16.04" ]; then
|
|
||||||
sudo "$debconf_fix" apt-get update >/dev/null 2>&1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ "$version" = "8.0" ]; then
|
|
||||||
IFS=' ' read -r -a libs <<< "$(echo "aspell curl4-gnutls enchant freetype6 icu jpeg onig png pq tidy webp xpm xslt zip" | sed "s/[^ ]*/lib&-dev/g")"
|
|
||||||
$apt_install "${libs[@]}"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
if [ "$version" = "$master_version" ]; then
|
||||||
|
IFS=' ' read -r -a libs <<< "$(echo "aspell curl4-gnutls enchant freetype6 icu jpeg onig png pq tidy webp xpm xslt zip" | sed "s/[^ ]*/lib&-dev/g")"
|
||||||
|
$apt_install "${libs[@]}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to configure PECL
|
# Function to configure PECL.
|
||||||
configure_pecl() {
|
configure_pecl() {
|
||||||
if [ "$pecl_config" = "false" ] && [ -e /usr/bin/pecl ]; then
|
if [ "$pecl_config" = "false" ] && [ -e /usr/bin/pecl ]; then
|
||||||
|
|
||||||
for tool in pear pecl; do
|
for tool in pear pecl; do
|
||||||
sudo "$tool" config-set php_ini "$scan_dir"/99-pecl.ini >/dev/null 2>&1
|
sudo "$tool" config-set php_ini "$scan_dir"/99-pecl.ini
|
||||||
sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1
|
sudo "$tool" channel-update "$tool".php.net
|
||||||
sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1
|
|
||||||
done
|
done
|
||||||
pecl_config="true"
|
pecl_config="true"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fuction to get the PECL version
|
# Fuction to get the PECL version of an extension.
|
||||||
get_pecl_version() {
|
get_pecl_version() {
|
||||||
extension=$1
|
extension=$1
|
||||||
stability=$2
|
stability=$2
|
||||||
@ -76,7 +84,7 @@ get_pecl_version() {
|
|||||||
echo "$pecl_version"
|
echo "$pecl_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to test if extension is loaded
|
# Function to check if an extension is loaded.
|
||||||
check_extension() {
|
check_extension() {
|
||||||
extension=$1
|
extension=$1
|
||||||
if [ "$extension" != "mysql" ]; then
|
if [ "$extension" != "mysql" ]; then
|
||||||
@ -86,7 +94,7 @@ check_extension() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to delete extensions
|
# Function to delete extensions.
|
||||||
delete_extension() {
|
delete_extension() {
|
||||||
extension=$1
|
extension=$1
|
||||||
sudo sed -i "/$extension/d" "$ini_file"
|
sudo sed -i "/$extension/d" "$ini_file"
|
||||||
@ -95,7 +103,7 @@ delete_extension() {
|
|||||||
sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
|
sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to disable and delete extensions
|
# Function to disable and delete extensions.
|
||||||
remove_extension() {
|
remove_extension() {
|
||||||
extension=$1
|
extension=$1
|
||||||
if check_extension "$extension"; then
|
if check_extension "$extension"; then
|
||||||
@ -110,14 +118,14 @@ remove_extension() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to enable existing extension
|
# Function to enable existing extensions.
|
||||||
enable_extension() {
|
enable_extension() {
|
||||||
if ! check_extension "$1" && [ -e "$ext_dir/$1.so" ]; then
|
if ! check_extension "$1" && [ -e "$ext_dir/$1.so" ]; then
|
||||||
echo "$2=$1.so" >>"$pecl_file"
|
echo "$2=$1.so" >>"$pecl_file"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Funcion to add PDO extension
|
# Funcion to add PDO extension.
|
||||||
add_pdo_extension() {
|
add_pdo_extension() {
|
||||||
pdo_ext="pdo_$1"
|
pdo_ext="pdo_$1"
|
||||||
if check_extension "$pdo_ext"; then
|
if check_extension "$pdo_ext"; then
|
||||||
@ -138,20 +146,20 @@ add_pdo_extension() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup extensions
|
# Function to add extensions.
|
||||||
add_extension() {
|
add_extension() {
|
||||||
extension=$1
|
extension=$1
|
||||||
install_command=$2
|
install_command=$2
|
||||||
prefix=$3
|
prefix=$3
|
||||||
if [[ "$version" =~ $old_versions ]]; then
|
|
||||||
install_command="update_ppa && ${install_command/5\.[4-5]-$extension/5-$extension=$release_version}"
|
|
||||||
fi
|
|
||||||
enable_extension "$extension" "$prefix"
|
enable_extension "$extension" "$prefix"
|
||||||
if check_extension "$extension"; then
|
if check_extension "$extension"; then
|
||||||
add_log "$tick" "$extension" "Enabled"
|
add_log "$tick" "$extension" "Enabled"
|
||||||
else
|
else
|
||||||
|
if [[ "$version" =~ 5.[4-5] ]]; then
|
||||||
|
install_command="update_lists && ${install_command/5\.[4-5]-$extension/5-$extension=$release_version}"
|
||||||
|
fi
|
||||||
eval "$install_command" >/dev/null 2>&1 ||
|
eval "$install_command" >/dev/null 2>&1 ||
|
||||||
(update_ppa && eval "$install_command" >/dev/null 2>&1) ||
|
(update_lists && eval "$install_command" >/dev/null 2>&1) ||
|
||||||
sudo pecl install -f "$extension" >/dev/null 2>&1
|
sudo pecl install -f "$extension" >/dev/null 2>&1
|
||||||
(check_extension "$extension" && add_log "$tick" "$extension" "Installed and enabled") ||
|
(check_extension "$extension" && add_log "$tick" "$extension" "Installed and enabled") ||
|
||||||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
|
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
|
||||||
@ -159,7 +167,7 @@ add_extension() {
|
|||||||
sudo chmod 777 "$ini_file"
|
sudo chmod 777 "$ini_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to install a PECL version
|
# Function to install a PECL version.
|
||||||
add_pecl_extension() {
|
add_pecl_extension() {
|
||||||
extension=$1
|
extension=$1
|
||||||
pecl_version=$2
|
pecl_version=$2
|
||||||
@ -180,7 +188,7 @@ add_pecl_extension() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to pre-release extensions using PECL
|
# Function to pre-release extensions using PECL.
|
||||||
add_unstable_extension() {
|
add_unstable_extension() {
|
||||||
extension=$1
|
extension=$1
|
||||||
stability=$2
|
stability=$2
|
||||||
@ -189,7 +197,7 @@ add_unstable_extension() {
|
|||||||
add_pecl_extension "$extension" "$pecl_version" "$prefix"
|
add_pecl_extension "$extension" "$pecl_version" "$prefix"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to update extension
|
# Function to update extension.
|
||||||
update_extension() {
|
update_extension() {
|
||||||
extension=$1
|
extension=$1
|
||||||
latest_version=$2
|
latest_version=$2
|
||||||
@ -198,13 +206,13 @@ update_extension() {
|
|||||||
if [ "$final_version" != "$current_version" ]; then
|
if [ "$final_version" != "$current_version" ]; then
|
||||||
version_exists=$(apt-cache policy -- *"$extension" | grep "$final_version")
|
version_exists=$(apt-cache policy -- *"$extension" | grep "$final_version")
|
||||||
if [ -z "$version_exists" ]; then
|
if [ -z "$version_exists" ]; then
|
||||||
update_ppa
|
update_lists
|
||||||
fi
|
fi
|
||||||
$apt_install php"$version"-"$extension"
|
$apt_install php"$version"-"$extension"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup a remote tool
|
# Function to setup a remote tool.
|
||||||
add_tool() {
|
add_tool() {
|
||||||
url=$1
|
url=$1
|
||||||
tool=$2
|
tool=$2
|
||||||
@ -239,7 +247,7 @@ add_tool() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup a tool using composer
|
# Function to setup a tool using composer.
|
||||||
add_composertool() {
|
add_composertool() {
|
||||||
tool=$1
|
tool=$1
|
||||||
release=$2
|
release=$2
|
||||||
@ -250,16 +258,17 @@ add_composertool() {
|
|||||||
) || add_log "$cross" "$tool" "Could not setup $tool"
|
) || add_log "$cross" "$tool" "Could not setup $tool"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup phpize and php-config
|
# Function to setup phpize and php-config.
|
||||||
add_devtools() {
|
add_devtools() {
|
||||||
if ! [ -e "/usr/bin/phpize$version" ] || ! [ -e "/usr/bin/php-config$version" ]; then
|
if ! [ -e "/usr/bin/phpize$version" ] || ! [ -e "/usr/bin/php-config$version" ]; then
|
||||||
update_ppa && $apt_install php"$version"-dev php"$version"-xml >/dev/null 2>&1
|
update_lists && $apt_install php"$version"-dev php"$version"-xml >/dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
sudo update-alternatives --set php-config /usr/bin/php-config"$version" >/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
|
sudo update-alternatives --set phpize /usr/bin/phpize"$version" >/dev/null 2>&1
|
||||||
configure_pecl
|
configure_pecl >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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 -o /tmp/blackfire-gpg.key -sSL https://packages.blackfire.io/gpg.key >/dev/null 2>&1
|
sudo curl -o /tmp/blackfire-gpg.key -sSL https://packages.blackfire.io/gpg.key >/dev/null 2>&1
|
||||||
@ -274,9 +283,9 @@ add_blackfire() {
|
|||||||
add_log "$tick" "blackfire-agent" "Added"
|
add_log "$tick" "blackfire-agent" "Added"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup the nightly build from master branch
|
# Function to setup the nightly build from master branch.
|
||||||
setup_master() {
|
setup_master() {
|
||||||
update_ppa && $apt_install libzip-dev libwebp-dev
|
update_lists && $apt_install libzip-dev libwebp-dev
|
||||||
tar_file=php_"$version"%2Bubuntu"$(lsb_release -r -s)".tar.xz
|
tar_file=php_"$version"%2Bubuntu"$(lsb_release -r -s)".tar.xz
|
||||||
install_dir=~/php/"$version"
|
install_dir=~/php/"$version"
|
||||||
bintray_url=https://dl.bintray.com/shivammathur/php/"$tar_file"
|
bintray_url=https://dl.bintray.com/shivammathur/php/"$tar_file"
|
||||||
@ -294,7 +303,7 @@ setup_master() {
|
|||||||
sudo ln -sf "$install_dir"/etc/php.ini /etc/php.ini
|
sudo ln -sf "$install_dir"/etc/php.ini /etc/php.ini
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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() {
|
||||||
dir=php-"$version"
|
dir=php-"$version"
|
||||||
tar_file="$dir".tar.xz
|
tar_file="$dir".tar.xz
|
||||||
@ -307,39 +316,45 @@ setup_old_versions() {
|
|||||||
release_version=$(php -v | head -n 1 | cut -d' ' -f 2)
|
release_version=$(php -v | head -n 1 | cut -d' ' -f 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup PECL
|
# Function to add PECL.
|
||||||
add_pecl() {
|
add_pecl() {
|
||||||
add_devtools
|
add_devtools >/dev/null 2>&1
|
||||||
if [ ! -e /usr/bin/pecl ]; then
|
if [ ! -e /usr/bin/pecl ]; then
|
||||||
$apt_install php-pear >/dev/null 2>&1
|
$apt_install php-pear >/dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
configure_pecl
|
configure_pecl >/dev/null 2>&1
|
||||||
add_log "$tick" "PECL" "Added"
|
add_log "$tick" "PECL" "Added"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to switch versions of PHP binaries
|
# Function to switch versions of PHP binaries.
|
||||||
switch_version() {
|
switch_version() {
|
||||||
for tool in pear pecl php phar phar.phar php-cgi php-config phpize phpdbg; do
|
for tool in pear pecl php phar phar.phar php-cgi php-config phpize phpdbg; do
|
||||||
if [ -e "/usr/bin/$tool$version" ]; then
|
if [ -e "/usr/bin/$tool$version" ]; then
|
||||||
sudo update-alternatives --set $tool /usr/bin/"$tool$version" >/dev/null 2>&1
|
sudo update-alternatives --set $tool /usr/bin/"$tool$version"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to get PHP version in semver format
|
# Function to get PHP version in semver format.
|
||||||
php_semver() {
|
php_semver() {
|
||||||
if [ ! "$version" = "8.0" ]; then
|
if [ ! "$version" = "$master_version" ]; then
|
||||||
php"$version" -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-'
|
php"$version" -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-'
|
||||||
else
|
else
|
||||||
php -v | head -n 1 | cut -f 2 -d ' '
|
php -v | head -n 1 | cut -f 2 -d ' '
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to update PHP
|
# Function to install packaged PHP
|
||||||
|
add_packaged_php() {
|
||||||
|
update_lists
|
||||||
|
IFS=' ' read -r -a packages <<< "$(echo "curl mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")"
|
||||||
|
$apt_install php"$version" "${packages[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to update PHP.
|
||||||
update_php() {
|
update_php() {
|
||||||
update_ppa
|
|
||||||
initial_version=$(php_semver)
|
initial_version=$(php_semver)
|
||||||
$apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml >/dev/null 2>&1
|
add_packaged_php
|
||||||
updated_version=$(php_semver)
|
updated_version=$(php_semver)
|
||||||
if [ "$updated_version" != "$initial_version" ]; then
|
if [ "$updated_version" != "$initial_version" ]; then
|
||||||
status="Updated to"
|
status="Updated to"
|
||||||
@ -348,56 +363,60 @@ update_php() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to install PHP.
|
||||||
|
add_php() {
|
||||||
|
if [ "$version" = "$master_version" ]; then
|
||||||
|
setup_master
|
||||||
|
elif [[ "$version" =~ $old_versions ]]; then
|
||||||
|
setup_old_versions
|
||||||
|
else
|
||||||
|
add_packaged_php
|
||||||
|
fi
|
||||||
|
status="Installed"
|
||||||
|
}
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
tick="✓"
|
tick="✓"
|
||||||
cross="✗"
|
cross="✗"
|
||||||
ppa_updated="false"
|
lists_updated="false"
|
||||||
pecl_config="false"
|
pecl_config="false"
|
||||||
version=$1
|
version=$1
|
||||||
old_versions="5.[4-5]"
|
master_version="8.0"
|
||||||
|
old_versions="5.[3-5]"
|
||||||
debconf_fix="DEBIAN_FRONTEND=noninteractive"
|
debconf_fix="DEBIAN_FRONTEND=noninteractive"
|
||||||
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"
|
||||||
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
|
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
|
||||||
[[ -z "${update}" ]] && update='false' && UPDATE='false' || update="${update}"
|
|
||||||
[ "$update" = false ] && [[ -n ${UPDATE} ]] && update="${UPDATE}"
|
|
||||||
[[ -z "${runner}" ]] && runner='github' && RUNNER='github' || runner="${runner}"
|
|
||||||
[ "$runner" = false ] && [[ -n ${RUNNER} ]] && runner="${RUNNER}"
|
|
||||||
|
|
||||||
# Setup PHP
|
# Setup PHP
|
||||||
step_log "Setup PHP"
|
step_log "Setup PHP"
|
||||||
pre_setup >/dev/null 2>&1
|
sudo_wa >/dev/null 2>&1
|
||||||
|
sudo mkdir -p /var/run /run/php
|
||||||
|
read_env
|
||||||
|
if [ "$runner" = "self-hosted" ]; then
|
||||||
|
self_hosted_setup >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$existing_version" != "$version" ]; then
|
if [ "$existing_version" != "$version" ]; then
|
||||||
if [ ! -e "/usr/bin/php$version" ]; then
|
if [ ! -e "/usr/bin/php$version" ]; then
|
||||||
if [ "$version" = "8.0" ]; then
|
add_php >/dev/null 2>&1
|
||||||
setup_master >/dev/null 2>&1
|
|
||||||
elif [[ "$version" =~ $old_versions ]] || [ "$version" = "5.3" ]; then
|
|
||||||
setup_old_versions >/dev/null 2>&1
|
|
||||||
else
|
|
||||||
update_ppa
|
|
||||||
$apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml php"$version"-intl >/dev/null 2>&1
|
|
||||||
fi
|
|
||||||
status="Installed"
|
|
||||||
else
|
else
|
||||||
if [ "$update" = "true" ]; then
|
if [ "$update" = "true" ]; then
|
||||||
update_php
|
update_php >/dev/null 2>&1
|
||||||
else
|
else
|
||||||
status="Switched to"
|
status="Switched to"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# PHP 5.3 is switched by install script, for rest switch_version
|
|
||||||
if [ "$version" != "5.3" ]; then
|
if [ "$version" != "5.3" ]; then
|
||||||
switch_version
|
switch_version >/dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
if [ "$update" = "true" ]; then
|
if [ "$update" = "true" ]; then
|
||||||
update_php
|
update_php >/dev/null 2>&1
|
||||||
else
|
else
|
||||||
status="Found"
|
status="Found"
|
||||||
if [ "$version" = "8.0" ]; then
|
if [ "$version" = "$master_version" ]; then
|
||||||
switch_version
|
switch_version >/dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -11,15 +11,18 @@ param (
|
|||||||
$dir
|
$dir
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Function to log start of a operation.
|
||||||
Function Step-Log($message) {
|
Function Step-Log($message) {
|
||||||
printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message
|
printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to log result of a operation.
|
||||||
Function Add-Log($mark, $subject, $message) {
|
Function Add-Log($mark, $subject, $message) {
|
||||||
$code = if ($mark -eq $cross) { "31" } else { "32" }
|
$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\n" $code $mark $subject $message
|
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $code $mark $subject $message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to fetch PATH from the registry.
|
||||||
Function Get-PathFromRegistry {
|
Function Get-PathFromRegistry {
|
||||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" +
|
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" +
|
||||||
[System.Environment]::GetEnvironmentVariable("Path","User")
|
[System.Environment]::GetEnvironmentVariable("Path","User")
|
||||||
@ -28,6 +31,7 @@ Function Get-PathFromRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to add a location to PATH.
|
||||||
Function Add-Path {
|
Function Add-Path {
|
||||||
param(
|
param(
|
||||||
[string]$PathItem
|
[string]$PathItem
|
||||||
@ -38,6 +42,7 @@ Function Add-Path {
|
|||||||
Get-PathFromRegistry
|
Get-PathFromRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to get a clean Powershell profile.
|
||||||
Function Get-CleanPSProfile {
|
Function Get-CleanPSProfile {
|
||||||
if(-not(Test-Path -LiteralPath $profile)) {
|
if(-not(Test-Path -LiteralPath $profile)) {
|
||||||
New-Item -Path $profile -ItemType "file" -Force
|
New-Item -Path $profile -ItemType "file" -Force
|
||||||
@ -48,6 +53,7 @@ Function Get-CleanPSProfile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to install PhpManager.
|
||||||
Function Install-PhpManager() {
|
Function Install-PhpManager() {
|
||||||
$repo = "mlocati/powershell-phpmanager"
|
$repo = "mlocati/powershell-phpmanager"
|
||||||
$zip_file = "$php_dir\PhpManager.zip"
|
$zip_file = "$php_dir\PhpManager.zip"
|
||||||
@ -61,6 +67,7 @@ Function Install-PhpManager() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to add PHP extensions.
|
||||||
Function Add-Extension {
|
Function Add-Extension {
|
||||||
Param (
|
Param (
|
||||||
[Parameter(Position = 0, Mandatory = $true)]
|
[Parameter(Position = 0, Mandatory = $true)]
|
||||||
@ -110,6 +117,7 @@ Function Add-Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to remove PHP extensions.
|
||||||
Function Remove-Extension() {
|
Function Remove-Extension() {
|
||||||
Param (
|
Param (
|
||||||
[Parameter(Position = 0, Mandatory = $true)]
|
[Parameter(Position = 0, Mandatory = $true)]
|
||||||
@ -133,6 +141,7 @@ Function Remove-Extension() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to add tools.
|
||||||
Function Add-Tool() {
|
Function Add-Tool() {
|
||||||
Param (
|
Param (
|
||||||
[Parameter(Position = 0, Mandatory = $true)]
|
[Parameter(Position = 0, Mandatory = $true)]
|
||||||
@ -187,6 +196,7 @@ Function Add-Tool() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to setup a tool using composer.
|
||||||
Function Add-Composertool() {
|
Function Add-Composertool() {
|
||||||
Param (
|
Param (
|
||||||
[Parameter(Position = 0, Mandatory = $true)]
|
[Parameter(Position = 0, Mandatory = $true)]
|
||||||
@ -213,10 +223,12 @@ Function Add-Composertool() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to handle request to add PECL.
|
||||||
Function Add-Pecl() {
|
Function Add-Pecl() {
|
||||||
Add-Log $tick "PECL" "Use extensions input to setup PECL extensions on windows"
|
Add-Log $tick "PECL" "Use extensions input to setup PECL extensions on windows"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to add blackfire and blackfire-agent.
|
||||||
Function Add-Blackfire() {
|
Function Add-Blackfire() {
|
||||||
$agent_data = Invoke-WebRequest https://blackfire.io/docs/up-and-running/update | ForEach-Object { $_.tostring() -split "[`r`n]" | Select-String '<td class="version">' | Select-Object -Index 0 }
|
$agent_data = Invoke-WebRequest https://blackfire.io/docs/up-and-running/update | ForEach-Object { $_.tostring() -split "[`r`n]" | Select-String '<td class="version">' | Select-Object -Index 0 }
|
||||||
$agent_version = [regex]::Matches($agent_data, '<td.*?>(.+)</td>') | ForEach-Object {$_.Captures[0].Groups[1].value }
|
$agent_version = [regex]::Matches($agent_data, '<td.*?>(.+)</td>') | ForEach-Object {$_.Captures[0].Groups[1].value }
|
||||||
|
Loading…
Reference in New Issue
Block a user