mirror of
https://github.com/YunoHost-Apps/dotclear2_ynh.git
synced 2024-09-03 18:26:29 +02:00
158 lines
5.1 KiB
Bash
158 lines
5.1 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC STARTING
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS
|
|
#=================================================
|
|
|
|
install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
|
current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
|
|
|
|
#=================================================
|
|
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
|
#=================================================
|
|
|
|
get__fpm_footprint() {
|
|
# Free footprint value for php-fpm
|
|
# Check if current_fpm_footprint is an integer
|
|
if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null
|
|
then
|
|
echo "specific"
|
|
else
|
|
echo "$current_fpm_footprint"
|
|
fi
|
|
}
|
|
|
|
get__free_footprint() {
|
|
# Free footprint value for php-fpm
|
|
# Check if current_fpm_footprint is an integer
|
|
if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null
|
|
then
|
|
# If current_fpm_footprint is an integer, that's a numeric value for the footprint
|
|
echo "$current_fpm_footprint"
|
|
else
|
|
echo "0"
|
|
fi
|
|
}
|
|
|
|
#=================================================
|
|
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
|
#=================================================
|
|
set__blogs_list() {
|
|
|
|
declare -A domain_array
|
|
declare -A path_array
|
|
|
|
for blog in $(echo $blogs_list | sed "s/,/ /"); do
|
|
id=$(echo $blog | cut -d@ -f1)
|
|
domain=$(echo $blog | cut -d@ -f2 | cut -d/ -f1)
|
|
path="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)"
|
|
|
|
domain_array+=([$id]=$domain)
|
|
path_array+=([$id]=$path)
|
|
done
|
|
|
|
declare -A old_domain_array
|
|
declare -A old_path_array
|
|
|
|
for blog in $(echo ${old[blogs_list]} | sed "s/,/ /"); do
|
|
id=$(echo $blog | cut -d@ -f1)
|
|
domain=$(echo $blog | cut -d@ -f2 | cut -d/ -f1)
|
|
path="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)"
|
|
|
|
old_domain_array+=([$id]=$domain)
|
|
old_path_array+=([$id]=$path)
|
|
done
|
|
|
|
# https://stackoverflow.com/questions/2312762/compare-difference-of-two-arrays-in-bash
|
|
# Get added and removed blogs
|
|
added_ids_array=(`echo ${!domain_array[@]} ${!old_domain_array[@]} | tr ' ' '\n' | sort | uniq -u `)
|
|
removed_ids_array=(`echo ${!old_domain_array[@]} $!domain_array[@]} | tr ' ' '\n' | sort | uniq -D | uniq `)
|
|
|
|
for id in $removed_ids_array; do
|
|
if [ ynh_permission_exists --permission="$id" ]; then
|
|
ynh_permission_delete --permission="$id"
|
|
fi
|
|
ynh_secure_remove --file="/etc/nginx/conf.d/${old_domain_array[$id]}.d/$app.conf"
|
|
done
|
|
|
|
for id in $domain_array; do
|
|
|
|
if [ $domain_array[$id] != $old_domain_array[$id] ]; then
|
|
mv /etc/nginx/conf.d/${old_domain_array[$id]}.d/$app.conf /etc/nginx/conf.d/${domain_array[$id]}.d/$app.conf
|
|
fi
|
|
|
|
if [ $path_array[$id] != $old_path_array[$id] ]; then
|
|
domain=$domain_array[$id]
|
|
path=$path_array[$id]
|
|
ynh_add_config --template="nginx.conf" --destination="/etc/nginx/conf.d/${domain_array[$id]}.d/$app.conf"
|
|
fi
|
|
|
|
if [ ynh_permission_exists --permission="$id" ]; then
|
|
ynh_permission_url --permission="$id" --url="$domain_array[$id]$path_array[$id]"
|
|
ynh_permission_url --permission="$id.admin" --url="$domain_array[$id]$path_array[$id]/admin"
|
|
else
|
|
ynh_permission_create --permission="$id" --url="$domain_array[$id]$path_array[$id]"
|
|
ynh_permission_create --permission="$id.admin" --url="$domain_array[$id]$path_array[$id]/admin"
|
|
fi
|
|
|
|
done
|
|
|
|
ynh_app_setting_set $app blogs_list $blogs_list
|
|
}
|
|
|
|
set__fpm_footprint() {
|
|
if [ "$fpm_footprint" != "specific" ]
|
|
then
|
|
ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint"
|
|
fi
|
|
}
|
|
|
|
set__fpm_free_footprint() {
|
|
if [ "$fpm_footprint" = "specific" ]
|
|
then
|
|
ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_free_footprint"
|
|
fi
|
|
}
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
|
|
ynh_app_config_validate() {
|
|
_ynh_app_config_validate
|
|
|
|
if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[fpm_free_footprint]}" == "true" ]; then
|
|
# If fpm_footprint is set to 'specific', use $fpm_free_footprint value.
|
|
if [ "$fpm_footprint" = "specific" ]
|
|
then
|
|
fpm_footprint=$fpm_free_footprint
|
|
fi
|
|
|
|
if [ "$fpm_footprint" == "0" ]
|
|
then
|
|
ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below."
|
|
|
|
exit 0
|
|
fi
|
|
fi
|
|
}
|
|
|
|
ynh_app_config_apply() {
|
|
_ynh_app_config_apply
|
|
|
|
ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint
|
|
}
|
|
|
|
ynh_app_config_run $1
|