upgrades: Add first boot step to run initial update

Closes: #1708.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2020-11-12 21:15:49 -05:00 committed by Sunil Mohan Adapa
parent 377010b078
commit 8b02c2bf3a
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
5 changed files with 69 additions and 1 deletions

View File

@ -30,6 +30,11 @@ first_boot_steps = [
'url': 'upgrades:backports-firstboot',
'order': 5,
},
{
'id': 'initial_update',
'url': 'upgrades:update-firstboot',
'order': 6,
},
]
_description = [

View File

@ -33,3 +33,9 @@ class BackportsFirstbootForm(forms.Form):
backports_enabled = forms.BooleanField(
label=_('Activate frequent feature updates (recommended)'),
required=False, initial=True)
class UpdateFirstbootForm(forms.Form):
"""Form to run or skip initial update during first boot wizard."""
update_now = forms.BooleanField(label=_('Update now (recommended)'),
required=False, initial=True)

View File

@ -0,0 +1,37 @@
{% extends "base_firstboot.html" %}
{% comment %}
# SPDX-License-Identifier: AGPL-3.0-or-later
{% endcomment %}
{% load bootstrap %}
{% load i18n %}
{% load static %}
{% block content %}
<h2>{% trans "Update" %}</h2>
<p>
{% blocktrans trimmed %}
Check for and apply the latest software and security updates.
{% endblocktrans %}
</p>
<p>
{% blocktrans trimmed %}
<strong>This may take a long time to complete.</strong> During an update,
you cannot install apps. Also, this web interface may be temporarily
unavailable and show an error. In that case, refresh the page to
continue.
{% endblocktrans %}
</p>
<form class="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input type="submit" class="btn btn-primary" name="update"
value="{% trans "Next" %}"/>
</form>
{% endblock %}

View File

@ -14,5 +14,7 @@ urlpatterns = [
name='activate-backports'),
url(r'^sys/upgrades/firstboot/backports/$',
views.BackportsFirstbootView.as_view(), name='backports-firstboot'),
url(r'^sys/upgrades/firstboot/update/$',
views.UpdateFirstbootView.as_view(), name='update-firstboot'),
url(r'^sys/upgrades/upgrade/$', views.upgrade, name='upgrade'),
]

View File

@ -17,7 +17,7 @@ from plinth.errors import ActionError
from plinth.modules import first_boot, upgrades
from plinth.views import AppView
from .forms import BackportsFirstbootForm, ConfigureForm
from .forms import BackportsFirstbootForm, ConfigureForm, UpdateFirstbootForm
class UpgradesConfigurationView(AppView):
@ -172,3 +172,21 @@ class BackportsFirstbootView(FormView):
upgrades.setup_repositories(None)
first_boot.mark_step_done('backports_wizard')
return super().form_valid(form)
class UpdateFirstbootView(FormView):
"""View to run initial update during first boot wizard."""
template_name = 'update-firstboot.html'
form_class = UpdateFirstbootForm
def get_success_url(self):
"""Return next firstboot step."""
return reverse_lazy(first_boot.next_step())
def form_valid(self, form):
"""Run update if selected, and mark step as done."""
if form.cleaned_data['update_now']:
actions.superuser_run('upgrades', ['run'])
first_boot.mark_step_done('initial_update')
return super().form_valid(form)