1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/monica_ynh.git synced 2024-09-03 19:46:23 +02:00
monica_ynh/scripts/_common.sh

122 lines
3.6 KiB
Bash
Raw Normal View History

2017-09-15 18:45:18 +02:00
#!/bin/bash
2017-06-08 13:32:01 +02:00
2017-09-15 18:45:18 +02:00
# =============================================================================
# YUNOHOST 2.7 FORTHCOMING HELPERS
# =============================================================================
2017-06-08 13:32:01 +02:00
2017-09-15 18:45:18 +02:00
# Create a dedicated php-fpm config
2017-06-08 13:32:01 +02:00
#
2017-09-15 18:45:18 +02:00
# 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"
2017-09-15 18:45:18 +02:00
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"
2017-09-15 18:45:18 +02:00
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
2017-09-15 18:45:18 +02:00
}
2017-06-14 22:16:25 +02:00
2017-09-15 18:45:18 +02:00
# 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
2017-06-14 22:16:25 +02:00
}
2017-06-08 13:32:01 +02:00
2017-09-15 18:45:18 +02:00
2017-06-08 13:32:01 +02:00
# 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
}
2017-06-14 20:48:24 +02:00
#
# Composer helpers
#
2017-06-08 13:32:01 +02:00
# 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" \
2017-09-15 18:45:18 +02:00
sudo /usr/bin/php7.1 "${WORKDIR}/composer.phar" $@ \
2017-06-08 13:32:01 +02:00
-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" \
2017-09-15 18:45:18 +02:00
sudo /usr/bin/php7.1 -- --quiet --install-dir="$DESTDIR" \
2017-06-08 13:32:01 +02:00
|| ynh_die "Unable to install Composer"
# update dependencies to create composer.lock
2017-07-17 21:48:01 +02:00
exec_composer "$DESTDIR" install --quiet --no-dev --prefer-dist \
2017-06-08 13:32:01 +02:00
|| ynh_die "Unable to update monica core dependencies"
}
sudo_path () {
sudo env "PATH=$PATH" $@
}
2017-06-14 20:48:24 +02:00
#
# PHP7 helpers
#
2017-06-13 22:18:05 +02:00
ynh_install_php7 () {
2017-06-18 21:36:49 +02:00
ynh_package_update
ynh_package_install apt-transport-https --no-install-recommends
2017-09-15 18:45:18 +02:00
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
2017-06-14 22:16:25 +02:00
2017-06-13 22:18:05 +02:00
ynh_package_update
2017-09-20 21:24:47 +02:00
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
2017-06-13 22:18:05 +02:00
sudo update-alternatives --install /usr/bin/php php /usr/bin/php5 70
}
ynh_remove_php7 () {
2017-06-14 22:16:25 +02:00
sudo rm -f /etc/apt/sources.list.d/php7.list
2017-06-13 22:18:05 +02:00
sudo apt-key del 4096R/89DF5277
2017-06-14 22:16:25 +02:00
sudo apt-key del 2048R/11A06851
2017-09-20 21:24:47 +02:00
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
2017-06-13 22:18:05 +02:00
}