Put the Update and Packages pages on one Updates page
Router software and packages are two parts of one page, with one overlay, one confirmation banner and both logs. /upgrade redirects to it; the actions keep their addresses. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -270,7 +270,7 @@ func newApp(sys System, metrics *Collector, dev bool) *app {
|
||||
func (a *app) parseTemplates() (map[string]*template.Template, error) {
|
||||
files := map[string][]string{"overview": {"templates/dashboard.html"}}
|
||||
pages := map[string]*template.Template{}
|
||||
for _, page := range []string{"login", "overview", "network", "dhcp", "dns", "wireguard", "firewall", "ddns", "dnsproviders", "certificate", "exporter", "advanced", "update", "upgrade", "tokens", "changes"} {
|
||||
for _, page := range []string{"login", "overview", "network", "dhcp", "dns", "wireguard", "firewall", "ddns", "dnsproviders", "certificate", "exporter", "advanced", "update", "tokens", "changes"} {
|
||||
t, err := template.New("layout.html").Funcs(a.funcs).
|
||||
ParseFS(assets, append([]string{"templates/layout.html", "templates/" + page + ".html"}, files[page]...)...)
|
||||
if err != nil {
|
||||
@@ -342,7 +342,7 @@ func (a *app) routes() http.Handler {
|
||||
mux.HandleFunc("POST /update/check", a.auth(a.updateCheck))
|
||||
mux.HandleFunc("POST /update/install", a.auth(a.updateInstall))
|
||||
mux.HandleFunc("POST /update/upload", a.updateUpload)
|
||||
mux.HandleFunc("GET /upgrade", a.auth(a.upgradePage))
|
||||
mux.HandleFunc("GET /upgrade", a.auth(upgradeRedirect))
|
||||
mux.HandleFunc("POST /upgrade/channel", a.auth(a.upgradeChannel))
|
||||
mux.HandleFunc("POST /upgrade/{step}", a.auth(a.upgradeStep))
|
||||
mux.HandleFunc("/mcp", a.mcp)
|
||||
|
||||
@@ -52,6 +52,8 @@ main { padding: 1.5rem clamp(1rem, 3vw, 3rem) 3rem; }
|
||||
.cols { columns: 38rem 3; column-gap: 1.5rem; }
|
||||
.cols > section, .cols > fieldset, .cols > form > fieldset { break-inside: avoid; }
|
||||
.cols > section.busy, .cols > section.pending, .cols > section.notice { column-span: all; }
|
||||
.cols > h2.part { column-span: all; margin: 1rem 0 .2rem; padding-bottom: .3rem; border-bottom: 1px solid var(--line); font-size: 1.1rem; }
|
||||
.cols > h2.part:first-child { margin-top: 0; }
|
||||
/* A fold of its own (a log) sits below the columns: opening it must not make them balance again. */
|
||||
.cols > details { column-span: all; break-inside: avoid; margin-top: 1rem; }
|
||||
.menu-toggle { position: absolute; opacity: 0; pointer-events: none; }
|
||||
|
||||
@@ -29,8 +29,7 @@
|
||||
<a href="/prometheus"{{if eq .Title "Prometheus"}} aria-current="page"{{end}}>Prometheus</a>
|
||||
</div>
|
||||
<div class="group"><span>System</span>
|
||||
<a href="/update"{{if eq .Title "Update"}} aria-current="page"{{end}}>Update</a>
|
||||
<a href="/upgrade"{{if eq .Title "Packages"}} aria-current="page"{{end}}>Packages</a>
|
||||
<a href="/update"{{if eq .Title "Updates"}} aria-current="page"{{end}}>Updates</a>
|
||||
<a href="/tokens"{{if eq .Title "API access"}} aria-current="page"{{end}}>API access</a>
|
||||
<a href="/advanced"{{if eq .Title "Advanced"}} aria-current="page"{{end}}>Advanced</a>
|
||||
</div>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
</section>
|
||||
{{end}}
|
||||
{{with .Data.NewRelease}}
|
||||
<section class="notice"><p>NixOS {{.}} is out. <a href="/upgrade">See what it would change</a>.</p></section>
|
||||
<section class="notice"><p>NixOS {{.}} is out. <a href="/update#packages">See what it would change</a>.</p></section>
|
||||
{{end}}
|
||||
|
||||
<div id="dashboard" data-range="{{.Data.Dashboard.Range}}" data-interval="{{.Data.Dashboard.Interval}}">
|
||||
|
||||
@@ -1,31 +1,43 @@
|
||||
{{define "content"}}
|
||||
<div class="cols">
|
||||
{{$d := .Data}}
|
||||
<section>
|
||||
<h2>Installed</h2>
|
||||
<dl>
|
||||
<dt>Version</dt><dd>{{or $d.Installed.Version "unknown"}}{{if $d.Installed.Rev}} <span class="muted">{{$d.Installed.Rev}}</span>{{end}}</dd>
|
||||
<dt>Settings schema</dt><dd>{{$d.Installed.Schema}}</dd>
|
||||
</dl>
|
||||
</section>
|
||||
{{$u := .Data.Update}}{{$g := .Data.Upgrade}}
|
||||
|
||||
{{if $d.Status.Running}}
|
||||
{{if $u.Status.Running}}
|
||||
<div class="upload-overlay" role="dialog" aria-modal="true">
|
||||
<div class="upload-card wide">
|
||||
<h2>Updating…</h2>
|
||||
<progress max="100" value="{{$d.Progress}}"></progress>
|
||||
<p>{{$d.Step}}</p>
|
||||
{{if $d.Status.Log}}<pre class="log">{{$d.Status.Log}}</pre>{{end}}
|
||||
<progress max="100" value="{{$u.Progress}}"></progress>
|
||||
<p>{{$u.Step}}</p>
|
||||
{{if $u.Status.Log}}<pre class="log">{{$u.Status.Log}}</pre>{{end}}
|
||||
<p class="muted">This takes a few minutes. The page reloads when it is done; the web UI restarts when the new
|
||||
version is switched on, and you log in again.</p>
|
||||
</div>
|
||||
</div>
|
||||
{{else if $d.Pending}}
|
||||
{{else if $g.Run.Running}}
|
||||
<div class="upload-overlay" role="dialog" aria-modal="true">
|
||||
<div class="upload-card wide">
|
||||
<h2>{{$g.Title}}</h2>
|
||||
<progress max="100"></progress>
|
||||
{{if $g.Run.Log}}<pre class="log">{{$g.Run.Log}}</pre>{{end}}
|
||||
<p class="muted">The page reloads when it is done. The web UI restarts when an upgrade is switched on, and you log in again.</p>
|
||||
</div>
|
||||
</div>
|
||||
{{else if $u.Pending}}
|
||||
<section class="pending"><h2>Waiting for confirmation</h2>
|
||||
<p>A new configuration is active and not confirmed yet. Confirm it on the <a href="/">Overview</a>, or the router
|
||||
goes back to the previous version.</p></section>
|
||||
<p>A new system is active and not confirmed yet. Confirm it on the <a href="/">Overview</a>, or the router goes back to the
|
||||
previous one.</p></section>
|
||||
{{end}}
|
||||
|
||||
<h2 class="part">Router software</h2>
|
||||
|
||||
<section>
|
||||
<h2>Installed</h2>
|
||||
<dl>
|
||||
<dt>Version</dt><dd>{{or $u.Installed.Version "unknown"}}{{if $u.Installed.Rev}} <span class="muted">{{$u.Installed.Rev}}</span>{{end}}</dd>
|
||||
<dt>Settings schema</dt><dd>{{$u.Installed.Schema}}</dd>
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Install a bundle</h2>
|
||||
<p>A <code>.bundle</code> file made with <code>nix run .#release</code>. It is installed only if it is signed with
|
||||
@@ -41,17 +53,17 @@
|
||||
<h2>Update server</h2>
|
||||
<form method="post" action="/update/url" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<label>Address <input name="url" value="{{$d.URL}}" size="40" placeholder="https://updates.example.com/router"></label>
|
||||
<label>Address <input name="url" value="{{$u.URL}}" size="40" placeholder="https://updates.example.com/router"></label>
|
||||
<button class="secondary">Save</button>
|
||||
</form>
|
||||
{{if $d.URL}}
|
||||
{{if $u.URL}}
|
||||
<form method="post" action="/update/check" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<button class="secondary">Check for updates</button>
|
||||
</form>
|
||||
{{end}}
|
||||
{{if $d.OfferErr}}<p class="error">Could not check: {{$d.OfferErr}}</p>{{end}}
|
||||
{{with $d.Offer}}
|
||||
{{if $u.OfferErr}}<p class="error">Could not check: {{$u.OfferErr}}</p>{{end}}
|
||||
{{with $u.Offer}}
|
||||
<p>{{if .Newer}}Available: <strong>{{.Version}}</strong>{{if .Rev}} <span class="muted">{{.Rev}}</span>{{end}}.{{else}}Nothing newer: the server has {{.Version}}.{{end}}</p>
|
||||
<form method="post" action="/update/install">
|
||||
<input type="hidden" name="csrf" value="{{$.CSRF}}">
|
||||
@@ -63,10 +75,121 @@
|
||||
<code>nix run .#release</code> writes. The data is signed, so plain HTTP works too.</p>
|
||||
</section>
|
||||
|
||||
{{if and $d.Status.Log (not $d.Status.Running)}}
|
||||
<h2 class="part" id="packages">Packages</h2>
|
||||
|
||||
{{with $g.NewerRelease}}
|
||||
<section class="notice">
|
||||
<h2>NixOS {{.}} is out</h2>
|
||||
<p>You follow {{$g.Channel}}. {{.}} is the newer stable release: switch the channel to it, then look for upgrades and
|
||||
preview what would change. Nothing is installed until you upgrade, and NixOS cannot go back to the older release afterwards.</p>
|
||||
<form method="post" action="/upgrade/channel" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{$.CSRF}}">
|
||||
<input type="hidden" name="channel" value="{{.}}">
|
||||
<button class="secondary">Follow {{.}}</button>
|
||||
</form>
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
<section>
|
||||
<h2>Last update{{if $d.Status.Result}} — {{if eq $d.Status.Result "success"}}succeeded{{else}}failed ({{$d.Status.Result}}){{end}}{{end}}</h2>
|
||||
<pre class="log">{{$d.Status.Log}}</pre>
|
||||
<h2>Channel</h2>
|
||||
<p>Upgrades the kernel and all programs (NixOS) without a new release of nixos-router. Nothing is downloaded until
|
||||
you ask for it, and an upgrade is activated like a settings change: unless you confirm it in time, the router
|
||||
goes back to the previous system.</p>
|
||||
<dl>
|
||||
<dt>Running</dt><dd>{{or $g.Version "unknown"}}</dd>
|
||||
</dl>
|
||||
<form method="post" action="/upgrade/channel" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<label>Follow
|
||||
<select name="channel">
|
||||
{{range $g.Choices}}<option value="{{.Value}}"{{if eq .Value $g.Channel}} selected{{end}}>{{.Label}}</option>{{end}}
|
||||
</select>
|
||||
</label>
|
||||
<button class="secondary">Save</button>
|
||||
</form>
|
||||
{{if $g.ReleasesSeen}}<p class="hint">Stable releases as the channel server listed them on {{$g.ReleasesSeen}}; Check for upgrades asks again.</p>{{end}}
|
||||
<p class="hint">The channel only chooses what an upgrade offers; saving it changes nothing on the router. Going back to an older release
|
||||
(unstable to 26.05) is refused unless you tick "downgrade anyway" when previewing; state written by the newer
|
||||
release may not work with the older one.</p>
|
||||
</section>
|
||||
|
||||
{{if $g.Channel}}
|
||||
<section>
|
||||
<h2>Check</h2>
|
||||
<form method="post" action="/upgrade/check" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<button class="secondary"{{if or $g.Run.Running $g.Updating}} disabled{{end}}>Check for upgrades</button>
|
||||
</form>
|
||||
{{with $g.Check}}
|
||||
<dl>
|
||||
<dt>Channel</dt><dd>{{.Branch}}</dd>
|
||||
<dt>Running</dt><dd>{{.Running.Version}}</dd>
|
||||
<dt>Newest</dt><dd>{{printf "%.7s" .Newest.Rev}} <span class="muted">checked {{.Time}}</span></dd>
|
||||
</dl>
|
||||
{{if .UpToDate}}<p>Up to date.</p>{{else}}<p>A newer revision is available.</p>{{end}}
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>What would change</h2>
|
||||
<form method="post" action="/upgrade/preview" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
{{if and $g.Check $g.Check.UpToDate}}<label><input type="checkbox" name="force"> look anyway</label>{{end}}
|
||||
<label><input type="checkbox" name="downgrade"> downgrade anyway</label>
|
||||
<button class="secondary"{{if or $g.Run.Running $g.Updating}} disabled{{end}}>Preview</button>
|
||||
</form>
|
||||
<p class="hint">Works it out from the new revision's description: no package is downloaded.</p>
|
||||
{{with $g.Preview}}
|
||||
<p>{{$g.Version}} → <strong>{{.Version}}</strong> <span class="muted">{{printf "%.7s" .Rev}}, previewed {{.Time}}</span></p>
|
||||
{{if .Changes}}
|
||||
<table>
|
||||
<thead><tr><th>Package</th><th>Now</th><th></th><th>New</th></tr></thead>
|
||||
<tbody>{{range .Changes}}<tr><td>{{.Name}}</td><td>{{.From}}</td><td>→</td><td>{{.To}}</td></tr>{{end}}</tbody>
|
||||
</table>
|
||||
{{else}}<p>No package changes.</p>{{end}}
|
||||
<p class="hint">The list shows the versions of programs the router runs; a program that is only rebuilt does not appear.</p>
|
||||
<dl>
|
||||
<dt>To download</dt><dd>{{or .Download "nothing, or the package cache cannot be reached"}}</dd>
|
||||
<dt>Built here</dt><dd>{{.Builds}} derivation{{if ne .Builds 1}}s{{end}}{{if gt .Builds 50}} <span class="muted">(many: the package cache may not have them yet; this takes long)</span>{{end}}</dd>
|
||||
{{if .RebootNeeded}}<dt>Kernel</dt><dd>A new kernel: it runs after the next reboot.</dd>{{end}}
|
||||
</dl>
|
||||
{{if .BuildNames}}
|
||||
<details>
|
||||
<summary>What is built here</summary>
|
||||
<p class="hint">The system's own pieces (they carry the nixpkgs revision) and programs the package cache does not have yet.</p>
|
||||
<ul>{{range .BuildNames}}<li>{{.}}</li>{{end}}</ul>
|
||||
{{if .MoreBuilds}}<p class="muted">… and {{.MoreBuilds}} more</p>{{end}}
|
||||
</details>
|
||||
{{end}}
|
||||
<div class="actions">
|
||||
<form method="post" action="/upgrade/download">
|
||||
<input type="hidden" name="csrf" value="{{$.CSRF}}">
|
||||
<button class="secondary"{{if or $g.Run.Running $g.Updating $g.Pending}} disabled{{end}}>Download now</button>
|
||||
</form>
|
||||
<form method="post" action="/upgrade/apply">
|
||||
<input type="hidden" name="csrf" value="{{$.CSRF}}">
|
||||
<button{{if or $g.Run.Running $g.Updating $g.Pending}} disabled{{end}}>Upgrade to {{.Version}}</button>
|
||||
</form>
|
||||
</div>
|
||||
<p class="hint">Downloading first lets you start the upgrade later without needing the internet. Upgrading
|
||||
downloads what is missing, builds the system and switches to it; confirm it on the Overview.</p>
|
||||
{{end}}
|
||||
</section>
|
||||
{{else}}
|
||||
<section><p>Choose a channel to look for upgrades.</p></section>
|
||||
{{end}}
|
||||
|
||||
{{if and $u.Status.Log (not $u.Status.Running)}}
|
||||
<section>
|
||||
<h2>Last update{{if $u.Status.Result}} — {{if eq $u.Status.Result "success"}}succeeded{{else}}failed ({{$u.Status.Result}}){{end}}{{end}}</h2>
|
||||
<pre class="log">{{$u.Status.Log}}</pre>
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
{{if and $g.Run.Log (not $g.Run.Running)}}
|
||||
<section>
|
||||
<h2>Last package run{{if $g.Run.Result}} — {{if eq $g.Run.Result "success"}}succeeded{{else}}failed ({{$g.Run.Result}}){{end}}{{end}}</h2>
|
||||
<pre class="log">{{$g.Run.Log}}</pre>
|
||||
</section>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
{{define "content"}}
|
||||
<div class="cols">
|
||||
{{$d := .Data}}
|
||||
<section>
|
||||
<h2>Packages</h2>
|
||||
<p>Upgrades the kernel and all programs (NixOS) without a new release of nixos-router. Nothing is downloaded until
|
||||
you ask for it, and an upgrade is activated like a settings change: unless you confirm it in time, the router
|
||||
goes back to the previous system.</p>
|
||||
<dl>
|
||||
<dt>Running</dt><dd>{{or $d.Version "unknown"}}</dd>
|
||||
</dl>
|
||||
<form method="post" action="/upgrade/channel" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<label>Follow
|
||||
<select name="channel">
|
||||
{{range $d.Choices}}<option value="{{.Value}}"{{if eq .Value $d.Channel}} selected{{end}}>{{.Label}}</option>{{end}}
|
||||
</select>
|
||||
</label>
|
||||
<button class="secondary">Save</button>
|
||||
</form>
|
||||
{{if $d.ReleasesSeen}}<p class="hint">Stable releases as the channel server listed them on {{$d.ReleasesSeen}}; Check for upgrades asks again.</p>{{end}}
|
||||
<p class="hint">The channel only chooses what an upgrade offers; saving it changes nothing on the router. Going back to an older release
|
||||
(unstable to 26.05) is refused unless you tick "downgrade anyway" when previewing; state written by the newer
|
||||
release may not work with the older one.</p>
|
||||
</section>
|
||||
|
||||
{{with $d.NewerRelease}}
|
||||
<section class="notice">
|
||||
<h2>NixOS {{.}} is out</h2>
|
||||
<p>You follow {{$d.Channel}}. {{.}} is the newer stable release: switch the channel to it, then look for upgrades and
|
||||
preview what would change. Nothing is installed until you upgrade, and NixOS cannot go back to the older release afterwards.</p>
|
||||
<form method="post" action="/upgrade/channel" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{$.CSRF}}">
|
||||
<input type="hidden" name="channel" value="{{.}}">
|
||||
<button class="secondary">Follow {{.}}</button>
|
||||
</form>
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
{{if $d.Updating}}
|
||||
<section class="busy"><h2>Updating…</h2><p>The router is installing a new version of nixos-router.</p></section>
|
||||
{{else if $d.Run.Running}}
|
||||
<div class="upload-overlay" role="dialog" aria-modal="true">
|
||||
<div class="upload-card wide">
|
||||
<h2>{{$d.Title}}</h2>
|
||||
<progress max="100"></progress>
|
||||
{{if $d.Run.Log}}<pre class="log">{{$d.Run.Log}}</pre>{{end}}
|
||||
<p class="muted">The page reloads when it is done. The web UI restarts when an upgrade is switched on, and you log in again.</p>
|
||||
</div>
|
||||
</div>
|
||||
{{else if $d.Pending}}
|
||||
<section class="pending"><h2>Waiting for confirmation</h2>
|
||||
<p>A new system is active and not confirmed yet. Confirm it on the <a href="/">Overview</a>, or the router goes back to the
|
||||
previous one.</p></section>
|
||||
{{end}}
|
||||
|
||||
{{if $d.Channel}}
|
||||
<section>
|
||||
<h2>Check</h2>
|
||||
<form method="post" action="/upgrade/check" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<button class="secondary"{{if or $d.Run.Running $d.Updating}} disabled{{end}}>Check for upgrades</button>
|
||||
</form>
|
||||
{{with $d.Check}}
|
||||
<dl>
|
||||
<dt>Channel</dt><dd>{{.Branch}}</dd>
|
||||
<dt>Running</dt><dd>{{.Running.Version}}</dd>
|
||||
<dt>Newest</dt><dd>{{printf "%.7s" .Newest.Rev}} <span class="muted">checked {{.Time}}</span></dd>
|
||||
</dl>
|
||||
{{if .UpToDate}}<p>Up to date.</p>{{else}}<p>A newer revision is available.</p>{{end}}
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>What would change</h2>
|
||||
<form method="post" action="/upgrade/preview" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
{{if and $d.Check $d.Check.UpToDate}}<label><input type="checkbox" name="force"> look anyway</label>{{end}}
|
||||
<label><input type="checkbox" name="downgrade"> downgrade anyway</label>
|
||||
<button class="secondary"{{if or $d.Run.Running $d.Updating}} disabled{{end}}>Preview</button>
|
||||
</form>
|
||||
<p class="hint">Works it out from the new revision's description: no package is downloaded.</p>
|
||||
{{with $d.Preview}}
|
||||
<p>{{$d.Version}} → <strong>{{.Version}}</strong> <span class="muted">{{printf "%.7s" .Rev}}, previewed {{.Time}}</span></p>
|
||||
{{if .Changes}}
|
||||
<table>
|
||||
<thead><tr><th>Package</th><th>Now</th><th></th><th>New</th></tr></thead>
|
||||
<tbody>{{range .Changes}}<tr><td>{{.Name}}</td><td>{{.From}}</td><td>→</td><td>{{.To}}</td></tr>{{end}}</tbody>
|
||||
</table>
|
||||
{{else}}<p>No package changes.</p>{{end}}
|
||||
<p class="hint">The list shows the versions of programs the router runs; a program that is only rebuilt does not appear.</p>
|
||||
<dl>
|
||||
<dt>To download</dt><dd>{{or .Download "nothing, or the package cache cannot be reached"}}</dd>
|
||||
<dt>Built here</dt><dd>{{.Builds}} derivation{{if ne .Builds 1}}s{{end}}{{if gt .Builds 50}} <span class="muted">(many: the package cache may not have them yet; this takes long)</span>{{end}}</dd>
|
||||
{{if .RebootNeeded}}<dt>Kernel</dt><dd>A new kernel: it runs after the next reboot.</dd>{{end}}
|
||||
</dl>
|
||||
{{if .BuildNames}}
|
||||
<details>
|
||||
<summary>What is built here</summary>
|
||||
<p class="hint">The system's own pieces (they carry the nixpkgs revision) and programs the package cache does not have yet.</p>
|
||||
<ul>{{range .BuildNames}}<li>{{.}}</li>{{end}}</ul>
|
||||
{{if .MoreBuilds}}<p class="muted">… and {{.MoreBuilds}} more</p>{{end}}
|
||||
</details>
|
||||
{{end}}
|
||||
<div class="actions">
|
||||
<form method="post" action="/upgrade/download">
|
||||
<input type="hidden" name="csrf" value="{{$.CSRF}}">
|
||||
<button class="secondary"{{if or $d.Run.Running $d.Updating $d.Pending}} disabled{{end}}>Download now</button>
|
||||
</form>
|
||||
<form method="post" action="/upgrade/apply">
|
||||
<input type="hidden" name="csrf" value="{{$.CSRF}}">
|
||||
<button{{if or $d.Run.Running $d.Updating $d.Pending}} disabled{{end}}>Upgrade to {{.Version}}</button>
|
||||
</form>
|
||||
</div>
|
||||
<p class="hint">Downloading first lets you start the upgrade later without needing the internet. Upgrading
|
||||
downloads what is missing, builds the system and switches to it; confirm it on the Overview.</p>
|
||||
{{end}}
|
||||
</section>
|
||||
{{else}}
|
||||
<section><p>Choose a channel to look for upgrades.</p></section>
|
||||
{{end}}
|
||||
|
||||
{{if and $d.Run.Log (not $d.Run.Running)}}
|
||||
<section>
|
||||
<h2>Last run{{if $d.Run.Result}} — {{if eq $d.Run.Result "success"}}succeeded{{else}}failed ({{$d.Run.Result}}){{end}}{{end}}</h2>
|
||||
<pre class="log">{{$d.Run.Log}}</pre>
|
||||
</section>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
@@ -289,15 +289,31 @@ func (a *app) updateData() updateData {
|
||||
return d
|
||||
}
|
||||
|
||||
// updatesData is the Updates page: the router software (a release of
|
||||
// nixos-router) and the packages (nixpkgs) on one page.
|
||||
type updatesData struct {
|
||||
Update updateData
|
||||
Upgrade upgradeData
|
||||
}
|
||||
|
||||
func (a *app) updatesData() updatesData {
|
||||
return updatesData{Update: a.updateData(), Upgrade: a.upgradeData()}
|
||||
}
|
||||
|
||||
func (a *app) updatePage(w http.ResponseWriter, r *http.Request, sess session) {
|
||||
d := a.updateData()
|
||||
p := page{Title: "Update", CSRF: sess.csrf, LoggedIn: true, Data: d, Flash: r.URL.Query().Get("msg")}
|
||||
if d.Status.Running {
|
||||
d := a.updatesData()
|
||||
p := page{Title: "Updates", CSRF: sess.csrf, LoggedIn: true, Data: d, Flash: r.URL.Query().Get("msg")}
|
||||
if d.Update.Status.Running || d.Upgrade.Run.Running {
|
||||
p.Live = 3
|
||||
}
|
||||
a.render(w, "update", p)
|
||||
}
|
||||
|
||||
// upgradeRedirect sends the old address of the packages part to the page.
|
||||
func upgradeRedirect(w http.ResponseWriter, r *http.Request, _ session) {
|
||||
http.Redirect(w, r, "/update#packages", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (a *app) updateBack(w http.ResponseWriter, r *http.Request, msg string) {
|
||||
http.Redirect(w, r, "/update?msg="+url.QueryEscape(msg), http.StatusSeeOther)
|
||||
}
|
||||
@@ -324,17 +340,17 @@ func (a *app) updateSaveURL(w http.ResponseWriter, r *http.Request, _ session) {
|
||||
}
|
||||
|
||||
func (a *app) updateCheck(w http.ResponseWriter, r *http.Request, sess session) {
|
||||
d := a.updateData()
|
||||
p := page{Title: "Update", CSRF: sess.csrf, LoggedIn: true}
|
||||
if d.URL == "" {
|
||||
d := a.updatesData()
|
||||
p := page{Title: "Updates", CSRF: sess.csrf, LoggedIn: true}
|
||||
if d.Update.URL == "" {
|
||||
a.updateBack(w, r, "Set the update server first.")
|
||||
return
|
||||
}
|
||||
offer, err := a.sys.checkUpdate(d.URL)
|
||||
offer, err := a.sys.checkUpdate(d.Update.URL)
|
||||
if err != nil {
|
||||
d.OfferErr = err.Error()
|
||||
d.Update.OfferErr = err.Error()
|
||||
} else {
|
||||
d.Offer = &offer
|
||||
d.Update.Offer = &offer
|
||||
}
|
||||
p.Data = d
|
||||
a.render(w, "update", p)
|
||||
|
||||
@@ -294,17 +294,8 @@ func (a *app) upgradeData() upgradeData {
|
||||
return d
|
||||
}
|
||||
|
||||
func (a *app) upgradePage(w http.ResponseWriter, r *http.Request, sess session) {
|
||||
d := a.upgradeData()
|
||||
p := page{Title: "Packages", CSRF: sess.csrf, LoggedIn: true, Data: d, Flash: r.URL.Query().Get("msg")}
|
||||
if d.Run.Running {
|
||||
p.Live = 3
|
||||
}
|
||||
a.render(w, "upgrade", p)
|
||||
}
|
||||
|
||||
func (a *app) upgradeBack(w http.ResponseWriter, r *http.Request, msg string) {
|
||||
http.Redirect(w, r, "/upgrade?msg="+url.QueryEscape(msg), http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/update?msg="+url.QueryEscape(msg)+"#packages", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (a *app) upgradeChannel(w http.ResponseWriter, r *http.Request, _ session) {
|
||||
|
||||
@@ -37,6 +37,25 @@ func TestReleaseOfAndChannelChoices(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOneUpdatesPage(t *testing.T) {
|
||||
a, _ := newTestApp(t)
|
||||
h := a.routes()
|
||||
cookie := login(t, h)
|
||||
// The old address of the packages leads to the page that has both parts.
|
||||
if rec := do(h, "GET", "/upgrade", nil, cookie); rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != "/update#packages" {
|
||||
t.Fatalf("/upgrade: %d %q", rec.Code, rec.Header().Get("Location"))
|
||||
}
|
||||
body := do(h, "GET", "/update", nil, cookie).Body.String()
|
||||
for _, want := range []string{"Router software", "Install a bundle", "Update server", `id="packages"`, "Choose a channel", `aria-current="page">Updates`} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("the page lacks %q", want)
|
||||
}
|
||||
}
|
||||
if strings.Contains(body, `href="/upgrade"`) {
|
||||
t.Error("the menu still links /upgrade")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReleaseNotice(t *testing.T) {
|
||||
seen := []string{"25.05", "25.11", "26.05", "26.11"}
|
||||
if got := supportedReleases(seen); strings.Join(got, ",") != "26.05,26.11" {
|
||||
@@ -69,16 +88,16 @@ func TestReleaseNoticeShows(t *testing.T) {
|
||||
}
|
||||
h := a.routes()
|
||||
cookie := do(h, "POST", "/login", url.Values{"password": {"hunter2hunter2"}}, nil).Result().Cookies()[0]
|
||||
if body := do(h, "GET", "/upgrade", nil, cookie).Body.String(); strings.Contains(body, "is out") {
|
||||
if body := do(h, "GET", "/update", nil, cookie).Body.String(); strings.Contains(body, "is out") {
|
||||
t.Fatalf("a notice before the channel server was asked:\n%s", body)
|
||||
}
|
||||
os.WriteFile(filepath.Join(sys.upgradeDir(), "releases.json"), []byte(`{"time":"2026-11-19T00:00:00Z","releases":["26.05","26.11"]}`), 0o644)
|
||||
for _, path := range []string{"/", "/upgrade"} {
|
||||
for _, path := range []string{"/", "/update"} {
|
||||
if body := do(h, "GET", path, nil, cookie).Body.String(); !strings.Contains(body, "NixOS 26.11 is out") {
|
||||
t.Errorf("%s has no notice:\n%s", path, body)
|
||||
}
|
||||
}
|
||||
if body := do(h, "GET", "/upgrade", nil, cookie).Body.String(); !strings.Contains(body, `<option value="26.11"`) {
|
||||
if body := do(h, "GET", "/update", nil, cookie).Body.String(); !strings.Contains(body, `<option value="26.11"`) {
|
||||
t.Errorf("26.11 is not offered:\n%s", body)
|
||||
}
|
||||
}
|
||||
@@ -128,7 +147,7 @@ func TestUpgradePage(t *testing.T) {
|
||||
defer func() { startUnit = orig }()
|
||||
h := a.routes()
|
||||
cookie := login(t, h)
|
||||
page := func() string { return do(h, "GET", "/upgrade", nil, cookie).Body.String() }
|
||||
page := func() string { return do(h, "GET", "/update", nil, cookie).Body.String() }
|
||||
post := func(path string, form url.Values) *http.Response {
|
||||
form.Set("csrf", csrfFrom(t, page()))
|
||||
return do(h, "POST", path, form, cookie).Result()
|
||||
@@ -226,7 +245,7 @@ func TestUpgradePage(t *testing.T) {
|
||||
|
||||
t.Run("the last run's output is shown", func(t *testing.T) {
|
||||
os.WriteFile(filepath.Join(a.sys.upgradeDir(), "last.log"), []byte("channel 26.11 (nixos-26.11)\nup to date\n"), 0o600)
|
||||
if body := page(); !strings.Contains(body, "Last run") || !strings.Contains(body, "nixos-26.11)") {
|
||||
if body := page(); !strings.Contains(body, "Last package run") || !strings.Contains(body, "nixos-26.11)") {
|
||||
t.Fatalf("no log:\n%s", body)
|
||||
}
|
||||
if got := tail("a\nbb\nccc\n", 6); got != "ccc\n" {
|
||||
|
||||
Reference in New Issue
Block a user