diff --git a/resources/lib/version_check/shell_handler_apt.py b/resources/lib/version_check/shell_handler_apt.py index 64577b1..eade8aa 100644 --- a/resources/lib/version_check/shell_handler_apt.py +++ b/resources/lib/version_check/shell_handler_apt.py @@ -19,7 +19,7 @@ try: - from subprocess import check_output + from subprocess import check_output, CalledProcessError except ImportError: def check_output(*args, **kwargs): return @@ -86,8 +86,12 @@ def _update_cache(self): _cmd = 'apt-get update' try: if self.sudo: - _ = check_output('echo \'%s\' | sudo -S %s' % - (self._get_password(), _cmd), shell=True) + try: + _ = check_output('sudo -n %s' % + (_cmd), shell=True) + except CalledProcessError: + _ = check_output('echo \'%s\' | sudo -S %s' % + (self._get_password(), _cmd), shell=True) else: _ = check_output(_cmd.split()) except Exception as error: # pylint: disable=broad-except @@ -107,8 +111,12 @@ def upgrade_package(self, package): _cmd = 'apt-get install -y ' + package try: if self.sudo: - _ = check_output('echo \'%s\' | sudo -S %s' % - (self._get_password(), _cmd), shell=True) + try: + _ = check_output('sudo -n %s' % + (_cmd), shell=True) + except CalledProcessError: + _ = check_output('echo \'%s\' | sudo -S %s' % + (self._get_password(), _cmd), shell=True) else: _ = check_output(_cmd.split()) log('Upgrade successful') @@ -128,8 +136,12 @@ def upgrade_system(self): try: log('Upgrading system') if self.sudo: - _ = check_output('echo \'%s\' | sudo -S %s' % - (self._get_password(), _cmd), shell=True) + try: + _ = check_output('sudo -n %s' % + (_cmd), shell=True) + except CalledProcessError: + _ = check_output('echo \'%s\' | sudo -S %s' % + (self._get_password(), _cmd), shell=True) else: _ = check_output(_cmd.split()) except Exception as error: # pylint: disable=broad-except