-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
283 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# *Gʰ*et | ||
# **Gʰ**et | ||
|
||
**Gʰ**et artifacts from GitHub releases. Also, a package manager. And an API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package api | ||
|
||
import "github.com/cardil/ghet/pkg/match" | ||
|
||
type Asset struct { | ||
ID int64 | ||
Name string | ||
ContentType string | ||
Size int | ||
URL string | ||
} | ||
|
||
type IndexedAssets struct { | ||
Archives []Asset | ||
Checksums []Asset | ||
Other []Asset | ||
} | ||
|
||
func CreateIndex(assets []Asset) IndexedAssets { | ||
index := IndexedAssets{} | ||
for _, asset := range assets { | ||
name := asset.Name | ||
if isArchive.Matches(name) { | ||
index.Archives = append(index.Archives, asset) | ||
} else if isChecksum.Matches(name) { | ||
index.Checksums = append(index.Checksums, asset) | ||
} else { | ||
index.Other = append(index.Other, asset) | ||
} | ||
} | ||
return index | ||
} | ||
|
||
var ( | ||
isArchive = match.Any( | ||
match.EndsWith(".tar.gz"), | ||
match.EndsWith(".tgz"), | ||
match.EndsWith(".tar.bz2"), | ||
match.EndsWith(".tbz2"), | ||
match.EndsWith(".tar.xz"), | ||
match.EndsWith(".txz"), | ||
match.EndsWith(".zip"), | ||
) | ||
|
||
isChecksum = match.Any( | ||
match.EndsWith(".sha256"), | ||
match.EndsWith(".sha512"), | ||
match.EndsWith(".md5"), | ||
match.Regex("checksums?\\.txt"), | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package github | ||
|
||
import ( | ||
"runtime" | ||
|
||
"github.com/cardil/ghet/pkg/match" | ||
) | ||
|
||
type Architecture string | ||
|
||
const ( | ||
ArchX86 Architecture = "x86" | ||
ArchAMD64 Architecture = "amd64" | ||
ArchARM Architecture = "arm" | ||
ArchARM64 Architecture = "arm64" | ||
ArchPPC64LE Architecture = "ppc64le" | ||
ArchS390X Architecture = "s390x" | ||
) | ||
|
||
func (a Architecture) Matches(name string) bool { | ||
return matchWith(name, archMatchers[a]) | ||
} | ||
|
||
func CurrentArchitecture() Architecture { | ||
return Architecture(runtime.GOARCH) | ||
} | ||
|
||
var archMatchers = map[Architecture]match.Matcher{ //nolint:gochecknoglobals | ||
ArchX86: match.Any( | ||
match.Every( | ||
match.Substr("x86"), | ||
match.Not(match.Substr("x86_64")), | ||
), | ||
match.Regex("i?[3-6]86"), | ||
), | ||
ArchAMD64: match.Any( | ||
match.Substr("amd64"), | ||
match.Substr("x86_64"), | ||
), | ||
ArchARM: match.Any( | ||
match.Substr("arm32"), | ||
match.Every( | ||
match.Substr("arm"), | ||
match.Not(match.Substr("arm64")), | ||
), | ||
), | ||
ArchARM64: match.Any(match.Substr("arm64")), | ||
ArchPPC64LE: match.Any(match.Regex("ppc-?64-?(?:le)?")), | ||
ArchS390X: match.Any(match.Substr("s390x")), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package github | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/cardil/ghet/pkg/match" | ||
) | ||
|
||
var notPackageManagers = match.Every( //nolint:gochecknoglobals | ||
match.Not(match.EndsWith(".deb")), | ||
match.Not(match.EndsWith(".rpm")), | ||
) | ||
|
||
func matchWith(name string, matcher match.Matcher) bool { | ||
name = strings.ToLower(name) | ||
return matcher.Matches(name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package github | ||
|
||
import ( | ||
"runtime" | ||
"strings" | ||
|
||
"github.com/cardil/ghet/pkg/match" | ||
"github.com/u-root/u-root/pkg/ldd" | ||
) | ||
|
||
type OsFamily string | ||
|
||
const ( | ||
OSFamilyDarwin OsFamily = "darwin" | ||
OSFamilyLinux OsFamily = "linux" | ||
OSFamilyWindows OsFamily = "windows" | ||
) | ||
|
||
type OperatingSystem string | ||
|
||
const ( | ||
OSDarwin OperatingSystem = "darwin" | ||
OSLinuxMusl OperatingSystem = "linux-musl" | ||
OSLinuxGnu OperatingSystem = "linux-gnu" | ||
OSWindows OperatingSystem = "windows" | ||
) | ||
|
||
func (os OperatingSystem) Matches(name string) bool { | ||
return matchWith(name, osMatchers[os]) | ||
} | ||
|
||
func CurrentOS() OperatingSystem { | ||
family := OsFamily(runtime.GOOS) | ||
//goland:noinspection GoBoolExpressions | ||
if family == OSFamilyLinux { | ||
return linuxFlavor() | ||
} | ||
return OperatingSystem(family) | ||
} | ||
|
||
var osMatchers = map[OperatingSystem]match.Matcher{ //nolint:gochecknoglobals | ||
OSLinuxMusl: match.Every( | ||
match.Any(match.Substr("linux", "musl")), | ||
notPackageManagers, | ||
), | ||
OSLinuxGnu: match.Every( | ||
match.Any( | ||
match.Substr("linux", "glibc"), | ||
match.Substr("linux", "gnu"), | ||
match.Every( | ||
match.Substr("linux"), | ||
match.Not(match.Substr("musl")), | ||
), | ||
), | ||
notPackageManagers, | ||
), | ||
OSDarwin: match.Any( | ||
match.Substr("darwin"), | ||
match.Substr("mac"), | ||
match.Substr("osx"), | ||
), | ||
OSWindows: match.Any( | ||
match.Substr("win"), | ||
), | ||
} | ||
|
||
func linuxFlavor() OperatingSystem { | ||
if fis, err := ldd.Ldd([]string{"/bin/sh"}); err == nil { | ||
for _, fi := range fis { | ||
if strings.Contains(fi.Name(), "musl") { | ||
return OSLinuxMusl | ||
} | ||
} | ||
} | ||
return OSLinuxGnu | ||
} |
Oops, something went wrong.