#!/bin/bash # ============================================================================= # YUNOHOST 2.7 FORTHCOMING HELPERS # ============================================================================= # Create a dedicated php-fpm config # # usage: ynh_add_fpm_config ynh_add_fpm7.1_config () { # Configure PHP-FPM 7.1 by default local fpm_config_dir="/etc/php/7.1/fpm" local fpm_service="php7.1-fpm" ynh_app_setting_set $app fpm_config_dir "$fpm_config_dir" ynh_app_setting_set $app fpm_service "$fpm_service" finalphpconf="$fpm_config_dir/pool.d/$app.conf" ynh_backup_if_checksum_is_different "$finalphpconf" sudo cp ../conf/php-fpm.conf "$finalphpconf" ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf" ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf" ynh_replace_string "__USER__" "$app" "$finalphpconf" sudo chown root: "$finalphpconf" ynh_store_file_checksum "$finalphpconf" if [ -e "../conf/php-fpm.ini" ] then finalphpini="$fpm_config_dir/conf.d/20-$app.ini" ynh_backup_if_checksum_is_different "$finalphpini" sudo cp ../conf/php-fpm.ini "$finalphpini" sudo chown root: "$finalphpini" ynh_store_file_checksum "$finalphpini" fi sudo systemctl reload $fpm_service } # Remove the dedicated php-fpm config # # usage: ynh_remove_fpm7.1_config ynh_remove_fpm7.1_config () { local fpm_config_dir=$(ynh_app_setting_get $app fpm_config_dir) local fpm_service=$(ynh_app_setting_get $app fpm_service) ynh_secure_remove "$fpm_config_dir/pool.d/$app.conf" ynh_secure_remove "$fpm_config_dir/conf.d/20-$app.ini" 2>&1 sudo systemctl reload $fpm_service } # Execute a command as another user # usage: exec_as USER COMMAND [ARG ...] exec_as() { local USER=$1 shift 1 if [[ $USER = $(whoami) ]]; then eval $@ else # use sudo twice to be root and be allowed to use another user sudo sudo -u "$USER" $@ fi } # # Composer helpers # # Execute a composer command from a given directory # usage: composer_exec AS_USER WORKDIR COMMAND [ARG ...] exec_composer() { local WORKDIR=$1 shift 1 COMPOSER_HOME="${WORKDIR}/.composer" \ sudo /usr/bin/php7.1 "${WORKDIR}/composer.phar" $@ \ -d "${WORKDIR}" --quiet --no-interaction } # Install and initialize Composer in the given directory # usage: init_composer DESTDIR [AS_USER] init_composer() { local DESTDIR=$1 local AS_USER=${2:-admin} # install composer curl -sS https://getcomposer.org/installer \ | COMPOSER_HOME="${DESTDIR}/.composer" \ sudo /usr/bin/php7.1 -- --quiet --install-dir="$DESTDIR" \ || ynh_die "Unable to install Composer" # update dependencies to create composer.lock exec_composer "$DESTDIR" install --quiet --no-dev --prefer-dist \ || ynh_die "Unable to update monica core dependencies" } sudo_path () { sudo env "PATH=$PATH" $@ } # # PHP7 helpers # ynh_install_php7 () { ynh_package_update ynh_package_install apt-transport-https --no-install-recommends wget -q -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php7.list ynh_package_update ynh_install_app_dependencies php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl php7.1-bcmath sudo update-alternatives --install /usr/bin/php php /usr/bin/php5 70 } ynh_remove_php7 () { sudo rm -f /etc/apt/sources.list.d/php7.list sudo apt-key del 4096R/89DF5277 sudo apt-key del 2048R/11A06851 ynh_remove_app_dependencies php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl php7.1-bcmath }