From de49ba5620c83879ab7ef4deb6a6d666f40cf893 Mon Sep 17 00:00:00 2001 From: Vlastimil Holer Date: Fri, 26 Mar 2021 17:36:15 +0100 Subject: [PATCH] B #223: Mask ssh service during dpkg-reconfigure openssh-server --- .../one-context.d/loc-24-ssh_host_key##deb | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/etc/one-context.d/loc-24-ssh_host_key##deb b/src/etc/one-context.d/loc-24-ssh_host_key##deb index 1063923..a206c21 100755 --- a/src/etc/one-context.d/loc-24-ssh_host_key##deb +++ b/src/etc/one-context.d/loc-24-ssh_host_key##deb @@ -16,7 +16,32 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +SERVICE_FILE='/etc/systemd/system/ssh.service' +SERVICE_LINK='/dev/null-one-context' + +setup() { + if [ -d "$(dirname "${SERVICE_FILE}")" ] && + ! stat "${SERVICE_FILE}" &>/dev/null; + then + ln -s "${SERVICE_LINK}" "${SERVICE_FILE}" + fi +} + +clean() { + if [ -L "${SERVICE_FILE}" ] && + [ "$(readlink "${SERVICE_FILE}")" = "${SERVICE_LINK}" ]; + then + unlink "${SERVICE_FILE}" + systemctl daemon-reload &>/dev/null || : + fi +} + +### + +trap 'clean' EXIT + if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then + setup + DEBIAN_FRONTEND=noninteractive dpkg-reconfigure openssh-server fi -