changing to packets user and creating internal.db, improved bat-bin

Packet.lua
This commit is contained in:
2025-11-02 21:29:52 -03:00
parent 22fb19a550
commit 1c3e448b8d
7 changed files with 57 additions and 7 deletions

View File

@@ -89,3 +89,13 @@ func MarkAsInstalled(pkg packet.PacketLua, db *sql.DB, image *[]byte) error {
}
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) }

View File

@@ -1,12 +1,15 @@
package main
import (
"database/sql"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
_ "github.com/mattn/go-sqlite3"
"github.com/roboogg133/packets/cmd/packets/database"
"github.com/roboogg133/packets/pkg/install"
"github.com/roboogg133/packets/pkg/packet.lua.d"
"github.com/spf13/cobra"
@@ -29,6 +32,10 @@ var executeCmd = &cobra.Command{
return GetConfiguration()
},
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 {
if !strings.HasSuffix(v, ".lua") {
@@ -93,8 +100,12 @@ var executeCmd = &cobra.Command{
fmt.Printf("error: %s", err.Error())
os.Exit(1)
}
_ = ChangeToNoPermission()
pkg.ExecuteBuild(configs)
pkg.ExecuteInstall(configs)
_ = ElevatePermission()
os.Chdir(backupDir)
files, err := install.GetPackageFiles(configs.PacketDir)
@@ -108,6 +119,18 @@ var executeCmd = &cobra.Command{
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)
}
}
},
}

View File

@@ -2,6 +2,7 @@ package main
const (
ConfigurationDir = "/etc/packets"
InternalDB = ConfigurationDir + "/internal.db"
HomeDir = "/var/lib/packets"
PackageRootDir = "_pkgtest"
NumberOfTryAttempts = 4