[lxc-devel] [distrobuilder/master] [wip] opkg: add distro
aparcar on Github
lxc-bot at linuxcontainers.org
Mon May 20 11:14:17 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 840 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190520/991cbc64/attachment.bin>
-------------- next part --------------
From 871f29940599c7c5249278a3dd50a59ee7f7d175 Mon Sep 17 00:00:00 2001
From: Paul Spooren <mail at aparcar.org>
Date: Mon, 20 May 2019 13:07:42 +0200
Subject: [PATCH] opkg: add distro
---
doc/examples/openwrt | 60 ++++++++++++++++++++++++++
managers/manager.go | 2 +
managers/opkg.go | 32 ++++++++++++++
shared/definition.go | 2 +
sources/openwrt-http.go | 94 +++++++++++++++++++++++++++++++++++++++++
sources/source.go | 2 +
6 files changed, 192 insertions(+)
create mode 100644 doc/examples/openwrt
create mode 100644 managers/opkg.go
create mode 100644 sources/openwrt-http.go
diff --git a/doc/examples/openwrt b/doc/examples/openwrt
new file mode 100644
index 0000000..1ef5648
--- /dev/null
+++ b/doc/examples/openwrt
@@ -0,0 +1,60 @@
+image:
+ distribution: OpenWrt
+ release: snapshot
+ description: OpenWrt {{ image.release }}
+ expiry: 30d
+ architecture: x86_64
+
+source:
+ downloader: openwrt-http
+ url: https://downloads.openwrt.org
+ keyserver: keyserver.ubuntu.com
+ keys:
+ - 0x6768C55E79B032D77A28DA5F0F20257417E1CE16
+ - 0x54CC74307A2C6DC9CE618269CD84BCED626471F1
+ - 0x6D9278A33A9AB3146262DCECF93525A88B699029
+
+targets:
+ lxc:
+ create-message: |
+ You just created an {{ image.distribution }} container (release={{ image.release }}, arch={{ image.architecture }})
+
+ config:
+ - type: all
+ before: 5
+ content: |-
+ lxc.include = LXC_TEMPLATE_CONFIG/openwrt.common.conf
+
+ - type: user
+ before: 5
+ content: |-
+ lxc.include = LXC_TEMPLATE_CONFIG/openwrt.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
+
+ - path: /tmp/lock/opkg.lock
+ generator: dump
+
+packages:
+ manager: opkg
+ update: false
+ cleanup: false
diff --git a/managers/manager.go b/managers/manager.go
index 5823052..4965e1a 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 "opkg":
+ return NewOpkg()
case "pacman":
return NewPacman()
case "portage":
diff --git a/managers/opkg.go b/managers/opkg.go
new file mode 100644
index 0000000..1b5aedb
--- /dev/null
+++ b/managers/opkg.go
@@ -0,0 +1,32 @@
+package managers
+
+// NewOpkg creates a new Manager instance.
+func NewOpkg() *Manager {
+ return &Manager{
+ commands: ManagerCommands{
+ clean: "echo",
+ install: "echo",
+ refresh: "opkg",
+ remove: "echo",
+ update: "echo",
+ },
+ flags: ManagerFlags{
+ clean: []string{
+ "",
+ },
+ global: []string{},
+ install: []string{
+ "install",
+ },
+ remove: []string{
+ "remove",
+ },
+ refresh: []string{
+ "update",
+ },
+ update: []string{
+ "",
+ },
+ },
+ }
+}
diff --git a/shared/definition.go b/shared/definition.go
index 5a83975..058a32b 100644
--- a/shared/definition.go
+++ b/shared/definition.go
@@ -259,6 +259,7 @@ func (d *Definition) Validate() error {
"docker-http",
"oraclelinux-http",
"opensuse-http",
+ "openwrt-http",
"plamolinux-http",
}
if !shared.StringInSlice(strings.TrimSpace(d.Source.Downloader), validDownloaders) {
@@ -270,6 +271,7 @@ func (d *Definition) Validate() error {
"apk",
"apt",
"dnf",
+ "opkg",
"pacman",
"portage",
"yum",
diff --git a/sources/openwrt-http.go b/sources/openwrt-http.go
new file mode 100644
index 0000000..d11fef6
--- /dev/null
+++ b/sources/openwrt-http.go
@@ -0,0 +1,94 @@
+package sources
+
+import (
+ "crypto/sha256"
+ "errors"
+ "fmt"
+ "net/url"
+ "path/filepath"
+ "strings"
+
+ lxd "github.com/lxc/lxd/shared"
+
+ "github.com/lxc/distrobuilder/shared"
+)
+
+// OpenWrtHTTP represents the ALT Linux downloader.
+type OpenWrtHTTP struct{}
+
+// NewOpenWrtHTTP creates a new OpenWrtHTTP instance.
+func NewOpenWrtHTTP() *OpenWrtHTTP {
+ return &OpenWrtHTTP{}
+}
+
+// Run downloads the tarball and unpacks it.
+func (s *OpenWrtHTTP) Run(definition shared.Definition, rootfsDir string) error {
+ release := definition.Image.Release
+
+ architecturePath := strings.Replace(definition.Image.ArchitectureMapped, "_", "/", 1)
+
+ baseURL := fmt.Sprintf("%s/releases/%s/targets/%s/",
+ definition.Source.URL, release, architecturePath)
+ if release == "snapshot" {
+ baseURL = fmt.Sprintf("%s/snapshots/targets/%s/",
+ definition.Source.URL, architecturePath)
+ }
+
+ releaseInFilename := strings.ToLower(release) + "-"
+
+ if release == "snapshot" {
+ releaseInFilename = ""
+ }
+
+ fname := fmt.Sprintf("openwrt-%s%s-generic-rootfs.tar.gz", releaseInFilename,
+ strings.Replace(definition.Image.ArchitectureMapped, "_", "-", 1))
+
+ url, err := url.Parse(baseURL)
+ if err != nil {
+ return err
+ }
+
+ checksumFile := ""
+ if definition.Source.SkipVerification {
+ if len(definition.Source.Keys) != 0 {
+
+ checksumFile = baseURL + "sha256sums"
+ fpath, err := shared.DownloadHash(definition.Image, checksumFile+".asc", "", nil)
+ if err != nil {
+ return err
+ }
+
+ shared.DownloadHash(definition.Image, checksumFile, "", nil)
+
+ valid, err := shared.VerifyFile(
+ filepath.Join(fpath, "sha256sums"),
+ filepath.Join(fpath, "sha256sums.asc"),
+ definition.Source.Keys,
+ definition.Source.Keyserver)
+ if err != nil {
+ return err
+ }
+ if !valid {
+ return fmt.Errorf("Failed to validate archive")
+ }
+ } else {
+ // Force gpg checks when using http
+ if url.Scheme != "https" {
+ return errors.New("GPG keys are required if downloading from HTTP")
+ }
+ }
+ }
+
+ fpath, err := shared.DownloadHash(definition.Image, baseURL+fname, checksumFile, sha256.New())
+ if err != nil {
+ return err
+ }
+
+ // 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 657bc8a..b6f9356 100644
--- a/sources/source.go
+++ b/sources/source.go
@@ -34,6 +34,8 @@ func Get(name string) Downloader {
return NewOracleLinuxHTTP()
case "opensuse-http":
return NewOpenSUSEHTTP()
+ case "openwrt-http":
+ return NewOpenWrtHTTP()
case "plamolinux-http":
return NewPlamoLinuxHTTP()
}
More information about the lxc-devel
mailing list