Compare commits
	
		
			2 Commits
		
	
	
		
			4c88ec3bc2
			...
			064ee7f404
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 064ee7f404 | |||
| 52ecacc4fe | 
							
								
								
									
										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)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										23
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								go.mod
									
									
									
									
									
								
							@@ -4,4 +4,25 @@ go 1.25.3
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
require github.com/yuin/gopher-lua v1.1.1
 | 
					require github.com/yuin/gopher-lua v1.1.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require github.com/klauspost/compress v1.18.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
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										64
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										64
									
								
								go.sum
									
									
									
									
									
								
							@@ -1,4 +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 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
 | 
				
			||||||
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
 | 
					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 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
 | 
				
			||||||
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
 | 
					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=
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,6 +39,7 @@ func LCopy(L *lua.LState) int {
 | 
				
			|||||||
	oldname := L.CheckString(1)
 | 
						oldname := L.CheckString(1)
 | 
				
			||||||
	newname := L.CheckString(2)
 | 
						newname := L.CheckString(2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						os.MkdirAll(filepath.Dir(newname), 0755)
 | 
				
			||||||
	if err := copyDir(oldname, newname); err != nil {
 | 
						if err := copyDir(oldname, newname); err != nil {
 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
							L.Push(lua.LFalse)
 | 
				
			||||||
		L.Push(lua.LString(err.Error()))
 | 
							L.Push(lua.LString(err.Error()))
 | 
				
			||||||
@@ -117,4 +118,33 @@ func LSetEnv(L *lua.LState) int {
 | 
				
			|||||||
	return 0
 | 
						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) }
 | 
					func llogger() *log.Logger { return log.New(os.Stderr, "script error: ", 0) }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,7 @@ func copyDir(src string, dest string) error {
 | 
				
			|||||||
				return err
 | 
									return err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if err := os.MkdirAll(dest, 0o755); err != nil {
 | 
								if err := os.MkdirAll(dest, 0755); err != nil {
 | 
				
			||||||
				return err
 | 
									return err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,7 +1,12 @@
 | 
				
			|||||||
package packet
 | 
					package packet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "path/filepath"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Config struct {
 | 
					type Config struct {
 | 
				
			||||||
	BinDir *string
 | 
						BinDir     string
 | 
				
			||||||
 | 
						PacketDir  string
 | 
				
			||||||
 | 
						SourcesDir string
 | 
				
			||||||
 | 
						RootDir    string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const defaultBinDir = "/usr/bin"
 | 
					const defaultBinDir = "/usr/bin"
 | 
				
			||||||
@@ -10,30 +15,19 @@ func checkConfig(cfg *Config) *Config {
 | 
				
			|||||||
	if cfg == nil {
 | 
						if cfg == nil {
 | 
				
			||||||
		bin := defaultBinDir
 | 
							bin := defaultBinDir
 | 
				
			||||||
		return &Config{
 | 
							return &Config{
 | 
				
			||||||
			BinDir: &bin,
 | 
								BinDir: bin,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if *cfg.BinDir == "" || cfg.BinDir == nil {
 | 
					 | 
				
			||||||
		bin := defaultBinDir
 | 
					 | 
				
			||||||
		return &Config{
 | 
					 | 
				
			||||||
			BinDir: &bin,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		return cfg
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
func checkConfigSrc(cfg *GetSourceConfig) *GetSourceConfig {
 | 
					 | 
				
			||||||
	if cfg == nil {
 | 
					 | 
				
			||||||
		return nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch {
 | 
						switch {
 | 
				
			||||||
	case *cfg.PacketDir == "" || cfg.PacketDir == nil:
 | 
						case cfg.BinDir == "":
 | 
				
			||||||
		s := randStringBytes(12)
 | 
							return &Config{
 | 
				
			||||||
		cfg.PacketDir = &s
 | 
								BinDir: defaultBinDir,
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						case cfg.PacketDir == "":
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							cfg.PacketDir = filepath.Join("/tmp", randStringBytes(12))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return cfg
 | 
						return cfg
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,10 +9,13 @@ import (
 | 
				
			|||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"runtime"
 | 
						"runtime"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/go-git/go-git/v6"
 | 
				
			||||||
 | 
						"github.com/go-git/go-git/v6/plumbing"
 | 
				
			||||||
	"github.com/klauspost/compress/zstd"
 | 
						"github.com/klauspost/compress/zstd"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	lua_utils "github.com/roboogg133/packets/internal/lua"
 | 
						lua_utils "github.com/roboogg133/packets/internal/lua"
 | 
				
			||||||
@@ -35,6 +38,7 @@ type PacketLua struct {
 | 
				
			|||||||
	Build     *lua.LFunction
 | 
						Build     *lua.LFunction
 | 
				
			||||||
	Install   *lua.LFunction
 | 
						Install   *lua.LFunction
 | 
				
			||||||
	PreRemove *lua.LFunction
 | 
						PreRemove *lua.LFunction
 | 
				
			||||||
 | 
						LuaState  *lua.LState
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Source struct {
 | 
					type Source struct {
 | 
				
			||||||
@@ -85,16 +89,16 @@ func ReadPacket(f []byte, cfg *Config) (PacketLua, error) {
 | 
				
			|||||||
	cfg = checkConfig(cfg)
 | 
						cfg = checkConfig(cfg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	L := lua.NewState()
 | 
						L := lua.NewState()
 | 
				
			||||||
	defer L.Close()
 | 
					
 | 
				
			||||||
 | 
						L.SetGlobal("error", L.NewFunction(lua_utils.LError))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	osObject := L.GetGlobal("os").(*lua.LTable)
 | 
						osObject := L.GetGlobal("os").(*lua.LTable)
 | 
				
			||||||
	osObject.RawSetString("setenv", L.NewFunction(lua_utils.LSetEnv))
 | 
					 | 
				
			||||||
	ioObject := L.GetGlobal("io").(*lua.LTable)
 | 
						ioObject := L.GetGlobal("io").(*lua.LTable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	L.SetGlobal("os", lua.LNil)
 | 
						L.SetGlobal("os", lua.LNil)
 | 
				
			||||||
	L.SetGlobal("io", lua.LNil)
 | 
						L.SetGlobal("io", lua.LNil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	L.SetGlobal("BIN_DIR", lua.LString(*cfg.BinDir))
 | 
						L.SetGlobal("BIN_DIR", lua.LString(cfg.BinDir))
 | 
				
			||||||
	L.SetGlobal("CURRENT_ARCH", lua.LString(runtime.GOARCH))
 | 
						L.SetGlobal("CURRENT_ARCH", lua.LString(runtime.GOARCH))
 | 
				
			||||||
	L.SetGlobal("CURRENT_ARCH_NORMALIZED", lua.LString(normalizeArch(runtime.GOARCH)))
 | 
						L.SetGlobal("CURRENT_ARCH_NORMALIZED", lua.LString(normalizeArch(runtime.GOARCH)))
 | 
				
			||||||
	L.SetGlobal("CURRENT_PLATAFORM", lua.LString(runtime.GOOS))
 | 
						L.SetGlobal("CURRENT_PLATAFORM", lua.LString(runtime.GOOS))
 | 
				
			||||||
@@ -139,6 +143,7 @@ func ReadPacket(f []byte, cfg *Config) (PacketLua, error) {
 | 
				
			|||||||
		PreRemove: getFunctionFromTable(table, "pre_remove"),
 | 
							PreRemove: getFunctionFromTable(table, "pre_remove"),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						packetLua.LuaState = L
 | 
				
			||||||
	if packetLua.Install == nil {
 | 
						if packetLua.Install == nil {
 | 
				
			||||||
		return PacketLua{}, ErrInstallFunctionDoesNotExist
 | 
							return PacketLua{}, ErrInstallFunctionDoesNotExist
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -179,11 +184,8 @@ func ReadPacketFromZSTDF(file io.Reader, cfg *Config) (PacketLua, error) {
 | 
				
			|||||||
	return PacketLua{}, ErrCantFindPacketDotLua
 | 
						return PacketLua{}, ErrCantFindPacketDotLua
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type GetSourceConfig struct {
 | 
					// GetSource returns file []byte if method is "GET" or "POST", if is "git" returns *git.CloneOptions{}
 | 
				
			||||||
	PacketDir *string
 | 
					func GetSource(url, method string, info any, tryAttempts int) (any, error) {
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func GetSource(url, method string, info any) ([]byte, error) {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch method {
 | 
						switch method {
 | 
				
			||||||
	case "GET":
 | 
						case "GET":
 | 
				
			||||||
@@ -194,15 +196,24 @@ func GetSource(url, method string, info any) ([]byte, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		specs := info.(GETSpecs)
 | 
							specs := info.(GETSpecs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for k, v := range *specs.Headers {
 | 
							if specs.Headers != nil {
 | 
				
			||||||
			req.Header.Set(k, v)
 | 
								for k, v := range *specs.Headers {
 | 
				
			||||||
 | 
									req.Header.Set(k, v)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		client := http.Client{Timeout: 5 * time.Minute}
 | 
							client := http.Client{Timeout: 5 * time.Minute}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		resp, err := client.Do(req)
 | 
							var resp *http.Response
 | 
				
			||||||
		if err != nil {
 | 
							for i := 0; i < tryAttempts; i++ {
 | 
				
			||||||
			return nil, err
 | 
								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()
 | 
							defer resp.Body.Close()
 | 
				
			||||||
@@ -231,15 +242,24 @@ func GetSource(url, method string, info any) ([]byte, error) {
 | 
				
			|||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for k, v := range *specs.Headers {
 | 
							if specs.Headers != nil {
 | 
				
			||||||
			req.Header.Set(k, v)
 | 
								for k, v := range *specs.Headers {
 | 
				
			||||||
 | 
									req.Header.Set(k, v)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		client := http.Client{Timeout: 5 * time.Minute}
 | 
							client := http.Client{Timeout: 5 * time.Minute}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		resp, err := client.Do(req)
 | 
							var resp *http.Response
 | 
				
			||||||
		if err != nil {
 | 
							for i := 0; i < tryAttempts; i++ {
 | 
				
			||||||
			return nil, err
 | 
								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()
 | 
							defer resp.Body.Close()
 | 
				
			||||||
@@ -254,6 +274,25 @@ func GetSource(url, method string, info any) ([]byte, error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return data, nil
 | 
							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")
 | 
						return nil, fmt.Errorf("invalid method")
 | 
				
			||||||
@@ -265,3 +304,71 @@ func verifySHA256(checksum string, src []byte) bool {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	return hex.EncodeToString(check[:]) == checksum
 | 
						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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +0,0 @@
 | 
				
			|||||||
package packet
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import "math/rand"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -44,10 +44,17 @@ return {
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    build = function() 
 | 
					    build = function() 
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
    end,
 | 
					    end,
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    install = function() -- required 
 | 
					    install = function() 
 | 
				
			||||||
    print("oi amores")
 | 
					      
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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,
 | 
					    end,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -24,11 +24,15 @@ return {
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    build = function()
 | 
					    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,
 | 
					    end,
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    install  = function() -- required 
 | 
					    install  = function() -- required 
 | 
				
			||||||
        print("goku")
 | 
					        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,
 | 
					    end,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user