mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] Properly calculate diff
This commit is contained in:
parent
2a812e0aec
commit
1ca528f6ce
5 changed files with 40 additions and 14 deletions
31
data/hooks/conf_regen/03-ssh
Normal file
31
data/hooks/conf_regen/03-ssh
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
force=$1
|
||||||
|
|
||||||
|
function safe_copy () {
|
||||||
|
if [ $force ]; then
|
||||||
|
sudo yunohost service safecopy \
|
||||||
|
-s ssh \
|
||||||
|
$1 $2 \
|
||||||
|
--force
|
||||||
|
else
|
||||||
|
sudo yunohost service safecopy \
|
||||||
|
-s ssh \
|
||||||
|
$1 $2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
cd /usr/share/yunohost/templates/ssh
|
||||||
|
|
||||||
|
# Only overwrite SSH configuration on an ISO installation
|
||||||
|
if [ ! -f /etc/yunohost/from_script ]; then
|
||||||
|
|
||||||
|
# Do not listen to IPv6 if unavailable
|
||||||
|
if [ ! -f /proc/net/if_inet6 ]; then
|
||||||
|
sudo sed -i "s/ListenAddress ::/#ListenAddress ::/g" sshd_config
|
||||||
|
fi
|
||||||
|
safe_copy sshd_config /etc/ssh/sshd_config
|
||||||
|
|
||||||
|
sudo service ssh restart
|
||||||
|
fi
|
|
@ -4,7 +4,7 @@ set -e
|
||||||
force=$1
|
force=$1
|
||||||
|
|
||||||
function safe_copy () {
|
function safe_copy () {
|
||||||
if [ $force ]; then
|
if [[ "$force" == "True" ]]; then
|
||||||
sudo yunohost service safecopy \
|
sudo yunohost service safecopy \
|
||||||
-s slapd \
|
-s slapd \
|
||||||
$1 $2 \
|
$1 $2 \
|
||||||
|
|
|
@ -4,7 +4,7 @@ set -e
|
||||||
force=$1
|
force=$1
|
||||||
|
|
||||||
function safe_copy () {
|
function safe_copy () {
|
||||||
if [ $force ]; then
|
if [[ "$force" == "True" ]]; then
|
||||||
sudo yunohost service safecopy \
|
sudo yunohost service safecopy \
|
||||||
-s nslcd \
|
-s nslcd \
|
||||||
$1 $2 \
|
$1 $2 \
|
||||||
|
|
|
@ -4,7 +4,7 @@ set -e
|
||||||
force=$1
|
force=$1
|
||||||
|
|
||||||
function safe_copy () {
|
function safe_copy () {
|
||||||
if [ $force ]; then
|
if [[ "$force" == "True" ]]; then
|
||||||
sudo yunohost service safecopy \
|
sudo yunohost service safecopy \
|
||||||
-s nginx \
|
-s nginx \
|
||||||
$1 $2 \
|
$1 $2 \
|
||||||
|
@ -36,7 +36,7 @@ safe_copy yunohost_local.conf \
|
||||||
/etc/nginx/conf.d/$main_domain.d/yunohost_local.conf
|
/etc/nginx/conf.d/$main_domain.d/yunohost_local.conf
|
||||||
|
|
||||||
|
|
||||||
need_restart=1
|
need_restart=False
|
||||||
|
|
||||||
# Copy a configuration file for each YunoHost domain
|
# Copy a configuration file for each YunoHost domain
|
||||||
for domain in $(sudo yunohost domain list --raw); do
|
for domain in $(sudo yunohost domain list --raw); do
|
||||||
|
@ -45,12 +45,12 @@ for domain in $(sudo yunohost domain list --raw); do
|
||||||
| sed "s/{{ domain }}/$domain/g" \
|
| sed "s/{{ domain }}/$domain/g" \
|
||||||
| sudo tee $domain.conf
|
| sudo tee $domain.conf
|
||||||
if [[ $(safe_copy $domain.conf /etc/nginx/conf.d/$domain.conf) == "True" ]]; then
|
if [[ $(safe_copy $domain.conf /etc/nginx/conf.d/$domain.conf) == "True" ]]; then
|
||||||
need_restart=0
|
need_restart=True
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Restart if need be
|
# Restart if need be
|
||||||
if [ $need_restart ]; then
|
if [[ "$need_restart" == "True" ]]; then
|
||||||
sudo service nginx restart
|
sudo service nginx restart
|
||||||
else
|
else
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
|
|
|
@ -283,14 +283,9 @@ def service_regenconf(service=None, force=False):
|
||||||
"""
|
"""
|
||||||
from yunohost.hook import hook_callback
|
from yunohost.hook import hook_callback
|
||||||
|
|
||||||
if force:
|
|
||||||
arg_force = 0
|
|
||||||
else:
|
|
||||||
arg_force = 1
|
|
||||||
|
|
||||||
if service is None:
|
if service is None:
|
||||||
# Regen ALL THE CONFIGURATIONS
|
# Regen ALL THE CONFIGURATIONS
|
||||||
hook_callback('conf_regen', args=[arg_force])
|
hook_callback('conf_regen', args=[force])
|
||||||
|
|
||||||
msignals.display(m18n.n('services_configured'), 'success')
|
msignals.display(m18n.n('services_configured'), 'success')
|
||||||
else:
|
else:
|
||||||
|
@ -402,7 +397,6 @@ def _get_diff(string, filename):
|
||||||
with open(filename, 'r') as f:
|
with open(filename, 'r') as f:
|
||||||
file_lines = f.readlines()
|
file_lines = f.readlines()
|
||||||
|
|
||||||
string = string + '\n'
|
|
||||||
new_lines = string.splitlines(1)
|
new_lines = string.splitlines(1)
|
||||||
return difflib.unified_diff(file_lines, new_lines)
|
return difflib.unified_diff(file_lines, new_lines)
|
||||||
except IOError: return []
|
except IOError: return []
|
||||||
|
@ -548,8 +542,9 @@ def service_safecopy(service, new_conf_file, conf_file, force=False):
|
||||||
# Handle conflicts
|
# Handle conflicts
|
||||||
if force or previous_hash == current_hash:
|
if force or previous_hash == current_hash:
|
||||||
with open(conf_file, 'w') as f: f.write(new_conf)
|
with open(conf_file, 'w') as f: f.write(new_conf)
|
||||||
regenerated = True
|
|
||||||
new_hash = _hash(conf_file)
|
new_hash = _hash(conf_file)
|
||||||
|
if current_hash != new_hash:
|
||||||
|
regenerated = True
|
||||||
elif len(diff) == 0:
|
elif len(diff) == 0:
|
||||||
new_hash = _hash(conf_file)
|
new_hash = _hash(conf_file)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Reference in a new issue