changing to packets user and creating internal.db, improved bat-bin
Packet.lua
This commit is contained in:
		@@ -89,3 +89,13 @@ func MarkAsInstalled(pkg packet.PacketLua, db *sql.DB, image *[]byte) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func MarkAsUninstalled(id string, db *sql.DB) error {
 | 
				
			||||||
 | 
						_, err := db.Exec("DELETE FROM installed_packages WHERE id = ?", id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func PrepareDataBase(db *sql.DB) { _, _ = db.Exec(CreateInstructions) }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +1,15 @@
 | 
				
			|||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"database/sql"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"runtime"
 | 
						"runtime"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_ "github.com/mattn/go-sqlite3"
 | 
				
			||||||
 | 
						"github.com/roboogg133/packets/cmd/packets/database"
 | 
				
			||||||
	"github.com/roboogg133/packets/pkg/install"
 | 
						"github.com/roboogg133/packets/pkg/install"
 | 
				
			||||||
	"github.com/roboogg133/packets/pkg/packet.lua.d"
 | 
						"github.com/roboogg133/packets/pkg/packet.lua.d"
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
@@ -29,6 +32,10 @@ var executeCmd = &cobra.Command{
 | 
				
			|||||||
		return GetConfiguration()
 | 
							return GetConfiguration()
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	Run: func(cmd *cobra.Command, args []string) {
 | 
						Run: func(cmd *cobra.Command, args []string) {
 | 
				
			||||||
 | 
							if os.Geteuid() != 0 {
 | 
				
			||||||
 | 
								fmt.Println("error: this operation must be run as root")
 | 
				
			||||||
 | 
								os.Exit(1)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for _, v := range args {
 | 
							for _, v := range args {
 | 
				
			||||||
			if !strings.HasSuffix(v, ".lua") {
 | 
								if !strings.HasSuffix(v, ".lua") {
 | 
				
			||||||
@@ -93,8 +100,12 @@ var executeCmd = &cobra.Command{
 | 
				
			|||||||
				fmt.Printf("error: %s", err.Error())
 | 
									fmt.Printf("error: %s", err.Error())
 | 
				
			||||||
				os.Exit(1)
 | 
									os.Exit(1)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								_ = ChangeToNoPermission()
 | 
				
			||||||
			pkg.ExecuteBuild(configs)
 | 
								pkg.ExecuteBuild(configs)
 | 
				
			||||||
			pkg.ExecuteInstall(configs)
 | 
								pkg.ExecuteInstall(configs)
 | 
				
			||||||
 | 
								_ = ElevatePermission()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			os.Chdir(backupDir)
 | 
								os.Chdir(backupDir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			files, err := install.GetPackageFiles(configs.PacketDir)
 | 
								files, err := install.GetPackageFiles(configs.PacketDir)
 | 
				
			||||||
@@ -108,6 +119,18 @@ var executeCmd = &cobra.Command{
 | 
				
			|||||||
				os.Exit(1)
 | 
									os.Exit(1)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								db, err := sql.Open("sqlite3", InternalDB)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									fmt.Printf("error: %s", err.Error())
 | 
				
			||||||
 | 
									os.Exit(1)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								defer db.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								database.PrepareDataBase(db)
 | 
				
			||||||
 | 
								if err := database.MarkAsInstalled(pkg, db, nil); err != nil {
 | 
				
			||||||
 | 
									fmt.Printf("error: %s", err.Error())
 | 
				
			||||||
 | 
									os.Exit(1)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ package main
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	ConfigurationDir       = "/etc/packets"
 | 
						ConfigurationDir       = "/etc/packets"
 | 
				
			||||||
 | 
						InternalDB             = ConfigurationDir + "/internal.db"
 | 
				
			||||||
	HomeDir                = "/var/lib/packets"
 | 
						HomeDir                = "/var/lib/packets"
 | 
				
			||||||
	PackageRootDir         = "_pkgtest"
 | 
						PackageRootDir         = "_pkgtest"
 | 
				
			||||||
	NumberOfTryAttempts    = 4
 | 
						NumberOfTryAttempts    = 4
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,6 @@
 | 
				
			|||||||
package install
 | 
					package install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
@@ -45,10 +44,8 @@ func walkAll(dirToWalk string) ([]BasicFileStatus, error) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func InstallFiles(files []BasicFileStatus, packetDir string) error {
 | 
					func InstallFiles(files []BasicFileStatus, packetDir string) error {
 | 
				
			||||||
	for i, v := range files {
 | 
						for _, v := range files {
 | 
				
			||||||
		sysPath, _ := strings.CutPrefix(v.Filepath, packetDir)
 | 
							sysPath, _ := strings.CutPrefix(v.Filepath, packetDir)
 | 
				
			||||||
		fmt.Printf("[%d] Installing file %s\n", i, v.Filepath)
 | 
					 | 
				
			||||||
		fmt.Printf("[%d] NEED to track file %s\n", i, sysPath)
 | 
					 | 
				
			||||||
		if v.IsDir {
 | 
							if v.IsDir {
 | 
				
			||||||
			if err := os.MkdirAll(sysPath, v.PermMode.Perm()); err != nil {
 | 
								if err := os.MkdirAll(sysPath, v.PermMode.Perm()); err != nil {
 | 
				
			||||||
				return err
 | 
									return err
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,7 +27,7 @@ type OperationalSystem string
 | 
				
			|||||||
type PacketLua struct {
 | 
					type PacketLua struct {
 | 
				
			||||||
	Name        string
 | 
						Name        string
 | 
				
			||||||
	Version     string
 | 
						Version     string
 | 
				
			||||||
	Maintaner   string
 | 
						Maintainer  string
 | 
				
			||||||
	Description string
 | 
						Description string
 | 
				
			||||||
	Serial      int
 | 
						Serial      int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -133,7 +133,7 @@ func ReadPacket(f []byte, cfg *Config) (PacketLua, error) {
 | 
				
			|||||||
	packetLua := &PacketLua{
 | 
						packetLua := &PacketLua{
 | 
				
			||||||
		Name:        getStringFromTable(pkgTable, "name"),
 | 
							Name:        getStringFromTable(pkgTable, "name"),
 | 
				
			||||||
		Version:     getStringFromTable(pkgTable, "version"),
 | 
							Version:     getStringFromTable(pkgTable, "version"),
 | 
				
			||||||
		Maintaner:   getStringFromTable(pkgTable, "maintainer"),
 | 
							Maintainer:  getStringFromTable(pkgTable, "maintainer"),
 | 
				
			||||||
		Description: getStringFromTable(pkgTable, "description"),
 | 
							Description: getStringFromTable(pkgTable, "description"),
 | 
				
			||||||
		Serial:      getIntFromTable(pkgTable, "serial"),
 | 
							Serial:      getIntFromTable(pkgTable, "serial"),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,7 @@ func (pkg PacketLua) IsValid() bool {
 | 
				
			|||||||
	switch {
 | 
						switch {
 | 
				
			||||||
	case pkg.Serial == -133:
 | 
						case pkg.Serial == -133:
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	case pkg.Description == "" || pkg.Maintaner == "" || pkg.Name == "" || pkg.Version == "":
 | 
						case pkg.Description == "" || pkg.Maintainer == "" || pkg.Name == "" || pkg.Version == "":
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return true
 | 
						return true
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ package packet
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"math/rand"
 | 
						"math/rand"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$%!@%&*()-=+[]{}:;.,1234567890"
 | 
					const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$%!@%&*()-=+[]{}:;.,1234567890"
 | 
				
			||||||
@@ -13,3 +14,21 @@ func randStringBytes(n int) string {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return string(b)
 | 
						return string(b)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PackageID struct {
 | 
				
			||||||
 | 
						ID string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (id PackageID) Name() string {
 | 
				
			||||||
 | 
						return strings.SplitAfter(id.ID, "@")[0]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (id PackageID) Version() string {
 | 
				
			||||||
 | 
						return strings.SplitAfter(id.ID, "@")[1]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewId(id string) PackageID {
 | 
				
			||||||
 | 
						var ID PackageID
 | 
				
			||||||
 | 
						ID.ID = id
 | 
				
			||||||
 | 
						return ID
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user