Compare commits
116 Commits
test
...
064ee7f404
| Author | SHA1 | Date | |
|---|---|---|---|
| 064ee7f404 | |||
| 52ecacc4fe | |||
| 4c88ec3bc2 | |||
| ff5e271195 | |||
| cbea1dd8b5 | |||
| acf00bc5f8 | |||
| b15d847fd2 | |||
| 05af0969e9 | |||
| dff912928b | |||
| 0001118bd0 | |||
| 43a24a4f36 | |||
| d3c4a604c3 | |||
| 6c5abdf4d4 | |||
| 1c4ade5db9 | |||
| b31630a6c0 | |||
|
|
25eabc92ed | ||
| a111b060f1 | |||
| a62ddf8270 | |||
| aa65b28112 | |||
| 72a5ab7c5d | |||
| 89b3fdbc84 | |||
| 0a531488a3 | |||
| 7fbaef7bd4 | |||
| b411eff6f4 | |||
| befa4e3ea4 | |||
| 807d9fa784 | |||
| 9883fd92dc | |||
| 51c51b96bf | |||
| a69de7e918 | |||
| 4178387e2a | |||
| b6d7ec8a5f | |||
| 8feaf5d19b | |||
| 820ffc299f | |||
| ecce74d2e9 | |||
| 5ba30c617a | |||
| e3772d0944 | |||
| df32178372 | |||
| cc9587821d | |||
| 31af4d5389 | |||
| dbd63d371b | |||
| 52f675ab60 | |||
| 26f9e20ae8 | |||
| 6377de7208 | |||
| b58173837b | |||
| 97408da348 | |||
| be96001d78 | |||
| 7c4fba5c86 | |||
| 4cee062889 | |||
| 93093382f4 | |||
| e4b4d43163 | |||
| b89abb31df | |||
| 0a965c67c2 | |||
| 147fca375e | |||
| afc19b6e4d | |||
| 690f180687 | |||
| 7ef7b60cf5 | |||
| 4e2d506a01 | |||
| df4c76bd99 | |||
| af24fa84a2 | |||
| 4b54a9c74b | |||
| f25366d40c | |||
| cadf5fedcb | |||
| cfb11cf6e6 | |||
| bb4f221fc9 | |||
| 9cf5ae61d8 | |||
| ff4c61315e | |||
| 76450789b0 | |||
| 0e8db8b40e | |||
| 3591460214 | |||
| 96db4572b4 | |||
| 17e1b4b3ab | |||
| 73171424e4 | |||
| b4f55ad36f | |||
| 2c322d4de8 | |||
| 2735749b12 | |||
| 05fbbde194 | |||
| fe81e6bf22 | |||
| 2cfe78721a | |||
| ff986ef943 | |||
| f34308367e | |||
| 68b394523d | |||
| b14bd1806a | |||
| 3929493bfb | |||
| 2620ec00ab | |||
| 0485b8325f | |||
| 33d636b41d | |||
| ac236342b6 | |||
| 910cad2734 | |||
| fdb21aacc5 | |||
| a22a2a70c0 | |||
| f5399a66ba | |||
| 9e09b1e3a4 | |||
| f8bda68a57 | |||
| b84d43200a | |||
| 35cbc2e47c | |||
| 3a068ed90b | |||
| bdbc580c82 | |||
| 3c770c469d | |||
| 1c00df24a4 | |||
| f3ccd6d683 | |||
| 8de2eaced7 | |||
| c0057ca053 | |||
| 61149ae711 | |||
| bf10e39ffc | |||
| 379f640f33 | |||
| c7b0555076 | |||
| a3d18ed3d7 | |||
| 5c39f7ab2c | |||
| b676ea873e | |||
| b6a67b30c5 | |||
| c0a8922c2e | |||
| fad209d23c | |||
| 8dd6c68a15 | |||
| 0c81469566 | |||
| 6775002886 | |||
| bf1f967581 |
154
cmd/main.go
Normal file
154
cmd/main.go
Normal file
@@ -0,0 +1,154 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/go-git/go-git/v6"
|
||||
"github.com/roboogg133/packets/pkg/install"
|
||||
"github.com/roboogg133/packets/pkg/packet.lua.d"
|
||||
)
|
||||
|
||||
const bipath = "/usr/bin"
|
||||
|
||||
func main() {
|
||||
|
||||
log.SetFlags(log.Llongfile)
|
||||
|
||||
switch os.Args[1] {
|
||||
case "install":
|
||||
|
||||
f, err := os.ReadFile(os.Args[2])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
options := &packet.Config{
|
||||
BinDir: bipath,
|
||||
}
|
||||
pkg, err := packet.ReadPacket(f, options)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
pkgId := pkg.Name + "@" + pkg.Version
|
||||
if err := os.MkdirAll("_pkgtest/"+pkgId, 0777); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
os.MkdirAll("_pkgtest/"+pkgId+"/src", 0777)
|
||||
os.MkdirAll("_pkgtest/"+pkgId+"/packet", 0777)
|
||||
if pkg.Plataforms != nil {
|
||||
tmp := *pkg.Plataforms
|
||||
|
||||
plataform := tmp[packet.OperationalSystem(runtime.GOOS)]
|
||||
|
||||
for _, v := range *plataform.Sources {
|
||||
src, err := packet.GetSource(v.Url, v.Method, v.Specs, 5)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if v.Method == "GET" || v.Method == "POST" {
|
||||
f := src.([]byte)
|
||||
|
||||
if err := os.WriteFile("_pkgtest/"+pkgId+"/"+path.Base(v.Url), f, 0777); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := packet.Dearchive("_pkgtest/"+pkgId+"/"+path.Base(v.Url), "_pkgtest/"+pkgId+"/src"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
os.Remove("_pkgtest/" + pkgId + "/" + path.Base(v.Url))
|
||||
|
||||
} else {
|
||||
result, err := packet.GetSource(v.Url, v.Method, v.Specs, -213123)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
reponame, _ := strings.CutSuffix(path.Base(v.Url), ".git")
|
||||
|
||||
_, err = git.PlainClone("_pkgtest/"+pkgId+"/src/"+reponame, result.(*git.CloneOptions))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if pkg.GlobalSources != nil {
|
||||
for _, v := range *pkg.GlobalSources {
|
||||
src, err := packet.GetSource(v.Url, v.Method, v.Specs, 5)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if v.Method == "GET" || v.Method == "POST" {
|
||||
f := src.([]byte)
|
||||
|
||||
if err := os.WriteFile("_pkgtest/"+pkgId+"/"+path.Base(v.Url), f, 0777); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := packet.Dearchive("_pkgtest/"+pkgId+"/"+path.Base(v.Url), "_pkgtest/"+pkgId+"/src"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
os.Remove("_pkgtest/" + pkgId + "/" + path.Base(v.Url))
|
||||
|
||||
} else {
|
||||
result, err := packet.GetSource(v.Url, v.Method, v.Specs, -213123)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
reponame, _ := strings.CutSuffix(path.Base(v.Url), ".git")
|
||||
|
||||
_, err = git.PlainClone("_pkgtest/"+pkgId+"/src/"+reponame, result.(*git.CloneOptions))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
packetdir, err := filepath.Abs("_pkgtest/" + pkgId + "/packet")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
srcdir, err := filepath.Abs("_pkgtest/" + pkgId + "/src")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
rootdir, err := filepath.Abs("_pkgtest/" + pkgId)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
pkg.ExecuteBuild(&packet.Config{
|
||||
BinDir: bipath,
|
||||
PacketDir: packetdir,
|
||||
SourcesDir: srcdir,
|
||||
RootDir: rootdir,
|
||||
})
|
||||
|
||||
pkg.ExecuteInstall(&packet.Config{
|
||||
BinDir: bipath,
|
||||
PacketDir: packetdir,
|
||||
SourcesDir: srcdir,
|
||||
RootDir: rootdir,
|
||||
})
|
||||
|
||||
files, err := install.GetPackageFiles(packetdir)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := install.InstallFiles(files, packetdir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
28
go.mod
Normal file
28
go.mod
Normal file
@@ -0,0 +1,28 @@
|
||||
module github.com/roboogg133/packets
|
||||
|
||||
go 1.25.3
|
||||
|
||||
require github.com/yuin/gopher-lua v1.1.1
|
||||
|
||||
require (
|
||||
github.com/go-git/go-git/v6 v6.0.0-20251029213217-0bbfc0875edd
|
||||
github.com/klauspost/compress v1.18.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||
github.com/ProtonMail/go-crypto v1.3.0 // indirect
|
||||
github.com/cloudflare/circl v1.6.1 // indirect
|
||||
github.com/cyphar/filepath-securejoin v0.5.0 // indirect
|
||||
github.com/emirpasic/gods v1.18.1 // indirect
|
||||
github.com/go-git/gcfg/v2 v2.0.2 // indirect
|
||||
github.com/go-git/go-billy/v6 v6.0.0-20251022185412-61e52df296a5 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
|
||||
github.com/kevinburke/ssh_config v1.4.0 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||
github.com/pjbgf/sha1cd v0.5.0 // indirect
|
||||
github.com/sergi/go-diff v1.4.0 // indirect
|
||||
golang.org/x/crypto v0.43.0 // indirect
|
||||
golang.org/x/net v0.46.0 // indirect
|
||||
golang.org/x/sys v0.37.0 // indirect
|
||||
)
|
||||
68
go.sum
Normal file
68
go.sum
Normal file
@@ -0,0 +1,68 @@
|
||||
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
||||
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
||||
github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw=
|
||||
github.com/ProtonMail/go-crypto v1.3.0/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
|
||||
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
|
||||
github.com/cyphar/filepath-securejoin v0.5.0 h1:hIAhkRBMQ8nIeuVwcAoymp7MY4oherZdAxD+m0u9zaw=
|
||||
github.com/cyphar/filepath-securejoin v0.5.0/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o=
|
||||
github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE=
|
||||
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
|
||||
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
|
||||
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
|
||||
github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU=
|
||||
github.com/go-git/gcfg/v2 v2.0.2 h1:MY5SIIfTGGEMhdA7d7JePuVVxtKL7Hp+ApGDJAJ7dpo=
|
||||
github.com/go-git/gcfg/v2 v2.0.2/go.mod h1:/lv2NsxvhepuMrldsFilrgct6pxzpGdSRC13ydTLSLs=
|
||||
github.com/go-git/go-billy/v6 v6.0.0-20251022185412-61e52df296a5 h1:9nXOQ3HupDEerUXxiPrw3olFy/jHGZ3O3DyM/o6ejdc=
|
||||
github.com/go-git/go-billy/v6 v6.0.0-20251022185412-61e52df296a5/go.mod h1:TpCYxdQ0tWZkrnAkd7yqK+z1C8RKcyjcaYAJNAcnUnM=
|
||||
github.com/go-git/go-git-fixtures/v5 v5.1.1 h1:OH8i1ojV9bWfr0ZfasfpgtUXQHQyVS8HXik/V1C099w=
|
||||
github.com/go-git/go-git-fixtures/v5 v5.1.1/go.mod h1:Altk43lx3b1ks+dVoAG2300o5WWUnktvfY3VI6bcaXU=
|
||||
github.com/go-git/go-git/v6 v6.0.0-20251029213217-0bbfc0875edd h1:pn6+tR4O8McyqEr2MbQwqcySovpG8jDd11F/jQ6aAfA=
|
||||
github.com/go-git/go-git/v6 v6.0.0-20251029213217-0bbfc0875edd/go.mod h1:z9pQiXCfyOZIs/8qa5zmozzbcsDPtGN91UD7+qeX3hk=
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
|
||||
github.com/kevinburke/ssh_config v1.4.0 h1:6xxtP5bZ2E4NF5tuQulISpTO2z8XbtH8cg1PWkxoFkQ=
|
||||
github.com/kevinburke/ssh_config v1.4.0/go.mod h1:q2RIzfka+BXARoNexmF9gkxEX7DmvbW9P4hIVx2Kg4M=
|
||||
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
|
||||
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/pjbgf/sha1cd v0.5.0 h1:a+UkboSi1znleCDUNT3M5YxjOnN1fz2FhN48FlwCxs0=
|
||||
github.com/pjbgf/sha1cd v0.5.0/go.mod h1:lhpGlyHLpQZoxMv8HcgXvZEhcGs0PG/vsZnEJ7H0iCM=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
|
||||
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
|
||||
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
|
||||
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
|
||||
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
|
||||
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
|
||||
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
|
||||
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
|
||||
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
|
||||
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
|
||||
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
|
||||
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
150
internal/lua/luafunctions.go
Normal file
150
internal/lua/luafunctions.go
Normal file
@@ -0,0 +1,150 @@
|
||||
package lua
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
func LRemove(L *lua.LState) int {
|
||||
filename := L.CheckString(1)
|
||||
|
||||
err := os.RemoveAll(filename)
|
||||
if err != nil {
|
||||
L.Push(lua.LFalse)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
return 2
|
||||
}
|
||||
L.Push(lua.LTrue)
|
||||
L.Push(lua.LNil)
|
||||
return 2
|
||||
}
|
||||
|
||||
func LRename(L *lua.LState) int {
|
||||
oldname := L.CheckString(1)
|
||||
newname := L.CheckString(2)
|
||||
|
||||
if err := os.Rename(oldname, newname); err != nil {
|
||||
L.Push(lua.LFalse)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
return 2
|
||||
}
|
||||
|
||||
L.Push(lua.LTrue)
|
||||
return 1
|
||||
}
|
||||
func LCopy(L *lua.LState) int {
|
||||
oldname := L.CheckString(1)
|
||||
newname := L.CheckString(2)
|
||||
|
||||
os.MkdirAll(filepath.Dir(newname), 0755)
|
||||
if err := copyDir(oldname, newname); err != nil {
|
||||
L.Push(lua.LFalse)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
return 2
|
||||
}
|
||||
|
||||
L.Push(lua.LTrue)
|
||||
L.Push(lua.LNil)
|
||||
return 2
|
||||
|
||||
}
|
||||
|
||||
func LSymlink(L *lua.LState) int {
|
||||
fileName := L.CheckString(1)
|
||||
destination := L.CheckString(2)
|
||||
|
||||
_ = os.RemoveAll(destination)
|
||||
if err := os.Symlink(fileName, destination); err != nil {
|
||||
L.Push(lua.LFalse)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
return 2
|
||||
}
|
||||
|
||||
L.Push(lua.LTrue)
|
||||
L.Push(lua.LNil)
|
||||
return 2
|
||||
}
|
||||
|
||||
func Ljoin(L *lua.LState) int {
|
||||
|
||||
n := L.GetTop()
|
||||
parts := make([]string, 0, n)
|
||||
|
||||
for i := 1; i <= n; i++ {
|
||||
val := L.Get(i)
|
||||
parts = append(parts, val.String())
|
||||
}
|
||||
|
||||
result := filepath.Join(parts...)
|
||||
L.Push(lua.LString(result))
|
||||
return 1
|
||||
}
|
||||
|
||||
func LMkdir(L *lua.LState) int {
|
||||
path := L.CheckString(1)
|
||||
perm := L.CheckInt(2)
|
||||
|
||||
if err := os.MkdirAll(path, os.FileMode(perm)); err != nil {
|
||||
L.Push(lua.LFalse)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
return 2
|
||||
}
|
||||
|
||||
L.Push(lua.LTrue)
|
||||
L.Push(lua.LNil)
|
||||
return 2
|
||||
}
|
||||
|
||||
func LError(L *lua.LState) int {
|
||||
n := L.GetTop()
|
||||
parts := make([]any, 0, n)
|
||||
|
||||
for i := 1; i <= n; i++ {
|
||||
val := L.Get(i)
|
||||
parts = append(parts, val.String())
|
||||
}
|
||||
|
||||
llogger().Panic(parts...)
|
||||
return 0
|
||||
}
|
||||
|
||||
func LSetEnv(L *lua.LState) int {
|
||||
env := L.CheckString(1)
|
||||
value := L.CheckString(2)
|
||||
os.Setenv(env, value)
|
||||
return 0
|
||||
}
|
||||
|
||||
func LCD(L *lua.LState) int {
|
||||
dir := L.CheckString(1)
|
||||
|
||||
if err := os.Chdir(dir); err != nil {
|
||||
L.Push(lua.LFalse)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
return 2
|
||||
}
|
||||
|
||||
L.Push(lua.LTrue)
|
||||
L.Push(lua.LNil)
|
||||
return 2
|
||||
}
|
||||
|
||||
func LChmod(L *lua.LState) int {
|
||||
f := L.CheckString(1)
|
||||
mode := L.CheckInt(2)
|
||||
|
||||
if err := os.Chmod(f, os.FileMode(mode)); err != nil {
|
||||
L.Push(lua.LFalse)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
return 2
|
||||
}
|
||||
|
||||
L.Push(lua.LTrue)
|
||||
L.Push(lua.LNil)
|
||||
return 2
|
||||
}
|
||||
|
||||
func llogger() *log.Logger { return log.New(os.Stderr, "script error: ", 0) }
|
||||
95
internal/lua/utils.go
Normal file
95
internal/lua/utils.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package lua
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func copyDir(src string, dest string) error {
|
||||
if stats, err := os.Stat(src); err != nil {
|
||||
return err
|
||||
} else {
|
||||
if stats.IsDir() {
|
||||
files, err := os.ReadDir(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(dest, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
if file.IsDir() {
|
||||
copyDir(filepath.Join(src, file.Name()), filepath.Join(dest, file.Name()))
|
||||
continue
|
||||
}
|
||||
srcFile := filepath.Join(src, file.Name())
|
||||
|
||||
f, err := os.Create(filepath.Join(dest, file.Name()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
opennedSrcFile, err := os.Open(srcFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer opennedSrcFile.Close()
|
||||
if _, err := io.Copy(f, opennedSrcFile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if err := copyFile(src, dest); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func copyFile(source string, destination string) error {
|
||||
src, err := os.Open(source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
status, err := src.Stat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.MkdirAll(filepath.Dir(destination), 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dst, err := os.Create(destination)
|
||||
if err != nil {
|
||||
if !os.IsExist(err) {
|
||||
dst, err = os.Open(destination)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
defer dst.Close()
|
||||
if err := dst.Chmod(status.Mode()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.Copy(dst, src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
10
main.go
Normal file
10
main.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(runtime.GOARCH)
|
||||
}
|
||||
Binary file not shown.
98
pkg/install/main.go
Normal file
98
pkg/install/main.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package install
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type BasicFileStatus struct {
|
||||
Filepath string
|
||||
PermMode os.FileMode
|
||||
IsDir bool
|
||||
}
|
||||
|
||||
func GetPackageFiles(packetDir string) ([]BasicFileStatus, error) {
|
||||
return walkAll(packetDir)
|
||||
}
|
||||
|
||||
func walkAll(dirToWalk string) ([]BasicFileStatus, error) {
|
||||
var filesSlice []BasicFileStatus
|
||||
files, err := os.ReadDir(dirToWalk)
|
||||
if err != nil {
|
||||
return []BasicFileStatus{}, err
|
||||
}
|
||||
|
||||
for _, v := range files {
|
||||
basicStat := &BasicFileStatus{
|
||||
Filepath: filepath.Join(dirToWalk, v.Name()),
|
||||
PermMode: v.Type().Perm(),
|
||||
IsDir: v.IsDir(),
|
||||
}
|
||||
filesSlice = append(filesSlice, *basicStat)
|
||||
if v.IsDir() {
|
||||
filesSlice, err = walkAll(filepath.Join(dirToWalk, v.Name()))
|
||||
if err != nil {
|
||||
return []BasicFileStatus{}, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filesSlice, nil
|
||||
}
|
||||
|
||||
func InstallFiles(files []BasicFileStatus, packetDir string) error {
|
||||
for i, v := range files {
|
||||
sysPath, _ := strings.CutPrefix(v.Filepath, packetDir)
|
||||
fmt.Printf("[%d] Installing file %s\n", i, v.Filepath)
|
||||
fmt.Printf("[%d] NEED tro track file %s\n", i, sysPath)
|
||||
if err := copyFile(v.Filepath, sysPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func copyFile(source string, destination string) error {
|
||||
src, err := os.Open(source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
status, err := src.Stat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.MkdirAll(filepath.Dir(destination), 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dst, err := os.Create(destination)
|
||||
if err != nil {
|
||||
if !os.IsExist(err) {
|
||||
dst, err = os.Open(destination)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
defer dst.Close()
|
||||
if err := dst.Chmod(status.Mode()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.Copy(dst, src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
344
pkg/packet.lua.d/auxiliar_functions.go
Normal file
344
pkg/packet.lua.d/auxiliar_functions.go
Normal file
@@ -0,0 +1,344 @@
|
||||
package packet
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
func getStringFromTable(table *lua.LTable, key string) string {
|
||||
value := table.RawGetString(key)
|
||||
if value.Type() == lua.LTString {
|
||||
return value.String()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func getIntFromTable(table *lua.LTable, key string) int {
|
||||
value := table.RawGetString(key)
|
||||
if value.Type() == lua.LTNumber {
|
||||
if num, ok := value.(lua.LNumber); ok {
|
||||
return int(num)
|
||||
}
|
||||
}
|
||||
return -133
|
||||
}
|
||||
|
||||
func getStringArrayFromTable(table *lua.LTable, key string) []string {
|
||||
value := table.RawGetString(key)
|
||||
if value.Type() != lua.LTTable {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
arrayTable := value.(*lua.LTable)
|
||||
var result []string
|
||||
|
||||
arrayTable.ForEach(func(_, value lua.LValue) {
|
||||
if value.Type() == lua.LTString {
|
||||
result = append(result, value.String())
|
||||
}
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func getFunctionFromTable(table *lua.LTable, key string) *lua.LFunction {
|
||||
value := table.RawGetString(key)
|
||||
if value.Type() == lua.LTFunction {
|
||||
return value.(*lua.LFunction)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type version struct {
|
||||
Name string
|
||||
Constraint VersionConstraint
|
||||
}
|
||||
|
||||
func getDependenciesFromTable(table *lua.LTable, key string) *PkgDependencies {
|
||||
value := table.RawGetString(key)
|
||||
if value.Type() != lua.LTTable {
|
||||
return &PkgDependencies{}
|
||||
}
|
||||
|
||||
var pkgDeps PkgDependencies
|
||||
|
||||
depnTable := value.(*lua.LTable)
|
||||
|
||||
pkgDeps.RuntimeDependencies = depsParse(depnTable, "runtime")
|
||||
pkgDeps.BuildDependencies = depsParse(depnTable, "build")
|
||||
pkgDeps.Conflicts = depsParse(depnTable, "conflicts")
|
||||
|
||||
return &pkgDeps
|
||||
}
|
||||
|
||||
func getSourcesFromTable(table *lua.LTable, key string) *[]Source {
|
||||
value := table.RawGetString(key)
|
||||
if value.Type() != lua.LTTable {
|
||||
return nil
|
||||
}
|
||||
|
||||
var srcList []Source
|
||||
|
||||
srcTable := value.(*lua.LTable)
|
||||
|
||||
srcTable.ForEach(func(_, value lua.LValue) {
|
||||
if value.Type() == lua.LTTable {
|
||||
src := value.(*lua.LTable)
|
||||
|
||||
var srcInfo Source
|
||||
|
||||
method := src.RawGetString("method")
|
||||
if method.Type() == lua.LTString {
|
||||
srcInfo.Method = method.String()
|
||||
}
|
||||
|
||||
url := src.RawGetString("url")
|
||||
|
||||
if url.Type() == lua.LTString {
|
||||
srcInfo.Url = url.String()
|
||||
}
|
||||
|
||||
switchlabel:
|
||||
switch srcInfo.Method {
|
||||
case "GET":
|
||||
var getSpecs GETSpecs
|
||||
|
||||
getSpecs.SHA256 = new(string)
|
||||
sha256sumL := src.RawGetString("sha256")
|
||||
if sha256sumL.Type() == lua.LTString {
|
||||
*getSpecs.SHA256 = sha256sumL.String()
|
||||
}
|
||||
|
||||
headersLT := src.RawGetString("headers")
|
||||
if headersLT.Type() == lua.LTTable {
|
||||
|
||||
headers := headersLT.(*lua.LTable)
|
||||
|
||||
tmpMap := make(map[string]string)
|
||||
headers.ForEach(func(headerKey, value lua.LValue) {
|
||||
if value.Type() == lua.LTString {
|
||||
tmpMap[headerKey.String()] = value.String()
|
||||
}
|
||||
})
|
||||
|
||||
getSpecs.Headers = &tmpMap
|
||||
}
|
||||
srcInfo.Specs = getSpecs
|
||||
break switchlabel
|
||||
|
||||
case "git":
|
||||
var gitSpecs GitSpecs
|
||||
|
||||
branchL := src.RawGetString("branch")
|
||||
|
||||
if branchL.Type() == lua.LTString {
|
||||
gitSpecs.Branch = branchL.String()
|
||||
}
|
||||
|
||||
tagL := src.RawGetString("tag")
|
||||
|
||||
if tagL.Type() == lua.LTString {
|
||||
*gitSpecs.Tag = tagL.String()
|
||||
}
|
||||
|
||||
srcInfo.Specs = gitSpecs
|
||||
break switchlabel
|
||||
case "POST":
|
||||
var postSpecs POSTSpecs
|
||||
|
||||
sha256sumL := src.RawGetString("sha256")
|
||||
if sha256sumL.Type() == lua.LTString {
|
||||
*postSpecs.SHA256 = sha256sumL.String()
|
||||
}
|
||||
|
||||
headersLT := src.RawGetString("headers")
|
||||
if headersLT.Type() == lua.LTTable {
|
||||
|
||||
headers := headersLT.(*lua.LTable)
|
||||
|
||||
tmpMap := make(map[string]string)
|
||||
headers.ForEach(func(headerKey, value lua.LValue) {
|
||||
if value.Type() == lua.LTString {
|
||||
tmpMap[headerKey.String()] = value.String()
|
||||
}
|
||||
})
|
||||
|
||||
postSpecs.Headers = &tmpMap
|
||||
}
|
||||
|
||||
bodyLt := src.RawGetString("body")
|
||||
|
||||
if bodyLt.Type() == lua.LTString {
|
||||
*postSpecs.Body = bodyLt.String()
|
||||
}
|
||||
|
||||
srcInfo.Specs = postSpecs
|
||||
break switchlabel
|
||||
}
|
||||
srcList = append(srcList, srcInfo)
|
||||
}
|
||||
})
|
||||
|
||||
return &srcList
|
||||
}
|
||||
|
||||
func getPlataformsFromTable(table *lua.LTable, key string) *map[OperationalSystem]Plataform {
|
||||
value := table.RawGetString(key)
|
||||
|
||||
if value.Type() != lua.LTTable {
|
||||
return nil
|
||||
}
|
||||
|
||||
tmpMap := make(map[OperationalSystem]Plataform)
|
||||
|
||||
plataform := value.(*lua.LTable)
|
||||
|
||||
plataform.ForEach(func(osString, value lua.LValue) {
|
||||
if value.Type() != lua.LTTable {
|
||||
return
|
||||
}
|
||||
|
||||
var plat Plataform
|
||||
plat.Architetures = getStringArrayFromTable(value.(*lua.LTable), "arch")
|
||||
plat.Name = osString.String()
|
||||
plat.Sources = getSourcesFromTable(value.(*lua.LTable), "sources")
|
||||
plat.Dependencies = getDependenciesFromTable(value.(*lua.LTable), "dependencies")
|
||||
|
||||
tmpMap[OperationalSystem(osString.String())] = plat
|
||||
})
|
||||
|
||||
if len(tmpMap) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &tmpMap
|
||||
}
|
||||
|
||||
func depsParse(depnTable *lua.LTable, key string) *map[string]*VersionConstraint {
|
||||
if runLTable := depnTable.RawGetString(key); runLTable.Type() == lua.LTTable {
|
||||
runtimeTable := runLTable.(*lua.LTable)
|
||||
|
||||
mapTemp := make(map[string]*VersionConstraint)
|
||||
|
||||
var found bool
|
||||
|
||||
runtimeTable.ForEach(func(_, value lua.LValue) {
|
||||
if value.Type() == lua.LTString {
|
||||
version := parseVersionString(value.String())
|
||||
mapTemp[version.Name] = &version.Constraint
|
||||
found = true
|
||||
}
|
||||
})
|
||||
if !found {
|
||||
return nil
|
||||
} else {
|
||||
return &mapTemp
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseVersionString(s string) version {
|
||||
// >=go@1.25.3 | <=go@1.25.3 | go | >go@1.25.3 | <go@1.25.3 | go@1.25.3
|
||||
if strings.ContainsAny(s, "@") {
|
||||
slice := strings.Split(s, "@")
|
||||
|
||||
switch {
|
||||
case !strings.ContainsAny(s, "<=>"):
|
||||
return version{
|
||||
Name: slice[0],
|
||||
Constraint: VersionConstraint(slice[1]),
|
||||
}
|
||||
case s[0] == '>' && s[1] == '=':
|
||||
|
||||
return version{
|
||||
Name: slice[0][2:],
|
||||
Constraint: VersionConstraint(">=" + slice[1]),
|
||||
}
|
||||
case s[0] == '<' && s[1] == '=':
|
||||
|
||||
return version{
|
||||
Name: slice[0][2:],
|
||||
Constraint: VersionConstraint("<=" + slice[1]),
|
||||
}
|
||||
|
||||
case s[0] == '>' && s[1] != '=':
|
||||
|
||||
return version{
|
||||
Name: slice[0][1:],
|
||||
Constraint: VersionConstraint(">" + slice[1]),
|
||||
}
|
||||
case s[0] == '<' && s[1] != '=':
|
||||
|
||||
return version{
|
||||
Name: slice[0][1:],
|
||||
Constraint: VersionConstraint("<" + slice[1]),
|
||||
}
|
||||
}
|
||||
|
||||
} else if !strings.ContainsAny(s, "@=<>") {
|
||||
return version{
|
||||
Name: s,
|
||||
Constraint: VersionConstraint(0x000),
|
||||
}
|
||||
}
|
||||
|
||||
return version{}
|
||||
}
|
||||
|
||||
func normalizeArch(arch string) string {
|
||||
switch arch {
|
||||
case "386":
|
||||
return "i686"
|
||||
case "amd64":
|
||||
return "x86_64"
|
||||
case "amd64p32":
|
||||
return "x86_64"
|
||||
case "arm":
|
||||
return "arm"
|
||||
case "arm64":
|
||||
return "aarch64"
|
||||
case "arm64be":
|
||||
return "aarch64_be"
|
||||
case "armbe":
|
||||
return "armbe"
|
||||
case "loong64":
|
||||
return "loongarch64"
|
||||
case "mips":
|
||||
return "mips"
|
||||
case "mips64":
|
||||
return "mips64"
|
||||
case "mips64le":
|
||||
return "mips64el"
|
||||
case "mips64p32":
|
||||
return "mips64"
|
||||
case "mips64p32le":
|
||||
return "mips64el"
|
||||
case "mipsle":
|
||||
return "mipsel"
|
||||
case "ppc":
|
||||
return "powerpc"
|
||||
case "ppc64":
|
||||
return "ppc64"
|
||||
case "ppc64le":
|
||||
return "ppc64le"
|
||||
case "riscv":
|
||||
return "riscv"
|
||||
case "riscv64":
|
||||
return "riscv64"
|
||||
case "s390":
|
||||
return "s390"
|
||||
case "s390x":
|
||||
return "s390x"
|
||||
case "sparc":
|
||||
return "sparc"
|
||||
case "sparc64":
|
||||
return "sparc64"
|
||||
case "wasm":
|
||||
return "wasm"
|
||||
default:
|
||||
return arch
|
||||
}
|
||||
}
|
||||
33
pkg/packet.lua.d/config.go
Normal file
33
pkg/packet.lua.d/config.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package packet
|
||||
|
||||
import "path/filepath"
|
||||
|
||||
type Config struct {
|
||||
BinDir string
|
||||
PacketDir string
|
||||
SourcesDir string
|
||||
RootDir string
|
||||
}
|
||||
|
||||
const defaultBinDir = "/usr/bin"
|
||||
|
||||
func checkConfig(cfg *Config) *Config {
|
||||
if cfg == nil {
|
||||
bin := defaultBinDir
|
||||
return &Config{
|
||||
BinDir: bin,
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case cfg.BinDir == "":
|
||||
return &Config{
|
||||
BinDir: defaultBinDir,
|
||||
}
|
||||
case cfg.PacketDir == "":
|
||||
|
||||
cfg.PacketDir = filepath.Join("/tmp", randStringBytes(12))
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
374
pkg/packet.lua.d/main.go
Normal file
374
pkg/packet.lua.d/main.go
Normal file
@@ -0,0 +1,374 @@
|
||||
package packet
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v6"
|
||||
"github.com/go-git/go-git/v6/plumbing"
|
||||
"github.com/klauspost/compress/zstd"
|
||||
|
||||
lua_utils "github.com/roboogg133/packets/internal/lua"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
type OperationalSystem string
|
||||
|
||||
type PacketLua struct {
|
||||
Name string
|
||||
Version string
|
||||
Maintaner string
|
||||
Description string
|
||||
Serial int
|
||||
|
||||
Plataforms *map[OperationalSystem]Plataform
|
||||
GlobalSources *[]Source
|
||||
GlobalDependencies *PkgDependencies
|
||||
|
||||
Build *lua.LFunction
|
||||
Install *lua.LFunction
|
||||
PreRemove *lua.LFunction
|
||||
LuaState *lua.LState
|
||||
}
|
||||
|
||||
type Source struct {
|
||||
Method string
|
||||
Url string
|
||||
Specs any
|
||||
}
|
||||
|
||||
type VersionConstraint string
|
||||
|
||||
type PkgDependencies struct {
|
||||
RuntimeDependencies *map[string]*VersionConstraint
|
||||
BuildDependencies *map[string]*VersionConstraint
|
||||
Conflicts *map[string]*VersionConstraint
|
||||
}
|
||||
|
||||
type Plataform struct {
|
||||
Name string
|
||||
Architetures []string
|
||||
Sources *[]Source
|
||||
Dependencies *PkgDependencies
|
||||
}
|
||||
|
||||
type GitSpecs struct {
|
||||
Branch string
|
||||
Tag *string
|
||||
}
|
||||
|
||||
type POSTSpecs struct {
|
||||
SHA256 *string
|
||||
Body *string
|
||||
Headers *map[string]string
|
||||
}
|
||||
|
||||
type GETSpecs struct {
|
||||
SHA256 *string
|
||||
Headers *map[string]string
|
||||
}
|
||||
|
||||
var ErrCantFindPacketDotLua = errors.New("can't find Packet.lua in .tar.zst file")
|
||||
var ErrFileDontReturnTable = errors.New("invalid Packet.lua format: the file do not return a table")
|
||||
var ErrCannotFindPackageTable = errors.New("invalid Packet.lua format: can't find package table")
|
||||
var ErrInstallFunctionDoesNotExist = errors.New("can not find instal()")
|
||||
var ErrSha256Sum = errors.New("false checksum")
|
||||
|
||||
// ReadPacket read a Packet.lua and alredy set global vars
|
||||
func ReadPacket(f []byte, cfg *Config) (PacketLua, error) {
|
||||
cfg = checkConfig(cfg)
|
||||
|
||||
L := lua.NewState()
|
||||
|
||||
L.SetGlobal("error", L.NewFunction(lua_utils.LError))
|
||||
|
||||
osObject := L.GetGlobal("os").(*lua.LTable)
|
||||
ioObject := L.GetGlobal("io").(*lua.LTable)
|
||||
|
||||
L.SetGlobal("os", lua.LNil)
|
||||
L.SetGlobal("io", lua.LNil)
|
||||
|
||||
L.SetGlobal("BIN_DIR", lua.LString(cfg.BinDir))
|
||||
L.SetGlobal("CURRENT_ARCH", lua.LString(runtime.GOARCH))
|
||||
L.SetGlobal("CURRENT_ARCH_NORMALIZED", lua.LString(normalizeArch(runtime.GOARCH)))
|
||||
L.SetGlobal("CURRENT_PLATAFORM", lua.LString(runtime.GOOS))
|
||||
|
||||
L.SetGlobal("pathjoin", L.NewFunction(lua_utils.Ljoin))
|
||||
|
||||
if err := L.DoString(string(f)); err != nil {
|
||||
return PacketLua{}, err
|
||||
}
|
||||
|
||||
L.SetGlobal("os", osObject)
|
||||
L.SetGlobal("io", ioObject)
|
||||
|
||||
tableLua := L.Get(-1)
|
||||
|
||||
if tableLua.Type() != lua.LTTable {
|
||||
return PacketLua{}, ErrFileDontReturnTable
|
||||
}
|
||||
|
||||
table := tableLua.(*lua.LTable)
|
||||
|
||||
pkgTableLua := table.RawGetString("package")
|
||||
if pkgTableLua.Type() != lua.LTTable {
|
||||
return PacketLua{}, ErrCannotFindPackageTable
|
||||
}
|
||||
pkgTable := pkgTableLua.(*lua.LTable)
|
||||
|
||||
packetLua := &PacketLua{
|
||||
Name: getStringFromTable(pkgTable, "name"),
|
||||
Version: getStringFromTable(pkgTable, "version"),
|
||||
Maintaner: getStringFromTable(pkgTable, "maintainer"),
|
||||
Description: getStringFromTable(pkgTable, "description"),
|
||||
Serial: getIntFromTable(pkgTable, "serial"),
|
||||
|
||||
Plataforms: getPlataformsFromTable(pkgTable, "plataforms"),
|
||||
|
||||
GlobalDependencies: getDependenciesFromTable(pkgTable, "build_dependencies"),
|
||||
GlobalSources: getSourcesFromTable(pkgTable, "sources"),
|
||||
|
||||
Build: getFunctionFromTable(table, "build"),
|
||||
Install: getFunctionFromTable(table, "install"),
|
||||
PreRemove: getFunctionFromTable(table, "pre_remove"),
|
||||
}
|
||||
|
||||
packetLua.LuaState = L
|
||||
if packetLua.Install == nil {
|
||||
return PacketLua{}, ErrInstallFunctionDoesNotExist
|
||||
}
|
||||
|
||||
return *packetLua, nil
|
||||
}
|
||||
|
||||
func ReadPacketFromZSTDF(file io.Reader, cfg *Config) (PacketLua, error) {
|
||||
cfg = checkConfig(cfg)
|
||||
|
||||
zstdReader, err := zstd.NewReader(file)
|
||||
if err != nil {
|
||||
return PacketLua{}, err
|
||||
}
|
||||
defer zstdReader.Close()
|
||||
|
||||
tarReader := tar.NewReader(zstdReader)
|
||||
for {
|
||||
header, err := tarReader.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return PacketLua{}, err
|
||||
}
|
||||
|
||||
if filepath.Base(header.Name) == "Packet.lua" {
|
||||
|
||||
packageLuaBlob, err := io.ReadAll(tarReader)
|
||||
if err != nil {
|
||||
return PacketLua{}, err
|
||||
}
|
||||
|
||||
return ReadPacket(packageLuaBlob, cfg)
|
||||
}
|
||||
|
||||
}
|
||||
return PacketLua{}, ErrCantFindPacketDotLua
|
||||
}
|
||||
|
||||
// GetSource returns file []byte if method is "GET" or "POST", if is "git" returns *git.CloneOptions{}
|
||||
func GetSource(url, method string, info any, tryAttempts int) (any, error) {
|
||||
|
||||
switch method {
|
||||
case "GET":
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
specs := info.(GETSpecs)
|
||||
|
||||
if specs.Headers != nil {
|
||||
for k, v := range *specs.Headers {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
client := http.Client{Timeout: 5 * time.Minute}
|
||||
|
||||
var resp *http.Response
|
||||
for i := 0; i < tryAttempts; i++ {
|
||||
resp, err = client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
break
|
||||
}
|
||||
resp.Body.Close()
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !verifySHA256(*specs.SHA256, data) {
|
||||
return nil, ErrSha256Sum
|
||||
}
|
||||
|
||||
return data, nil
|
||||
case "POST":
|
||||
specs := info.(POSTSpecs)
|
||||
var body *bytes.Reader
|
||||
|
||||
if specs.Body != nil {
|
||||
body = bytes.NewReader([]byte(*specs.Body))
|
||||
} else {
|
||||
body = nil
|
||||
}
|
||||
req, err := http.NewRequest("POST", url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if specs.Headers != nil {
|
||||
for k, v := range *specs.Headers {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
client := http.Client{Timeout: 5 * time.Minute}
|
||||
|
||||
var resp *http.Response
|
||||
for i := 0; i < tryAttempts; i++ {
|
||||
resp, err = client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
break
|
||||
}
|
||||
resp.Body.Close()
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !verifySHA256(*specs.SHA256, data) {
|
||||
return nil, ErrSha256Sum
|
||||
}
|
||||
|
||||
return data, nil
|
||||
|
||||
case "git":
|
||||
specs := info.(GitSpecs)
|
||||
|
||||
if specs.Tag == nil {
|
||||
return &git.CloneOptions{
|
||||
URL: url,
|
||||
SingleBranch: true,
|
||||
ReferenceName: plumbing.NewBranchReferenceName(specs.Branch),
|
||||
Depth: 1,
|
||||
}, nil
|
||||
} else {
|
||||
return &git.CloneOptions{
|
||||
URL: url,
|
||||
SingleBranch: true,
|
||||
ReferenceName: plumbing.NewTagReferenceName(*specs.Tag),
|
||||
Depth: 1,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("invalid method")
|
||||
}
|
||||
|
||||
func verifySHA256(checksum string, src []byte) bool {
|
||||
|
||||
check := sha256.Sum256(src)
|
||||
|
||||
return hex.EncodeToString(check[:]) == checksum
|
||||
}
|
||||
|
||||
func (pkg PacketLua) ExecuteBuild(cfg *Config) error {
|
||||
L := pkg.LuaState
|
||||
|
||||
L.SetGlobal("error", L.NewFunction(lua_utils.LError))
|
||||
|
||||
osObject := L.GetGlobal("os").(*lua.LTable)
|
||||
osObject.RawSetString("chdir", L.NewFunction(lua_utils.LCD))
|
||||
osObject.RawSetString("setenv", L.NewFunction(lua_utils.LSetEnv))
|
||||
osObject.RawSetString("copy", L.NewFunction(lua_utils.LCopy))
|
||||
osObject.RawSetString("mkdir", L.NewFunction(lua_utils.LMkdir))
|
||||
osObject.RawSetString("remove", L.NewFunction(lua_utils.LRemove))
|
||||
osObject.RawSetString("rename", L.NewFunction(lua_utils.LRename))
|
||||
osObject.RawSetString("symlink", L.NewFunction(lua_utils.LSymlink))
|
||||
osObject.RawSetString("chmod", L.NewFunction(lua_utils.LChmod))
|
||||
|
||||
L.SetGlobal("BIN_DIR", lua.LString(cfg.BinDir))
|
||||
L.SetGlobal("CURRENT_ARCH", lua.LString(runtime.GOARCH))
|
||||
L.SetGlobal("CURRENT_ARCH_NORMALIZED", lua.LString(normalizeArch(runtime.GOARCH)))
|
||||
L.SetGlobal("CURRENT_PLATAFORM", lua.LString(runtime.GOOS))
|
||||
|
||||
L.SetGlobal("SOURCESDIR", lua.LString(cfg.SourcesDir))
|
||||
L.SetGlobal("PACKETDIR", lua.LString(cfg.PacketDir))
|
||||
|
||||
L.SetGlobal("pathjoin", L.NewFunction(lua_utils.Ljoin))
|
||||
|
||||
os.Chdir(cfg.RootDir)
|
||||
|
||||
os.Setenv("PATH", os.Getenv("PATH")+":"+cfg.BinDir)
|
||||
|
||||
L.Push(pkg.Build)
|
||||
return L.PCall(0, 0, nil)
|
||||
}
|
||||
|
||||
func (pkg PacketLua) ExecuteInstall(cfg *Config) error {
|
||||
L := pkg.LuaState
|
||||
defer L.Close()
|
||||
|
||||
L.SetGlobal("error", L.NewFunction(lua_utils.LError))
|
||||
|
||||
osObject := L.GetGlobal("os").(*lua.LTable)
|
||||
osObject.RawSetString("chdir", L.NewFunction(lua_utils.LCD))
|
||||
osObject.RawSetString("setenv", L.NewFunction(lua_utils.LSetEnv))
|
||||
osObject.RawSetString("copy", L.NewFunction(lua_utils.LCopy))
|
||||
osObject.RawSetString("mkdir", L.NewFunction(lua_utils.LMkdir))
|
||||
osObject.RawSetString("remove", L.NewFunction(lua_utils.LRemove))
|
||||
osObject.RawSetString("rename", L.NewFunction(lua_utils.LRename))
|
||||
osObject.RawSetString("symlink", L.NewFunction(lua_utils.LSymlink))
|
||||
osObject.RawSetString("chmod", L.NewFunction(lua_utils.LChmod))
|
||||
|
||||
L.SetGlobal("BIN_DIR", lua.LString(cfg.BinDir))
|
||||
L.SetGlobal("CURRENT_ARCH", lua.LString(runtime.GOARCH))
|
||||
L.SetGlobal("CURRENT_ARCH_NORMALIZED", lua.LString(normalizeArch(runtime.GOARCH)))
|
||||
L.SetGlobal("CURRENT_PLATAFORM", lua.LString(runtime.GOOS))
|
||||
|
||||
L.SetGlobal("SOURCESDIR", lua.LString(cfg.SourcesDir))
|
||||
L.SetGlobal("PACKETDIR", lua.LString(cfg.PacketDir))
|
||||
|
||||
L.SetGlobal("pathjoin", L.NewFunction(lua_utils.Ljoin))
|
||||
|
||||
os.Chdir(cfg.RootDir)
|
||||
|
||||
os.Setenv("PATH", os.Getenv("PATH")+":"+cfg.BinDir)
|
||||
L.Push(pkg.Install)
|
||||
L.Call(0, 0)
|
||||
|
||||
return nil
|
||||
}
|
||||
25
pkg/packet.lua.d/properties.go
Normal file
25
pkg/packet.lua.d/properties.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package packet
|
||||
|
||||
func (pkg PacketLua) IsValid() bool {
|
||||
|
||||
var a, b int
|
||||
|
||||
for _, v := range *pkg.Plataforms {
|
||||
a += len(*v.Sources)
|
||||
b += len(v.Architetures)
|
||||
}
|
||||
|
||||
a += len(*pkg.GlobalSources)
|
||||
|
||||
if a < 1 || len(*pkg.Plataforms) > b {
|
||||
return false
|
||||
}
|
||||
|
||||
switch {
|
||||
case pkg.Serial == -133:
|
||||
return false
|
||||
case pkg.Description == "" || pkg.Maintaner == "" || pkg.Name == "" || pkg.Version == "":
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
81
pkg/packet.lua.d/utils.go
Normal file
81
pkg/packet.lua.d/utils.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package packet
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$%!@%&*()-=+[]{}:;.,1234567890"
|
||||
|
||||
func randStringBytes(n int) string {
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func Dearchive(archive, outdir string) error {
|
||||
|
||||
switch {
|
||||
case strings.HasSuffix(archive, ".tar.gz"):
|
||||
|
||||
f, err := os.Open(archive)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gzReader, err := gzip.NewReader(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tarReader := tar.NewReader(gzReader)
|
||||
|
||||
for {
|
||||
header, err := tarReader.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
destination := filepath.Join(outdir, header.Name)
|
||||
|
||||
fmt.Println(destination)
|
||||
|
||||
switch header.Typeflag {
|
||||
case tar.TypeDir:
|
||||
if err := os.Mkdir(destination, header.FileInfo().Mode()); err != nil {
|
||||
return err
|
||||
}
|
||||
case tar.TypeReg:
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(destination), 0777); err != nil {
|
||||
return err
|
||||
}
|
||||
outFile, err := os.Create(destination)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := io.Copy(outFile, tarReader); err != nil {
|
||||
return err
|
||||
}
|
||||
outFile.Close()
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknow filetype")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Binary file not shown.
60
test/bat/Packet.lua
Normal file
60
test/bat/Packet.lua
Normal file
@@ -0,0 +1,60 @@
|
||||
return {
|
||||
package = {
|
||||
name = "bat-bin", -- required
|
||||
version = "0.26.0", -- required
|
||||
maintainer = "robogg133", -- required
|
||||
description = "A cat(1) clone with syntax highlighting and Git integration.", -- required
|
||||
serial = 0,-- required
|
||||
|
||||
plataforms = {
|
||||
windows = {
|
||||
arch = {"amd64"},
|
||||
sources = {
|
||||
{
|
||||
url = "https://github.com/sharkdp/bat/releases/download/v0.26.0/bat-v0.26.0-" ..CURRENT_ARCH_NORMALIZED.."-pc-windows-msvc.zip",
|
||||
method = "GET",
|
||||
sha256="a8a6862f14698b45e101b0932c69bc47a007f4c0456f3a129fdcef54d443d501"
|
||||
}
|
||||
},
|
||||
dependencies = {
|
||||
build = {},
|
||||
runtime = {},
|
||||
conflicts = {}
|
||||
}
|
||||
},
|
||||
linux = {
|
||||
arch = {"amd64"},
|
||||
sources = {
|
||||
{
|
||||
url = "https://github.com/sharkdp/bat/releases/download/v0.26.0/bat-v0.26.0-".. CURRENT_ARCH_NORMALIZED .."-unknown-linux-gnu.tar.gz",
|
||||
method = "GET",
|
||||
sha256 = "7efed0c768fae36f18ddbbb4a38f5c4b64db7c55a170dfc89fd380805809a44b"
|
||||
}
|
||||
},
|
||||
dependencies = {
|
||||
build = {},
|
||||
runtime = {},
|
||||
conflicts = {}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
sources = {}
|
||||
|
||||
},
|
||||
|
||||
build = function()
|
||||
|
||||
end,
|
||||
|
||||
install = function()
|
||||
|
||||
|
||||
|
||||
local suc, errmsg = os.copy(pathjoin(SOURCESDIR,"bat-v0.26.0-".. CURRENT_ARCH_NORMALIZED .."-unknown-linux-gnu", "bat"), pathjoin(PACKETDIR, BIN_DIR, "bat"))
|
||||
if not suc then
|
||||
error(errmsg)
|
||||
end
|
||||
end,
|
||||
|
||||
}
|
||||
38
test/utctimerightnow/Packet.lua
Normal file
38
test/utctimerightnow/Packet.lua
Normal file
@@ -0,0 +1,38 @@
|
||||
return {
|
||||
package = {
|
||||
name = "utctimerightnow", -- required
|
||||
version = "0.1.0", -- required
|
||||
maintainer = "robogg133", -- required
|
||||
description = "shows utc time", -- required
|
||||
serial = 0,-- required
|
||||
|
||||
dependencies = {
|
||||
build = {"go"},
|
||||
runtime = {},
|
||||
conflicts = {}
|
||||
},
|
||||
|
||||
sources = { --optional
|
||||
{
|
||||
url = "https://git.opentty.xyz/robogg133/utctimerightnow.git", -- required
|
||||
method = "git", -- required
|
||||
branch = "main" -- required
|
||||
-- tag = ""
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
build = function()
|
||||
-- os.setenv("GOPATH", pathjoin(SOURCESDIR, "gopath"))
|
||||
os.chdir(pathjoin(SOURCESDIR, "utctimerightnow"))
|
||||
os.execute('go build -trimpath -ldflags="-s -w" -o utctimerightnow main.go')
|
||||
os.chmod(utctimerightnow, 0777)
|
||||
end,
|
||||
|
||||
install = function() -- required
|
||||
os.copy(pathjoin(SOURCESDIR, "utctimerightnow", "utctimerightnow"), pathjoin(PACKETDIR, BIN_DIR, "utctimerightnow"))
|
||||
os.copy(pathjoin(SOURCESDIR, "utctimerightnow", "LICENSE"), pathjoin(PACKETDIR, "/usr/share/licenses/utctimerightnow/LICENSE"))
|
||||
end,
|
||||
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user