changed xz package for zst
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
@@ -27,11 +26,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
|
"github.com/klauspost/compress/zstd"
|
||||||
"github.com/schollz/progressbar/v3"
|
"github.com/schollz/progressbar/v3"
|
||||||
"golang.org/x/net/ipv4"
|
"golang.org/x/net/ipv4"
|
||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite"
|
||||||
|
|
||||||
"github.com/ulikunitz/xz"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConfigTOML struct {
|
type ConfigTOML struct {
|
||||||
@@ -85,13 +83,19 @@ type Quer1 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Manifest struct {
|
type Manifest struct {
|
||||||
Name string `json:"name"`
|
Info struct {
|
||||||
Version string `json:"version"`
|
Name string `toml:"name"`
|
||||||
Description string `json:"description"`
|
Version string `toml:"version"`
|
||||||
Dependencies []string `json:"dependencies"`
|
Description string `toml:"description"`
|
||||||
Author string `json:"author"`
|
Dependencies []string `toml:"dependencies"`
|
||||||
Family string `json:"family"`
|
Author string `toml:"author"`
|
||||||
Serial uint `json:"serial"`
|
Family string `toml:"family"`
|
||||||
|
Serial uint `toml:"serial"`
|
||||||
|
} `toml:"Info"`
|
||||||
|
Hooks struct {
|
||||||
|
Install string `toml:"install"`
|
||||||
|
Remove string `toml:"remove"`
|
||||||
|
} `toml:"Hooks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var serialPass uint
|
var serialPass uint
|
||||||
@@ -375,7 +379,7 @@ func Install(packagepath string, serial uint) error {
|
|||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
name := manifest.Name
|
name := manifest.Info.Name
|
||||||
|
|
||||||
var destDir = filepath.Join(cfg.Config.DataDir, name)
|
var destDir = filepath.Join(cfg.Config.DataDir, name)
|
||||||
|
|
||||||
@@ -436,6 +440,7 @@ func Install(packagepath string, serial uint) error {
|
|||||||
bar.Finish()
|
bar.Finish()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
f.WriteString("\n\n# BE CAREFULL CHANGING BIN_DIR, BECAUSE THE BINARIES DON'T MOVE AUTOMATICALLY\n#NEVER CHANGE lastDataDir\n")
|
f.WriteString("\n\n# BE CAREFULL CHANGING BIN_DIR, BECAUSE THE BINARIES DON'T MOVE AUTOMATICALLY\n#NEVER CHANGE lastDataDir\n")
|
||||||
os.Remove(cfg.Config.LastDataDir)
|
os.Remove(cfg.Config.LastDataDir)
|
||||||
bar.Finish()
|
bar.Finish()
|
||||||
@@ -455,12 +460,12 @@ func Install(packagepath string, serial uint) error {
|
|||||||
|
|
||||||
counter := &CountingReader{R: f}
|
counter := &CountingReader{R: f}
|
||||||
|
|
||||||
xzr, err := xz.NewReader(counter)
|
zs, err := zstd.NewReader(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tr := tar.NewReader(xzr)
|
tr := tar.NewReader(zs)
|
||||||
|
|
||||||
bar := progressbar.NewOptions64(
|
bar := progressbar.NewOptions64(
|
||||||
totalsize,
|
totalsize,
|
||||||
@@ -479,7 +484,6 @@ func Install(packagepath string, serial uint) error {
|
|||||||
rel := filepath.Clean(hdr.Name)
|
rel := filepath.Clean(hdr.Name)
|
||||||
|
|
||||||
if rel == ".." || strings.HasPrefix(rel, ".."+string(os.PathSeparator)) {
|
if rel == ".." || strings.HasPrefix(rel, ".."+string(os.PathSeparator)) {
|
||||||
fmt.Println("Ignored :", rel)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,45 +532,16 @@ func Install(packagepath string, serial uint) error {
|
|||||||
|
|
||||||
bar.Finish()
|
bar.Finish()
|
||||||
|
|
||||||
manifest.Serial = serial
|
// TODO LUA SCRIPT
|
||||||
|
|
||||||
jsonData, err := json.Marshal(manifest)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.WriteFile(fmt.Sprintf("%s/manifest.json", destDir), jsonData, 0777)
|
|
||||||
|
|
||||||
script := fmt.Sprintf("%s/postinstall.sh", destDir)
|
|
||||||
|
|
||||||
os.Chmod(script, 0777)
|
|
||||||
os.Chmod(fmt.Sprintf("%s/remove.sh", destDir), 0777)
|
|
||||||
|
|
||||||
fmt.Println("\nMaking post install configuration...")
|
|
||||||
cmd := exec.Command(script)
|
|
||||||
|
|
||||||
cmd.Env = append(os.Environ(),
|
|
||||||
fmt.Sprintf("PACKETS_PACKAGE_DIR=%s", cfg.Config.DataDir),
|
|
||||||
fmt.Sprintf("PACKETS_PACKAGE_BIN_DIR=%s", cfg.Config.BinDir),
|
|
||||||
)
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
|
|
||||||
err = cmd.Run()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
return fmt.Errorf("error exec postinstall script %e", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Package %s fully installed\n", name)
|
fmt.Printf("Package %s fully installed\n", name)
|
||||||
|
|
||||||
var insert = Installed{
|
var insert = Installed{
|
||||||
Realname: manifest.Name,
|
Realname: manifest.Info.Name,
|
||||||
Version: manifest.Version,
|
Version: manifest.Info.Version,
|
||||||
Dependencies: manifest.Dependencies,
|
Dependencies: manifest.Info.Dependencies,
|
||||||
Family: manifest.Family,
|
Family: manifest.Info.Family,
|
||||||
Serial: manifest.Serial,
|
Serial: manifest.Info.Serial,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := AddToInstalledDB(insert); err != nil {
|
if err := AddToInstalledDB(insert); err != nil {
|
||||||
@@ -1331,7 +1306,7 @@ func Upgrade(packagepath string, og_realname string, serial uint) error {
|
|||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
name := manifest.Name
|
name := manifest.Info.Name
|
||||||
|
|
||||||
fmt.Printf("Unpacking (%s) above (%s)\n", name, og_realname)
|
fmt.Printf("Unpacking (%s) above (%s)\n", name, og_realname)
|
||||||
|
|
||||||
@@ -1347,12 +1322,12 @@ func Upgrade(packagepath string, og_realname string, serial uint) error {
|
|||||||
|
|
||||||
counter := &CountingReader{R: f}
|
counter := &CountingReader{R: f}
|
||||||
|
|
||||||
xzr, err := xz.NewReader(counter)
|
zs, err := zstd.NewReader(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tr := tar.NewReader(xzr)
|
tr := tar.NewReader(zs)
|
||||||
|
|
||||||
bar := progressbar.NewOptions64(
|
bar := progressbar.NewOptions64(
|
||||||
totalSize,
|
totalSize,
|
||||||
@@ -1372,7 +1347,6 @@ func Upgrade(packagepath string, og_realname string, serial uint) error {
|
|||||||
rel := filepath.Clean(hdr.Name)
|
rel := filepath.Clean(hdr.Name)
|
||||||
|
|
||||||
if rel == ".." || strings.HasPrefix(rel, ".."+string(os.PathSeparator)) {
|
if rel == ".." || strings.HasPrefix(rel, ".."+string(os.PathSeparator)) {
|
||||||
fmt.Println("Ignored :", rel)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1421,45 +1395,19 @@ func Upgrade(packagepath string, og_realname string, serial uint) error {
|
|||||||
bar.Finish()
|
bar.Finish()
|
||||||
|
|
||||||
os.Rename(destDir, filepath.Join(cfg.Config.DataDir, name))
|
os.Rename(destDir, filepath.Join(cfg.Config.DataDir, name))
|
||||||
|
|
||||||
destDir = filepath.Join(cfg.Config.DataDir, name)
|
destDir = filepath.Join(cfg.Config.DataDir, name)
|
||||||
|
|
||||||
manifest.Serial = serial
|
//TODO manifest.toml things
|
||||||
|
|
||||||
jsonData, err := json.Marshal(manifest)
|
fmt.Printf("Package %s fully installed", name)
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.WriteFile(filepath.Join(destDir, "manifest.json"), jsonData, 0777)
|
|
||||||
|
|
||||||
script := fmt.Sprintf(filepath.Join(destDir, "postinstall.sh"), destDir)
|
|
||||||
|
|
||||||
os.Chmod(script, 0777)
|
|
||||||
os.Chmod(fmt.Sprintf(filepath.Join(destDir, "remove.sh"), destDir), 0777)
|
|
||||||
|
|
||||||
fmt.Println("Making post install configuration...")
|
|
||||||
cmd := exec.Command(script)
|
|
||||||
|
|
||||||
cmd.Env = append(os.Environ(),
|
|
||||||
fmt.Sprintf("PACKETS_PACKAGE_DIR=%s", cfg.Config.DataDir),
|
|
||||||
fmt.Sprintf("PACKETS_PACKAGE_BIN_DIR=%s", cfg.Config.BinDir),
|
|
||||||
)
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
|
|
||||||
err = cmd.Run()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error exec postinstall script %e", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Package %s fully installed you maybe run: \"source ~/.bashrc \"\n", name)
|
|
||||||
|
|
||||||
var insert = Installed{
|
var insert = Installed{
|
||||||
Realname: manifest.Name,
|
Realname: manifest.Info.Name,
|
||||||
Version: manifest.Version,
|
Version: manifest.Info.Version,
|
||||||
Dependencies: manifest.Dependencies,
|
Dependencies: manifest.Info.Dependencies,
|
||||||
Family: manifest.Family,
|
Family: manifest.Info.Family,
|
||||||
Serial: manifest.Serial,
|
Serial: manifest.Info.Serial,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.Exec("DELETE FROM packages WHERE realname = ?", og_realname)
|
_, err = db.Exec("DELETE FROM packages WHERE realname = ?", og_realname)
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ package internal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ulikunitz/xz"
|
"github.com/BurntSushi/toml"
|
||||||
|
"github.com/klauspost/compress/zstd"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConfigTOML struct {
|
type ConfigTOML struct {
|
||||||
@@ -25,13 +25,19 @@ type ConfigTOML struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Manifest struct {
|
type Manifest struct {
|
||||||
Name string `json:"name"`
|
Info struct {
|
||||||
Version string `json:"version"`
|
Name string `toml:"name"`
|
||||||
Description string `json:"description"`
|
Version string `toml:"version"`
|
||||||
Dependencies []string `json:"dependencies"`
|
Description string `toml:"description"`
|
||||||
Author string `json:"author"`
|
Dependencies []string `toml:"dependencies"`
|
||||||
Family string `json:"family"`
|
Author string `toml:"author"`
|
||||||
Serial uint `json:"serial"`
|
Family string `toml:"family"`
|
||||||
|
Serial uint `toml:"serial"`
|
||||||
|
} `toml:"Info"`
|
||||||
|
Hooks struct {
|
||||||
|
Install string `toml:"install"`
|
||||||
|
Remove string `toml:"remove"`
|
||||||
|
} `toml:"Hooks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func PacketsPackageDir() string {
|
func PacketsPackageDir() string {
|
||||||
@@ -52,15 +58,16 @@ func ManifestReadXZ(path string) (*Manifest, error) {
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
xzr, err := xz.NewReader(f)
|
zr, err := zstd.NewReader(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer zr.Close()
|
||||||
|
|
||||||
tr := tar.NewReader(xzr)
|
tarReader := tar.NewReader(zr)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
hdr, err := tr.Next()
|
header, err := tarReader.Next()
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -68,17 +75,18 @@ func ManifestReadXZ(path string) (*Manifest, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasSuffix(hdr.Name, "/manifest.json") || hdr.Name == "manifest.json" {
|
if header.Name == "/manifest.toml" || header.Name == "manifest.toml" {
|
||||||
|
decoder := toml.NewDecoder(tarReader)
|
||||||
|
|
||||||
var manifest Manifest
|
var manifest Manifest
|
||||||
decoder := json.NewDecoder(tr)
|
|
||||||
if err := decoder.Decode(&manifest); err != nil {
|
decoder.Decode(manifest)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &manifest, nil
|
return &manifest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("can't find manifest.json")
|
return nil, fmt.Errorf("can't find manifest.toml")
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultConfigTOML() *ConfigTOML {
|
func DefaultConfigTOML() *ConfigTOML {
|
||||||
|
|||||||
Reference in New Issue
Block a user