[lxc-devel] [distrobuilder/master] sources: Fix Oracle Linux 6

monstermunchkin on Github lxc-bot at linuxcontainers.org
Tue Feb 26 21:04:13 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190226/3138dc44/attachment.bin>
-------------- next part --------------
From f4dad0b7296c73936bd643595e107fff467051ed Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Tue, 26 Feb 2019 21:58:47 +0100
Subject: [PATCH] sources: Fix Oracle Linux 6

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 sources/oraclelinux-http.go | 39 +++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/sources/oraclelinux-http.go b/sources/oraclelinux-http.go
index 6cdb152..6e8d591 100644
--- a/sources/oraclelinux-http.go
+++ b/sources/oraclelinux-http.go
@@ -8,6 +8,7 @@ import (
 	"strings"
 	"syscall"
 
+	lxd "github.com/lxc/lxd/shared"
 	"gopkg.in/antchfx/htmlquery.v1"
 
 	"github.com/lxc/distrobuilder/shared"
@@ -34,13 +35,13 @@ func (s *OracleLinuxHTTP) Run(definition shared.Definition, rootfsDir string) er
 		return err
 	}
 
-	err = shared.DownloadHash(fmt.Sprintf("%s/u%s/x86_64/%s", baseURL, latestUpdate, fname),
+	err = shared.DownloadHash(fmt.Sprintf("%s/%s/x86_64/%s", baseURL, latestUpdate, fname),
 		"", nil)
 	if err != nil {
 		return fmt.Errorf("Error downloading Oracle Linux image: %s", err)
 	}
 
-	return s.unpackISO(latestUpdate, filepath.Join(os.TempDir(), fname), rootfsDir)
+	return s.unpackISO(latestUpdate[1:], filepath.Join(os.TempDir(), fname), rootfsDir)
 }
 
 func (s *OracleLinuxHTTP) unpackISO(latestUpdate, filePath, rootfsDir string) error {
@@ -63,16 +64,21 @@ func (s *OracleLinuxHTTP) unpackISO(latestUpdate, filePath, rootfsDir string) er
 
 	var rootfsImage string
 	squashfsImage := filepath.Join(isoDir, "LiveOS", "squashfs.img")
+	if lxd.PathExists(squashfsImage) {
 
-	// The squashfs.img contains an image containing the rootfs, so first
-	// mount squashfs.img
-	err = shared.RunCommand("mount", "-o", "ro", squashfsImage, squashfsDir)
-	if err != nil {
-		return err
-	}
-	defer syscall.Unmount(squashfsDir, 0)
+		// The squashfs.img contains an image containing the rootfs, so first
+		// mount squashfs.img
+		err = shared.RunCommand("mount", "-o", "ro", squashfsImage, squashfsDir)
+		if err != nil {
+			return err
+		}
+		defer syscall.Unmount(squashfsDir, 0)
+
+		rootfsImage = filepath.Join(squashfsDir, "LiveOS", "rootfs.img")
+	} else {
+		rootfsImage = filepath.Join(isoDir, "images", "install.img")
 
-	rootfsImage = filepath.Join(squashfsDir, "LiveOS", "rootfs.img")
+	}
 
 	err = shared.RunCommand("mount", "-o", "ro", rootfsImage, roRootDir)
 	if err != nil {
@@ -111,14 +117,14 @@ update="%s"
 touch /etc/mtab /etc/fstab
 
 # Fetch and install rpm and yum from the Oracle repo
-_rpm=$(curl -s https://yum.oracle.com/repo/OracleLinux/OL${version}/${update}/base/x86_64/index.html | grep -Eo '>rpm-[[:digit:]][^ ]+\.rpm<' | tail -1 | tr -d '<>')
-_yum=$(curl -s https://yum.oracle.com/repo/OracleLinux/OL${version}/${update}/base/x86_64/index.html | grep -Eo '>yum-[[:digit:]][^ ]+\.rpm<' | tail -1 | tr -d '<>')
+_rpm=$(curl -s https://yum.oracle.com/repo/OracleLinux/OL${version}/${update}/base/x86_64/index.html | grep -Eo '>rpm-[[:digit:]][^ ]+\.rpm<' | tail -1 | sed 's|[<>]||g')
+_yum=$(curl -s https://yum.oracle.com/repo/OracleLinux/OL${version}/${update}/base/x86_64/index.html | grep -Eo '>yum-[[:digit:]][^ ]+\.rpm<' | tail -1 | sed 's|[<>]||g')
 
-wget https://yum.oracle.com/repo/OracleLinux/OL${version}/${update}/base/x86_64/getPackage/${_rpm}
-wget https://yum.oracle.com/repo/OracleLinux/OL${version}/${update}/base/x86_64/getPackage/${_yum}
+wget --no-check-certificate https://yum.oracle.com/repo/OracleLinux/OL${version}/${update}/base/x86_64/getPackage/${_rpm}
+wget --no-check-certificate https://yum.oracle.com/repo/OracleLinux/OL${version}/${update}/base/x86_64/getPackage/${_yum}
 
 # There's no OL7 key!
-wget https://oss.oracle.com/ol6/RPM-GPG-KEY-oracle
+wget --no-check-certificate https://oss.oracle.com/ol6/RPM-GPG-KEY-oracle
 
 rpm -ivh --nodeps "${_rpm}" "${_yum}"
 rpm --import RPM-GPG-KEY-oracle
@@ -161,7 +167,7 @@ EOF
 }
 
 func (s *OracleLinuxHTTP) getLatestUpdate(URL string) (string, error) {
-	re := regexp.MustCompile(`^u\d+/$`)
+	re := regexp.MustCompile(`^[uU]\d+/$`)
 
 	doc, err := htmlquery.LoadURL(URL)
 	if err != nil {
@@ -180,6 +186,5 @@ func (s *OracleLinuxHTTP) getLatestUpdate(URL string) (string, error) {
 		return "", fmt.Errorf("No update found")
 	}
 
-	latestUpdate = strings.TrimPrefix(latestUpdate, "u")
 	return strings.TrimSuffix(latestUpdate, "/"), nil
 }


More information about the lxc-devel mailing list