From d123fd7674a936648f6117bcfd0ec538e775bc62 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 18 Feb 2023 16:08:26 +0100 Subject: [PATCH] appsv2: fix user provisionion ... Aleks was drunk ... check_output('cmd &>/dev/null') will always return empty string... --- src/utils/resources.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils/resources.py b/src/utils/resources.py index 9e9bdac98..331d10f11 100644 --- a/src/utils/resources.py +++ b/src/utils/resources.py @@ -469,13 +469,13 @@ class SystemuserAppResource(AppResource): # FIXME : validate that no yunohost user exists with that name? # and/or that no system user exists during install ? - if not check_output(f"getent passwd {self.app} &>/dev/null || true").strip(): + if os.system(f"getent passwd {self.app} &>/dev/null") != 0: # FIXME: improve logging ? os.system wont log stdout / stderr cmd = f"useradd --system --user-group {self.app}" ret = os.system(cmd) assert ret == 0, f"useradd command failed with exit code {ret}" - if not check_output(f"getent passwd {self.app} &>/dev/null || true").strip(): + if os.system(f"getent passwd {self.app} &>/dev/null") != 0: raise YunohostError( f"Failed to create system user for {self.app}", raw_msg=True ) @@ -495,16 +495,16 @@ class SystemuserAppResource(AppResource): os.system(f"usermod -G {','.join(groups)} {self.app}") def deprovision(self, context: Dict = {}): - if check_output(f"getent passwd {self.app} &>/dev/null || true").strip(): + if os.system(f"getent passwd {self.app} &>/dev/null") == 0: os.system(f"deluser {self.app} >/dev/null") - if check_output(f"getent passwd {self.app} &>/dev/null || true").strip(): + if os.system(f"getent passwd {self.app} &>/dev/null") == 0: raise YunohostError( f"Failed to delete system user for {self.app}", raw_msg=True ) - if check_output(f"getent group {self.app} &>/dev/null || true").strip(): + if os.system(f"getent group {self.app} &>/dev/null") == 0: os.system(f"delgroup {self.app} >/dev/null") - if check_output(f"getent group {self.app} &>/dev/null || true").strip(): + if os.system(f"getent group {self.app} &>/dev/null") == 0: raise YunohostError( f"Failed to delete system user for {self.app}", raw_msg=True )