The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/252
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
From f904cb27d4f418dd34ea5b7933e7334830d9121a Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Wed, 23 Oct 2019 11:07:24 +0200 Subject: [PATCH] sources/oracle: Add support for Oracle Linux 8 Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- sources/oraclelinux-http.go | 125 ++++++++++++++++++++---------------- 1 file changed, 69 insertions(+), 56 deletions(-) diff --git a/sources/oraclelinux-http.go b/sources/oraclelinux-http.go index b3a1117..e02564a 100644 --- a/sources/oraclelinux-http.go +++ b/sources/oraclelinux-http.go @@ -10,6 +10,7 @@ import ( "syscall" lxd "github.com/lxc/lxd/shared" + "golang.org/x/sys/unix" "gopkg.in/antchfx/htmlquery.v1" "github.com/lxc/distrobuilder/shared" @@ -63,7 +64,7 @@ func (s *OracleLinuxHTTP) unpackISO(latestUpdate, filePath, rootfsDir string) er if err != nil { return err } - defer syscall.Unmount(isoDir, 0) + defer unix.Unmount(isoDir, 0) var rootfsImage string squashfsImage := filepath.Join(isoDir, "LiveOS", "squashfs.img") @@ -75,7 +76,7 @@ func (s *OracleLinuxHTTP) unpackISO(latestUpdate, filePath, rootfsDir string) er if err != nil { return err } - defer syscall.Unmount(squashfsDir, 0) + defer unix.Unmount(squashfsDir, 0) rootfsImage = filepath.Join(squashfsDir, "LiveOS", "rootfs.img") } else { @@ -133,53 +134,47 @@ func (s *OracleLinuxHTTP) unpackISO(latestUpdate, filePath, rootfsDir string) er } } - if rpmPkg == "" { - return fmt.Errorf("Couldn't determine RPM package") - } - - if yumPkg == "" { - return fmt.Errorf("Couldn't determine YUM package") - } + if rpmPkg != "" && yumPkg != "" { + rpmFileName := filepath.Join(tempRootDir, filepath.Base(rpmPkg)) + yumFileName := filepath.Join(tempRootDir, filepath.Base(yumPkg)) + gpgFileName := filepath.Join(tempRootDir, "RPM-GPG-KEY-oracle") - rpmFileName := filepath.Join(tempRootDir, filepath.Base(rpmPkg)) - yumFileName := filepath.Join(tempRootDir, filepath.Base(yumPkg)) - gpgFileName := filepath.Join(tempRootDir, "RPM-GPG-KEY-oracle") - - rpmFile, err := os.Create(rpmFileName) - if err != nil { - return err - } - defer rpmFile.Close() + rpmFile, err := os.Create(rpmFileName) + if err != nil { + return err + } + defer rpmFile.Close() - yumFile, err := os.Create(yumFileName) - if err != nil { - return err - } - defer yumFile.Close() + yumFile, err := os.Create(yumFileName) + if err != nil { + return err + } + defer yumFile.Close() - gpgFile, err := os.Create(gpgFileName) - if err != nil { - return err - } - defer gpgFile.Close() + gpgFile, err := os.Create(gpgFileName) + if err != nil { + return err + } + defer gpgFile.Close() - _, err = lxd.DownloadFileHash(http.DefaultClient, "", nil, nil, rpmFileName, fmt.Sprintf("%s/%s", baseURL, rpmPkg), "", nil, rpmFile) - if err != nil { - return err - } - rpmFile.Close() + _, err = lxd.DownloadFileHash(http.DefaultClient, "", nil, nil, rpmFileName, fmt.Sprintf("%s/%s", baseURL, rpmPkg), "", nil, rpmFile) + if err != nil { + return err + } + rpmFile.Close() - _, err = lxd.DownloadFileHash(http.DefaultClient, "", nil, nil, yumFileName, fmt.Sprintf("%s/%s", baseURL, yumPkg), "", nil, yumFile) - if err != nil { - return err - } - yumFile.Close() + _, err = lxd.DownloadFileHash(http.DefaultClient, "", nil, nil, yumFileName, fmt.Sprintf("%s/%s", baseURL, yumPkg), "", nil, yumFile) + if err != nil { + return err + } + yumFile.Close() - _, err = lxd.DownloadFileHash(http.DefaultClient, "", nil, nil, gpgFileName, "https://oss.oracle.com/ol6/RPM-GPG-KEY-oracle", "", nil, gpgFile) - if err != nil { - return err + _, err = lxd.DownloadFileHash(http.DefaultClient, "", nil, nil, gpgFileName, "https://oss.oracle.com/ol6/RPM-GPG-KEY-oracle", "", nil, gpgFile) + if err != nil { + return err + } + gpgFile.Close() } - gpgFile.Close() // Setup the mounts and chroot into the rootfs exitChroot, err := shared.SetupChroot(tempRootDir, shared.DefinitionEnv{}) @@ -198,39 +193,57 @@ arch="%s" # Create required files 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/${arch}/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/${arch}/index.html | grep -Eo '>yum-[[:digit:]][^ ]+\.rpm<' | tail -1 | sed 's|[<>]||g') +mkdir -p /etc/yum.repos.d /rootfs -rpm -ivh --nodeps "${_rpm}" "${_yum}" -rpm --import RPM-GPG-KEY-oracle +if which dnf; then + alias yum=dnf + baseurl=http://yum.oracle.com/repo/OracleLinux/OL${version}/baseos/latest/${arch}/ + gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle +else + baseurl=http://yum.oracle.com/repo/OracleLinux/OL${version}/${update}/base/${arch} + gpgkey=file:///RPM-GPG-KEY-oracle + + # Fetch and install rpm and yum from the Oracle repo + _rpm=$(curl -s ${baseurl}/index.html | grep -Eo '>rpm-[[:digit:]][^ ]+\.rpm<' | tail -1 | sed 's|[<>]||g') + _yum=$(curl -s ${baseurl}/index.html | grep -Eo '>yum-[[:digit:]][^ ]+\.rpm<' | tail -1 | sed 's|[<>]||g') + + rpm -ivh --nodeps "${_rpm}" "${_yum}" + rpm --import RPM-GPG-KEY-oracle +fi # Add repo -mkdir -p /etc/yum.repos.d cat <<- EOF > /etc/yum.repos.d/base.repo [base] name=Oracle Linux -baseurl=https://yum.oracle.com/repo/OracleLinux/OL${version}/${update}/base/${arch} +baseurl=${baseurl} enabled=1 gpgcheck=1 -gpgkey=file:///RPM-GPG-KEY-oracle +gpgkey=${gpgkey} EOF -mkdir /rootfs -yum --installroot=/rootfs -y --releasever=${version} install basesystem oraclelinux-release yum -rm -rf /rootfs/var/cache/yum +rm -rf /var/rootfs/* -cp RPM-GPG-KEY-oracle /rootfs +yum install --releasever=${version} --installroot=/rootfs -y basesystem oraclelinux-release yum +rm -rf /rootfs/var/cache/yum mkdir -p /rootfs/etc/yum.repos.d +cp /etc/yum.repos.d/base.repo /rootfs/etc/yum.repos.d/ + +if [ -f RPM-GPG-KEY-oracle ] && ! [ -f /rootfs/etc/pki/rpm-gpg/RPM-GPG-KEY-oracle ]; then + mkdir -p /rootfs/etc/pki/rpm-gpg/ + cp RPM-GPG-KEY-oracle /rootfs/etc/pki/rpm-gpg/ +fi + + cat <<- EOF > /rootfs/etc/yum.repos.d/base.repo [base] name=Oracle Linux -baseurl=https://yum.oracle.com/repo/OracleLinux/OL${version}/${update}/base/${arch} +baseurl=${baseurl} enabled=1 gpgcheck=1 -gpgkey=file:///RPM-GPG-KEY-oracle +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle EOF + `, s.majorVersion, latestUpdate, s.architecture)) if err != nil { exitChroot()
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel