The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/207

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: Moritz Maxeiner <m...@ucw.sh>
From aa35c11f17c04abd6952b1b968f0e8441fb557c9 Mon Sep 17 00:00:00 2001
From: Moritz Maxeiner <m...@ucw.sh>
Date: Fri, 26 Jul 2019 16:57:38 +0200
Subject: [PATCH] Add Funtoo

Signed-off-by: Moritz Maxeiner <m...@ucw.sh>
---
 doc/examples/funtoo    | 74 ++++++++++++++++++++++++++++++++++++++
 managers/egoportage.go | 31 ++++++++++++++++
 managers/manager.go    |  2 ++
 shared/definition.go   |  3 ++
 shared/osarch.go       |  8 +++++
 sources/funtoo-http.go | 80 ++++++++++++++++++++++++++++++++++++++++++
 sources/source.go      |  2 ++
 7 files changed, 200 insertions(+)
 create mode 100644 doc/examples/funtoo
 create mode 100644 managers/egoportage.go
 create mode 100644 sources/funtoo-http.go

diff --git a/doc/examples/funtoo b/doc/examples/funtoo
new file mode 100644
index 0000000..1dd81ab
--- /dev/null
+++ b/doc/examples/funtoo
@@ -0,0 +1,74 @@
+image:
+  distribution: funtoo
+  description: Funtoo
+  expiry: 30d
+  release: 1.3
+  architecture: x86_64
+
+source:
+  downloader: funtoo-http
+  url: http://build.funtoo.org
+  keys:
+    - 30737D12308C9D0C882FC34B57CB0A121BAECB2E
+
+targets:
+  lxc:
+    create-message: |
+      You just created a Funtoo container (arch={{ image.architecture }})
+
+    config:
+      - type: all
+        before: 5
+        content: |-
+          lxc.include = LXC_TEMPLATE_CONFIG/gentoo.common.conf
+
+      - type: user
+        before: 5
+        content: |-
+          lxc.include = LXC_TEMPLATE_CONFIG/gentoo.userns.conf
+
+      - type: all
+        after: 4
+        content: |-
+          lxc.include = LXC_TEMPLATE_CONFIG/common.conf
+
+      - type: user
+        after: 4
+        content: |-
+          lxc.include = LXC_TEMPLATE_CONFIG/userns.conf
+
+      - type: all
+        content: |-
+          lxc.arch = {{ image.architecture_kernel }}
+
+files:
+ - path: /etc/hostname
+   generator: hostname
+
+ - path: /etc/hosts
+   generator: hosts
+
+packages:
+  manager: egoportage
+
+  update: true
+  cleanup: true
+
+actions:
+  - trigger: post-packages
+    action: |-
+      #! /bin/sh
+      set -eux
+
+      rm -rf /boot/*
+      rm -rf /usr/src/*
+      rm -rf /var/git/meta-repo
+      rm -rf /var/cache/portage
+
+      cd /etc/init.d
+      ln -s netif.tmpl net.eth0
+      rc-update add net.eth0 default
+      echo template=dhcpcd > /etc/conf.d/net.eth0
+
+mappings:
+  architecture_map: funtoo
diff --git a/managers/egoportage.go b/managers/egoportage.go
new file mode 100644
index 0000000..4a6778e
--- /dev/null
+++ b/managers/egoportage.go
@@ -0,0 +1,31 @@
+package managers
+
+// NewEgoPortage creates a new Manager instance.
+func NewEgoPortage() *Manager {
+       return &Manager{
+               commands: ManagerCommands{
+                       clean:   "emerge",
+                       install: "emerge",
+                       refresh: "ego",
+                       remove:  "emerge",
+                       update:  "emerge",
+               },
+               flags: ManagerFlags{
+                       global: []string{},
+                       clean:  []string{},
+                       install: []string{
+                               "--autounmask-continue",
+                               "--quiet-build=y",
+                       },
+                       remove: []string{
+                               "--unmerge",
+                       },
+                       refresh: []string{
+                               "sync",
+                       },
+                       update: []string{
+                               "--update", "@world",
+                       },
+               },
+       }
+}
diff --git a/managers/manager.go b/managers/manager.go
index 39a2393..86ea8fd 100644
--- a/managers/manager.go
+++ b/managers/manager.go
@@ -43,6 +43,8 @@ func Get(name string) *Manager {
                return NewApt()
        case "dnf":
                return NewDnf()
+       case "egoportage":
+               return NewEgoPortage()
        case "opkg":
                return NewOpkg()
        case "pacman":
diff --git a/shared/definition.go b/shared/definition.go
index d9ab154..dce7831 100644
--- a/shared/definition.go
+++ b/shared/definition.go
@@ -263,6 +263,7 @@ func (d *Definition) Validate() error {
                "openwrt-http",
                "plamolinux-http",
                "voidlinux-http",
+               "funtoo-http",
        }
        if !shared.StringInSlice(strings.TrimSpace(d.Source.Downloader), 
validDownloaders) {
                return fmt.Errorf("source.downloader must be one of %v", 
validDownloaders)
@@ -273,6 +274,7 @@ func (d *Definition) Validate() error {
                        "apk",
                        "apt",
                        "dnf",
+                       "egoportage",
                        "opkg",
                        "pacman",
                        "portage",
@@ -339,6 +341,7 @@ func (d *Definition) Validate() error {
                "gentoo",
                "plamolinux",
                "voidlinux",
+               "funtoo",
        }
 
        architectureMap := strings.TrimSpace(d.Mappings.ArchitectureMap)
diff --git a/shared/osarch.go b/shared/osarch.go
index b178ee9..d7e0e37 100644
--- a/shared/osarch.go
+++ b/shared/osarch.go
@@ -58,6 +58,13 @@ var voidLinuxArchitectureNames = map[int]string{
        osarch.ARCH_64BIT_ARMV8_LITTLE_ENDIAN: "aarch64",
 }
 
+var funtooArchitectureNames = map[int]string{
+       osarch.ARCH_32BIT_INTEL_X86:             "generic_32",
+       osarch.ARCH_64BIT_INTEL_X86:             "generic_64",
+       osarch.ARCH_32BIT_ARMV7_LITTLE_ENDIAN:   "armv7a_vfpv3_hardfp",
+       osarch.ARCH_64BIT_ARMV8_LITTLE_ENDIAN:   "arm64_generic",
+}
+
 var distroArchitecture = map[string]map[int]string{
        "alpinelinux": alpineLinuxArchitectureNames,
        "altlinux":    altLinuxArchitectureNames,
@@ -67,6 +74,7 @@ var distroArchitecture = map[string]map[int]string{
        "gentoo":      gentooArchitectureNames,
        "plamolinux":  plamoLinuxArchitectureNames,
        "voidlinux":   voidLinuxArchitectureNames,
+       "funtoo":      funtooArchitectureNames,
 }
 
 // GetArch returns the correct architecture name used by the specified
diff --git a/sources/funtoo-http.go b/sources/funtoo-http.go
new file mode 100644
index 0000000..b8ac969
--- /dev/null
+++ b/sources/funtoo-http.go
@@ -0,0 +1,80 @@
+package sources
+
+import (
+       "errors"
+       "fmt"
+       "net/url"
+       "path/filepath"
+
+       lxd "github.com/lxc/lxd/shared"
+
+       "github.com/lxc/distrobuilder/shared"
+)
+
+// FuntooHTTP represents the Funtoo downloader.
+type FuntooHTTP struct{}
+
+// NewFuntooHTTP creates a new FuntooHTTP instance.
+func NewFuntooHTTP() *FuntooHTTP {
+       return &FuntooHTTP{}
+}
+
+// Run downloads a Funtoo stage3 tarball.
+func (s *FuntooHTTP) Run(definition shared.Definition, rootfsDir string) error 
{
+       topLevelArch := definition.Image.ArchitectureMapped
+       if topLevelArch == "generic_32" {
+               topLevelArch = "x86-32bit"
+       } else if topLevelArch == "generic_64" {
+               topLevelArch = "x86-64bit"
+       } else if topLevelArch == "armv7a_vfpv3_hardfp" {
+               topLevelArch = "arm-32bit"
+       } else if topLevelArch == "arm64_generic" {
+               topLevelArch = "arm-64bit"
+       }
+
+       fname := "stage3-latest.tar.xz"
+       tarball := fmt.Sprintf("%s/%s-release-std/%s/%s/%s",
+               definition.Source.URL, definition.Image.Release,
+               topLevelArch, definition.Image.ArchitectureMapped, fname)
+
+       url, err := url.Parse(tarball)
+       if err != nil {
+               return err
+       }
+
+       if !definition.Source.SkipVerification && url.Scheme != "https" &&
+               len(definition.Source.Keys) == 0 {
+               return errors.New("GPG keys are required if downloading from 
HTTP")
+       }
+
+       var fpath string
+
+       fpath, err = shared.DownloadHash(definition.Image, tarball, "", nil)
+       if err != nil {
+               return err
+       }
+
+       // Force gpg checks when using http
+       if !definition.Source.SkipVerification && url.Scheme != "https" {
+               shared.DownloadHash(definition.Image, tarball+".gpg", "", nil)
+               valid, err := shared.VerifyFile(
+                       filepath.Join(fpath, fname),
+                       filepath.Join(fpath, fname+".gpg"),
+                       definition.Source.Keys,
+                       definition.Source.Keyserver)
+               if err != nil {
+                       return err
+               }
+               if !valid {
+                       return errors.New("Failed to verify tarball")
+               }
+       }
+
+       // Unpack
+       err = lxd.Unpack(filepath.Join(fpath, fname), rootfsDir, false, false, 
nil)
+       if err != nil {
+               return err
+       }
+
+       return nil
+}
diff --git a/sources/source.go b/sources/source.go
index 4c953e7..b2ea519 100644
--- a/sources/source.go
+++ b/sources/source.go
@@ -40,6 +40,8 @@ func Get(name string) Downloader {
                return NewPlamoLinuxHTTP()
        case "voidlinux-http":
                return NewVoidLinuxHTTP()
+       case "funtoo-http":
+               return NewFuntooHTTP()
        }
 
        return nil
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to