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

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) ===
This fixes connectivity issues, and makes OpenWrt more usable.
The build.sh [1] script uses subversion which makes it a new dependency
of distrobuilder.

[1] https://github.com/mikma/lxd-openwrt

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
From f459e453df405795158f5f32be2bf68b9601a57e Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Thu, 5 Sep 2019 15:26:15 +0200
Subject: [PATCH] sources: Run OpenWrt correctly

This fixes connectivity issues, and makes OpenWrt more usable.
The build.sh [1] script uses subversion which makes it a new dependency
of distrobuilder.

[1] https://github.com/mikma/lxd-openwrt

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 sources/openwrt-http.go | 151 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 151 insertions(+)

diff --git a/sources/openwrt-http.go b/sources/openwrt-http.go
index 4c7ee0c..3bb71f4 100644
--- a/sources/openwrt-http.go
+++ b/sources/openwrt-http.go
@@ -1,6 +1,7 @@
 package sources
 
 import (
+       "bytes"
        "crypto/sha256"
        "errors"
        "fmt"
@@ -103,12 +104,138 @@ func (s *OpenWrtHTTP) Run(definition shared.Definition, 
rootfsDir string) error
                return err
        }
 
+       sdk := s.getSDK(baseURL, release)
+       if sdk == "" {
+               return fmt.Errorf("Failed to find SDK")
+       }
+
+       _, err = shared.DownloadHash(definition.Image, baseURL+sdk, 
checksumFile, sha256.New())
+       if err != nil {
+               return err
+       }
+
+       _, err = shared.DownloadHash(definition.Image, 
"https://github.com/mikma/lxd-openwrt/archive/master.tar.gz";, "", sha256.New())
+       if err != nil {
+               return err
+       }
+
+       tempScriptsDir := filepath.Join(os.TempDir(), "distrobuilder", "fixes", 
"lxd-openwrt-master")
+       tempSDKDir := filepath.Join(tempScriptsDir, "build_dir")
+
+       os.MkdirAll(tempSDKDir, 0755)
+       os.MkdirAll(tempScriptsDir, 0755)
+       defer os.RemoveAll(filepath.Join(os.TempDir(), "distrobuilder"))
+
        // Unpack
        err = lxd.Unpack(filepath.Join(fpath, fname), rootfsDir, false, false, 
nil)
        if err != nil {
                return err
        }
 
+       err = lxd.Unpack(filepath.Join(fpath, "master.tar.gz"), 
filepath.Join(os.TempDir(), "distrobuilder", "fixes"), false, false, nil)
+       if err != nil {
+               return fmt.Errorf("Failed to unpack scripts: %v", err)
+       }
+
+       err = lxd.Unpack(filepath.Join(fpath, sdk), tempSDKDir, false, false, 
nil)
+       if err != nil {
+               return fmt.Errorf("Failed to unpack SDK: %v", err)
+       }
+
+       // Set environment used in the lxd-openwrt scripts
+       os.Setenv("OPENWRT_ROOTFS", filepath.Join(fpath, fname))
+       os.Setenv("OPENWRT_ROOTFS_DIR", rootfsDir)
+       os.Setenv("OPENWRT_SDK", fmt.Sprintf("build_dir/%s", 
strings.TrimSuffix(sdk, ".tar.xz")))
+       os.Setenv("OPENWRT_ARCH", definition.Image.Architecture)
+       os.Setenv("OPENWRT_VERSION", release)
+
+       diff := `diff --git a/build.sh b/build.sh
+index 2347d05..eebb515 100755
+--- a/build.sh
++++ b/build.sh
+@@ -2,8 +2,8 @@
+
+ set -e
+
+-arch_lxd=x86_64
+-ver=18.06.4
++arch_lxd=${OPENWRT_ARCH}
++ver=${OPENWRT_VERSION}
+ dist=openwrt
+ type=lxd
+ super=fakeroot
+@@ -13,6 +13,9 @@ packages=iptables-mod-checksum
+ # Workaround for Debian/Ubuntu systems which use C.UTF-8 which is nsupported 
by OpenWrt
+ export LC_ALL=C
+
++readonly rootfs=${OPENWRT_ROOTFS}
++readonly sdk=${OPENWRT_SDK}
++
+ usage() {
+        echo "Usage: $0 [-a|--arch x86_64|i686|aarch64] [-v|--version 
version>] [-p|--packages <packages>] [-f|--files] [-t|--type lxd|lain] 
[-s|--super fakeroot|sudo] [--help]"
+        exit 1
+@@ -289,8 +292,6 @@ EOF
+ #     template: hostname.tpl
+ }
+
+-download_rootfs
+-download_sdk
+ if need_procd; then
+        download_procd
+        build_procd
+diff --git a/scripts/build_rootfs.sh b/scripts/build_rootfs.sh
+index b7ee533..e89379f 100755
+--- a/scripts/build_rootfs.sh
++++ b/scripts/build_rootfs.sh
+@@ -52,9 +52,9 @@ fi
+
+ src_tar=$1
+ base=` + "`basename $src_tar`" + `
+-dir=/tmp/build.$$
++dir=/tmp/distrobuilder
+ files_dir=files/
+-instroot=$dir/rootfs
++instroot=${OPENWRT_ROOTFS_DIR}
+ cache=dl/packages/$arch/$subarch
+
+ test -e $cache || mkdir -p $cache
+@@ -158,7 +158,6 @@ create_manifest() {
+        $OPKG list-installed > $instroot/etc/openwrt_manifest
+ }
+
+-unpack
+ disable_root
+ if test -n "$metadata"; then
+        add_file $metadata $metadata_dir $dir
+@@ -175,5 +174,3 @@ if test -n "$files"; then
+        add_files $files $instroot
+ fi
+ create_manifest
+-pack
+-#pack_squashfs
+`
+
+       currentDir, err := os.Getwd()
+       if err != nil {
+               return err
+       }
+       defer os.Chdir(currentDir)
+
+       err = os.Chdir(tempScriptsDir)
+       if err != nil {
+               return err
+       }
+
+       err = lxd.RunCommandWithFds(bytes.NewBufferString(diff), os.Stdout, 
"patch", "-p1")
+       if err != nil {
+               return err
+       }
+
+       _, err = lxd.RunCommand("sh", "build.sh")
+       if err != nil {
+               return err
+       }
+
        return nil
 }
 
@@ -135,3 +262,27 @@ func (s *OpenWrtHTTP) getLatestServiceRelease(baseURL, 
release string) string {
 
        return ""
 }
+
+func (s *OpenWrtHTTP) getSDK(baseURL, release string) string {
+       resp, err := http.Get(baseURL)
+       if err != nil {
+               fmt.Fprintln(os.Stderr, err)
+               return ""
+       }
+       defer resp.Body.Close()
+
+       body, err := ioutil.ReadAll(resp.Body)
+       if err != nil {
+               fmt.Fprintln(os.Stderr, err)
+               return ""
+       }
+
+       regex := 
regexp.MustCompile(fmt.Sprintf(">(openwrt-sdk-%s-.*\\.tar\\.xz)<", release))
+       releases := regex.FindAllStringSubmatch(string(body), -1)
+
+       if len(releases) > 0 {
+               return releases[len(releases)-1][1]
+       }
+
+       return ""
+}
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to