From f2b9a4fa5d2bb5c5820c352b7fce641e79323c3d Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 6 Aug 2024 12:25:21 -0400 Subject: [PATCH] Improve handling of ssh service being pre-hooked --- imgutil/imgutil | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/imgutil/imgutil b/imgutil/imgutil index bc34af01..5b5de0b2 100644 --- a/imgutil/imgutil +++ b/imgutil/imgutil @@ -661,11 +661,20 @@ class DebHandler(OsHandler): run_constrainedx(fancy_chroot, (args, self.targpath)) args.cmd = ['apt-get', '-y', 'install'] + self.includepkgs run_constrainedx(fancy_chroot, (args, self.targpath)) - servicefile = os.path.join(self.targpath, 'usr/lib/systemd/system/ssh.service') + servicefile = os.path.join( + self.targpath, 'usr/lib/systemd/system/ssh.service') if os.path.exists(servicefile): - os.symlink('/usr/lib/systemd/system/ssh.service', os.path.join(self.targpath, 'etc/systemd/system/multi-user.target.wants/ssh.service')) + targfile = os.path.join( + self.targpath, + 'etc/systemd/system/multi-user.target.wants/ssh.service') + if not os.path.exists(targfile): + os.symlink('/usr/lib/systemd/system/ssh.service', targfile) else: - os.symlink('/usr/lib/systemd/system/sshd.service', os.path.join(self.targpath, 'etc/systemd/system/multi-user.target.wants/sshd.service')) + targfile = os.path.join( + self.targpath, + 'etc/systemd/system/multi-user.target.wants/sshd.service') + if not os.path.exists(targfile): + os.symlink('/usr/lib/systemd/system/sshd.service', targfile)