sources: Get latest release from mirror
Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
This commit is contained in:
parent
7c8186e42d
commit
7e8a05b899
@ -7,7 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"regexp"
|
||||||
|
|
||||||
"github.com/lxc/distrobuilder/shared"
|
"github.com/lxc/distrobuilder/shared"
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, rootfsDir string) erro
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Get latest release
|
// Get latest release
|
||||||
release, err = s.getLatestRelease()
|
release, err = s.getLatestRelease(definition.Source.URL, definition.Image.ArchitectureMapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -110,16 +110,30 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, rootfsDir string) erro
|
|||||||
definition.Image.ArchitectureMapped))
|
definition.Image.ArchitectureMapped))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ArchLinuxHTTP) getLatestRelease() (string, error) {
|
func (s *ArchLinuxHTTP) getLatestRelease(URL string, arch string) (string, error) {
|
||||||
doc, err := htmlquery.LoadURL("https://www.archlinux.org/download/")
|
u, err := url.Parse(URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
node := htmlquery.FindOne(doc, `//*[@id="arch-downloads"]/ul[1]/li[1]/text()`)
|
u.Path = path.Join(u.Path, "latest")
|
||||||
|
|
||||||
|
doc, err := htmlquery.LoadURL(u.String())
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
node := htmlquery.FindOne(doc, `//a[starts-with(text(),'archlinux-bootstrap-')][ends-with(text(),'.tar.gz')][@href]/text()`)
|
||||||
if node == nil {
|
if node == nil {
|
||||||
return "", fmt.Errorf("Failed to determine latest release")
|
return "", fmt.Errorf("Failed to determine latest release")
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.TrimSpace(node.Data), nil
|
re := regexp.MustCompile(fmt.Sprintf(`^archlinux-bootstrap-(\d{4}\.\d{2}\.\d{2})-%s.tar.gz$`, arch))
|
||||||
|
match := re.FindStringSubmatch(node.Data)
|
||||||
|
|
||||||
|
if len(match) != 2 {
|
||||||
|
return "", fmt.Errorf("Failed to determine latest release")
|
||||||
|
}
|
||||||
|
|
||||||
|
return match[1], nil
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
func TestArchLinuxGetLatestRelease(t *testing.T) {
|
func TestArchLinuxGetLatestRelease(t *testing.T) {
|
||||||
var src ArchLinuxHTTP
|
var src ArchLinuxHTTP
|
||||||
|
|
||||||
release, err := src.getLatestRelease()
|
release, err := src.getLatestRelease("https://mirrors.evowise.com/archlinux/iso/", "x86_64")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Regexp(t, regexp.MustCompile(`^\d{4}\.\d{2}\.\d{2}$`), release)
|
require.Regexp(t, regexp.MustCompile(`^\d{4}\.\d{2}\.\d{2}$`), release)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user