From 73741c225f24d5c97dd5c5f4f3b51f78a173df45 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 31 Mar 2020 04:30:11 +0200 Subject: [PATCH] Allow sudo -u as a legit usage of sudo since ynh_exec_as ain't official --- package_linter.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/package_linter.py b/package_linter.py index bdce479..682c142 100755 --- a/package_linter.py +++ b/package_linter.py @@ -493,6 +493,15 @@ class Script(): return any(command in line for line in [' '.join(line) for line in self.lines]) + def containsregex(self, regex): + """ + Iterate on lines to check if command is contained in line + + For instance, "app setting" is contained in "yunohost app setting $app ..." + """ + return any(re.match(regex, line) + for line in [' '.join(line) for line in self.lines]) + def analyze(self): print_header(self.name.upper() + " SCRIPT") @@ -594,7 +603,7 @@ class Script(): print_error("[YEP-2.12] You should avoid using 'rm -rf', please use 'ynh_secure_remove' instead") if self.contains("sed -i"): print_warning("[YEP-2.12] You should avoid using 'sed -i', please use 'ynh_replace_string' instead") - if self.contains("sudo "): + if self.containsregex(r"sudo \w"): # \w is here to not match sudo -u, legit use because ynh_exec_as not official yet... print_warning( "[YEP-2.12] You should not need to use 'sudo', the script is being run as root. " "(If you need to run a command using a specific user, use 'ynh_exec_as')"