Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip password prompt if sudo NOPASSWD configured #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions resources/lib/version_check/shell_handler_apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


try:
from subprocess import check_output
from subprocess import check_output, CalledProcessError
except ImportError:
def check_output(*args, **kwargs):
return
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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
Expand Down
Loading