mirror of
https://github.com/YunoHost-Apps/dotclear2_ynh.git
synced 2024-09-03 18:26:29 +02:00
Better handle defautl blog
This commit is contained in:
parent
69beb13e96
commit
35386e0855
3 changed files with 56 additions and 33 deletions
|
@ -16,6 +16,8 @@ ynh_abort_if_errors
|
||||||
|
|
||||||
install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
|
install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
|
||||||
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
||||||
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
|
path=$(ynh_app_setting_get --app=$app --key=path)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
||||||
|
@ -25,13 +27,15 @@ set__blogs_list() {
|
||||||
declare -A domain_array
|
declare -A domain_array
|
||||||
declare -A path_array
|
declare -A path_array
|
||||||
|
|
||||||
|
default_present=false
|
||||||
for blog in $(echo $blogs_list | sed "s/,/ /"); do
|
for blog in $(echo $blogs_list | sed "s/,/ /"); do
|
||||||
id=$(echo $blog | cut -d@ -f1)
|
id=$(echo $blog | cut -d@ -f1)
|
||||||
domain=$(echo $blog | cut -d@ -f2 | cut -d/ -f1)
|
d=$(echo $blog | cut -d@ -f2 | cut -d/ -f1)
|
||||||
path="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)"
|
p="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)"
|
||||||
|
[ $id = "default" ] && default_present=true
|
||||||
|
|
||||||
domain_array+=([$id]=$domain)
|
domain_array+=([$id]=$d)
|
||||||
path_array+=([$id]=$path)
|
path_array+=([$id]=$p)
|
||||||
done
|
done
|
||||||
|
|
||||||
declare -A old_domain_array
|
declare -A old_domain_array
|
||||||
|
@ -39,43 +43,62 @@ set__blogs_list() {
|
||||||
|
|
||||||
for blog in $(echo ${old[blogs_list]} | sed "s/,/ /"); do
|
for blog in $(echo ${old[blogs_list]} | sed "s/,/ /"); do
|
||||||
id=$(echo $blog | cut -d@ -f1)
|
id=$(echo $blog | cut -d@ -f1)
|
||||||
domain=$(echo $blog | cut -d@ -f2 | cut -d/ -f1)
|
d=$(echo $blog | cut -d@ -f2 | cut -d/ -f1)
|
||||||
path="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)"
|
p="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)"
|
||||||
|
|
||||||
old_domain_array+=([$id]=$domain)
|
old_domain_array+=([$id]=$d)
|
||||||
old_path_array+=([$id]=$path)
|
old_path_array+=([$id]=$p)
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
# https://stackoverflow.com/questions/2312762/compare-difference-of-two-arrays-in-bash
|
# https://stackoverflow.com/questions/2312762/compare-difference-of-two-arrays-in-bash
|
||||||
# Get added and removed blogs
|
# Get added and removed blogs
|
||||||
added_ids_array=(`echo ${!domain_array[@]} ${!old_domain_array[@]} | tr ' ' '\n' | sort | uniq -u `)
|
added_ids_array=()
|
||||||
removed_ids_array=(`echo ${!old_domain_array[@]} ${!domain_array[@]} | tr ' ' '\n' | sort | uniq -D | uniq `)
|
added_ids_array+=(`echo ${!domain_array[@]} ${!old_domain_array[@]} | tr ' ' '\n' | sort | uniq -u `)
|
||||||
|
removed_ids_array=()
|
||||||
|
removed_ids_array+=(`echo ${!domain_array[@]} ${!old_domain_array[@]} | tr ' ' '\n' | sort | uniq -D | uniq `)
|
||||||
|
|
||||||
for id in $removed_ids_array; do
|
ynh_print_info --message="Added blogs: ${added_ids_array[@]}"
|
||||||
if [ ynh_permission_exists --permission="$id" ]; then
|
ynh_print_info --message="Removed blogs: ${removed_ids_array[@]}"
|
||||||
ynh_permission_delete --permission="$id"
|
|
||||||
|
for id in ${removed_ids_array[@]}; do
|
||||||
|
if [ $id != "default" ]; then
|
||||||
|
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-$id.conf"
|
||||||
fi
|
fi
|
||||||
ynh_secure_remove --file="/etc/nginx/conf.d/${old_domain_array[$id]}.d/$app.conf"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
for id in $domain_array; do
|
for id in ${!domain_array[@]}; do
|
||||||
|
if [ $id != "default" ]; then
|
||||||
|
if [ ${domain_array[$id]:-} != ${old_domain_array[$id]:-} ] ||
|
||||||
|
[ ${path_array[$id]:-} != ${old_path_array[$id]:-} ]; then
|
||||||
|
domain=${domain_array[$id]}
|
||||||
|
path=${path_array[$id]}
|
||||||
|
[ ! -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 [ $domain_array[$id] != $old_domain_array[$id] ]; then
|
if ynh_permission_exists --permission="$id"; then
|
||||||
mv /etc/nginx/conf.d/${old_domain_array[$id]}.d/$app.conf /etc/nginx/conf.d/${domain_array[$id]}.d/$app.conf
|
ynh_permission_url --permission="$id" --url="${domain_array[$id]}${path_array[$id]}"
|
||||||
fi
|
ynh_permission_url --permission="${id}-admin" --url="${domain_array[$id]}${path_array[$id]}/admin"
|
||||||
|
else
|
||||||
if [ $path_array[$id] != $old_path_array[$id] ]; then
|
ynh_permission_create --permission="$id" --url="${domain_array[$id]}${path_array[$id]}" --show_tile=true
|
||||||
domain=$domain_array[$id]
|
ynh_permission_create --permission="${id}-admin" --url="${domain_array[$id]}${path_array[$id]}/admin" --show_tile=true
|
||||||
path=$path_array[$id]
|
fi
|
||||||
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
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
|
@ -132,7 +132,7 @@ installUrl="/admin/install/index.php"
|
||||||
ynh_local_curl $installUrl "u_email=$email" "u_firstname=$firstname" "u_name=$lastname" "u_login=$admin" "u_pwd=$password" "u_pwd2=$password"
|
ynh_local_curl $installUrl "u_email=$email" "u_firstname=$firstname" "u_name=$lastname" "u_login=$admin" "u_pwd=$password" "u_pwd2=$password"
|
||||||
|
|
||||||
# Initializing blogs_list (excluding default)
|
# Initializing blogs_list (excluding default)
|
||||||
ynh_app_setting_set --app=$app --key=blogs_list --value=""
|
ynh_app_setting_set --app=$app --key=blogs_list --value="default@$domain$path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
|
|
|
@ -57,7 +57,7 @@ fi
|
||||||
|
|
||||||
if [ -z "$blogs_list" ]; then
|
if [ -z "$blogs_list" ]; then
|
||||||
# Initializing blogs_list (excluding default)
|
# Initializing blogs_list (excluding default)
|
||||||
ynh_app_setting_set --app=$app --key=blogs_list --value=""
|
ynh_app_setting_set --app=$app --key=blogs_list --value="default@$domain$path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Add table
Reference in a new issue