mirror of
https://github.com/jlengrand/asdf-php.git
synced 2026-03-10 08:01:22 +00:00
316 lines
9.1 KiB
Bash
Executable File
316 lines
9.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
# or more contributor license agreements. See the NOTICE file
|
|
# distributed with this work for additional information
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
# to you under the Apache License, Version 2.0 (the
|
|
# "License"); you may not use this file except in compliance
|
|
# with the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing,
|
|
# software distributed under the License is distributed on an
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
# KIND, either express or implied. See the License for the
|
|
# specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
set -eo pipefail
|
|
|
|
install_php() {
|
|
local install_type=$1
|
|
local version=$2
|
|
local install_path=$3
|
|
|
|
if [ "$TMPDIR" = "" ]; then
|
|
local tmp_download_dir=$(mktemp -d)
|
|
else
|
|
local tmp_download_dir=${TMPDIR%/}
|
|
fi
|
|
|
|
local source_path=$(get_download_file_path $install_type $version $tmp_download_dir)
|
|
local configure_options="$(construct_configure_options $install_path)"
|
|
local make_flags="-j$ASDF_CONCURRENCY"
|
|
|
|
download_source $install_type $version $source_path
|
|
|
|
# Running this in a subshell because we don't to disturb the current
|
|
# working directory.
|
|
(
|
|
cd $(dirname $source_path)
|
|
tar -zxf $source_path || exit 1
|
|
|
|
cd $(untar_path $install_type $version $tmp_download_dir)
|
|
|
|
# Target is OS-specific
|
|
# target=$(get_target)
|
|
|
|
# Build PHP
|
|
./buildconf --force || exit 1
|
|
./configure $configure_options || exit 1
|
|
make "$make_flags" || exit 1
|
|
# make "$make_flags" test || exit 1
|
|
make "$make_flags" install || exit 1
|
|
)
|
|
}
|
|
|
|
install_composer() {
|
|
local bin_path=$1/bin
|
|
local expected_signature="$(wget -q -O - https://composer.github.io/installer.sig)"
|
|
|
|
$bin_path/php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
|
$bin_path/php -r "if (hash_file('sha384', 'composer-setup.php') === '${expected_signature}') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
|
|
$bin_path/php composer-setup.php --install-dir=$bin_path --filename=composer
|
|
$bin_path/php -r "unlink('composer-setup.php');"
|
|
}
|
|
|
|
construct_configure_options() {
|
|
local install_path=$1
|
|
|
|
global_config="--prefix=$install_path \
|
|
--sysconfdir=$install_path \
|
|
--with-config-file-path=$install_path \
|
|
--with-config-file-scan-dir=$install_path/conf.d \
|
|
--enable-bcmath \
|
|
--enable-calendar \
|
|
--enable-dba \
|
|
--enable-exif \
|
|
--enable-ftp \
|
|
--enable-gd-native-ttf \
|
|
--enable-intl \
|
|
--enable-mbregex \
|
|
--enable-mbstring \
|
|
--enable-shmop \
|
|
--enable-soap \
|
|
--enable-sockets \
|
|
--enable-sysvmsg \
|
|
--enable-sysvsem \
|
|
--enable-sysvshm \
|
|
--enable-wddx \
|
|
--enable-zip \
|
|
--with-zip \
|
|
--with-gd \
|
|
--enable-gd \
|
|
--with-mhash \
|
|
--with-xmlrpc \
|
|
--with-curl \
|
|
--without-gmp \
|
|
--without-snmp \
|
|
--with-mysql=mysqlnd \
|
|
--with-mysqli=mysqlnd \
|
|
--with-pdo-mysql=mysqlnd \
|
|
--enable-mysqlnd \
|
|
--enable-pcntl \
|
|
--enable-fpm \
|
|
--with-fpm-user=www-data \
|
|
--with-fpm-group=www-data"
|
|
|
|
if [ "$PHP_CONFIGURE_OPTIONS" = "" ]; then
|
|
local configure_options="$(os_based_configure_options) $global_config"
|
|
else
|
|
local configure_options="$PHP_CONFIGURE_OPTIONS $global_config"
|
|
fi
|
|
|
|
if [ "${PHP_WITHOUT_PEAR:-no}" != "no" ]; then
|
|
configure_options="$configure_options --without-pear"
|
|
else
|
|
configure_options="$configure_options --with-pear"
|
|
fi
|
|
|
|
echo "$configure_options"
|
|
}
|
|
|
|
homebrew_package_path() {
|
|
local package_name=$1
|
|
|
|
if [ "$(brew ls --versions $package_name)" = "" ]; then
|
|
echo ""
|
|
else
|
|
echo "$(brew --prefix $package_name)"
|
|
fi
|
|
}
|
|
|
|
exit_if_homebrew_not_installed() {
|
|
if [ "$(brew --version 2>/dev/null)" = "" ]; then
|
|
echo "ERROR: Please install homebrew for OSX"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
os_based_configure_options() {
|
|
local operating_system=$(uname -a)
|
|
local configure_options=""
|
|
|
|
if [[ "$operating_system" =~ "Darwin" ]]; then
|
|
|
|
exit_if_homebrew_not_installed
|
|
|
|
local freetype_path=$(homebrew_package_path freetype)
|
|
local bison27_path=$(homebrew_package_path bison@2.7)
|
|
local gettext_path=$(homebrew_package_path gettext)
|
|
local icu4c_path=$(homebrew_package_path icu4c)
|
|
local webp_path=$(homebrew_package_path webp)
|
|
local jpeg_path=$(homebrew_package_path jpeg)
|
|
local libpng_path=$(homebrew_package_path libpng)
|
|
local openssl_path=$(homebrew_package_path openssl)
|
|
local libxml2_path=$(homebrew_package_path libxml2)
|
|
local zlib_path=$(homebrew_package_path zlib)
|
|
local readline_path=$(homebrew_package_path readline)
|
|
local libedit_path=$(homebrew_package_path libedit)
|
|
local iconv_path=$(homebrew_package_path libiconv)
|
|
local bzip2_path=$(homebrew_package_path bzip2)
|
|
local libzip_path=$(homebrew_package_path libzip)
|
|
|
|
if [ "$freetype_path" = "" ]; then
|
|
export ASDF_PKG_MISSING="freetype"
|
|
else
|
|
configure_options="--with-freetype-dir=$freetype_path"
|
|
fi
|
|
|
|
if [ "$bison27_path" = "" ]; then
|
|
export ASDF_PKG_MISSING="$ASDF_PKG_MISSING bison27"
|
|
fi
|
|
|
|
if [ "$gettext_path" = "" ]; then
|
|
export ASDF_PKG_MISSING="$ASDF_PKG_MISSING gettext"
|
|
else
|
|
configure_options="$configure_options --with-gettext=$gettext_path"
|
|
fi
|
|
|
|
if [ "$icu4c_path" = "" ]; then
|
|
export ASDF_PKG_MISSING="$ASDF_PKG_MISSING icu4c"
|
|
else
|
|
configure_options="$configure_options --with-icu-dir=$icu4c_path"
|
|
fi
|
|
|
|
if [ "$jpeg_path" = "" ]; then
|
|
export ASDF_PKG_MISSING="$ASDF_PKG_MISSING jpeg"
|
|
else
|
|
configure_options="$configure_options --with-jpeg-dir=$jpeg_path"
|
|
fi
|
|
|
|
if [ "$webp_path" = "" ]; then
|
|
export ASDF_PKG_MISSING="$ASDF_PKG_MISSING webp"
|
|
else
|
|
configure_options="$configure_options --with-webp-dir=$webp_path"
|
|
fi
|
|
|
|
if [ "$libpng_path" = "" ]; then
|
|
export ASDF_PKG_MISSING="$ASDF_PKG_MISSING libpng"
|
|
else
|
|
configure_options="$configure_options --with-png-dir=$libpng_path"
|
|
fi
|
|
|
|
if [ "$openssl_path" = "" ]; then
|
|
export ASDF_PKG_MISSING="$ASDF_PKG_MISSING openssl"
|
|
else
|
|
configure_options="$configure_options --with-openssl=$openssl_path"
|
|
fi
|
|
|
|
if [ "$libxml2_path" = "" ]; then
|
|
export ASDF_PKG_MISSING="$ASDF_PKG_MISSING libxml2"
|
|
else
|
|
configure_options="$configure_options --with-libxml-dir=$libxml2_path"
|
|
fi
|
|
|
|
if [ "$zlib_path" = "" ]; then
|
|
export ASDF_PKG_MISSING="$ASDF_PKG_MISSING zlib"
|
|
else
|
|
configure_options="$configure_options --with-zlib-dir=$zlib_path"
|
|
fi
|
|
|
|
if [ "$libzip_path" != "" ]; then
|
|
configure_options="$configure_options --with-libzip=$libzip_path"
|
|
fi
|
|
|
|
if [ "$readline_path" != "" ]; then
|
|
configure_options="$configure_options --with-readline=$readline_path"
|
|
fi
|
|
|
|
if [ "$libedit_path" != "" ]; then
|
|
configure_options="$configure_options --with-libedit=$libedit_path"
|
|
fi
|
|
|
|
if [ "$bzip2_path" != "" ]; then
|
|
configure_options="$configure_options --with-bz2=$bzip2_path"
|
|
fi
|
|
|
|
if [ "$iconv_path" != "" ]; then
|
|
configure_options="$configure_options --with-iconv=$iconv_path"
|
|
else
|
|
configure_options="$configure_options --without-iconv"
|
|
fi
|
|
else
|
|
local jpeg_path=$(locate libjpeg.so | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1)
|
|
local libpng_path=$(locate libpng.so | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1)
|
|
configure_options="--with-openssl --with-curl --with-zlib --with-readline --with-gettext"
|
|
|
|
if [ "$jpeg_path" = "" ]; then
|
|
export ASDF_PKG_MISSING="$ASDF_PKG_MISSING jpeg"
|
|
else
|
|
configure_options="$configure_options --with-jpeg-dir=$jpeg_path --with-jpeg"
|
|
fi
|
|
|
|
if [ "$libpng_path" = "" ]; then
|
|
export ASDF_PKG_MISSING="$ASDF_PKG_MISSING libpng"
|
|
else
|
|
configure_options="$configure_options --with-png-dir=$libpng_path --with-png"
|
|
fi
|
|
fi
|
|
|
|
echo $configure_options
|
|
}
|
|
|
|
download_source() {
|
|
local install_type=$1
|
|
local version=$2
|
|
local download_path=$3
|
|
local download_url=$(get_download_url $install_type $version)
|
|
|
|
# curl -Lo $download_path -C - $download_url
|
|
curl -Lo $download_path $download_url
|
|
}
|
|
|
|
get_download_file_path() {
|
|
local install_type=$1
|
|
local version=$2
|
|
local tmp_download_dir=$3
|
|
local php_version=$(get_php_version $version)
|
|
local pkg_name="php-${php_version}.tar.gz"
|
|
|
|
echo "$tmp_download_dir/$pkg_name"
|
|
}
|
|
|
|
untar_path() {
|
|
local install_type=$1
|
|
local version=$2
|
|
local tmp_download_dir=$3
|
|
|
|
local php_version=$(get_php_version $version)
|
|
|
|
local dir_name="php-src-php-${php_version}"
|
|
|
|
echo "$tmp_download_dir/$dir_name"
|
|
}
|
|
|
|
get_download_url() {
|
|
local install_type=$1
|
|
local version=$2
|
|
|
|
echo "https://github.com/php/php-src/archive/php-${version}.tar.gz"
|
|
}
|
|
|
|
get_php_version() {
|
|
IFS='-' read -a version_info <<<"$1"
|
|
|
|
if [ "${#version_info[@]}" -eq 1 ]; then
|
|
echo "${version_info[0]}"
|
|
else
|
|
echo "${version_info[0]}-${version_info[1]}"
|
|
fi
|
|
}
|
|
|
|
install_php $ASDF_INSTALL_TYPE $ASDF_INSTALL_VERSION $ASDF_INSTALL_PATH
|
|
install_composer $ASDF_INSTALL_PATH
|