mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
100 lines
2.1 KiB
Bash
Executable file
100 lines
2.1 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
do_init_regen() {
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "You must be root to run this script" 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
do_pre_regen ""
|
|
}
|
|
|
|
do_pre_regen() {
|
|
pending_dir=$1
|
|
|
|
cd /usr/share/yunohost/templates/nginx
|
|
|
|
nginx_dir="${pending_dir}/etc/nginx"
|
|
nginx_conf_dir="${nginx_dir}/conf.d"
|
|
mkdir -p "$nginx_conf_dir"
|
|
|
|
# install plain conf files
|
|
cp plain/* "$nginx_conf_dir"
|
|
|
|
# probably run with init: just disable default site, restart NGINX and exit
|
|
if [[ -z "$pending_dir" ]]; then
|
|
rm -f "${nginx_dir}/sites-enabled/default"
|
|
service nginx restart
|
|
exit 0
|
|
fi
|
|
|
|
# retrieve variables
|
|
main_domain=$(cat /etc/yunohost/current_host)
|
|
domain_list=$(sudo yunohost domain list --output-as plain --quiet)
|
|
|
|
# add domain conf files
|
|
for domain in $domain_list; do
|
|
domain_conf_dir="${nginx_conf_dir}/${domain}.d"
|
|
mkdir -p "$domain_conf_dir"
|
|
|
|
# NGINX server configuration
|
|
cat server.tpl.conf \
|
|
| sed "s/{{ domain }}/${domain}/g" \
|
|
> "${nginx_conf_dir}/${domain}.conf"
|
|
|
|
[[ $main_domain != $domain ]] \
|
|
&& touch "${domain_conf_dir}/yunohost_local.conf" \
|
|
|| cp yunohost_local.conf "${domain_conf_dir}/yunohost_local.conf"
|
|
done
|
|
|
|
# remove old domain conf files
|
|
conf_files=$(ls -1 /etc/nginx/conf.d \
|
|
| awk '/^[^\.]+\.[^\.]+.*\.conf$/ { print $1 }')
|
|
for file in $conf_files; do
|
|
domain=${file%.conf}
|
|
[[ $domain_list =~ $domain ]] \
|
|
|| touch "${nginx_conf_dir}/${file}"
|
|
done
|
|
|
|
# disable default site
|
|
mkdir -p "${nginx_dir}/sites-enabled"
|
|
touch "${nginx_dir}/sites-enabled/default"
|
|
}
|
|
|
|
do_post_regen() {
|
|
regen_conf_files=$1
|
|
|
|
[ -z "$regen_conf_files" ] && exit 0
|
|
|
|
# retrieve variables
|
|
domain_list=$(sudo yunohost domain list --output-as plain --quiet)
|
|
|
|
# create NGINX conf directories for domains
|
|
for domain in $domain_list; do
|
|
sudo mkdir -p "/etc/nginx/conf.d/${domain}.d"
|
|
done
|
|
|
|
sudo service nginx restart
|
|
}
|
|
|
|
FORCE=$2
|
|
|
|
case "$1" in
|
|
pre)
|
|
do_pre_regen $3
|
|
;;
|
|
post)
|
|
do_post_regen $3
|
|
;;
|
|
init)
|
|
do_init_regen
|
|
;;
|
|
*)
|
|
echo "hook called with unknown argument \`$1'" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
exit 0
|