2020-11-08 14:36:21 +07:00
|
|
|
# Function to setup environment for self-hosted runners.
|
|
|
|
self_hosted_helper() {
|
2021-07-28 01:00:00 +07:00
|
|
|
if ! command -v sudo >/dev/null; then
|
2021-08-10 03:07:46 +07:00
|
|
|
apt-get update
|
2021-07-28 01:00:00 +07:00
|
|
|
apt-get install -y sudo || add_log "${cross:?}" "sudo" "Could not install sudo"
|
|
|
|
fi
|
2020-11-08 14:36:21 +07:00
|
|
|
if ! command -v apt-fast >/dev/null; then
|
|
|
|
sudo ln -sf /usr/bin/apt-get /usr/bin/apt-fast
|
2021-07-28 01:00:00 +07:00
|
|
|
trap "sudo rm -f /usr/bin/apt-fast 2>/dev/null" exit
|
2019-10-17 03:11:13 +07:00
|
|
|
fi
|
2021-08-10 03:07:46 +07:00
|
|
|
install_packages apt-transport-https ca-certificates curl file make jq unzip autoconf automake gcc g++ gnupg
|
2020-07-25 13:57:51 +07:00
|
|
|
}
|
|
|
|
|
2020-11-08 14:36:21 +07:00
|
|
|
# Function to install a package
|
|
|
|
install_packages() {
|
|
|
|
packages=("$@")
|
2021-08-24 20:59:33 +07:00
|
|
|
[[ "${packages[*]}" =~ php ]] && add_ppa ondrej/php >/dev/null 2>&1
|
2021-08-10 03:07:46 +07:00
|
|
|
$apt_install "${packages[@]}" >/dev/null 2>&1 || (update_lists && $apt_install "${packages[@]}" >/dev/null 2>&1)
|
2019-12-20 19:59:05 +07:00
|
|
|
}
|
|
|
|
|
2021-01-05 18:22:41 +07:00
|
|
|
# Function to disable an extension.
|
|
|
|
disable_extension() {
|
2020-01-26 02:34:09 +07:00
|
|
|
extension=$1
|
2021-02-19 15:00:02 +07:00
|
|
|
sudo sed -Ei "/=(.*\/)?\"?$extension(.so)?$/d" "${ini_file[@]}"
|
|
|
|
sudo sed -Ei "/=(.*\/)?\"?$extension(.so)?$/d" "$pecl_file"
|
2021-01-05 18:22:41 +07:00
|
|
|
sudo find "$ini_dir"/.. -name "*$extension.ini" -delete >/dev/null 2>&1 || true
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to delete an extension.
|
|
|
|
delete_extension() {
|
|
|
|
extension=$1
|
|
|
|
disable_extension "$extension"
|
|
|
|
sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
|
2021-05-28 09:28:36 +07:00
|
|
|
sudo sed -i "/Package: php$version-$extension/,/^$/d" /var/lib/dpkg/status
|
2020-01-26 02:34:09 +07:00
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to disable and delete extensions.
|
2019-12-26 20:01:18 +07:00
|
|
|
remove_extension() {
|
|
|
|
extension=$1
|
2020-05-07 04:57:00 +07:00
|
|
|
if check_extension "$extension"; then
|
2020-11-08 14:36:21 +07:00
|
|
|
if [[ ! "$version" =~ ${old_versions:?} ]] && [ -e /etc/php/"$version"/mods-available/"$extension".ini ]; then
|
2020-05-07 04:57:00 +07:00
|
|
|
sudo phpdismod -v "$version" "$extension" >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
delete_extension "$extension"
|
2020-11-08 14:36:21 +07:00
|
|
|
(! check_extension "$extension" && add_log "${tick:?}" ":$extension" "Removed") ||
|
|
|
|
add_log "${cross:?}" ":$extension" "Could not remove $extension on PHP ${semver:?}"
|
2020-05-07 04:57:00 +07:00
|
|
|
else
|
2020-11-15 20:22:43 +07:00
|
|
|
delete_extension "$extension"
|
2020-11-08 14:36:21 +07:00
|
|
|
add_log "${tick:?}" ":$extension" "Could not find $extension on PHP $semver"
|
2020-03-05 07:28:24 +07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-10-08 18:57:52 +07:00
|
|
|
# Function to add PDO extension.
|
2020-03-05 07:28:24 +07:00
|
|
|
add_pdo_extension() {
|
|
|
|
pdo_ext="pdo_$1"
|
|
|
|
if check_extension "$pdo_ext"; then
|
2020-11-08 14:36:21 +07:00
|
|
|
add_log "${tick:?}" "$pdo_ext" "Enabled"
|
2020-03-05 07:28:24 +07:00
|
|
|
else
|
2020-12-02 07:20:56 +07:00
|
|
|
ext=$1
|
|
|
|
ext_name=$1
|
2021-04-03 06:43:18 +07:00
|
|
|
if [ -e "$ext_dir"/pdo.so ]; then
|
|
|
|
disable_extension pdo
|
|
|
|
echo "extension=pdo.so" | sudo tee "${ini_file[@]/php.ini/conf.d/10-pdo.ini}" >/dev/null 2>&1
|
|
|
|
fi
|
2020-03-05 07:28:24 +07:00
|
|
|
if [ "$ext" = "mysql" ]; then
|
|
|
|
enable_extension "mysqlnd" "extension"
|
2021-02-19 15:00:02 +07:00
|
|
|
ext_name='mysqli'
|
|
|
|
elif [ "$ext" = "dblib" ]; then
|
|
|
|
ext_name="sybase"
|
|
|
|
elif [ "$ext" = "firebird" ]; then
|
|
|
|
install_packages libfbclient2 >/dev/null 2>&1
|
|
|
|
enable_extension "pdo_firebird" "extension"
|
|
|
|
ext_name="interbase"
|
2020-05-17 12:49:52 +07:00
|
|
|
elif [ "$ext" = "sqlite" ]; then
|
2020-12-02 07:20:56 +07:00
|
|
|
ext="sqlite3"
|
|
|
|
ext_name="sqlite3"
|
2020-03-05 07:28:24 +07:00
|
|
|
fi
|
2020-11-08 14:36:21 +07:00
|
|
|
add_extension "$ext_name" "extension" >/dev/null 2>&1
|
|
|
|
add_extension "$pdo_ext" "extension" >/dev/null 2>&1
|
2020-07-26 17:18:19 +07:00
|
|
|
add_extension_log "$pdo_ext" "Enabled"
|
2020-03-05 07:28:24 +07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to add extensions.
|
2020-02-23 20:30:40 +07:00
|
|
|
add_extension() {
|
|
|
|
extension=$1
|
2020-11-08 14:36:21 +07:00
|
|
|
prefix=$2
|
2020-03-05 07:28:24 +07:00
|
|
|
enable_extension "$extension" "$prefix"
|
|
|
|
if check_extension "$extension"; then
|
2020-11-08 14:36:21 +07:00
|
|
|
add_log "${tick:?}" "$extension" "Enabled"
|
2020-03-05 07:28:24 +07:00
|
|
|
else
|
2021-04-03 17:21:47 +07:00
|
|
|
if [[ "$version" =~ ${nightly_versions:?} ]]; then
|
2020-10-28 23:51:08 +07:00
|
|
|
pecl_install "$extension"
|
|
|
|
else
|
2020-11-08 14:36:21 +07:00
|
|
|
install_packages "php$version-$extension" || pecl_install "$extension"
|
2020-10-28 23:51:08 +07:00
|
|
|
fi
|
2020-07-26 17:18:19 +07:00
|
|
|
add_extension_log "$extension" "Installed and enabled"
|
2020-02-23 20:30:40 +07:00
|
|
|
fi
|
2020-12-02 07:20:56 +07:00
|
|
|
sudo chmod 777 "${ini_file[@]}"
|
2020-02-23 20:30:40 +07:00
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to setup phpize and php-config.
|
2020-01-17 14:28:28 +07:00
|
|
|
add_devtools() {
|
2020-09-28 12:28:02 +07:00
|
|
|
tool=$1
|
2020-11-08 14:36:21 +07:00
|
|
|
if ! command -v "$tool$version" >/dev/null; then
|
|
|
|
install_packages "php$version-dev" "php$version-xml"
|
2020-01-17 14:28:28 +07:00
|
|
|
fi
|
2021-04-03 06:43:18 +07:00
|
|
|
switch_version "phpize" "php-config"
|
2020-11-08 14:36:21 +07:00
|
|
|
add_log "${tick:?}" "$tool" "Added $tool $semver"
|
2020-01-17 14:28:28 +07:00
|
|
|
}
|
|
|
|
|
2020-10-12 20:03:13 +07:00
|
|
|
# Function to setup the nightly build from shivammathur/php-builder
|
|
|
|
setup_nightly() {
|
2021-08-10 03:07:46 +07:00
|
|
|
run_script "php-builder" "${runner:?}" "$version"
|
2019-12-19 12:59:27 +07:00
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to setup PHP 5.3, PHP 5.4 and PHP 5.5.
|
2020-02-09 05:38:48 +07:00
|
|
|
setup_old_versions() {
|
2020-11-11 03:53:45 +07:00
|
|
|
run_script "php5-ubuntu" "$version"
|
2020-02-09 05:38:48 +07:00
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to add PECL.
|
2019-12-27 08:26:49 +07:00
|
|
|
add_pecl() {
|
2020-09-28 12:28:02 +07:00
|
|
|
add_devtools phpize >/dev/null 2>&1
|
2020-11-08 14:36:21 +07:00
|
|
|
if ! command -v pecl >/dev/null; then
|
|
|
|
install_packages php-pear
|
2020-01-30 13:33:30 +07:00
|
|
|
fi
|
2020-05-27 17:53:52 +07:00
|
|
|
configure_pecl >/dev/null 2>&1
|
2020-09-28 12:28:02 +07:00
|
|
|
pecl_version=$(get_tool_version "pecl" "version")
|
2020-11-08 14:36:21 +07:00
|
|
|
add_log "${tick:?}" "PECL" "Added PECL $pecl_version"
|
2019-12-20 19:59:05 +07:00
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to switch versions of PHP binaries.
|
2019-12-20 19:59:05 +07:00
|
|
|
switch_version() {
|
2021-04-03 06:43:18 +07:00
|
|
|
tools=("$@") && ! (( ${#tools[@]} )) && tools+=(pear pecl php phar phar.phar php-cgi php-config phpize phpdbg)
|
|
|
|
to_wait=()
|
|
|
|
for tool in "${tools[@]}"; do
|
2019-12-20 19:59:05 +07:00
|
|
|
if [ -e "/usr/bin/$tool$version" ]; then
|
2021-04-03 06:43:18 +07:00
|
|
|
sudo update-alternatives --set "$tool" /usr/bin/"$tool$version" &
|
2020-12-02 07:20:56 +07:00
|
|
|
to_wait+=($!)
|
2019-12-20 19:59:05 +07:00
|
|
|
fi
|
|
|
|
done
|
2020-11-08 14:36:21 +07:00
|
|
|
wait "${to_wait[@]}"
|
2020-02-21 09:28:19 +07:00
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to install packaged PHP
|
|
|
|
add_packaged_php() {
|
2020-07-22 13:10:30 +07:00
|
|
|
if [ "$runner" = "self-hosted" ] || [ "${use_package_cache:-true}" = "false" ]; then
|
|
|
|
update_lists
|
2020-11-08 14:36:21 +07:00
|
|
|
IFS=' ' read -r -a packages <<<"$(echo "cli curl mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")"
|
2021-08-10 03:07:46 +07:00
|
|
|
install_packages "${packages[@]}"
|
2020-07-22 13:10:30 +07:00
|
|
|
else
|
2020-11-11 03:53:45 +07:00
|
|
|
run_script "php-ubuntu" "$version"
|
2020-07-22 13:10:30 +07:00
|
|
|
fi
|
2020-05-27 17:53:52 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to update PHP.
|
2020-02-21 09:28:19 +07:00
|
|
|
update_php() {
|
|
|
|
initial_version=$(php_semver)
|
2021-03-06 01:04:26 +07:00
|
|
|
add_packaged_php
|
2020-02-21 09:28:19 +07:00
|
|
|
updated_version=$(php_semver)
|
|
|
|
if [ "$updated_version" != "$initial_version" ]; then
|
|
|
|
status="Updated to"
|
|
|
|
else
|
|
|
|
status="Switched to"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to install PHP.
|
|
|
|
add_php() {
|
2020-11-08 14:36:21 +07:00
|
|
|
if [[ "$version" =~ ${nightly_versions:?} ]]; then
|
2020-10-12 20:03:13 +07:00
|
|
|
setup_nightly
|
2020-11-08 14:36:21 +07:00
|
|
|
elif [[ "$version" =~ ${old_versions:?} ]]; then
|
2020-05-27 17:53:52 +07:00
|
|
|
setup_old_versions
|
|
|
|
else
|
|
|
|
add_packaged_php
|
|
|
|
fi
|
|
|
|
status="Installed"
|
|
|
|
}
|
|
|
|
|
2020-12-02 07:20:56 +07:00
|
|
|
# Function to ini file for pear and link it to each SAPI.
|
|
|
|
link_pecl_file() {
|
|
|
|
echo '' | sudo tee "$pecl_file" >/dev/null 2>&1
|
|
|
|
for file in "${ini_file[@]}"; do
|
|
|
|
sapi_scan_dir="$(realpath -m "$(dirname "$file")")/conf.d"
|
|
|
|
[ "$sapi_scan_dir" != "$scan_dir" ] && ! [ -h "$sapi_scan_dir" ] && sudo ln -sf "$pecl_file" "$sapi_scan_dir/99-pecl.ini"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-07-12 18:30:40 +07:00
|
|
|
# Function to get extra version.
|
|
|
|
php_extra_version() {
|
|
|
|
if [[ ${version:?} =~ ${nightly_versions:?} ]]; then
|
|
|
|
echo " ($(cat "/etc/php/$version/COMMIT"))"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-11-08 14:36:21 +07:00
|
|
|
# Function to Setup PHP
|
|
|
|
setup_php() {
|
|
|
|
step_log "Setup PHP"
|
|
|
|
sudo mkdir -m 777 -p /var/run /run/php
|
|
|
|
if [ "$(php-config --version 2>/dev/null | cut -c 1-3)" != "$version" ]; then
|
|
|
|
if [ ! -e "/usr/bin/php$version" ]; then
|
|
|
|
add_php >/dev/null 2>&1
|
|
|
|
else
|
|
|
|
if [ "${update:?}" = "true" ]; then
|
|
|
|
update_php >/dev/null 2>&1
|
|
|
|
else
|
|
|
|
status="Switched to"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if ! [[ "$version" =~ ${old_versions:?}|${nightly_versions:?} ]]; then
|
|
|
|
switch_version >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ "$update" = "true" ]; then
|
|
|
|
update_php >/dev/null 2>&1
|
|
|
|
else
|
|
|
|
status="Found"
|
|
|
|
fi
|
|
|
|
fi
|
2020-12-17 05:50:39 +07:00
|
|
|
if ! command -v php"$version" >/dev/null; then
|
|
|
|
add_log "$cross" "PHP" "Could not setup PHP $version"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-11-08 14:36:21 +07:00
|
|
|
semver=$(php_semver)
|
2021-07-12 18:30:40 +07:00
|
|
|
extra_version=$(php_extra_version)
|
2020-11-08 14:36:21 +07:00
|
|
|
ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||")
|
|
|
|
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
|
2020-12-02 07:20:56 +07:00
|
|
|
ini_dir=$(php --ini | grep "(php.ini)" | sed -e "s|.*: s*||")
|
2020-11-08 14:36:21 +07:00
|
|
|
pecl_file="$scan_dir"/99-pecl.ini
|
2020-12-02 07:20:56 +07:00
|
|
|
mapfile -t ini_file < <(sudo find "$ini_dir/.." -name "php.ini" -exec readlink -m {} +)
|
|
|
|
link_pecl_file
|
2020-12-17 22:19:20 +07:00
|
|
|
configure_php
|
2020-11-08 14:36:21 +07:00
|
|
|
sudo rm -rf /usr/local/bin/phpunit >/dev/null 2>&1
|
2020-12-02 07:20:56 +07:00
|
|
|
sudo chmod 777 "${ini_file[@]}" "$pecl_file" "${tool_path_dir:?}"
|
2020-11-08 14:36:21 +07:00
|
|
|
sudo cp "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/"
|
2021-07-12 18:30:40 +07:00
|
|
|
echo "::set-output name=php-version::$semver"
|
2021-03-14 00:00:13 +07:00
|
|
|
add_log "${tick:?}" "PHP" "$status PHP $semver$extra_version"
|
2020-11-08 14:36:21 +07:00
|
|
|
}
|
|
|
|
|
2019-12-20 19:59:05 +07:00
|
|
|
# Variables
|
|
|
|
version=$1
|
2020-10-05 07:45:50 +07:00
|
|
|
dist=$2
|
2020-02-14 00:09:00 +07:00
|
|
|
debconf_fix="DEBIAN_FRONTEND=noninteractive"
|
2021-07-28 23:57:37 +07:00
|
|
|
apt_install="sudo $debconf_fix apt-fast install -y --no-install-recommends"
|
2021-02-20 11:45:25 +07:00
|
|
|
scripts="${dist}"/../src/scripts
|
2019-12-20 19:59:05 +07:00
|
|
|
|
2021-07-28 01:00:00 +07:00
|
|
|
. /etc/os-release
|
2020-11-08 14:36:21 +07:00
|
|
|
# shellcheck source=.
|
2021-03-17 10:16:13 +07:00
|
|
|
. "${scripts:?}"/ext/source.sh
|
2021-08-10 03:07:46 +07:00
|
|
|
. "${scripts:?}"/tools/ppa.sh
|
2021-02-20 11:45:25 +07:00
|
|
|
. "${scripts:?}"/tools/add_tools.sh
|
|
|
|
. "${scripts:?}"/common.sh
|
2020-05-27 17:53:52 +07:00
|
|
|
read_env
|
2020-11-08 14:36:21 +07:00
|
|
|
self_hosted_setup
|
|
|
|
setup_php
|