1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dotclear2_ynh.git synced 2024-09-03 18:26:29 +02:00
dotclear2_ynh/scripts/config

117 lines
4.5 KiB
Text
Raw Normal View History

2023-10-11 22:55:00 +02:00
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
ynh_abort_if_errors
2023-10-11 23:30:47 +02:00
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
admin=$(ynh_app_setting_get --app=$app --key=admin)
2023-10-12 00:59:42 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path=$(ynh_app_setting_get --app=$app --key=path)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
2023-10-11 23:30:47 +02:00
2023-10-11 22:55:00 +02:00
#=================================================
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================
set__blogs_list() {
declare -A domain_array
declare -A path_array
2023-10-12 00:59:42 +02:00
default_present=false
2023-10-11 22:55:00 +02:00
for blog in $(echo $blogs_list | sed "s/,/ /"); do
id=$(echo $blog | cut -d@ -f1)
2023-10-12 00:59:42 +02:00
d=$(echo $blog | cut -d@ -f2 | cut -d/ -f1)
p="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)"
[ $id = "default" ] && default_present=true
2023-10-11 22:55:00 +02:00
2023-10-12 00:59:42 +02:00
domain_array+=([$id]=$d)
path_array+=([$id]=$p)
2023-10-11 22:55:00 +02:00
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)
2023-10-12 00:59:42 +02:00
d=$(echo $blog | cut -d@ -f2 | cut -d/ -f1)
p="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)"
2023-10-11 22:55:00 +02:00
2023-10-12 00:59:42 +02:00
old_domain_array+=([$id]=$d)
old_path_array+=([$id]=$p)
2023-10-11 22:55:00 +02:00
done
2023-10-12 00:59:42 +02:00
# Make sure the default blog is always listed
domain_array+=(["default"]=$domain)
path_array+=(["default"]=$path)
old_domain_array+=(["default"]=$domain)
old_path_array+=(["default"]=$path)
if [ $default_present = false ]; then
if [ -z ${blogs_list:-} ]; then
blogs_list="default@$domain$path"
else
blogs_list+=",default@$domain$path"
fi
fi
2023-10-11 22:55:00 +02:00
# https://stackoverflow.com/questions/2312762/compare-difference-of-two-arrays-in-bash
# Get added and removed blogs
2023-10-12 23:25:50 +02:00
difference_ids_array=(`echo ${!domain_array[@]} ${!old_domain_array[@]} | tr ' ' '\n' | sort | uniq -u `)
added_ids_array=(`echo ${!domain_array[@]} ${difference_ids_array[@]} | tr ' ' '\n' | sort | uniq -D | uniq `)
removed_ids_array=(`echo ${!old_domain_array[@]} ${difference_ids_array[@]} | tr ' ' '\n' | sort | uniq -D | uniq `)
2023-10-12 00:59:42 +02:00
ynh_print_info --message="Added blogs: ${added_ids_array[@]}"
ynh_print_info --message="Removed blogs: ${removed_ids_array[@]}"
2023-10-12 23:25:50 +02:00
2023-10-12 00:59:42 +02:00
for id in ${removed_ids_array[@]}; do
if [ $id != "default" ]; then
if ynh_permission_exists --permission="$id"; then
ynh_permission_delete --permission="$id"
fi
if ynh_permission_exists --permission="${id}-admin"; then
ynh_permission_delete --permission="${id}-admin"
fi
2023-10-12 00:59:42 +02:00
ynh_secure_remove --file="/etc/nginx/conf.d/${old_domain_array[$id]}.d/$app-$id.conf"
2023-10-11 22:55:00 +02:00
fi
done
2023-10-12 00:59:42 +02:00
for id in ${!domain_array[@]}; do
if [ $id != "default" ]; then
2023-10-12 23:25:50 +02:00
if [ "${domain_array[$id]:-}" != "${old_domain_array[$id]:-}" ] ||
[ "${path_array[$id]:-}" != "${old_path_array[$id]:-}" ]; then
2023-10-12 00:59:42 +02:00
domain=${domain_array[$id]}
path=${path_array[$id]}
blog_id=$id
2023-10-12 00:59:42 +02:00
[ ! -z ${old_domain_array[$id]:-} ] && ynh_secure_remove --file="/etc/nginx/conf.d/${old_domain_array[$id]}.d/$app-$id.conf"
ynh_add_config --template="nginx.conf" --destination="/etc/nginx/conf.d/${domain_array[$id]}.d/$app-$id.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]}" --show_tile=true --allowed=visitors all_users
ynh_permission_create --permission="${id}-admin" --url="${domain_array[$id]}${path_array[$id]}/admin" --show_tile=false --allowed=admins
2023-10-12 00:59:42 +02:00
fi
2023-10-11 22:55:00 +02:00
fi
done
ynh_app_setting_set $app blogs_list $blogs_list
}
2023-10-11 23:30:47 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
ynh_app_config_run $1