Add ALT Linux downloader
Signed-off-by: Mikhail Gordeev <obirvalger@altlinux.org>
This commit is contained in:
parent
c611867224
commit
6103aa0aa5
@ -231,6 +231,7 @@ func (d *Definition) Validate() error {
|
||||
|
||||
validDownloaders := []string{
|
||||
"alpinelinux-http",
|
||||
"alt-http",
|
||||
"archlinux-http",
|
||||
"centos-http",
|
||||
"debootstrap",
|
||||
|
81
sources/alt-http.go
Normal file
81
sources/alt-http.go
Normal file
@ -0,0 +1,81 @@
|
||||
package sources
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/lxc/distrobuilder/shared"
|
||||
lxd "github.com/lxc/lxd/shared"
|
||||
)
|
||||
|
||||
// ALTHTTP represents the ALT Linux downloader.
|
||||
type ALTHTTP struct{}
|
||||
|
||||
// NewALTHTTP creates a new ALTHTTP instance.
|
||||
func NewALTHTTP() *ALTHTTP {
|
||||
return &ALTHTTP{}
|
||||
}
|
||||
|
||||
// Run downloads the tarball and unpacks it.
|
||||
func (s *ALTHTTP) Run(definition shared.Definition, rootfsDir string) error {
|
||||
release := definition.Image.Release
|
||||
|
||||
baseURL := fmt.Sprintf("%s/pub/distributions/ALTLinux/images/%s/cloud/",
|
||||
definition.Source.URL, release)
|
||||
|
||||
fname := fmt.Sprintf("alt-%s-rootfs-systemd-%s.tar.xz", strings.ToLower(release),
|
||||
definition.Image.ArchitectureMapped)
|
||||
|
||||
url, err := url.Parse(baseURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
checksumFile := ""
|
||||
if !definition.Source.SkipVerification {
|
||||
if len(definition.Source.Keys) != 0 {
|
||||
|
||||
checksumFile = baseURL + "SHA256SUM"
|
||||
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, "SHA256SUM"),
|
||||
filepath.Join(fpath, "SHA256SUM.asc"),
|
||||
definition.Source.Keys,
|
||||
definition.Source.Keyserver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !valid {
|
||||
return fmt.Errorf("Failed to validate tarball")
|
||||
}
|
||||
} 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
|
||||
}
|
@ -12,6 +12,8 @@ func Get(name string) Downloader {
|
||||
switch name {
|
||||
case "alpinelinux-http":
|
||||
return NewAlpineLinuxHTTP()
|
||||
case "alt-http":
|
||||
return NewALTHTTP()
|
||||
case "archlinux-http":
|
||||
return NewArchLinuxHTTP()
|
||||
case "centos-http":
|
||||
|
Loading…
Reference in New Issue
Block a user