1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/firefly-iii_ynh.git synced 2024-09-03 18:36:13 +02:00
firefly-iii_ynh/scripts/_common.sh

130 lines
3.9 KiB
Bash
Raw Normal View History

2018-06-17 00:50:26 +02:00
#!/bin/bash
# ============= FUTURE YUNOHOST HELPER =============
# Delete a file checksum from the app settings
#
# $app should be defined when calling this helper
#
# usage: ynh_remove_file_checksum file
# | arg: file - The file for which the checksum will be deleted
ynh_delete_file_checksum () {
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
ynh_app_setting_delete $app $checksum_setting_name
}
# Create a dedicated php-fpm config
#
# usage: ynh_add_fpm_config
2018-10-08 05:16:13 +02:00
ynh_add_fpm7.2_config () {
2018-06-17 00:50:26 +02:00
# Configure PHP-FPM 7.1 by default
2018-10-08 05:16:13 +02:00
local fpm_config_dir="/etc/php/7.2/fpm"
local fpm_service="php7.2-fpm"
2018-06-17 00:50:26 +02:00
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
2018-10-08 05:16:13 +02:00
ynh_remove_fpm7.2_config () {
2018-06-17 00:50:26 +02:00
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" \
2018-10-08 05:16:13 +02:00
sudo /usr/bin/php7.2 "${WORKDIR}/composer.phar" $@ \
2018-06-17 00:50:26 +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" \
2018-10-08 05:16:13 +02:00
sudo /usr/bin/php7.2 -- --quiet --install-dir="$DESTDIR" \
2018-06-17 00:50:26 +02:00
|| ynh_die "Unable to install Composer"
# update dependencies to create composer.lock
2018-06-17 06:32:42 +02:00
exec_composer "$DESTDIR" install --no-dev --prefer-dist --no-scripts \
2018-06-17 00:50:26 +02:00
|| ynh_die "Unable to update firefly-iii 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
2018-10-08 05:16:13 +02:00
ynh_install_app_dependencies php7.2 php7.2-zip php7.2-fpm php7.2-mysql php7.2-xml php7.2-intl php7.2-mbstring php7.2-gd php7.2-curl php7.2-bcmath php7.2-opcache
2018-06-17 00:50:26 +02:00
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
2018-10-08 05:16:13 +02:00
ynh_remove_app_dependencies php7.2 php7.2-zip php7.2-fpm php7.2-mysql php7.2-xml php7.2-intl php7.2-mbstring php7.2-gd php7.2-curl php7.2-bcmath php7.2-opcache
2018-06-17 00:50:26 +02:00
}