simple checking for remote packets
This commit is contained in:
@@ -10,6 +10,16 @@ func getStringFromTable(table *lua.LTable, key string) string {
|
|||||||
return ""
|
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(L *lua.LState, table *lua.LTable, key string) []string {
|
func getStringArrayFromTable(L *lua.LState, table *lua.LTable, key string) []string {
|
||||||
value := table.RawGetString(key)
|
value := table.RawGetString(key)
|
||||||
if value.Type() != lua.LTTable {
|
if value.Type() != lua.LTTable {
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ type PacketLua struct {
|
|||||||
Author string
|
Author string
|
||||||
Architetures []string
|
Architetures []string
|
||||||
Os []string
|
Os []string
|
||||||
|
Serial int
|
||||||
|
Type string
|
||||||
|
|
||||||
PkgType string
|
PkgType string
|
||||||
GitUrl string
|
GitUrl string
|
||||||
@@ -85,6 +87,7 @@ func ReadPacket(f []byte) (PacketLua, error) {
|
|||||||
Author: getStringFromTable(pkgTable, "author"),
|
Author: getStringFromTable(pkgTable, "author"),
|
||||||
Description: getStringFromTable(pkgTable, "description"),
|
Description: getStringFromTable(pkgTable, "description"),
|
||||||
PkgType: getStringFromTable(pkgTable, "type"),
|
PkgType: getStringFromTable(pkgTable, "type"),
|
||||||
|
Serial: getIntFromTable(pkgTable, "serial"),
|
||||||
|
|
||||||
Dependencies: getDependenciesFromTable(L, pkgTable, "dependencies"),
|
Dependencies: getDependenciesFromTable(L, pkgTable, "dependencies"),
|
||||||
BuildDependencies: getDependenciesFromTable(L, pkgTable, "build_dependencies"),
|
BuildDependencies: getDependenciesFromTable(L, pkgTable, "build_dependencies"),
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ func LGitCheckout(L *lua.LState) int {
|
|||||||
func LGitPUll(L *lua.LState) int {
|
func LGitPUll(L *lua.LState) int {
|
||||||
dir := L.CheckString(1)
|
dir := L.CheckString(1)
|
||||||
|
|
||||||
|
|
||||||
|
git.PlainClone("/tmp", &git.CloneOptions{})
|
||||||
|
|
||||||
depth := 1
|
depth := 1
|
||||||
if L.GetTop() > 1 {
|
if L.GetTop() > 1 {
|
||||||
depth = L.CheckInt(2)
|
depth = L.CheckInt(2)
|
||||||
|
|||||||
@@ -264,6 +264,9 @@ func ResolvDependencies(depnList map[string]string) ([]string, error) {
|
|||||||
value := strings.TrimLeft(constraint, "<>=")
|
value := strings.TrimLeft(constraint, "<>=")
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
case constraint == "any":
|
||||||
|
filter = ""
|
||||||
|
order = "ORDER BY serial DESC LIMIT 1"
|
||||||
case strings.HasPrefix(constraint, ">"):
|
case strings.HasPrefix(constraint, ">"):
|
||||||
filter = fmt.Sprintf("AND serial > %s", value)
|
filter = fmt.Sprintf("AND serial > %s", value)
|
||||||
order = "ORDER BY serial DESC LIMIT 1"
|
order = "ORDER BY serial DESC LIMIT 1"
|
||||||
|
|||||||
68
pkg/main.go
68
pkg/main.go
@@ -49,6 +49,43 @@ type Package struct {
|
|||||||
|
|
||||||
// Install exctract and fully install from a package file ( tar.zst )
|
// Install exctract and fully install from a package file ( tar.zst )
|
||||||
func InstallPackage(file []byte, destDir string) error {
|
func InstallPackage(file []byte, destDir string) error {
|
||||||
|
|
||||||
|
packetLua, err := packet.ReadPacket(file)
|
||||||
|
if err == nil {
|
||||||
|
L, err := utils_lua.GetSandBox()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
bootstrapcontainer, err := build.NewContainer(packetLua)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Chdir(destDir)
|
||||||
|
|
||||||
|
if err := utils.ChangeToNoPermission(); err != nil {
|
||||||
|
return fmt.Errorf("error changing to packet user: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := bootstrapcontainer.ExecutePrepare(packetLua, &L); err != nil {
|
||||||
|
return fmt.Errorf("error executing prepare: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := bootstrapcontainer.ExecuteBuild(packetLua, &L); err != nil {
|
||||||
|
return fmt.Errorf("error executing build: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := utils.ElevatePermission(); err != nil {
|
||||||
|
return fmt.Errorf("error changing to root: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := bootstrapcontainer.ExecuteInstall(packetLua, &L); err != nil {
|
||||||
|
return fmt.Errorf("error executing build: %s", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
manifest, err := packet.ReadPacketFromFile(bytes.NewReader(file))
|
manifest, err := packet.ReadPacketFromFile(bytes.NewReader(file))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -151,6 +188,10 @@ func InstallPackage(file []byte, destDir string) error {
|
|||||||
|
|
||||||
os.Chdir(destDir)
|
os.Chdir(destDir)
|
||||||
|
|
||||||
|
if err := utils.ChangeToNoPermission(); err != nil {
|
||||||
|
return fmt.Errorf("error changing to packet user: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := bootstrapcontainer.ExecutePrepare(manifest, &L); err != nil {
|
if err := bootstrapcontainer.ExecutePrepare(manifest, &L); err != nil {
|
||||||
return fmt.Errorf("error executing prepare: %s", err)
|
return fmt.Errorf("error executing prepare: %s", err)
|
||||||
}
|
}
|
||||||
@@ -159,17 +200,14 @@ func InstallPackage(file []byte, destDir string) error {
|
|||||||
return fmt.Errorf("error executing build: %s", err)
|
return fmt.Errorf("error executing build: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := utils.ChangeToNoPermission(); err != nil {
|
|
||||||
return fmt.Errorf("error changing to packet user: %s", err)
|
|
||||||
}
|
|
||||||
if err := bootstrapcontainer.ExecuteInstall(manifest, &L); err != nil {
|
|
||||||
return fmt.Errorf("error executing build: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := utils.ElevatePermission(); err != nil {
|
if err := utils.ElevatePermission(); err != nil {
|
||||||
return fmt.Errorf("error changing to root: %s", err)
|
return fmt.Errorf("error changing to root: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := bootstrapcontainer.ExecuteInstall(manifest, &L); err != nil {
|
||||||
|
return fmt.Errorf("error executing build: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,8 +223,8 @@ func GetPackage(id string) (Package, error) {
|
|||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
var packageUrl string
|
var packageUrl, typePackage string
|
||||||
err = db.QueryRow("SELECT query_name, version, package_url, image_url, description, author, author_verified, os, arch, signature, public_key, serial, size FROM packages WHERE id = ?", id).
|
err = db.QueryRow("SELECT query_name, version, package_url, image_url, description, author, author_verified, os, arch, signature, public_key, serial, size, type FROM packages WHERE id = ?", id).
|
||||||
Scan(
|
Scan(
|
||||||
&this.QueryName,
|
&this.QueryName,
|
||||||
&this.Version,
|
&this.Version,
|
||||||
@@ -201,6 +239,7 @@ func GetPackage(id string) (Package, error) {
|
|||||||
&this.PublicKey,
|
&this.PublicKey,
|
||||||
&this.Serial,
|
&this.Serial,
|
||||||
&this.Size,
|
&this.Size,
|
||||||
|
&typePackage,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Package{}, err
|
return Package{}, err
|
||||||
@@ -221,6 +260,8 @@ func GetPackage(id string) (Package, error) {
|
|||||||
this.Dependencies[a] = vConstraint
|
this.Dependencies[a] = vConstraint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(typePackage, " ") {
|
||||||
|
|
||||||
filename := path.Base(packageUrl)
|
filename := path.Base(packageUrl)
|
||||||
this.Filename = filename
|
this.Filename = filename
|
||||||
|
|
||||||
@@ -269,6 +310,15 @@ func GetPackage(id string) (Package, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
filds := strings.Fields(typePackage)
|
||||||
|
pkt, err := packet.GetPackageDotLuaFromRemote(filds[0], filds[1])
|
||||||
|
if err != nil {
|
||||||
|
return Package{}, err
|
||||||
|
}
|
||||||
|
this.Manifest = pkt
|
||||||
|
return this, nil
|
||||||
|
}
|
||||||
|
|
||||||
skipping:
|
skipping:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user