mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
68 lines
1.6 KiB
Bash
68 lines
1.6 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
force=$1
|
|
|
|
function safe_copy () {
|
|
if [[ "$force" == "True" ]]; then
|
|
sudo yunohost service safecopy \
|
|
-s nginx \
|
|
$1 $2 \
|
|
--force
|
|
else
|
|
sudo yunohost service safecopy \
|
|
-s nginx \
|
|
$1 $2
|
|
fi
|
|
}
|
|
|
|
cd /usr/share/yunohost/templates/nginx
|
|
|
|
# Copy plain single configuration files
|
|
files="ssowat.conf
|
|
yunohost_admin.conf
|
|
yunohost_admin.conf.inc
|
|
yunohost_api.conf.inc
|
|
yunohost_panel.conf.inc"
|
|
|
|
for file in $files; do
|
|
safe_copy $file /etc/nginx/conf.d/$file
|
|
done
|
|
|
|
|
|
# Copy 'yunohost.local' to the main domain conf directory
|
|
main_domain=$(cat /etc/yunohost/current_host)
|
|
safe_copy yunohost_local.conf \
|
|
/etc/nginx/conf.d/$main_domain.d/yunohost_local.conf
|
|
|
|
|
|
need_restart=False
|
|
domain_list=$(sudo yunohost domain list --raw)
|
|
|
|
# Copy a configuration file for each YunoHost domain
|
|
for domain in $domain_list; do
|
|
sudo mkdir -p /etc/nginx/conf.d/$domain.d
|
|
cat server.conf.sed \
|
|
| sed "s/{{ domain }}/$domain/g" \
|
|
| sudo tee $domain.conf
|
|
if [[ $(safe_copy $domain.conf /etc/nginx/conf.d/$domain.conf) == "True" ]]; then
|
|
need_restart=True
|
|
fi
|
|
done
|
|
|
|
# Remove old domains files
|
|
for file in /etc/nginx/conf.d/*.*.conf; do
|
|
domain=$(echo $file \
|
|
| sed 's|/etc/nginx/conf.d/||' \
|
|
| sed 's|.conf||')
|
|
[[ $domain_list =~ $domain ]] \
|
|
|| ($(sudo yunohost service saferemove -s nginx $file) == "True" \
|
|
&& (rm -r /etc/nginx/conf.d/$domain.d || true))
|
|
done
|
|
|
|
# Restart if need be
|
|
if [[ "$need_restart" == "True" ]]; then
|
|
sudo service nginx restart
|
|
else
|
|
sudo service nginx reload
|
|
fi
|