Skip to content

Commit

Permalink
add short form of qcow2 images
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn authored and igorpecovnik committed Jan 11, 2025
1 parent c897ff3 commit 1c66551
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 73 deletions.
19 changes: 9 additions & 10 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/csv"
"encoding/json"
"errors"
"fmt"
"io"
"net/url"
"os"
Expand Down Expand Up @@ -126,8 +127,8 @@ func loadMapJSON(f io.Reader) (map[string]string, error) {
sb.WriteString(file.KernelBranch)

//if file.ImageVariant != "server" {
sb.WriteString("_")
sb.WriteString(file.ImageVariant)
sb.WriteString("_")
sb.WriteString(file.ImageVariant)
//}

if file.Preinstalled != "" {
Expand All @@ -137,22 +138,20 @@ func loadMapJSON(f io.Reader) (map[string]string, error) {

// Check special case for some extensions
switch {
case strings.HasSuffix(file.Extension, "boot-sms.img.xz"):
case strings.Contains(file.Extension, "boot-sms.img.xz"):
sb.WriteString("-boot-sms")
case strings.HasSuffix(file.Extension, "boot-boe.img.xz"):
case strings.Contains(file.Extension, "boot-boe.img.xz"):
sb.WriteString("-boot-boe")
case strings.HasSuffix(file.Extension, "boot-csot.img.xz"):
case strings.Contains(file.Extension, "boot-csot.img.xz"):
sb.WriteString("-boot-csot")
case strings.HasSuffix(file.Extension, "rootfs.img.xz"):
case strings.Contains(file.Extension, "rootfs.img.xz"):
sb.WriteString("-rootfs")
case strings.HasSuffix(file.Extension, "img.qcow2.xz"):
case strings.Contains(file.Extension, "img.qcow2.xz"):
sb.WriteString("-qcow2")
case strings.HasSuffix(file.Extension, "oowow.img.xz"):
sb.WriteString("")
}

// Add board into the map without an extension
if strings.HasSuffix(file.Extension, "img.xz") {
if strings.HasSuffix(file.Extension, "img.xz") || strings.HasSuffix(file.Extension, "img.qcow2.xz") {
m[sb.String()] = u.Path
}

Expand Down
175 changes: 112 additions & 63 deletions map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,74 +16,74 @@ var _ = Describe("Map", func() {
})
It("Should successfully load the map from a JSON file", func() {
data := `{
"assets": [
{
"board_slug": "aml-s9xx-box",
"armbian_version": "23.11.1",
"file_url": "https://dl.armbian.com/aml-s9xx-box/archive/Armbian_23.11.1_Aml-s9xx-box_bookworm_current_6.1.63.img.xz",
"file_updated": "2023-11-30T01:14:49Z",
"file_size": "566235552",
"distro_release": "bookworm",
"kernel_branch": "current",
"image_variant": "server",
"preinstalled_application": "",
"promoted": "true",
"download_repository": "archive",
"file_extension": "img.xz"
}
]
}`
"assets": [
{
"board_slug": "aml-s9xx-box",
"armbian_version": "23.11.1",
"file_url": "https://dl.armbian.com/aml-s9xx-box/archive/Armbian_23.11.1_Aml-s9xx-box_bookworm_current_6.1.63.img.xz",
"file_updated": "2023-11-30T01:14:49Z",
"file_size": "566235552",
"distro_release": "bookworm",
"kernel_branch": "current",
"image_variant": "server",
"preinstalled_application": "",
"promoted": "true",
"download_repository": "archive",
"file_extension": "img.xz"
}
]
}`

m, err := loadMapJSON(strings.NewReader(data))

Expect(err).To(BeNil())
Expect(m["aml-s9xx-box/Bookworm_current"]).To(Equal("/aml-s9xx-box/archive/Armbian_23.11.1_Aml-s9xx-box_bookworm_current_6.1.63.img.xz"))
Expect(m["aml-s9xx-box/Bookworm_current_server"]).To(Equal("/aml-s9xx-box/archive/Armbian_23.11.1_Aml-s9xx-box_bookworm_current_6.1.63.img.xz"))
})

It("Should successfully load the map from a JSON file, rewriting extension paths as necessary", func() {
data := `{
"assets": [
{
"board_slug": "khadas-vim1",
"file_url": "https://dl.armbian.com/khadas-vim1/archive/Armbian_23.11.1_Khadas-vim1_bookworm_current_6.1.63_xfce_desktop.img.xz",
"file_updated": "2023-11-30T01:06:34Z",
"file_size": "1605260504",
"distro_release": "bookworm",
"kernel_branch": "current",
"image_variant": "xfce",
"preinstalled_application": "",
"promoted": "false",
"download_repository": "archive",
"file_extension": "img.xz"
},
{
"board_slug": "khadas-vim1",
"file_url": "https://dl.armbian.com/khadas-vim1/archive/Armbian_23.11.1_Khadas-vim1_bookworm_current_6.1.63_xfce_desktop.img.xz.sha",
"file_updated": "2023-11-30T01:06:34Z",
"file_size": "1605260504",
"distro_release": "bookworm",
"kernel_branch": "current",
"image_variant": "xfce",
"preinstalled_application": "",
"promoted": "false",
"download_repository": "archive",
"file_extension": "img.xz.sha"
},
{
"board_slug": "khadas-vim1",
"file_url": "https://dl.armbian.com/khadas-vim1/archive/Armbian_23.11.1_Khadas-vim1_bookworm_current_6.1.63_xfce_desktop.img.xz",
"file_updated": "2023-11-30T01:06:34Z",
"file_size": "1605260504",
"distro_release": "bookworm",
"kernel_branch": "current",
"image_variant": "xfce",
"preinstalled_application": "test",
"promoted": "false",
"download_repository": "archive",
"file_extension": "img.xz"
}
]
}`
"assets": [
{
"board_slug": "khadas-vim1",
"file_url": "https://dl.armbian.com/khadas-vim1/archive/Armbian_23.11.1_Khadas-vim1_bookworm_current_6.1.63_xfce_desktop.img.xz",
"file_updated": "2023-11-30T01:06:34Z",
"file_size": "1605260504",
"distro_release": "bookworm",
"kernel_branch": "current",
"image_variant": "xfce",
"preinstalled_application": "",
"promoted": "false",
"download_repository": "archive",
"file_extension": "img.xz"
},
{
"board_slug": "khadas-vim1",
"file_url": "https://dl.armbian.com/khadas-vim1/archive/Armbian_23.11.1_Khadas-vim1_bookworm_current_6.1.63_xfce_desktop.img.xz.sha",
"file_updated": "2023-11-30T01:06:34Z",
"file_size": "1605260504",
"distro_release": "bookworm",
"kernel_branch": "current",
"image_variant": "xfce",
"preinstalled_application": "",
"promoted": "false",
"download_repository": "archive",
"file_extension": "img.xz.sha"
},
{
"board_slug": "khadas-vim1",
"file_url": "https://dl.armbian.com/khadas-vim1/archive/Armbian_23.11.1_Khadas-vim1_bookworm_current_6.1.63_xfce_desktop.img.xz",
"file_updated": "2023-11-30T01:06:34Z",
"file_size": "1605260504",
"distro_release": "bookworm",
"kernel_branch": "current",
"image_variant": "xfce",
"preinstalled_application": "test",
"promoted": "false",
"download_repository": "archive",
"file_extension": "img.xz"
}
]
}`

m, err := loadMapJSON(strings.NewReader(data))

Expand Down Expand Up @@ -136,15 +136,64 @@ var _ = Describe("Map", func() {
"promoted": "true",
"download_repository": "archive",
"file_extension": "oowow.img.xz.sha"
},
{
"board_slug": "uefi-arm64",
"armbian_version": "24.5.5",
"file_url": "https://dl.armbian.com/uefi-arm64/archive/Armbian_24.5.5_Uefi-arm64_bookworm_current_6.6.42_minimal.img.qcow2.xz",
"redi_url": "https://dl.armbian.com/uefi-arm64/Bookworm_current_minimal",
"file_updated": "2024-07-25T18:01:20Z",
"file_size": "673315888",
"distro_release": "bookworm",
"kernel_branch": "current",
"image_variant": "minimal",
"preinstalled_application": "",
"promoted": "false",
"download_repository": "archive",
"file_extension": "img.qcow2.xz"
},
{
"board_slug": "uefi-arm64",
"armbian_version": "24.5.5",
"file_url": "https://dl.armbian.com/uefi-arm64/archive/Armbian_24.5.5_Uefi-arm64_bookworm_current_6.6.42_minimal.img.qcow2.xz.asc",
"redi_url": "https://dl.armbian.com/uefi-arm64/Bookworm_current_minimal.asc",
"file_updated": "2024-07-25T18:01:20Z",
"file_size": "833",
"distro_release": "bookworm",
"kernel_branch": "current",
"image_variant": "minimal",
"preinstalled_application": "",
"promoted": "false",
"download_repository": "archive",
"file_extension": "img.qcow2.xz.asc"
},
{
"board_slug": "uefi-arm64",
"armbian_version": "24.5.5",
"file_url": "https://dl.armbian.com/uefi-arm64/archive/Armbian_24.5.5_Uefi-arm64_bookworm_current_6.6.42_minimal.img.qcow2.xz.sha",
"redi_url": "https://dl.armbian.com/uefi-arm64/Bookworm_current_minimal.sha",
"file_updated": "2024-07-25T18:01:20Z",
"file_size": "194",
"distro_release": "bookworm",
"kernel_branch": "current",
"image_variant": "minimal",
"preinstalled_application": "",
"promoted": "false",
"download_repository": "archive",
"file_extension": "img.qcow2.xz.sha"
}
]
}`

m, err := loadMapJSON(strings.NewReader(data))

Expect(err).To(BeNil())
Expect(m["khadas-vim4/Bookworm_legacy"]).To(Equal("/khadas-vim4/archive/Armbian_23.11.1_Khadas-vim4_bookworm_legacy_5.4.180.oowow.img.xz"))
Expect(m["khadas-vim4/Bookworm_legacy.asc"]).To(Equal("/khadas-vim4/archive/Armbian_23.11.1_Khadas-vim4_bookworm_legacy_5.4.180.oowow.img.xz.asc"))
Expect(m["khadas-vim4/Bookworm_legacy.sha"]).To(Equal("/khadas-vim4/archive/Armbian_23.11.1_Khadas-vim4_bookworm_legacy_5.4.180.oowow.img.xz.sha"))
Expect(m["khadas-vim4/Bookworm_legacy_server"]).To(Equal("/khadas-vim4/archive/Armbian_23.11.1_Khadas-vim4_bookworm_legacy_5.4.180.oowow.img.xz"))
Expect(m["khadas-vim4/Bookworm_legacy_server.asc"]).To(Equal("/khadas-vim4/archive/Armbian_23.11.1_Khadas-vim4_bookworm_legacy_5.4.180.oowow.img.xz.asc"))
Expect(m["khadas-vim4/Bookworm_legacy_server.sha"]).To(Equal("/khadas-vim4/archive/Armbian_23.11.1_Khadas-vim4_bookworm_legacy_5.4.180.oowow.img.xz.sha"))

Expect(m["uefi-arm64/Bookworm_current_minimal-qcow2"]).To(Equal("/uefi-arm64/archive/Armbian_24.5.5_Uefi-arm64_bookworm_current_6.6.42_minimal.img.qcow2.xz"))
Expect(m["uefi-arm64/Bookworm_current_minimal-qcow2.asc"]).To(Equal("/uefi-arm64/archive/Armbian_24.5.5_Uefi-arm64_bookworm_current_6.6.42_minimal.img.qcow2.xz.asc"))
Expect(m["uefi-arm64/Bookworm_current_minimal-qcow2.sha"]).To(Equal("/uefi-arm64/archive/Armbian_24.5.5_Uefi-arm64_bookworm_current_6.6.42_minimal.img.qcow2.xz.sha"))
})
})

0 comments on commit 1c66551

Please sign in to comment.