[lxc-devel] [distrobuilder/master] sources/funtoo: Fix image and gpg URLs

monstermunchkin on Github lxc-bot at linuxcontainers.org
Wed Apr 15 15:00:21 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 310 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200415/13b48fd6/attachment.bin>
-------------- next part --------------
From 2c580632d383451e63f9a5c4dab26eef300d3557 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 15 Apr 2020 16:59:52 +0200
Subject: [PATCH] sources/funtoo: Fix image and gpg URLs

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 sources/funtoo-http.go | 43 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/sources/funtoo-http.go b/sources/funtoo-http.go
index b8ac969..cf833b3 100644
--- a/sources/funtoo-http.go
+++ b/sources/funtoo-http.go
@@ -5,8 +5,12 @@ import (
 	"fmt"
 	"net/url"
 	"path/filepath"
+	"regexp"
+	"sort"
+	"strings"
 
 	lxd "github.com/lxc/lxd/shared"
+	"gopkg.in/antchfx/htmlquery.v1"
 
 	"github.com/lxc/distrobuilder/shared"
 )
@@ -32,10 +36,17 @@ func (s *FuntooHTTP) Run(definition shared.Definition, rootfsDir string) error {
 		topLevelArch = "arm-64bit"
 	}
 
-	fname := "stage3-latest.tar.xz"
-	tarball := fmt.Sprintf("%s/%s-release-std/%s/%s/%s",
+	baseURL := fmt.Sprintf("%s/%s-release-std/%s/%s",
 		definition.Source.URL, definition.Image.Release,
-		topLevelArch, definition.Image.ArchitectureMapped, fname)
+		topLevelArch, definition.Image.ArchitectureMapped)
+
+	releaseDate, err := s.getReleaseDate(baseURL)
+	if err != nil {
+		return err
+	}
+
+	fname := fmt.Sprintf("stage3-%s-%s-release-std-%s.tar.xz", definition.Image.ArchitectureMapped, definition.Image.Release, releaseDate)
+	tarball := fmt.Sprintf("%s/%s/%s", baseURL, releaseDate, fname)
 
 	url, err := url.Parse(tarball)
 	if err != nil {
@@ -78,3 +89,29 @@ func (s *FuntooHTTP) Run(definition shared.Definition, rootfsDir string) error {
 
 	return nil
 }
+
+func (s *FuntooHTTP) getReleaseDate(URL string) (string, error) {
+	doc, err := htmlquery.LoadURL(URL)
+	if err != nil {
+		return "", err
+	}
+
+	re := regexp.MustCompile(`^\d{4}\-\d{2}\-\d{2}/?$`)
+
+	var dirs []string
+
+	for _, node := range htmlquery.Find(doc, `//a[@href]/text()`) {
+		if re.MatchString(node.Data) {
+			dirs = append(dirs, strings.TrimSuffix(node.Data, "/"))
+		}
+	}
+
+	if len(dirs) == 0 {
+		return "", fmt.Errorf("Failed to get release date")
+	}
+
+	// Sort dirs in case they're out-of-order
+	sort.Strings(dirs)
+
+	return dirs[len(dirs)-1], nil
+}


More information about the lxc-devel mailing list