Compare commits
6 Commits
v0.0.9
...
d59c4036ef
| Author | SHA1 | Date | |
|---|---|---|---|
| d59c4036ef | |||
| ffc79b8ca3 | |||
| dada9d68f2 | |||
| 10893c07c3 | |||
| e7e742d98d | |||
| f2d4d5250a |
12
build.go
12
build.go
@@ -47,6 +47,7 @@ import (
|
|||||||
"go.elara.ws/lure/internal/db"
|
"go.elara.ws/lure/internal/db"
|
||||||
"go.elara.ws/lure/internal/dl"
|
"go.elara.ws/lure/internal/dl"
|
||||||
"go.elara.ws/lure/internal/repos"
|
"go.elara.ws/lure/internal/repos"
|
||||||
|
"go.elara.ws/lure/internal/osutils"
|
||||||
"go.elara.ws/lure/internal/shutils"
|
"go.elara.ws/lure/internal/shutils"
|
||||||
"go.elara.ws/lure/internal/shutils/decoder"
|
"go.elara.ws/lure/internal/shutils/decoder"
|
||||||
"go.elara.ws/lure/manager"
|
"go.elara.ws/lure/manager"
|
||||||
@@ -91,6 +92,9 @@ type Scripts struct {
|
|||||||
|
|
||||||
func buildCmd(c *cli.Context) error {
|
func buildCmd(c *cli.Context) error {
|
||||||
script := c.String("script")
|
script := c.String("script")
|
||||||
|
if c.String("package") != "" {
|
||||||
|
script = filepath.Join(config.RepoDir, c.String("package"), "lure.sh")
|
||||||
|
}
|
||||||
|
|
||||||
err := repos.Pull(c.Context, gdb, cfg.Repos)
|
err := repos.Pull(c.Context, gdb, cfg.Repos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -114,7 +118,7 @@ func buildCmd(c *cli.Context) error {
|
|||||||
|
|
||||||
for _, pkgPath := range pkgPaths {
|
for _, pkgPath := range pkgPaths {
|
||||||
name := filepath.Base(pkgPath)
|
name := filepath.Base(pkgPath)
|
||||||
err = os.Rename(pkgPath, filepath.Join(wd, name))
|
err = osutils.Move(pkgPath, filepath.Join(wd, name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error moving the package").Err(err).Send()
|
log.Fatal("Error moving the package").Err(err).Send()
|
||||||
}
|
}
|
||||||
@@ -689,8 +693,10 @@ func archMatches(architectures []string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(architectures, "arm") {
|
for _, arch := range architectures {
|
||||||
architectures = append(architectures, cpu.ARMVariant())
|
if strings.HasPrefix(arch, "arm") {
|
||||||
|
architectures = append(architectures, cpu.CompatibleARMReverse(arch)...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return slices.Contains(architectures, cpu.Arch())
|
return slices.Contains(architectures, cpu.Arch())
|
||||||
|
|||||||
@@ -44,11 +44,55 @@ func ARMVariant() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CompatibleARM returns all the compatible ARM variants given the system architecture
|
||||||
|
func CompatibleARM(variant string) []string {
|
||||||
|
switch variant {
|
||||||
|
case "arm7", "arm":
|
||||||
|
return []string{"arm7", "arm6", "arm5"}
|
||||||
|
case "arm6":
|
||||||
|
return []string{"arm6", "arm5"}
|
||||||
|
case "arm5":
|
||||||
|
return []string{"arm5"}
|
||||||
|
default:
|
||||||
|
return []string{variant}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompatibleARMReverse returns all the compatible ARM variants given the package's architecture
|
||||||
|
func CompatibleARMReverse(variant string) []string {
|
||||||
|
switch variant {
|
||||||
|
case "arm7":
|
||||||
|
return []string{"arm7"}
|
||||||
|
case "arm6":
|
||||||
|
return []string{"arm6", "arm7"}
|
||||||
|
case "arm5", "arm":
|
||||||
|
return []string{"arm5", "arm6", "arm7"}
|
||||||
|
default:
|
||||||
|
return []string{variant}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Arch returns the canonical CPU architecture of the system
|
// Arch returns the canonical CPU architecture of the system
|
||||||
func Arch() string {
|
func Arch() string {
|
||||||
arch := runtime.GOARCH
|
arch := os.Getenv("LURE_ARCH")
|
||||||
|
if arch == "" {
|
||||||
|
arch = runtime.GOARCH
|
||||||
|
}
|
||||||
if arch == "arm" {
|
if arch == "arm" {
|
||||||
arch = ARMVariant()
|
arch = ARMVariant()
|
||||||
}
|
}
|
||||||
return arch
|
return arch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Arches returns all the architectures the system is compatible with
|
||||||
|
func Arches() []string {
|
||||||
|
arch := os.Getenv("LURE_ARCH")
|
||||||
|
if arch == "" {
|
||||||
|
arch = runtime.GOARCH
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(arch, "arm") {
|
||||||
|
return append(CompatibleARM(arch), "arm")
|
||||||
|
} else {
|
||||||
|
return []string{Arch()}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
92
internal/osutils/move.go
Normal file
92
internal/osutils/move.go
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
package osutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Move attempts to use os.Rename and if that fails (such as for a cross-device move),
|
||||||
|
// it instead copies the source to the destination and then removes the source.
|
||||||
|
func Move(sourcePath, destPath string) error {
|
||||||
|
// Try to rename the source to the destination
|
||||||
|
err := os.Rename(sourcePath, destPath)
|
||||||
|
if err == nil {
|
||||||
|
return nil // Successful move
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rename failed, so copy the source to the destination
|
||||||
|
err = copyDirOrFile(sourcePath, destPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy successful, remove the original source
|
||||||
|
err = os.RemoveAll(sourcePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyDirOrFile(sourcePath, destPath string) error {
|
||||||
|
sourceInfo, err := os.Stat(sourcePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if sourceInfo.IsDir() {
|
||||||
|
return copyDir(sourcePath, destPath, sourceInfo)
|
||||||
|
} else if sourceInfo.Mode().IsRegular() {
|
||||||
|
return copyFile(sourcePath, destPath, sourceInfo)
|
||||||
|
} else {
|
||||||
|
// ignore non-regular files
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyDir(sourcePath, destPath string, sourceInfo os.FileInfo) error {
|
||||||
|
err := os.MkdirAll(destPath, sourceInfo.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
entries, err := os.ReadDir(sourcePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
|
sourceEntry := filepath.Join(sourcePath, entry.Name())
|
||||||
|
destEntry := filepath.Join(destPath, entry.Name())
|
||||||
|
|
||||||
|
err = copyDirOrFile(sourceEntry, destEntry)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyFile(sourcePath, destPath string, sourceInfo os.FileInfo) error {
|
||||||
|
sourceFile, err := os.Open(sourcePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer sourceFile.Close()
|
||||||
|
|
||||||
|
destFile, err := os.OpenFile(destPath, os.O_CREATE|os.O_TRUNC|os.O_RDWR, sourceInfo.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer destFile.Close()
|
||||||
|
|
||||||
|
_, err = io.Copy(destFile, sourceFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -20,7 +20,6 @@ package overrides
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.elara.ws/lure/distro"
|
"go.elara.ws/lure/distro"
|
||||||
@@ -59,13 +58,7 @@ func Resolve(info *distro.OSRelease, opts *Opts) ([]string, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
architectures := []string{runtime.GOARCH}
|
architectures := cpu.Arches()
|
||||||
|
|
||||||
if runtime.GOARCH == "arm" {
|
|
||||||
// More specific goes first
|
|
||||||
architectures[0] = cpu.ARMVariant()
|
|
||||||
architectures = append(architectures, "arm")
|
|
||||||
}
|
|
||||||
|
|
||||||
distros := []string{info.ID}
|
distros := []string{info.ID}
|
||||||
if opts.LikeDistros {
|
if opts.LikeDistros {
|
||||||
|
|||||||
5
main.go
5
main.go
@@ -160,6 +160,11 @@ func main() {
|
|||||||
Value: "lure.sh",
|
Value: "lure.sh",
|
||||||
Usage: "Path to the build script",
|
Usage: "Path to the build script",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "package",
|
||||||
|
Aliases: []string{"p"},
|
||||||
|
Usage: "Name of the package to build and its repo (example: default/go-bin)",
|
||||||
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "clean",
|
Name: "clean",
|
||||||
Aliases: []string{"c"},
|
Aliases: []string{"c"},
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ else
|
|||||||
error "No supported package manager detected!"
|
error "No supported package manager detected!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
latestVersion=$(curl -sI 'https://gitea.elara.ws/Elara6331/lure/releases/latest' | grep -o 'location: .*' | rev | cut -d '/' -f1 | rev | tr -d '[:space:]')
|
latestVersion=$(curl -sI 'https://gitea.elara.ws/Elara6331/lure/releases/latest' | grep -io 'location: .*' | rev | cut -d '/' -f1 | rev | tr -d '[:space:]')
|
||||||
info "Found latest LURE version:" $latestVersion
|
info "Found latest LURE version:" $latestVersion
|
||||||
|
|
||||||
fname="$(mktemp -u -p /tmp "lure.XXXXXXXXXX").${pkgFormat}"
|
fname="$(mktemp -u -p /tmp "lure.XXXXXXXXXX").${pkgFormat}"
|
||||||
|
|||||||
Reference in New Issue
Block a user