mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
upgrades: Run status operations as non-root
Current check whether the package manager is busy and getting the unattended upgrades log requires root. This will not allow Plinth to run as non-root. Fix this by moving the operations to actions script.
This commit is contained in:
parent
afdea208ec
commit
7b68dd55f2
@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
|
||||
### Changed
|
||||
- dynamicdns: Allowed Plinth to run as non-root.
|
||||
- transmission: Read configuration as super user.
|
||||
- upgrades: Run status operations as non-root.
|
||||
|
||||
## [0.10.0] - 2016-08-12
|
||||
### Added
|
||||
|
||||
@ -28,6 +28,8 @@ import sys
|
||||
|
||||
CONF_FILE = '/etc/apt/apt.conf.d/50unattended-upgrades'
|
||||
AUTO_CONF_FILE = '/etc/apt/apt.conf.d/20auto-upgrades'
|
||||
LOCK_FILE = '/var/lib/dpkg/lock'
|
||||
LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log'
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
@ -35,18 +37,14 @@ def parse_arguments():
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
# Run unattended-upgrades
|
||||
subparsers.add_parser('run', help='Upgrade packages on the system')
|
||||
|
||||
# Check if automatic upgrades are enabled
|
||||
subparsers.add_parser('check-auto',
|
||||
help='Check if automatic upgrades are enabled')
|
||||
|
||||
# Enable automatic upgrades
|
||||
subparsers.add_parser('enable-auto', help='Enable automatic upgrades')
|
||||
|
||||
# Disable automatic upgrades
|
||||
subparsers.add_parser('disable-auto', help='Disable automatic upgrades.')
|
||||
subparsers.add_parser('is-package-manager-busy',
|
||||
help='Return whether package manager is busy')
|
||||
subparsers.add_parser('get-log', help='Print the automatic upgrades log')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
@ -130,6 +128,23 @@ def setup():
|
||||
conffile.write(' "origin=Debian";\n')
|
||||
|
||||
|
||||
def subcommand_is_package_manager_busy(_):
|
||||
"""Return whether package manager is busy."""
|
||||
try:
|
||||
subprocess.check_output(['lsof', LOCK_FILE])
|
||||
except subprocess.CalledProcessError:
|
||||
sys.exit(-1)
|
||||
|
||||
|
||||
def subcommand_get_log(_):
|
||||
"""Print the automatic upgrades log."""
|
||||
try:
|
||||
with open(LOG_FILE, 'r') as file_handle:
|
||||
print(file_handle.read())
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties"""
|
||||
arguments = parse_arguments()
|
||||
|
||||
@ -36,9 +36,6 @@ subsubmenu = [{'url': reverse_lazy('upgrades:index'),
|
||||
{'url': reverse_lazy('upgrades:upgrade'),
|
||||
'text': ugettext_lazy('Upgrade Packages')}]
|
||||
|
||||
LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log'
|
||||
LOCK_FILE = '/var/log/dpkg/lock'
|
||||
|
||||
|
||||
class UpgradesConfigurationView(FormView):
|
||||
"""Serve configuration page."""
|
||||
@ -91,19 +88,15 @@ class UpgradesConfigurationView(FormView):
|
||||
def is_package_manager_busy():
|
||||
"""Return whether a package manager is running."""
|
||||
try:
|
||||
subprocess.check_output(['lsof', '/var/lib/dpkg/lock'])
|
||||
actions.superuser_run('upgrades', ['is-package-manager-busy'])
|
||||
return True
|
||||
except subprocess.CalledProcessError:
|
||||
except actions.ActionError:
|
||||
return False
|
||||
|
||||
|
||||
def get_log():
|
||||
"""Return the current log for unattended upgrades."""
|
||||
try:
|
||||
with open(LOG_FILE, 'r') as file_handle:
|
||||
return file_handle.read()
|
||||
except IOError:
|
||||
return None
|
||||
return actions.superuser_run('upgrades', ['get-log'])
|
||||
|
||||
|
||||
def upgrade(request):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user