mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
setup: Disable install/upgrade when dpkg/apt is running
Show a warning message that a package manager is running. This prevents users from getting an installation error just because another installation/upgrade is running. Closes: #625.
This commit is contained in:
parent
6a53dd015e
commit
76a63d102b
@ -28,6 +28,8 @@ import sys
|
|||||||
|
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
|
|
||||||
|
LOCK_FILE = '/var/lib/dpkg/lock'
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
"""Return parsed command line arguments as dictionary."""
|
"""Return parsed command line arguments as dictionary."""
|
||||||
@ -41,6 +43,8 @@ def parse_arguments():
|
|||||||
'module', help='name of module for which package is being installed')
|
'module', help='name of module for which package is being installed')
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'packages', nargs='+', help='list of packages to install')
|
'packages', nargs='+', help='list of packages to install')
|
||||||
|
subparsers.add_parser('is-package-manager-busy',
|
||||||
|
help='Return whether package manager is busy')
|
||||||
|
|
||||||
subparsers.required = True
|
subparsers.required = True
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
@ -94,6 +98,14 @@ def _assert_managed_packages(module, packages):
|
|||||||
assert package in module.managed_packages
|
assert package in module.managed_packages
|
||||||
|
|
||||||
|
|
||||||
|
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 main():
|
def main():
|
||||||
"""Parse arguments and perform all duties."""
|
"""Parse arguments and perform all duties."""
|
||||||
arguments = parse_arguments()
|
arguments = parse_arguments()
|
||||||
|
|||||||
@ -28,7 +28,6 @@ import sys
|
|||||||
|
|
||||||
CONF_FILE = '/etc/apt/apt.conf.d/50unattended-upgrades'
|
CONF_FILE = '/etc/apt/apt.conf.d/50unattended-upgrades'
|
||||||
AUTO_CONF_FILE = '/etc/apt/apt.conf.d/20auto-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'
|
LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log'
|
||||||
|
|
||||||
|
|
||||||
@ -42,8 +41,6 @@ def parse_arguments():
|
|||||||
help='Check if automatic upgrades are enabled')
|
help='Check if automatic upgrades are enabled')
|
||||||
subparsers.add_parser('enable-auto', help='Enable automatic upgrades')
|
subparsers.add_parser('enable-auto', help='Enable automatic upgrades')
|
||||||
subparsers.add_parser('disable-auto', help='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')
|
subparsers.add_parser('get-log', help='Print the automatic upgrades log')
|
||||||
|
|
||||||
subparsers.required = True
|
subparsers.required = True
|
||||||
@ -129,14 +126,6 @@ def setup():
|
|||||||
conffile.write(' "origin=Debian";\n')
|
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(_):
|
def subcommand_get_log(_):
|
||||||
"""Print the automatic upgrades log."""
|
"""Print the automatic upgrades log."""
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -84,11 +84,10 @@ class UpgradesConfigurationView(FormView):
|
|||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def is_package_manager_busy():
|
def is_package_manager_busy():
|
||||||
"""Return whether a package manager is running."""
|
"""Return whether a package manager is running."""
|
||||||
try:
|
try:
|
||||||
actions.superuser_run('upgrades', ['is-package-manager-busy'])
|
actions.superuser_run('packages', ['is-package-manager-busy'])
|
||||||
return True
|
return True
|
||||||
except actions.ActionError:
|
except actions.ActionError:
|
||||||
return False
|
return False
|
||||||
|
|||||||
@ -50,8 +50,19 @@
|
|||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<input type="submit" class="btn btn-md btn-primary"
|
{% if package_manager_is_busy %}
|
||||||
value="{% trans "Install" %}" />
|
<div class="alert alert-warning" role="alert">
|
||||||
|
{% blocktrans trimmed %}
|
||||||
|
Another installation or upgrade is already running.
|
||||||
|
Please wait for a few moments before trying again.
|
||||||
|
{% endblocktrans %}
|
||||||
|
</div>
|
||||||
|
<input type="submit" class="btn btn-md btn-primary"
|
||||||
|
disabled="disabled" value="{% trans "Install" %}" />
|
||||||
|
{% else %}
|
||||||
|
<input type="submit" class="btn btn-md btn-primary"
|
||||||
|
value="{% trans "Install" %}" />
|
||||||
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
{% elif setup_helper.get_state == 'needs-update' %}
|
{% elif setup_helper.get_state == 'needs-update' %}
|
||||||
<p>
|
<p>
|
||||||
@ -63,8 +74,19 @@
|
|||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<input type="submit" class="btn btn-md btn-primary"
|
{% if package_manager_is_busy %}
|
||||||
value="{% trans "Update" %}" />
|
<div class="alert alert-warning" role="alert">
|
||||||
|
{% blocktrans trimmed %}
|
||||||
|
Another installation or upgrade is already running.
|
||||||
|
Please wait for a few moments before trying again.
|
||||||
|
{% endblocktrans %}
|
||||||
|
</div>
|
||||||
|
<input type="submit" class="btn btn-md btn-primary"
|
||||||
|
disabled="disabled" value="{% trans "Install" %}" />
|
||||||
|
{% else %}
|
||||||
|
<input type="submit" class="btn btn-md btn-primary"
|
||||||
|
value="{% trans "Update" %}" />
|
||||||
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import time
|
|||||||
|
|
||||||
from . import forms, frontpage
|
from . import forms, frontpage
|
||||||
import plinth
|
import plinth
|
||||||
|
from plinth import actions
|
||||||
|
|
||||||
|
|
||||||
@public
|
@public
|
||||||
@ -208,8 +209,17 @@ class SetupView(TemplateView):
|
|||||||
"""Return the context data rendering the template."""
|
"""Return the context data rendering the template."""
|
||||||
context = super(SetupView, self).get_context_data(**kwargs)
|
context = super(SetupView, self).get_context_data(**kwargs)
|
||||||
context['setup_helper'] = self.kwargs['setup_helper']
|
context['setup_helper'] = self.kwargs['setup_helper']
|
||||||
|
context['package_manager_is_busy'] = self.is_package_manager_busy()
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
def is_package_manager_busy(self):
|
||||||
|
"""Return whether a package manager is running."""
|
||||||
|
try:
|
||||||
|
actions.superuser_run('packages', ['is-package-manager-busy'])
|
||||||
|
return True
|
||||||
|
except actions.ActionError:
|
||||||
|
return False
|
||||||
|
|
||||||
def post(self, *args, **kwargs):
|
def post(self, *args, **kwargs):
|
||||||
"""Handle installing/upgrading applications.
|
"""Handle installing/upgrading applications.
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user