#!/bin/bash # Install another version of php. # # usage: ynh_install_php --phpversion=phpversion [--package=packages] # | arg: -v, --phpversion - Version of php to install. Can be one of 7.1, 7.2 or 7.3 # | arg: -p, --package - Additionnal php packages to install ynh_install_php () { # Declare an array to define the options of this helper. local legacy_args=vp declare -Ar args_array=( [v]=phpversion= [p]=package= ) local phpversion local package # Manage arguments with getopts ynh_handle_getopts_args "$@" package=${package:-} # Store php_version into the config of this app ynh_app_setting_set $app php_version $phpversion if [ "$phpversion" == "7.0" ] then ynh_die "Do not use ynh_install_php to install php7.0" fi # Store the ID of this app and the version of php requested for it echo "$YNH_APP_INSTANCE_NAME:$phpversion" | tee --append "/etc/php/ynh_app_version" # Add an extra repository for those packages if [ ! -f "/etc/apt/sources.list.d/sury.list" ]; then ynh_install_extra_repo --repo="https://packages.sury.org/php/ $(lsb_release -sc) main" --key="https://packages.sury.org/php/apt.gpg" --priority=995 --name=extra_php_version fi # Install requested dependencies from this extra repository. # Install php-fpm first, otherwise php will install apache as a dependency. ynh_add_app_dependencies --package="php${phpversion}-fpm" ynh_add_app_dependencies --package="php$phpversion php${phpversion}-common $package" # Set php7.0 back as the default version for php-cli. update-alternatives --set php /usr/bin/php7.0 # Remove this extra repository after packages are installed if [ ! -f "/etc/apt/sources.list.d/sury.list" ]; then ynh_remove_extra_repo --name=extra_php_version fi # Advertise service in admin panel yunohost service add php${phpversion}-fpm --log "/var/log/php${phpversion}-fpm.log" } ynh_remove_php () { # Get the version of php used by this app local phpversion=$(ynh_app_setting_get $app php_version) if [ "$phpversion" == "7.0" ] || [ -z "$phpversion" ] then if [ "$phpversion" == "7.0" ] then ynh_print_err "Do not use ynh_remove_php to install php7.0" fi return 0 fi # Remove the line for this app sed --in-place "/$YNH_APP_INSTANCE_NAME:$phpversion/d" "/etc/php/ynh_app_version" # If no other app uses this version of php, remove it. if ! grep --quiet "$phpversion" "/etc/php/ynh_app_version" then # Purge php dependences for this version. ynh_package_autopurge "php$phpversion php${phpversion}-fpm php${phpversion}-common" # Remove the service from the admin panel yunohost service remove php${phpversion}-fpm fi # If no other app uses alternate php versions, remove the extra repo for php if [ ! -s "/etc/php/ynh_app_version" ] then ynh_secure_remove /etc/php/ynh_app_version fi }