Hardcode the repository releases come from
routerUpdate.repository (a module option beside the update keys, not a router.* setting) defaults to the project's repository; the Updates page names it but no longer has a field for it. Forks and tests set it in a module. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,21 +3,20 @@ package main
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Updates from a git repository (router.update.repository): router-update
|
||||
// check looks at the repository's release tags (vX.Y.Z) once a day and when the
|
||||
// page asks, and writes what it found to update/check.json; installing builds
|
||||
// the router from a tag, like an update from a bundle.
|
||||
// Updates from a git repository: router-update check looks at the
|
||||
// repository's release tags (vX.Y.Z) once a day and when the page asks, and
|
||||
// writes what it found to update/check.json; installing builds the router
|
||||
// from a tag, like an update from a bundle. The repository is part of the
|
||||
// installed version (routerUpdate.repository, written to
|
||||
// /etc/router-update-repository), not something the page sets.
|
||||
|
||||
var (
|
||||
// The same shape the option accepts: no credentials, no query.
|
||||
repositoryRe = regexp.MustCompile(`^https?://[A-Za-z0-9.-]+(:[0-9]+)?(/[A-Za-z0-9._~/-]*)?$`)
|
||||
releaseTagRe = regexp.MustCompile(`^v[0-9]+\.[0-9]+\.[0-9]+$`)
|
||||
)
|
||||
var releaseTagRe = regexp.MustCompile(`^v[0-9]+\.[0-9]+\.[0-9]+$`)
|
||||
|
||||
// GitCheck is update/check.json: the newest release tag of the repository.
|
||||
type GitCheck struct {
|
||||
@@ -32,14 +31,23 @@ type GitCheck struct {
|
||||
Newer bool `json:"newer"`
|
||||
}
|
||||
|
||||
func (s Settings) repository() string { return str(s, "router", "update", "repository") }
|
||||
// repository is where releases come from ("" if the router has none).
|
||||
func (s System) repository() string {
|
||||
path := s.RepositoryFile
|
||||
if path == "" {
|
||||
path = "/etc/router-update-repository"
|
||||
}
|
||||
data, _ := os.ReadFile(path)
|
||||
return strings.TrimSpace(string(data))
|
||||
}
|
||||
|
||||
const gitCheckUnit = "router-update-check.service"
|
||||
|
||||
// gitCheck is what the last check found, if it is still about this repository
|
||||
// and this installed version.
|
||||
func (a *app) gitCheck(repository string) *GitCheck {
|
||||
func (a *app) gitCheck() *GitCheck {
|
||||
var c GitCheck
|
||||
repository := a.sys.repository()
|
||||
if repository == "" || !readUpgradeFile(filepath.Join(a.sys.updateDir(), "check.json"), &c) {
|
||||
return nil
|
||||
}
|
||||
@@ -52,37 +60,15 @@ func (a *app) gitCheck(repository string) *GitCheck {
|
||||
// newRouterVersion is the version of a release that is out and not installed,
|
||||
// for the Overview ("" if there is none or nothing was checked).
|
||||
func (a *app) newRouterVersion() string {
|
||||
s, err := loadSettings(a.sys.settingsPath())
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
if c := a.gitCheck(s.repository()); c != nil && c.Newer {
|
||||
if c := a.gitCheck(); c != nil && c.Newer {
|
||||
return c.Newest.Version
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (a *app) updateSaveRepository(w http.ResponseWriter, r *http.Request, _ session) {
|
||||
v := strings.TrimRight(strings.TrimSpace(r.PostFormValue("repository")), "/")
|
||||
if !r.PostForm.Has("repository") {
|
||||
a.updateBack(w, r, "Not saved: no address was sent.")
|
||||
return
|
||||
}
|
||||
if v != "" && !repositoryRe.MatchString(v) {
|
||||
a.updateBack(w, r, "Not saved: an http:// or https:// address of a public repository, without credentials or a query.")
|
||||
return
|
||||
}
|
||||
if err := a.sys.setUpdateField("repository", v); err != nil {
|
||||
a.updateBack(w, r, "Not saved: "+err.Error())
|
||||
return
|
||||
}
|
||||
a.updateBack(w, r, "Saved.")
|
||||
}
|
||||
|
||||
func (a *app) updateGitCheck(w http.ResponseWriter, r *http.Request, _ session) {
|
||||
s, err := loadSettings(a.sys.settingsPath())
|
||||
if err != nil || s.repository() == "" {
|
||||
a.updateBack(w, r, "Set the repository first.")
|
||||
if a.sys.repository() == "" {
|
||||
a.updateBack(w, r, "This router has no repository to look at.")
|
||||
return
|
||||
}
|
||||
if err := startUnit(gitCheckUnit); err != nil {
|
||||
@@ -102,9 +88,8 @@ func (a *app) updateGitInstall(w http.ResponseWriter, r *http.Request, _ session
|
||||
a.updateBack(w, r, "Not a release tag: "+url.QueryEscape(tag))
|
||||
return
|
||||
}
|
||||
s, err := loadSettings(a.sys.settingsPath())
|
||||
if err != nil || s.repository() == "" {
|
||||
a.updateBack(w, r, "Set the repository first.")
|
||||
if a.sys.repository() == "" {
|
||||
a.updateBack(w, r, "This router has no repository to update from.")
|
||||
return
|
||||
}
|
||||
if err := a.sys.requestUpdate("git", tag, r.PostFormValue("force") == "on"); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user