diff --git a/data/hooks/conf_regen/03-ssh b/data/hooks/conf_regen/03-ssh new file mode 100644 index 000000000..2481bd312 --- /dev/null +++ b/data/hooks/conf_regen/03-ssh @@ -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 diff --git a/data/hooks/conf_regen/06-slapd b/data/hooks/conf_regen/06-slapd index ccc418ddc..24e76d98a 100644 --- a/data/hooks/conf_regen/06-slapd +++ b/data/hooks/conf_regen/06-slapd @@ -4,7 +4,7 @@ set -e force=$1 function safe_copy () { - if [ $force ]; then + if [[ "$force" == "True" ]]; then sudo yunohost service safecopy \ -s slapd \ $1 $2 \ diff --git a/data/hooks/conf_regen/09-nslcd b/data/hooks/conf_regen/09-nslcd index 9356eec47..da09e6acc 100644 --- a/data/hooks/conf_regen/09-nslcd +++ b/data/hooks/conf_regen/09-nslcd @@ -4,7 +4,7 @@ set -e force=$1 function safe_copy () { - if [ $force ]; then + if [[ "$force" == "True" ]]; then sudo yunohost service safecopy \ -s nslcd \ $1 $2 \ diff --git a/data/hooks/conf_regen/15-nginx b/data/hooks/conf_regen/15-nginx index 0eaa4ea19..37f976ed4 100644 --- a/data/hooks/conf_regen/15-nginx +++ b/data/hooks/conf_regen/15-nginx @@ -4,7 +4,7 @@ set -e force=$1 function safe_copy () { - if [ $force ]; then + if [[ "$force" == "True" ]]; then sudo yunohost service safecopy \ -s nginx \ $1 $2 \ @@ -36,7 +36,7 @@ safe_copy 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 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" \ | sudo tee $domain.conf if [[ $(safe_copy $domain.conf /etc/nginx/conf.d/$domain.conf) == "True" ]]; then - need_restart=0 + need_restart=True fi done # Restart if need be -if [ $need_restart ]; then +if [[ "$need_restart" == "True" ]]; then sudo service nginx restart else sudo service nginx reload diff --git a/lib/yunohost/service.py b/lib/yunohost/service.py index 52fe6ad37..8f3a7693a 100644 --- a/lib/yunohost/service.py +++ b/lib/yunohost/service.py @@ -283,14 +283,9 @@ def service_regenconf(service=None, force=False): """ from yunohost.hook import hook_callback - if force: - arg_force = 0 - else: - arg_force = 1 - if service is None: # Regen ALL THE CONFIGURATIONS - hook_callback('conf_regen', args=[arg_force]) + hook_callback('conf_regen', args=[force]) msignals.display(m18n.n('services_configured'), 'success') else: @@ -402,7 +397,6 @@ def _get_diff(string, filename): with open(filename, 'r') as f: file_lines = f.readlines() - string = string + '\n' new_lines = string.splitlines(1) return difflib.unified_diff(file_lines, new_lines) except IOError: return [] @@ -548,8 +542,9 @@ def service_safecopy(service, new_conf_file, conf_file, force=False): # Handle conflicts if force or previous_hash == current_hash: with open(conf_file, 'w') as f: f.write(new_conf) - regenerated = True new_hash = _hash(conf_file) + if current_hash != new_hash: + regenerated = True elif len(diff) == 0: new_hash = _hash(conf_file) else: