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:
Sunil Mohan Adapa authored and James Valleroy committed 2016-08-16 18:51:37 -04:00
1 parent afdea208ec
commit 7b68dd55f2
3 files changed
+26 -17

No files matched your search

+22 -7
View File
@@ -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()