From 0576b17442282867a6b011a41cdaf7bcfafaaad3 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 28 Nov 2018 21:03:28 +0000 Subject: [PATCH] Simplify code / indentation levels --- data/hooks/conf_regen/03-ssh | 53 ++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/data/hooks/conf_regen/03-ssh b/data/hooks/conf_regen/03-ssh index 271ad9bb8..76fab7cd4 100755 --- a/data/hooks/conf_regen/03-ssh +++ b/data/hooks/conf_regen/03-ssh @@ -5,39 +5,44 @@ set -e . /usr/share/yunohost/helpers.d/utils do_pre_regen() { - pending_dir=$1 + pending_dir=$1 - cd /usr/share/yunohost/templates/ssh + # If the (legacy) 'from_script' flag is here, + # we won't touch anything in the ssh config. + [[ ! -f /etc/yunohost/from_script ]] || return - # Don't overwrite configuration if from_script - if [[ ! -f /etc/yunohost/from_script ]]; then + cd /usr/share/yunohost/templates/ssh - # do not listen to IPv6 if unavailable - [[ -f /proc/net/if_inet6 ]] && ipv6_enabled=true || ipv6_enabled=false + # do not listen to IPv6 if unavailable + [[ -f /proc/net/if_inet6 ]] && ipv6_enabled=true || ipv6_enabled=false - ssh_keys=$(ls /etc/ssh/ssh_host_{ed25519,rsa,ecdsa}_key 2>/dev/null) + ssh_keys=$(ls /etc/ssh/ssh_host_{ed25519,rsa,ecdsa}_key 2>/dev/null) - # Support legacy setting (this setting might be disabled by a user during a migration) - if [[ "$(yunohost settings get 'service.ssh.allow_deprecated_dsa_hostkey')" == "True" ]]; then - ssh_keys="$ssh_keys $(ls /etc/ssh/ssh_host_dsa_key 2>/dev/null)" - fi + # Support legacy setting (this setting might be disabled by a user during a migration) + if [[ "$(yunohost settings get 'service.ssh.allow_deprecated_dsa_hostkey')" == "True" ]]; then + ssh_keys="$ssh_keys $(ls /etc/ssh/ssh_host_dsa_key 2>/dev/null)" + fi - export ssh_keys - export ipv6_enabled - ynh_render_template "sshd_config" "${pending_dir}/etc/ssh/sshd_config" - fi + export ssh_keys + export ipv6_enabled + ynh_render_template "sshd_config" "${pending_dir}/etc/ssh/sshd_config" } do_post_regen() { - regen_conf_files=$1 - if [[ ! -f /etc/yunohost/from_script ]]; then - if [[ -n "$regen_conf_files" ]]; - then - sudo service ssh restart - chown root:root "/etc/ssh/sshd_config" - chmod 644 "/etc/ssh/sshd_config" - fi - fi + regen_conf_files=$1 + + # If the (legacy) 'from_script' flag is here, + # we won't touch anything in the ssh config. + [[ ! -f /etc/yunohost/from_script ]] || return + + # If no file changed, there's nothing to do + [[ -n "$regen_conf_files" ]] || return + + # Enforce permissions for /etc/ssh/sshd_config + chown root:root "/etc/ssh/sshd_config" + chmod 644 "/etc/ssh/sshd_config" + + systemctl restart ssh } FORCE=${2:-0}