Compare commits
	
		
			113 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| fe0da8ad63 | |||
| 885ce25fe9 | |||
| 1c3e448b8d | |||
| 22fb19a550 | |||
| aa98cd81b3 | |||
| e33f7b6d3c | |||
| a0704d6ac6 | |||
| c44abc78d6 | |||
| 064ee7f404 | |||
| 52ecacc4fe | |||
| 4c88ec3bc2 | |||
| ff5e271195 | |||
| cbea1dd8b5 | |||
| acf00bc5f8 | |||
| b15d847fd2 | |||
| 05af0969e9 | |||
| dff912928b | |||
| 0001118bd0 | |||
| 43a24a4f36 | |||
| d3c4a604c3 | |||
| 6c5abdf4d4 | |||
| 1c4ade5db9 | |||
| b31630a6c0 | |||
| 
						 | 
					25eabc92ed | ||
| a111b060f1 | |||
| a62ddf8270 | |||
| aa65b28112 | |||
| 72a5ab7c5d | |||
| 89b3fdbc84 | |||
| 0a531488a3 | |||
| 7fbaef7bd4 | |||
| b411eff6f4 | |||
| befa4e3ea4 | |||
| 807d9fa784 | |||
| 9883fd92dc | |||
| 51c51b96bf | |||
| a69de7e918 | |||
| 4178387e2a | |||
| b6d7ec8a5f | |||
| 8feaf5d19b | |||
| 820ffc299f | |||
| ecce74d2e9 | |||
| 5ba30c617a | |||
| e3772d0944 | |||
| df32178372 | |||
| cc9587821d | |||
| 31af4d5389 | |||
| dbd63d371b | |||
| 52f675ab60 | |||
| 26f9e20ae8 | |||
| 6377de7208 | |||
| b58173837b | |||
| 97408da348 | |||
| be96001d78 | |||
| 7c4fba5c86 | |||
| 4cee062889 | |||
| 93093382f4 | |||
| e4b4d43163 | |||
| b89abb31df | |||
| 0a965c67c2 | |||
| 147fca375e | |||
| afc19b6e4d | |||
| 690f180687 | |||
| 7ef7b60cf5 | |||
| 4e2d506a01 | |||
| df4c76bd99 | |||
| af24fa84a2 | |||
| 4b54a9c74b | |||
| f25366d40c | |||
| cadf5fedcb | |||
| cfb11cf6e6 | |||
| bb4f221fc9 | |||
| 9cf5ae61d8 | |||
| ff4c61315e | |||
| 76450789b0 | |||
| 0e8db8b40e | |||
| 3591460214 | |||
| 96db4572b4 | |||
| 17e1b4b3ab | |||
| 73171424e4 | |||
| b4f55ad36f | |||
| 2c322d4de8 | |||
| 2735749b12 | |||
| 05fbbde194 | |||
| fe81e6bf22 | |||
| 2cfe78721a | |||
| ff986ef943 | |||
| f34308367e | |||
| 68b394523d | |||
| b14bd1806a | |||
| 3929493bfb | |||
| 2620ec00ab | |||
| 0485b8325f | |||
| 33d636b41d | |||
| ac236342b6 | |||
| 910cad2734 | |||
| fdb21aacc5 | |||
| a22a2a70c0 | |||
| f5399a66ba | |||
| 9e09b1e3a4 | |||
| f8bda68a57 | |||
| b84d43200a | |||
| 35cbc2e47c | |||
| 3a068ed90b | |||
| bdbc580c82 | |||
| 3c770c469d | |||
| 1c00df24a4 | |||
| f3ccd6d683 | |||
| 8de2eaced7 | |||
| c0057ca053 | |||
| 61149ae711 | |||
| bf10e39ffc | |||
| 379f640f33 | 
							
								
								
									
										163
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										163
									
								
								README.md
									
									
									
									
									
								
							@@ -1,163 +0,0 @@
 | 
				
			|||||||
# 📦 Packets – Custom Package Manager for Linux
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
> A fast and minimal package manager written in Go with Lua hooks, local network discovery, and SQLite-based indexing.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
---
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## 📘 Overview
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
**Packets** is a lightweight package manager for Linux, written in Go. It supports:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
- Installation and removal of packages
 | 
					 | 
				
			||||||
- Dependency resolution and upgrading
 | 
					 | 
				
			||||||
- `.tar.zst` compressed packages with `manifest.toml` metadata
 | 
					 | 
				
			||||||
- Lua-based install/remove hooks
 | 
					 | 
				
			||||||
- Local cache with SHA-256 validation
 | 
					 | 
				
			||||||
- Peer-to-peer discovery over LAN
 | 
					 | 
				
			||||||
- Remote package syncing via HTTP
 | 
					 | 
				
			||||||
- SQLite-based local database
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
---
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## 📁 Directory Structure
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| Path                  | Description                      |
 | 
					 | 
				
			||||||
|-----------------------|----------------------------------|
 | 
					 | 
				
			||||||
| `/etc/packets/`       | Configuration files              |
 | 
					 | 
				
			||||||
| `/opt/packets/`       | Installed package data           |
 | 
					 | 
				
			||||||
| `/var/cache/packets/` | Cached `.tar.zst` package files  |
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(This can be changed in `/etc/packets/config.toml`)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
---
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Available Commands
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| Command                   | Description                                                                |
 | 
					 | 
				
			||||||
|---------------------------|----------------------------------------------------------------------------|
 | 
					 | 
				
			||||||
|`packets install <name>`	|    Install a package (resolves dependencies, executes Lua install hook)    |
 | 
					 | 
				
			||||||
|`packets remove <name>`	|    Remove a package (executes Lua remove hook)                             |
 | 
					 | 
				
			||||||
|`packets upgrade <name>`	|    Upgrade a package by checking family and serial in the manifest         |
 | 
					 | 
				
			||||||
|`packets sync [url]`	    |    Synchronize index.db from remote HTTP source                            |
 | 
					 | 
				
			||||||
|`packets serve init/stop`  |    Starts and stop the LAN service daemon                                  |
 | 
					 | 
				
			||||||
|`packets list`	            |    List all installed packages                                             |
 | 
					 | 
				
			||||||
|`packets info`             |    Get technical package information                                       |
 | 
					 | 
				
			||||||
|`packets search`           |    List all packages in index.db                                           |
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# 📦 Package Format
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Packages must be compressed as .tar.zst and include:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
- ├── manifest.toml       # Package metadata
 | 
					 | 
				
			||||||
- ├── data/               # Files to install
 | 
					 | 
				
			||||||
- ├── install.lua         # Lua install hook
 | 
					 | 
				
			||||||
- └── remove.lua          # Lua remove hook
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## Example manifest.toml
 | 
					 | 
				
			||||||
    [Info]
 | 
					 | 
				
			||||||
     name = "packets"
 | 
					 | 
				
			||||||
     version = "1.0.0"
 | 
					 | 
				
			||||||
     description = "offline and online packetmanager"
 | 
					 | 
				
			||||||
     dependencies = []
 | 
					 | 
				
			||||||
     author = "robo"
 | 
					 | 
				
			||||||
     family = "1f84ca15-5077-4f1d-a370-0ec860766eb2"
 | 
					 | 
				
			||||||
     serial = 0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    [Hooks]
 | 
					 | 
				
			||||||
     install = "install.lua"
 | 
					 | 
				
			||||||
     remove = "remove.lua"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
--
 | 
					 | 
				
			||||||
# 🔄 Installation Process
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
- Check if package is already cached and validated via SHA-256.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
- If not, search the package:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Via LAN: Sends UDP broadcast (Q:filename) to peers.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Via HTTP: Downloads from configured mirrors.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Decompress .tar.zst, install files.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Execute Lua install hook.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# 🧩 Core Features
 | 
					 | 
				
			||||||
✅ Dependency Resolution
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Installs required dependencies listed in the manifest.
 | 
					 | 
				
			||||||
## 🌐 LAN Discovery
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Broadcasts package request to devices in the same network via UDP.
 | 
					 | 
				
			||||||
## 📡 Remote Download
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Downloads package via HTTP if not found on LAN.
 | 
					 | 
				
			||||||
## 🔒 Security
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    SHA-256 checksum validation
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Path validation to avoid exploits (..)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Safe, sandboxed Lua runtime with limited API
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# 🌍 Global Variables Available in Lua Scripts
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
During the execution of install.lua and remove.lua hooks, some global variables are automatically provided to the Lua environment. These help simplify file path handling and access to package-specific directories.
 | 
					 | 
				
			||||||
## Available variables:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
|Name	             |Type	  |  Description
 | 
					 | 
				
			||||||
|--------------------|--------|--------------------------------------------------------------------------|
 | 
					 | 
				
			||||||
|packets_package_dir |	string|	Absolute path to the package's data directory (e.g., /opt/packets/...)   | 
 | 
					 | 
				
			||||||
| packets_bin_dir      |  string| Path where executables should be installed (e.g., /usr/bin)            |
 | 
					 | 
				
			||||||
|script              |  string|	Path to the currently executing script (e.g., "install.lua")             |
 | 
					 | 
				
			||||||
|data_dir            |  string|	Path to the /data folder of the current package                          |
 | 
					 | 
				
			||||||
### Example usage in Lua:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        print("Installing into: " .. packets_bin_dir)
 | 
					 | 
				
			||||||
        print("Package data in: " .. data_dir)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        -- Copy a binary to /usr/bin
 | 
					 | 
				
			||||||
        os.copy(path_join(data_dir, "htop"), path_join(packets_bin_dir, "htop"))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
These variables are preloaded in the Lua environment—no need to manually declare or initialize them.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## 🛠️ Allowed Lua API (install/remove hooks)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
To ensure security, only a limited set of safe functions are exposed in Lua hooks:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    os.remove(path)
 | 
					 | 
				
			||||||
    os.rename(old, new)
 | 
					 | 
				
			||||||
    os.copy(source, target)
 | 
					 | 
				
			||||||
    os.symlink(source, target)
 | 
					 | 
				
			||||||
    io.open(path, mode)
 | 
					 | 
				
			||||||
    os.mkdir(path, filemode)
 | 
					 | 
				
			||||||
    path_join(...) 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
### Note: Dangerous functions like os.execute, os.getenv, etc. are removed.
 | 
					 | 
				
			||||||
## 🗃️ Databases
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    index.db: Available packages (after sync)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    installed.db: Packages currently installed
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# ⚠️ Restrictions & Notes
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Linux only (//go:build linux)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Root permissions required for most commands
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Changing dataDir triggers prompt to migrate installed packages
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Binaries in binDir are not automatically moved if path changes
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Do not manually edit lastDataDir
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# TODO
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
- Auto-compile packages
 | 
					 | 
				
			||||||
- An web page to upload packages
 | 
					 | 
				
			||||||
@@ -1,37 +0,0 @@
 | 
				
			|||||||
package main
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"log"
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
	"os"
 | 
					 | 
				
			||||||
	"path/filepath"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"packets/internal"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/BurntSushi/toml"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type ConfigTOML struct {
 | 
					 | 
				
			||||||
	Config struct {
 | 
					 | 
				
			||||||
		DefaultHttpPort int    `toml:"httpPort"`
 | 
					 | 
				
			||||||
		DefaultCacheDir string `toml:"cacheDir"`
 | 
					 | 
				
			||||||
	} `toml:"Config"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func main() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	internal.PacketsPackageDir()
 | 
					 | 
				
			||||||
	var cfg ConfigTOML
 | 
					 | 
				
			||||||
	toml.Decode(filepath.Join(internal.PacketsPackageDir(), "config.toml"), &cfg)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pid := os.Getpid()
 | 
					 | 
				
			||||||
	if err := os.WriteFile(filepath.Join(internal.PacketsPackageDir(), "http.pid"), []byte(fmt.Sprint(pid)), 0644); err != nil {
 | 
					 | 
				
			||||||
		fmt.Println("error saving subprocess pid", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	fs := http.FileServer(http.Dir(cfg.Config.DefaultCacheDir))
 | 
					 | 
				
			||||||
	http.Handle("/", fs)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", cfg.Config.DefaultHttpPort), nil))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										66
									
								
								cmd/packets/cli.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								cmd/packets/cli.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"os/exec"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/charmbracelet/bubbles/list"
 | 
				
			||||||
 | 
						tea "github.com/charmbracelet/bubbletea"
 | 
				
			||||||
 | 
						"github.com/charmbracelet/lipgloss"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var docStyle = lipgloss.NewStyle().Margin(1, 2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type item struct {
 | 
				
			||||||
 | 
						title, desc string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (i item) Title() string       { return i.title }
 | 
				
			||||||
 | 
					func (i item) Description() string { return i.desc }
 | 
				
			||||||
 | 
					func (i item) FilterValue() string { return i.title }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type model struct {
 | 
				
			||||||
 | 
						list list.Model
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m model) Init() tea.Cmd {
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type vimMsg struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 | 
				
			||||||
 | 
						switch msg := msg.(type) {
 | 
				
			||||||
 | 
						case tea.KeyMsg:
 | 
				
			||||||
 | 
							if msg.String() == "ctrl+c" || msg.String() == "q" {
 | 
				
			||||||
 | 
								return m, tea.Quit
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if msg.String() == "enter" {
 | 
				
			||||||
 | 
								path := m.list.SelectedItem().(item).desc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								tea.ExecProcess(openEditor("vim", path), nil)
 | 
				
			||||||
 | 
								return m, tea.Quit
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						case tea.WindowSizeMsg:
 | 
				
			||||||
 | 
							h, v := docStyle.GetFrameSize()
 | 
				
			||||||
 | 
							m.list.SetSize(msg.Width-h, msg.Height-v)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var cmd tea.Cmd
 | 
				
			||||||
 | 
						m.list, cmd = m.list.Update(msg)
 | 
				
			||||||
 | 
						return m, cmd
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m model) View() string {
 | 
				
			||||||
 | 
						return docStyle.Render(m.list.View())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func openEditor(editor, path string) *exec.Cmd {
 | 
				
			||||||
 | 
						time.Sleep(1 * time.Second)
 | 
				
			||||||
 | 
						cmd := exec.Command(editor, path)
 | 
				
			||||||
 | 
						cmd.Stdin = os.Stdin
 | 
				
			||||||
 | 
						cmd.Stdout = os.Stdout
 | 
				
			||||||
 | 
						cmd.Stderr = os.Stderr
 | 
				
			||||||
 | 
						return cmd
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										28
									
								
								cmd/packets/config.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								cmd/packets/config.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/pelletier/go-toml/v2"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PacketsConfiguration struct {
 | 
				
			||||||
 | 
						BinDir string `toml:"BinDir"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetConfiguration() error {
 | 
				
			||||||
 | 
						configFile := filepath.Join(ConfigurationDir, "config.toml")
 | 
				
			||||||
 | 
						data, err := os.ReadFile(configFile)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var config PacketsConfiguration
 | 
				
			||||||
 | 
						err = toml.Unmarshal(data, &config)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Config = &config
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										132
									
								
								cmd/packets/database/execute.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								cmd/packets/database/execute.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,132 @@
 | 
				
			|||||||
 | 
					package database
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"database/sql"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_ "github.com/mattn/go-sqlite3"
 | 
				
			||||||
 | 
						"github.com/roboogg133/packets/internal/lua"
 | 
				
			||||||
 | 
						"github.com/roboogg133/packets/pkg/install"
 | 
				
			||||||
 | 
						"github.com/roboogg133/packets/pkg/packet.lua.d"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						CreateInstructions = `
 | 
				
			||||||
 | 
					CREATE TABLE IF NOT EXISTS installed_packages(
 | 
				
			||||||
 | 
					    name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    id TEXT PRIMARY KEY,
 | 
				
			||||||
 | 
					    version TEXT NOT NULL,
 | 
				
			||||||
 | 
					    serial INTEGER NOT NULL,
 | 
				
			||||||
 | 
					    maintainer TEXT NOT NULL,
 | 
				
			||||||
 | 
					    verified INTEGER NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					    description TEXT NOT NULL,
 | 
				
			||||||
 | 
					    upload_time TEXT NOT NULL,
 | 
				
			||||||
 | 
					    installed_time INTEGER NOT NULL,
 | 
				
			||||||
 | 
					    image BLOB,
 | 
				
			||||||
 | 
					    UNIQUE(name, version),
 | 
				
			||||||
 | 
					    UNIQUE(name, serial)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE IF NOT EXISTS package_files(
 | 
				
			||||||
 | 
					    package_id TEXT NOT NULL,
 | 
				
			||||||
 | 
					    path TEXT NOT NULL,
 | 
				
			||||||
 | 
					    is_dir INTEGER NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					    UNIQUE(package_id, path)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE IF NOT EXISTS dependencies(
 | 
				
			||||||
 | 
					    package_id TEXT NOT NULL,
 | 
				
			||||||
 | 
					    dependency_name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    version_constraint TEXT NOT NULL,
 | 
				
			||||||
 | 
					    PRIMARY KEY (package_id, dependency_name)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE IF NOT EXISTS build_dependencies(
 | 
				
			||||||
 | 
					    package_id TEXT NOT NULL,
 | 
				
			||||||
 | 
					    dependency_name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    version_constraint TEXT NOT NULL,
 | 
				
			||||||
 | 
					    PRIMARY KEY (package_id, dependency_name)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE IF NOT EXISTS conflicts(
 | 
				
			||||||
 | 
					    package_id TEXT NOT NULL,
 | 
				
			||||||
 | 
					    dependency_name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    version_constraint TEXT NOT NULL,
 | 
				
			||||||
 | 
					    PRIMARY KEY (package_id, dependency_name)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE IF NOT EXISTS package_flags(
 | 
				
			||||||
 | 
					    package_id TEXT NOT NULL,
 | 
				
			||||||
 | 
					    flag TEXT NOT NULL,
 | 
				
			||||||
 | 
					    name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    path TEXT NOT NULL
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type DatabaseOptions struct {
 | 
				
			||||||
 | 
						// Add any additional options here
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func MarkAsInstalled(pkg packet.PacketLua, files []install.BasicFileStatus, PACKETDIR string, flags []lua.Flag, db *sql.DB, image []byte, upload_time int64) error {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch {
 | 
				
			||||||
 | 
						case upload_time == 0:
 | 
				
			||||||
 | 
							upload_time = time.Now().UnixMilli()
 | 
				
			||||||
 | 
						case image == nil:
 | 
				
			||||||
 | 
							image = []byte{1}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := db.Exec("INSERT INTO installed_packages (name, id, version, installed_time, image, serial, maintainer, description, upload_time) VALUES (?, ?, ?, ?, ?, ?,?,?,?)", pkg.Name, pkg.Name+"@"+pkg.Version, pkg.Version, time.Now().UnixMilli(), image, pkg.Serial, pkg.Maintainer, pkg.Description, time.Now().UnixMilli())
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							db.Exec("DELETE FROM installed_packages WHERE id = ?", pkg.Name+"@"+pkg.Version)
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, v := range files {
 | 
				
			||||||
 | 
							v.Filepath, _ = strings.CutPrefix(v.Filepath, PACKETDIR)
 | 
				
			||||||
 | 
							_, err = db.Exec("INSERT INTO package_files (package_id, path, is_dir) VALUES (?, ?, ?)", pkg.Name+"@"+pkg.Version, v.Filepath, v.IsDir)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								db.Exec("DELETE FROM installed_packages WHERE id = ?", pkg.Name+"@"+pkg.Version)
 | 
				
			||||||
 | 
								db.Exec("DELETE FROM package_files WHERE package_id = ?", pkg.Name+"@"+pkg.Version)
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, v := range flags {
 | 
				
			||||||
 | 
							_, err = db.Exec("INSERT INTO package_flags (package_id, flag, name, path) VALUES (?, ?, ?, ?)", pkg.Name+"@"+pkg.Version, v.FlagType, v.Name, v.Path)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								db.Exec("DELETE FROM installed_packages WHERE id = ?", pkg.Name+"@"+pkg.Version)
 | 
				
			||||||
 | 
								db.Exec("DELETE FROM package_files WHERE package_id = ?", pkg.Name+"@"+pkg.Version)
 | 
				
			||||||
 | 
								db.Exec("DELETE FROM package_flags WHERE package_id = ?", pkg.Name+"@"+pkg.Version)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func MarkAsUninstalled(id string, db *sql.DB) error {
 | 
				
			||||||
 | 
						if _, err := db.Exec("DELETE FROM installed_packages WHERE id = ?", id); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := db.Exec("DELETE FROM package_files WHERE package_id = ?", id); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := db.Exec("DELETE FROM package_flags WHERE package_id = ?", id); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func PrepareDataBase(db *sql.DB) {
 | 
				
			||||||
 | 
						_, err := db.Exec(CreateInstructions)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error preparing database:", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										72
									
								
								cmd/packets/database/query.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								cmd/packets/database/query.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,72 @@
 | 
				
			|||||||
 | 
					package database
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"database/sql"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/roboogg133/packets/internal/lua"
 | 
				
			||||||
 | 
						"github.com/roboogg133/packets/pkg/install"
 | 
				
			||||||
 | 
						"github.com/roboogg133/packets/pkg/packet.lua.d"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// this function will get from a package name an id based on installed packages
 | 
				
			||||||
 | 
					func GetPackageId(name string, db *sql.DB) (packet.PackageID, error) {
 | 
				
			||||||
 | 
						var id packet.PackageID
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if strings.Contains(name, "@") {
 | 
				
			||||||
 | 
							id.ID = strings.SplitAfter(name, "@")[0]
 | 
				
			||||||
 | 
							return id, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err := db.QueryRow("SELECT id FROM installed_packages WHERE name = ?", name).Scan(&id.ID)
 | 
				
			||||||
 | 
						return id, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func SearchIfIsInstalled(name string, db *sql.DB) (bool, error) {
 | 
				
			||||||
 | 
						var exists bool
 | 
				
			||||||
 | 
						err := db.QueryRow("SELECT EXISTS(SELECT 1 FROM installed_packages WHERE name = ?)", name).Scan(&exists)
 | 
				
			||||||
 | 
						return exists, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetAllFromFlag(packageID packet.PackageID, flagType string, db *sql.DB) ([]lua.Flag, error) {
 | 
				
			||||||
 | 
						var flags []lua.Flag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rows, err := db.Query("SELECT name, path FROM package_flags WHERE package_id = ? AND flag = ?", packageID.ID, flagType)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer rows.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for rows.Next() {
 | 
				
			||||||
 | 
							var flag lua.Flag
 | 
				
			||||||
 | 
							if err := rows.Scan(&flag.Name, &flag.Path); err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							flag.FlagType = flagType
 | 
				
			||||||
 | 
							flags = append(flags, flag)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return flags, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetPackageFiles(packageID packet.PackageID, db *sql.DB) ([]install.BasicFileStatus, error) {
 | 
				
			||||||
 | 
						var files []install.BasicFileStatus
 | 
				
			||||||
 | 
						rows, err := db.Query("SELECT path, is_dir FROM package_files WHERE package_id = ?", packageID.ID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer rows.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for rows.Next() {
 | 
				
			||||||
 | 
							var file install.BasicFileStatus
 | 
				
			||||||
 | 
							if err := rows.Scan(&file.Filepath, &file.IsDir); err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							files = append(files, file)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := rows.Err(); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return files, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										153
									
								
								cmd/packets/decompress/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										153
									
								
								cmd/packets/decompress/main.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,153 @@
 | 
				
			|||||||
 | 
					package decompress
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"archive/tar"
 | 
				
			||||||
 | 
						"archive/zip"
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
 | 
						"compress/bzip2"
 | 
				
			||||||
 | 
						"compress/gzip"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/klauspost/compress/zstd"
 | 
				
			||||||
 | 
						"github.com/pierrec/lz4/v4"
 | 
				
			||||||
 | 
						"github.com/ulikunitz/xz"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func extractZipFile(file *zip.File, dest string) error {
 | 
				
			||||||
 | 
						rc, err := file.Open()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer rc.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						path := filepath.Join(dest, file.Name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if file.FileInfo().IsDir() {
 | 
				
			||||||
 | 
							return os.MkdirAll(path, file.Mode())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						outFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode())
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer outFile.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err = io.Copy(outFile, rc)
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Decompress(data io.Reader, outputDir, filename string) error {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var reader io.Reader
 | 
				
			||||||
 | 
						switch {
 | 
				
			||||||
 | 
						case strings.HasSuffix(filename, ".gz"):
 | 
				
			||||||
 | 
							var err error
 | 
				
			||||||
 | 
							reader, err = gzip.NewReader(data)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							filename, _ = strings.CutSuffix(filename, ".gz")
 | 
				
			||||||
 | 
						case strings.HasSuffix(filename, ".xz"):
 | 
				
			||||||
 | 
							var err error
 | 
				
			||||||
 | 
							reader, err = xz.NewReader(data)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							filename, _ = strings.CutSuffix(filename, ".xz")
 | 
				
			||||||
 | 
						case strings.HasSuffix(filename, ".zst"), strings.HasSuffix(filename, ".pkt"):
 | 
				
			||||||
 | 
							var err error
 | 
				
			||||||
 | 
							reader, err = zstd.NewReader(data)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							filename, _ = strings.CutSuffix(filename, ".zst")
 | 
				
			||||||
 | 
						case strings.HasSuffix(filename, ".bz2"):
 | 
				
			||||||
 | 
							reader = bzip2.NewReader(data)
 | 
				
			||||||
 | 
							filename, _ = strings.CutSuffix(filename, ".bz2")
 | 
				
			||||||
 | 
						case strings.HasSuffix(filename, ".lz4"):
 | 
				
			||||||
 | 
							reader = lz4.NewReader(data)
 | 
				
			||||||
 | 
							filename, _ = strings.CutSuffix(filename, ".lz4")
 | 
				
			||||||
 | 
						case strings.HasSuffix(filename, ".zip"):
 | 
				
			||||||
 | 
							content, err := io.ReadAll(data)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							reader, err := zip.NewReader(bytes.NewReader(content), int64(len(content)))
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err := os.MkdirAll(outputDir, 0755); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for _, file := range reader.File {
 | 
				
			||||||
 | 
								err := extractZipFile(file, outputDir)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return fmt.Errorf("error unziping %s: %w", file.Name, err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if strings.HasSuffix(filename, ".tar") || strings.HasSuffix(filename, ".pkt") {
 | 
				
			||||||
 | 
							tarReader := tar.NewReader(reader)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for {
 | 
				
			||||||
 | 
								header, err := tarReader.Next()
 | 
				
			||||||
 | 
								if err == io.EOF {
 | 
				
			||||||
 | 
									break
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								targetPath := filepath.Join(outputDir, filepath.Clean(header.Name))
 | 
				
			||||||
 | 
								if !strings.HasPrefix(targetPath, outputDir) {
 | 
				
			||||||
 | 
									return fmt.Errorf("invalid path: %s", targetPath)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								switch header.Typeflag {
 | 
				
			||||||
 | 
								case tar.TypeDir:
 | 
				
			||||||
 | 
									if err := os.MkdirAll(targetPath, os.FileMode(header.Mode)); err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								case tar.TypeReg, tar.TypeRegA:
 | 
				
			||||||
 | 
									if err := os.MkdirAll(filepath.Dir(targetPath), 0755); err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									outFile, err := os.OpenFile(targetPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(header.Mode))
 | 
				
			||||||
 | 
									if err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									defer outFile.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if _, err := io.Copy(outFile, tarReader); err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								case tar.TypeSymlink:
 | 
				
			||||||
 | 
									if err := os.Symlink(header.Linkname, targetPath); err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								case tar.TypeLink:
 | 
				
			||||||
 | 
									linkPath := filepath.Join(outputDir, header.Linkname)
 | 
				
			||||||
 | 
									if err := os.Link(linkPath, targetPath); err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								default:
 | 
				
			||||||
 | 
									return fmt.Errorf("unknown file type: %c => %s", header.Typeflag, header.Name)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										84
									
								
								cmd/packets/flags.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								cmd/packets/flags.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,84 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"database/sql"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/charmbracelet/bubbles/list"
 | 
				
			||||||
 | 
						tea "github.com/charmbracelet/bubbletea"
 | 
				
			||||||
 | 
						"github.com/roboogg133/packets/cmd/packets/database"
 | 
				
			||||||
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var configCmd = &cobra.Command{
 | 
				
			||||||
 | 
						Use:   "config {name or id}",
 | 
				
			||||||
 | 
						Short: "Show package configuration file",
 | 
				
			||||||
 | 
						Long:  "Show package configuration file",
 | 
				
			||||||
 | 
						Args:  cobra.RangeArgs(1, 1),
 | 
				
			||||||
 | 
						PreRun: func(cmd *cobra.Command, args []string) {
 | 
				
			||||||
 | 
							GrantPrivilegies()
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						Run: func(cmd *cobra.Command, args []string) {
 | 
				
			||||||
 | 
							insertedName := args[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							db, err := sql.Open("sqlite3", InternalDB)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								fmt.Println("Error opening database:", err)
 | 
				
			||||||
 | 
								os.Exit(1)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							defer db.Close()
 | 
				
			||||||
 | 
							database.PrepareDataBase(db)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							id, err := database.GetPackageId(insertedName, db)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								fmt.Println("Error getting package ID:", err)
 | 
				
			||||||
 | 
								os.Exit(1)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							flags, err := database.GetAllFromFlag(id, "config", db)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								fmt.Println("Error getting flags:", err)
 | 
				
			||||||
 | 
								os.Exit(1)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var all []list.Item
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for _, flag := range flags {
 | 
				
			||||||
 | 
								item := item{
 | 
				
			||||||
 | 
									title: flag.Name,
 | 
				
			||||||
 | 
									desc:  flag.Path,
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								all = append(all, item)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								delegate1 := list.NewDefaultDelegate()
 | 
				
			||||||
 | 
								delegate1.Styles.NormalTitle = lipgloss.NewStyle().
 | 
				
			||||||
 | 
									Foreground(lipgloss.Color("#FFFFFF")).
 | 
				
			||||||
 | 
									Background(lipgloss.Color("#000000")).
 | 
				
			||||||
 | 
									Margin(1)
 | 
				
			||||||
 | 
								delegate1.Styles.NormalDesc = lipgloss.NewStyle().
 | 
				
			||||||
 | 
									Foreground(lipgloss.Color("#000000"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								delegate1.Styles.SelectedTitle = lipgloss.NewStyle().
 | 
				
			||||||
 | 
									Foreground(lipgloss.Color("#0056FF")).
 | 
				
			||||||
 | 
									Bold(true).
 | 
				
			||||||
 | 
									Blink(true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								delegate1.Styles.SelectedDesc = lipgloss.NewStyle().
 | 
				
			||||||
 | 
									Foreground(lipgloss.Color("#FFFFFF")).
 | 
				
			||||||
 | 
									Bold(true).
 | 
				
			||||||
 | 
									Faint(true)
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							m := model{list: list.New(all, list.NewDefaultDelegate(), 0, 0)}
 | 
				
			||||||
 | 
							m.list.Title = "Configuration files"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							p := tea.NewProgram(m, tea.WithAltScreen())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if _, err := p.Run(); err != nil {
 | 
				
			||||||
 | 
								fmt.Println("Error running program:", err)
 | 
				
			||||||
 | 
								os.Exit(1)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										44
									
								
								cmd/packets/functions.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								cmd/packets/functions.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"path"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/go-git/go-git/v6"
 | 
				
			||||||
 | 
						"github.com/roboogg133/packets/cmd/packets/decompress"
 | 
				
			||||||
 | 
						"github.com/roboogg133/packets/pkg/packet.lua.d"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func DownloadSource(sources *[]packet.Source, configs *packet.Config) error {
 | 
				
			||||||
 | 
						for _, source := range *sources {
 | 
				
			||||||
 | 
							downloaded, err := packet.GetSource(source.Url, source.Method, source.Specs, NumberOfTryAttempts)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return fmt.Errorf("error: %s", err.Error())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if source.Method == "GET" || source.Method == "POST" {
 | 
				
			||||||
 | 
								f := downloaded.([]byte)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								buf := bytes.NewBuffer(f)
 | 
				
			||||||
 | 
								_ = os.MkdirAll(configs.SourcesDir, 0755)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if err := decompress.Decompress(buf, configs.SourcesDir, path.Base(source.Url)); err != nil {
 | 
				
			||||||
 | 
									return fmt.Errorf("error: %s", err.Error())
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								options := downloaded.(*git.CloneOptions)
 | 
				
			||||||
 | 
								repoName, _ := strings.CutSuffix(filepath.Base(source.Url), ".git")
 | 
				
			||||||
 | 
								_ = os.MkdirAll(filepath.Join(configs.SourcesDir, repoName), 0755)
 | 
				
			||||||
 | 
								_, err := git.PlainClone(filepath.Join(configs.SourcesDir, repoName), options)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return fmt.Errorf("error: %s", err.Error())
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								os.RemoveAll(filepath.Join(configs.SourcesDir, repoName, ".git"))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										2043
									
								
								cmd/packets/main.go
									
									
									
									
									
								
							
							
						
						
									
										2043
									
								
								cmd/packets/main.go
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										11
									
								
								cmd/packets/specifications.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								cmd/packets/specifications.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						ConfigurationDir       = "/etc/packets"
 | 
				
			||||||
 | 
						InternalDB             = ConfigurationDir + "/internal.db"
 | 
				
			||||||
 | 
						HomeDir                = "/var/lib/packets"
 | 
				
			||||||
 | 
						PackageRootDir         = "/var/lib/packets/packages"
 | 
				
			||||||
 | 
						NumberOfTryAttempts    = 4
 | 
				
			||||||
 | 
						UserHomeDirPlaceholder = "{{ USER HOME FOLDER }}"
 | 
				
			||||||
 | 
						UsernamePlaceholder    = "{{ USERNAME }}"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
							
								
								
									
										37
									
								
								cmd/packets/user.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								cmd/packets/user.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"os/exec"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"syscall"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetPacketsUID() (int, error) {
 | 
				
			||||||
 | 
						_ = exec.Command("useradd", "-M", "-N", "-r", "-s", "/bin/false", "-d", "/etc/packets", "packets").Run()
 | 
				
			||||||
 | 
						cmd := exec.Command("id", "-u", "packets")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						out, err := cmd.CombinedOutput()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return -1, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s := strings.TrimSpace(string(out))
 | 
				
			||||||
 | 
						uid, err := strconv.Atoi(s)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return -1, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return uid, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ChangeToNoPermission() error {
 | 
				
			||||||
 | 
						uid, err := GetPacketsUID()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return syscall.Setresuid(0, uid, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ElevatePermission() error { return syscall.Setresuid(0, 0, 0) }
 | 
				
			||||||
@@ -1,65 +0,0 @@
 | 
				
			|||||||
package main
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"log"
 | 
					 | 
				
			||||||
	"net"
 | 
					 | 
				
			||||||
	"os"
 | 
					 | 
				
			||||||
	"packets/internal"
 | 
					 | 
				
			||||||
	"path/filepath"
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/BurntSushi/toml"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type ConfigTOML struct {
 | 
					 | 
				
			||||||
	Config struct {
 | 
					 | 
				
			||||||
		HttpPort int    `toml:"httpPort"`
 | 
					 | 
				
			||||||
		CacheDir string `toml:"cacheDir"`
 | 
					 | 
				
			||||||
	} `toml:"Config"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var cfg ConfigTOML
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func CheckDownloaded(filename string) bool {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	_, err := os.Stat(filepath.Join(cfg.Config.CacheDir))
 | 
					 | 
				
			||||||
	if os.IsNotExist(err) {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		return true
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func main() {
 | 
					 | 
				
			||||||
	pid := os.Getpid()
 | 
					 | 
				
			||||||
	if err := os.WriteFile(filepath.Join(internal.PacketsPackageDir(), "udp.pid"), []byte(fmt.Sprint(pid)), 0644); err != nil {
 | 
					 | 
				
			||||||
		fmt.Println("error saving subprocess pid", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	toml.Decode(filepath.Join(internal.PacketsPackageDir(), "config.toml"), &cfg)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	addr := net.UDPAddr{IP: net.IPv4zero, Port: 1333}
 | 
					 | 
				
			||||||
	conn, err := net.ListenUDP("udp", &addr)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		log.Fatal(err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	defer conn.Close()
 | 
					 | 
				
			||||||
	buf := make([]byte, 1500)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for {
 | 
					 | 
				
			||||||
		n, remote, err := conn.ReadFromUDP(buf)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			log.Println("error creating udp socket", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		msg := string(buf[:n])
 | 
					 | 
				
			||||||
		if !strings.HasPrefix(msg, "Q:") {
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		filename := strings.TrimPrefix(msg, "Q:")
 | 
					 | 
				
			||||||
		if CheckDownloaded(filename) {
 | 
					 | 
				
			||||||
			reply := fmt.Sprintf("H:%s:%d", filename, cfg.Config.HttpPort)
 | 
					 | 
				
			||||||
			conn.WriteToUDP([]byte(reply), remote)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										61
									
								
								doc/internal.db.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								doc/internal.db.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
				
			|||||||
 | 
					CREATE TABLE installed_packges(
 | 
				
			||||||
 | 
					    name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    id TEXT PRIMARY KEY,
 | 
				
			||||||
 | 
					    version TEXT NOT NULL,
 | 
				
			||||||
 | 
					    serial INTEGER NOT NULL,
 | 
				
			||||||
 | 
					    maintainer TEXT NOT NULL,
 | 
				
			||||||
 | 
					    verified INTEGER NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					    description TEXT NOT NULL,
 | 
				
			||||||
 | 
					    upload_time TEXT NOT NULL,
 | 
				
			||||||
 | 
					    installed_time TEXT NOT NULL,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public_key BLOB NOT NULL,
 | 
				
			||||||
 | 
					    signature BLOB NOT NULL,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    image BLOB,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    UNIQUE(name, signature),
 | 
				
			||||||
 | 
					    UNIQUE(name, version),
 | 
				
			||||||
 | 
					    UNIQUE(name, serial)
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE package_files(
 | 
				
			||||||
 | 
					    package_id TEXT PRIMARY KEY,
 | 
				
			||||||
 | 
					    filepath TEXT NOT NULL,
 | 
				
			||||||
 | 
					    is_dir INTEGER NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    UNIQUE(package_id, filepath)
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE dependencies(
 | 
				
			||||||
 | 
					    package_id TEXT NOT NULL,
 | 
				
			||||||
 | 
					    dependency_name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    constraint TEXT NOT NULL,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    PRIMARY KEY (package_id, dependency_name)
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE build_dependencies(
 | 
				
			||||||
 | 
					    package_id TEXT NOT NULL,
 | 
				
			||||||
 | 
					    dependency_name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    constraint TEXT NOT NULL,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    PRIMARY KEY (package_id, dependency_name)
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE conflicts(
 | 
				
			||||||
 | 
					    package_id TEXT NOT NULL,
 | 
				
			||||||
 | 
					    dependency_name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    constraint TEXT NOT NULL,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    PRIMARY KEY (package_id, dependency_name)
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE package_flags(
 | 
				
			||||||
 | 
					    package_id TEXT NOT NULL,
 | 
				
			||||||
 | 
					    flag TEXT NOT NULL,
 | 
				
			||||||
 | 
					    name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    path TEXT NOT NULL,
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
							
								
								
									
										41
									
								
								doc/source.db.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								doc/source.db.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					CREATE TABLE packges(
 | 
				
			||||||
 | 
					    name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    id TEXT PRIMARY KEY,
 | 
				
			||||||
 | 
					    version TEXT NOT NULL,
 | 
				
			||||||
 | 
					    serial INTEGER NOT NULL,
 | 
				
			||||||
 | 
					    maintainer TEXT NOT NULL,
 | 
				
			||||||
 | 
					    verified INTEGER NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					    description TEXT NOT NULL,
 | 
				
			||||||
 | 
					    upload_time TEXT NOT NULL,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    UNIQUE(name, signature),
 | 
				
			||||||
 | 
					    UNIQUE(name, version),
 | 
				
			||||||
 | 
					    UNIQUE(name, serial)
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE dependencies(
 | 
				
			||||||
 | 
					    package_id TEXT NOT NULL,
 | 
				
			||||||
 | 
					    dependency_name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    constraint TEXT NOT NULL,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    PRIMARY KEY (package_id, dependency_name)
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE build_dependencies(
 | 
				
			||||||
 | 
					    package_id TEXT NOT NULL,
 | 
				
			||||||
 | 
					    dependency_name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    constraint TEXT NOT NULL,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    PRIMARY KEY (package_id, dependency_name)
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE conflicts(
 | 
				
			||||||
 | 
					    package_id TEXT NOT NULL,
 | 
				
			||||||
 | 
					    dependency_name TEXT NOT NULL,
 | 
				
			||||||
 | 
					    constraint TEXT NOT NULL,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    PRIMARY KEY (package_id, dependency_name)
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
@@ -1 +0,0 @@
 | 
				
			|||||||
-- PACKETS SCRIPTS EXAMPLES
 | 
					 | 
				
			||||||
							
								
								
									
										67
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										67
									
								
								go.mod
									
									
									
									
									
								
							@@ -1,31 +1,56 @@
 | 
				
			|||||||
module packets
 | 
					module github.com/roboogg133/packets
 | 
				
			||||||
 | 
					
 | 
				
			||||||
go 1.24.4
 | 
					go 1.25.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require github.com/yuin/gopher-lua v1.1.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/BurntSushi/toml v1.5.0
 | 
						github.com/go-git/go-git/v6 v6.0.0-20251029213217-0bbfc0875edd
 | 
				
			||||||
	github.com/klauspost/compress v1.18.0
 | 
						github.com/klauspost/compress v1.18.1
 | 
				
			||||||
	github.com/schollz/progressbar/v3 v3.18.0
 | 
						github.com/mattn/go-sqlite3 v1.14.32
 | 
				
			||||||
	github.com/spf13/cobra v1.9.1
 | 
						github.com/pelletier/go-toml/v2 v2.2.4
 | 
				
			||||||
	github.com/yuin/gopher-lua v1.1.1
 | 
						github.com/pierrec/lz4/v4 v4.1.22
 | 
				
			||||||
	golang.org/x/net v0.41.0
 | 
						github.com/spf13/cobra v1.10.1
 | 
				
			||||||
	modernc.org/sqlite v1.38.0
 | 
						github.com/ulikunitz/xz v0.5.15
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/dustin/go-humanize v1.0.1 // indirect
 | 
						github.com/Microsoft/go-winio v0.6.2 // indirect
 | 
				
			||||||
	github.com/google/uuid v1.6.0 // indirect
 | 
						github.com/ProtonMail/go-crypto v1.3.0 // indirect
 | 
				
			||||||
 | 
						github.com/atotto/clipboard v0.1.4 // indirect
 | 
				
			||||||
 | 
						github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
 | 
				
			||||||
 | 
						github.com/charmbracelet/bubbles v0.21.0 // indirect
 | 
				
			||||||
 | 
						github.com/charmbracelet/bubbletea v1.3.10 // indirect
 | 
				
			||||||
 | 
						github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
 | 
				
			||||||
 | 
						github.com/charmbracelet/lipgloss v1.1.0 // indirect
 | 
				
			||||||
 | 
						github.com/charmbracelet/x/ansi v0.10.1 // indirect
 | 
				
			||||||
 | 
						github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
 | 
				
			||||||
 | 
						github.com/charmbracelet/x/term v0.2.1 // 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/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // 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/inconshreveable/mousetrap v1.1.0 // indirect
 | 
						github.com/inconshreveable/mousetrap v1.1.0 // indirect
 | 
				
			||||||
 | 
						github.com/kevinburke/ssh_config v1.4.0 // indirect
 | 
				
			||||||
 | 
						github.com/klauspost/cpuid/v2 v2.3.0 // indirect
 | 
				
			||||||
 | 
						github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
 | 
				
			||||||
	github.com/mattn/go-isatty v0.0.20 // indirect
 | 
						github.com/mattn/go-isatty v0.0.20 // indirect
 | 
				
			||||||
	github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
 | 
						github.com/mattn/go-localereader v0.0.1 // indirect
 | 
				
			||||||
	github.com/ncruces/go-strftime v0.1.9 // indirect
 | 
						github.com/mattn/go-runewidth v0.0.16 // indirect
 | 
				
			||||||
	github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
 | 
						github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
 | 
				
			||||||
 | 
						github.com/muesli/cancelreader v0.2.2 // indirect
 | 
				
			||||||
 | 
						github.com/muesli/termenv v0.16.0 // indirect
 | 
				
			||||||
 | 
						github.com/pjbgf/sha1cd v0.5.0 // indirect
 | 
				
			||||||
	github.com/rivo/uniseg v0.4.7 // indirect
 | 
						github.com/rivo/uniseg v0.4.7 // indirect
 | 
				
			||||||
	github.com/spf13/pflag v1.0.7 // indirect
 | 
						github.com/sahilm/fuzzy v0.1.1 // indirect
 | 
				
			||||||
	golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect
 | 
						github.com/sergi/go-diff v1.4.0 // indirect
 | 
				
			||||||
	golang.org/x/sys v0.33.0 // indirect
 | 
						github.com/spf13/pflag v1.0.9 // indirect
 | 
				
			||||||
	golang.org/x/term v0.32.0 // indirect
 | 
						github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
 | 
				
			||||||
	modernc.org/libc v1.65.10 // indirect
 | 
						golang.org/x/crypto v0.43.0 // indirect
 | 
				
			||||||
	modernc.org/mathutil v1.7.1 // indirect
 | 
						golang.org/x/net v0.46.0 // indirect
 | 
				
			||||||
	modernc.org/memory v1.11.0 // indirect
 | 
						golang.org/x/sys v0.37.0 // indirect
 | 
				
			||||||
 | 
						golang.org/x/text v0.30.0 // indirect
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										174
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										174
									
								
								go.sum
									
									
									
									
									
								
							@@ -1,85 +1,129 @@
 | 
				
			|||||||
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
 | 
					github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
 | 
				
			||||||
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
 | 
					github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
 | 
				
			||||||
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
 | 
					github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw=
 | 
				
			||||||
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY=
 | 
					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/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
 | 
				
			||||||
 | 
					github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
 | 
				
			||||||
 | 
					github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
 | 
				
			||||||
 | 
					github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
 | 
				
			||||||
 | 
					github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
 | 
				
			||||||
 | 
					github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg=
 | 
				
			||||||
 | 
					github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw=
 | 
				
			||||||
 | 
					github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
 | 
				
			||||||
 | 
					github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
 | 
				
			||||||
 | 
					github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
 | 
				
			||||||
 | 
					github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
 | 
				
			||||||
 | 
					github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
 | 
				
			||||||
 | 
					github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=
 | 
				
			||||||
 | 
					github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
 | 
				
			||||||
 | 
					github.com/charmbracelet/x/ansi v0.10.1 h1:rL3Koar5XvX0pHGfovN03f5cxLbCF2YvLeyz7D2jVDQ=
 | 
				
			||||||
 | 
					github.com/charmbracelet/x/ansi v0.10.1/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
 | 
				
			||||||
 | 
					github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
 | 
				
			||||||
 | 
					github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
 | 
				
			||||||
 | 
					github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
 | 
				
			||||||
 | 
					github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
 | 
				
			||||||
 | 
					github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
 | 
				
			||||||
 | 
					github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
 | 
				
			||||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
 | 
					github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
 | 
				
			||||||
 | 
					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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 | 
				
			||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
					github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
				
			||||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
 | 
					github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o=
 | 
				
			||||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
 | 
					github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE=
 | 
				
			||||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
 | 
					github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
 | 
				
			||||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
 | 
					github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
 | 
				
			||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
 | 
					github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
 | 
				
			||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 | 
					github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
 | 
				
			||||||
 | 
					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/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
 | 
					github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
 | 
				
			||||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
 | 
					github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
 | 
				
			||||||
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
 | 
					github.com/kevinburke/ssh_config v1.4.0 h1:6xxtP5bZ2E4NF5tuQulISpTO2z8XbtH8cg1PWkxoFkQ=
 | 
				
			||||||
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
 | 
					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/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/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
 | 
				
			||||||
 | 
					github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 | 
					github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 | 
				
			||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
 | 
					github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
 | 
				
			||||||
 | 
					github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
 | 
				
			||||||
 | 
					github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
 | 
				
			||||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
 | 
					github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
 | 
				
			||||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
 | 
					github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
 | 
				
			||||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
 | 
					github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs=
 | 
				
			||||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
 | 
					github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
 | 
				
			||||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
 | 
					github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
 | 
				
			||||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
 | 
					github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
 | 
				
			||||||
 | 
					github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
 | 
				
			||||||
 | 
					github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
 | 
				
			||||||
 | 
					github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
 | 
				
			||||||
 | 
					github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
 | 
				
			||||||
 | 
					github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
 | 
				
			||||||
 | 
					github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
 | 
				
			||||||
 | 
					github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
 | 
				
			||||||
 | 
					github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
 | 
				
			||||||
 | 
					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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 | 
				
			||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 | 
					github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 | 
				
			||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
 | 
					github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
 | 
				
			||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
 | 
					 | 
				
			||||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
 | 
					github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
 | 
				
			||||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
 | 
					github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
 | 
				
			||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 | 
					github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 | 
				
			||||||
github.com/schollz/progressbar/v3 v3.18.0 h1:uXdoHABRFmNIjUfte/Ex7WtuyVslrw2wVPQmCN62HpA=
 | 
					github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=
 | 
				
			||||||
github.com/schollz/progressbar/v3 v3.18.0/go.mod h1:IsO3lpbaGuzh8zIMzgY3+J8l4C8GjO0Y9S69eFvNsec=
 | 
					github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
 | 
				
			||||||
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
 | 
					github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
 | 
				
			||||||
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
 | 
					github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
 | 
				
			||||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
 | 
					github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
 | 
				
			||||||
github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=
 | 
					github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0=
 | 
				
			||||||
github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
 | 
					github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
 | 
				
			||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
 | 
					github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
 | 
				
			||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
 | 
					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/ulikunitz/xz v0.5.15 h1:9DNdB5s+SgV3bQ2ApL10xRc35ck0DuIX/isZvIk+ubY=
 | 
				
			||||||
 | 
					github.com/ulikunitz/xz v0.5.15/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
 | 
				
			||||||
 | 
					github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
 | 
				
			||||||
 | 
					github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
 | 
				
			||||||
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/exp v0.0.0-20250408133849-7e4ce0ab07d0 h1:R84qjqJb5nVJMxqWYb3np9L5ZsaDtB+a39EqjV0JSUM=
 | 
					golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
 | 
				
			||||||
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0/go.mod h1:S9Xr4PYopiDyqSyp5NjCrhFrqg6A5zA2E/iPHPhqnS8=
 | 
					golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
 | 
				
			||||||
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
 | 
					golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
 | 
				
			||||||
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
 | 
					golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
 | 
				
			||||||
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
 | 
					golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
 | 
					 | 
				
			||||||
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
 | 
					 | 
				
			||||||
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
 | 
					 | 
				
			||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
 | 
					golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
 | 
				
			||||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
 | 
					golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
 | 
				
			||||||
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
 | 
					golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
 | 
				
			||||||
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
 | 
					golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
 | 
				
			||||||
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
 | 
					golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
 | 
				
			||||||
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
 | 
					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 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 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
					gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
modernc.org/cc/v4 v4.26.1 h1:+X5NtzVBn0KgsBCBe+xkDC7twLb/jNVj9FPgiwSQO3s=
 | 
					 | 
				
			||||||
modernc.org/cc/v4 v4.26.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
 | 
					 | 
				
			||||||
modernc.org/ccgo/v4 v4.28.0 h1:rjznn6WWehKq7dG4JtLRKxb52Ecv8OUGah8+Z/SfpNU=
 | 
					 | 
				
			||||||
modernc.org/ccgo/v4 v4.28.0/go.mod h1:JygV3+9AV6SmPhDasu4JgquwU81XAKLd3OKTUDNOiKE=
 | 
					 | 
				
			||||||
modernc.org/fileutil v1.3.3 h1:3qaU+7f7xxTUmvU1pJTZiDLAIoJVdUSSauJNHg9yXoA=
 | 
					 | 
				
			||||||
modernc.org/fileutil v1.3.3/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
 | 
					 | 
				
			||||||
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
 | 
					 | 
				
			||||||
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
 | 
					 | 
				
			||||||
modernc.org/libc v1.65.10 h1:ZwEk8+jhW7qBjHIT+wd0d9VjitRyQef9BnzlzGwMODc=
 | 
					 | 
				
			||||||
modernc.org/libc v1.65.10/go.mod h1:StFvYpx7i/mXtBAfVOjaU0PWZOvIRoZSgXhrwXzr8Po=
 | 
					 | 
				
			||||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
 | 
					 | 
				
			||||||
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
 | 
					 | 
				
			||||||
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
 | 
					 | 
				
			||||||
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
 | 
					 | 
				
			||||||
modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
 | 
					 | 
				
			||||||
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
 | 
					 | 
				
			||||||
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
 | 
					 | 
				
			||||||
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
 | 
					 | 
				
			||||||
modernc.org/sqlite v1.38.0 h1:+4OrfPQ8pxHKuWG4md1JpR/EYAh3Md7TdejuuzE7EUI=
 | 
					 | 
				
			||||||
modernc.org/sqlite v1.38.0/go.mod h1:1Bj+yES4SVvBZ4cBOpVZ6QgesMCKpJZDq0nxYzOpmNE=
 | 
					 | 
				
			||||||
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
 | 
					 | 
				
			||||||
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
 | 
					 | 
				
			||||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
 | 
					 | 
				
			||||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,557 +0,0 @@
 | 
				
			|||||||
package internal
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"archive/tar"
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
					 | 
				
			||||||
	"io/fs"
 | 
					 | 
				
			||||||
	"log"
 | 
					 | 
				
			||||||
	"os"
 | 
					 | 
				
			||||||
	"os/exec"
 | 
					 | 
				
			||||||
	"path/filepath"
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/BurntSushi/toml"
 | 
					 | 
				
			||||||
	"github.com/klauspost/compress/zstd"
 | 
					 | 
				
			||||||
	lua "github.com/yuin/gopher-lua"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var AllowedCmds = map[string]string{
 | 
					 | 
				
			||||||
	"go":          "go",          // "Go code compiler"
 | 
					 | 
				
			||||||
	"gcc":         "gcc",         // "C"
 | 
					 | 
				
			||||||
	"g++":         "g++",         // "C++"
 | 
					 | 
				
			||||||
	"rustc":       "rustc",       // "Rust"
 | 
					 | 
				
			||||||
	"javac":       "javac",       // "Java"
 | 
					 | 
				
			||||||
	"luac":        "luac",        // "Lua"
 | 
					 | 
				
			||||||
	"pyinstaller": "pyinstaller", // "Python"
 | 
					 | 
				
			||||||
	"kotlinc":     "kotlinc",     // "Kotlin"
 | 
					 | 
				
			||||||
	"mcs":         "mcs",         // "C# compiler"
 | 
					 | 
				
			||||||
	"swiftc":      "swiftc",      // "Swift compiler"
 | 
					 | 
				
			||||||
	"ts":          "tsc",         // "TypeScript compiler"
 | 
					 | 
				
			||||||
	"ruby":        "rubyc",       // "Ruby compiler"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type ConfigTOML struct {
 | 
					 | 
				
			||||||
	Config struct {
 | 
					 | 
				
			||||||
		HttpPort           int    `toml:"httpPort"`
 | 
					 | 
				
			||||||
		CacheDir           string `toml:"cacheDir"`
 | 
					 | 
				
			||||||
		AutoDeleteCacheDir bool   `toml:"dayToDeleteCacheDir"`
 | 
					 | 
				
			||||||
		DaysToDelete       int    `toml:"daysToDelete"`
 | 
					 | 
				
			||||||
		DataDir            string `toml:"dataDir"`
 | 
					 | 
				
			||||||
		BinDir             string `toml:"binDir"`
 | 
					 | 
				
			||||||
		LastDataDir        string `toml:"lastDataDir"`
 | 
					 | 
				
			||||||
	} `toml:"Config"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Manifest struct {
 | 
					 | 
				
			||||||
	Info struct {
 | 
					 | 
				
			||||||
		Name         string   `toml:"name"`
 | 
					 | 
				
			||||||
		Version      string   `toml:"version"`
 | 
					 | 
				
			||||||
		Description  string   `toml:"description"`
 | 
					 | 
				
			||||||
		Dependencies []string `toml:"dependencies"`
 | 
					 | 
				
			||||||
		Author       string   `toml:"author"`
 | 
					 | 
				
			||||||
		Family       string   `toml:"family"`
 | 
					 | 
				
			||||||
		Serial       uint     `toml:"serial"`
 | 
					 | 
				
			||||||
	} `toml:"Info"`
 | 
					 | 
				
			||||||
	Hooks struct {
 | 
					 | 
				
			||||||
		Install string `toml:"install"`
 | 
					 | 
				
			||||||
		Remove  string `toml:"remove"`
 | 
					 | 
				
			||||||
	} `toml:"Hooks"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var SandboxDir string
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func PacketsPackageDir() string {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	out, _ := exec.Command("uname", "-s").Output()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if uname := strings.TrimSpace(string(out)); uname == "J2ME" {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		_, err := os.Stat("packets.help")
 | 
					 | 
				
			||||||
		if os.IsNotExist(err) {
 | 
					 | 
				
			||||||
			err = nil
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			var thedirectory string
 | 
					 | 
				
			||||||
			err := filepath.WalkDir("/mnt", func(path string, d fs.DirEntry, err error) error {
 | 
					 | 
				
			||||||
				if d.IsDir() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					thedirectory = filepath.Join(path, "packets")
 | 
					 | 
				
			||||||
					if err := os.Mkdir(thedirectory, 0644); err != nil {
 | 
					 | 
				
			||||||
						return err
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					if err := os.WriteFile("packets.help", []byte(thedirectory), 0644); err != nil {
 | 
					 | 
				
			||||||
						return err
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					if err := os.Mkdir(filepath.Join(filepath.Join(thedirectory, "cache")), 0644); err != nil {
 | 
					 | 
				
			||||||
						return err
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					if err := os.Mkdir(filepath.Join(filepath.Join(thedirectory, "packages")), 0644); err != nil {
 | 
					 | 
				
			||||||
						return err
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					if err := os.Mkdir(filepath.Join(filepath.Join(thedirectory, "bin")), 0644); err != nil {
 | 
					 | 
				
			||||||
						return err
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					return nil
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				return nil
 | 
					 | 
				
			||||||
			})
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				log.Fatal(err)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			return thedirectory
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		byt, err := os.ReadFile("packets.help")
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			log.Fatal(err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return string(byt)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		return "/etc/packets"
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func ManifestReadXZ(path string) (*Manifest, error) {
 | 
					 | 
				
			||||||
	f, err := os.Open(path)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	defer f.Close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	zr, err := zstd.NewReader(f)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	defer zr.Close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	tarReader := tar.NewReader(zr)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for {
 | 
					 | 
				
			||||||
		header, err := tarReader.Next()
 | 
					 | 
				
			||||||
		if err == io.EOF {
 | 
					 | 
				
			||||||
			break
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return nil, err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if filepath.Base(header.Name) == "manifest.toml" {
 | 
					 | 
				
			||||||
			decoder := toml.NewDecoder(tarReader)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			var manifest Manifest
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if _, err := decoder.Decode(&manifest); err != nil {
 | 
					 | 
				
			||||||
				log.Fatal(err)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			return &manifest, nil
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil, fmt.Errorf("can't find manifest.toml")
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func DefaultConfigTOML() *ConfigTOML {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	var cfg ConfigTOML
 | 
					 | 
				
			||||||
	out, _ := exec.Command("uname", "-s").Output()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if uname := strings.TrimSpace(string(out)); uname == "J2ME" {
 | 
					 | 
				
			||||||
		cfg.Config.HttpPort = 9123
 | 
					 | 
				
			||||||
		cfg.Config.AutoDeleteCacheDir = false
 | 
					 | 
				
			||||||
		cfg.Config.CacheDir = filepath.Join(PacketsPackageDir(), "cache")
 | 
					 | 
				
			||||||
		cfg.Config.DataDir = filepath.Join(PacketsPackageDir(), "data")
 | 
					 | 
				
			||||||
		cfg.Config.DaysToDelete = -1
 | 
					 | 
				
			||||||
		cfg.Config.BinDir = filepath.Join(PacketsPackageDir(), "bin")
 | 
					 | 
				
			||||||
		cfg.Config.LastDataDir = filepath.Join(PacketsPackageDir(), "data")
 | 
					 | 
				
			||||||
		return &cfg
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		cfg.Config.HttpPort = 9123
 | 
					 | 
				
			||||||
		cfg.Config.AutoDeleteCacheDir = false
 | 
					 | 
				
			||||||
		cfg.Config.CacheDir = "/var/cache/packets"
 | 
					 | 
				
			||||||
		cfg.Config.DataDir = "/opt/packets"
 | 
					 | 
				
			||||||
		cfg.Config.DaysToDelete = -1
 | 
					 | 
				
			||||||
		cfg.Config.BinDir = "/usr/bin"
 | 
					 | 
				
			||||||
		cfg.Config.LastDataDir = "/opt/packets"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return &cfg
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func IsSafe(str string) bool {
 | 
					 | 
				
			||||||
	s, err := filepath.EvalSymlinks(filepath.Clean(str))
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		s = filepath.Clean(str)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	var cfg ConfigTOML
 | 
					 | 
				
			||||||
	toml.DecodeFile(filepath.Join(PacketsPackageDir(), "config.toml"), &cfg)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if strings.HasPrefix(s, cfg.Config.DataDir) || strings.HasPrefix(s, cfg.Config.BinDir) {
 | 
					 | 
				
			||||||
		return true
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.Contains(s, ".ssh") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/etc") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/usr") || strings.HasPrefix(s, "/bin") {
 | 
					 | 
				
			||||||
		fmt.Println(s, "está dentro de usr")
 | 
					 | 
				
			||||||
		return strings.HasPrefix(s, "/usr/share")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/var/mail") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/proc") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/sys") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/var/run") || strings.HasPrefix(s, "/run") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/tmp") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/dev") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/boot") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/home") {
 | 
					 | 
				
			||||||
		if strings.Contains(s, "/Pictures") || strings.Contains(s, "/Videos") || strings.Contains(s, "/Documents") || strings.Contains(s, "/Downloads") {
 | 
					 | 
				
			||||||
			return false
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/lib") || strings.HasPrefix(s, "/lib64") || strings.HasPrefix(s, "/var/lib64") || strings.HasPrefix(s, "/lib") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/sbin") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/srv") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/mnt") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/media") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
	} else if strings.HasPrefix(s, "/snap") {
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return true
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func SafeRemove(L *lua.LState) int {
 | 
					 | 
				
			||||||
	filename := L.CheckString(1)
 | 
					 | 
				
			||||||
	if !IsSafe(filename) {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] unsafe filepath"))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	err := os.RemoveAll(filename)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] remove failed\n" + err.Error()))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	L.Push(lua.LTrue)
 | 
					 | 
				
			||||||
	L.Push(lua.LNil)
 | 
					 | 
				
			||||||
	return 2
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func SafeRename(L *lua.LState) int {
 | 
					 | 
				
			||||||
	oldname := L.CheckString(1)
 | 
					 | 
				
			||||||
	newname := L.CheckString(2)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if !IsSafe(oldname) || !IsSafe(newname) {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] unsafe filepath"))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err := os.Rename(oldname, newname); err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] rename failed\n" + err.Error()))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	L.Push(lua.LTrue)
 | 
					 | 
				
			||||||
	return 1
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
func SafeCopy(L *lua.LState) int {
 | 
					 | 
				
			||||||
	oldname := L.CheckString(1)
 | 
					 | 
				
			||||||
	newname := L.CheckString(2)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if !IsSafe(oldname) || !IsSafe(newname) {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] unsafe filepath"))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	src, err := os.Open(oldname)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] copy failed\n" + err.Error()))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	defer src.Close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	status, err := src.Stat()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] copy failed\n" + err.Error()))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	err = os.MkdirAll(filepath.Dir(newname), 0755)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] copy failed\n" + err.Error()))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	dst, err := os.Create(newname)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		if !os.IsExist(err) {
 | 
					 | 
				
			||||||
			dst, err = os.Open(newname)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
				L.Push(lua.LString("[packets] copy failed\n" + err.Error()))
 | 
					 | 
				
			||||||
				return 2
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
			L.Push(lua.LString("[packets] copy failed\n" + err.Error()))
 | 
					 | 
				
			||||||
			return 2
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	defer dst.Close()
 | 
					 | 
				
			||||||
	if err := dst.Chmod(status.Mode()); err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] copy failed\n" + err.Error()))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	_, err = io.Copy(dst, src)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] copy failed\n" + err.Error()))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	L.Push(lua.LTrue)
 | 
					 | 
				
			||||||
	L.Push(lua.LNil)
 | 
					 | 
				
			||||||
	return 2
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func SymbolicLua(L *lua.LState) int {
 | 
					 | 
				
			||||||
	fileName := L.CheckString(1)
 | 
					 | 
				
			||||||
	destination := L.CheckString(2)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if !IsSafe(fileName) || !IsSafe(destination) {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] unsafe filepath"))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	_ = os.RemoveAll(destination)
 | 
					 | 
				
			||||||
	if err := os.Symlink(fileName, destination); err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] symlink failed\n" + err.Error()))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	L.Push(lua.LTrue)
 | 
					 | 
				
			||||||
	L.Push(lua.LNil)
 | 
					 | 
				
			||||||
	return 2
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func modeFlags(mode string) int {
 | 
					 | 
				
			||||||
	switch mode {
 | 
					 | 
				
			||||||
	case "r", "rb":
 | 
					 | 
				
			||||||
		return os.O_RDONLY
 | 
					 | 
				
			||||||
	case "w", "wb":
 | 
					 | 
				
			||||||
		return os.O_CREATE | os.O_WRONLY | os.O_TRUNC
 | 
					 | 
				
			||||||
	case "a", "ab":
 | 
					 | 
				
			||||||
		return os.O_CREATE | os.O_WRONLY | os.O_APPEND
 | 
					 | 
				
			||||||
	case "r+", "r+b", "rb+", "br+":
 | 
					 | 
				
			||||||
		return os.O_RDWR
 | 
					 | 
				
			||||||
	case "w+", "w+b", "wb+", "bw+":
 | 
					 | 
				
			||||||
		return os.O_CREATE | os.O_RDWR | os.O_TRUNC
 | 
					 | 
				
			||||||
	case "a+", "a+b", "ab+", "ba+":
 | 
					 | 
				
			||||||
		return os.O_CREATE | os.O_RDWR | os.O_APPEND
 | 
					 | 
				
			||||||
	default:
 | 
					 | 
				
			||||||
		return os.O_RDONLY
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func SafeOpen(L *lua.LState) int {
 | 
					 | 
				
			||||||
	path := L.CheckString(1)
 | 
					 | 
				
			||||||
	mode := L.OptString(2, "r")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if !IsSafe(path) {
 | 
					 | 
				
			||||||
		L.Push(lua.LNil)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] unsafe filepath"))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	file, err := os.OpenFile(path, modeFlags(mode), 0644)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LNil)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] open failed\n" + err.Error()))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	ud := L.NewUserData()
 | 
					 | 
				
			||||||
	ud.Value = file
 | 
					 | 
				
			||||||
	L.SetMetatable(ud, L.GetTypeMetatable("file"))
 | 
					 | 
				
			||||||
	L.Push(ud)
 | 
					 | 
				
			||||||
	L.Push(lua.LNil)
 | 
					 | 
				
			||||||
	return 2
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func Ljoin(L *lua.LState) int {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	n := L.GetTop()
 | 
					 | 
				
			||||||
	parts := make([]string, 0, n)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for i := 1; i <= n; i++ {
 | 
					 | 
				
			||||||
		val := L.Get(i)
 | 
					 | 
				
			||||||
		parts = append(parts, val.String())
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	result := filepath.Join(parts...)
 | 
					 | 
				
			||||||
	L.Push(lua.LString(result))
 | 
					 | 
				
			||||||
	return 1
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func LMkdir(L *lua.LState) int {
 | 
					 | 
				
			||||||
	path := L.CheckString(1)
 | 
					 | 
				
			||||||
	perm := L.CheckInt(2)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if !IsSafe(path) {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] unsafe filepath\n"))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err := os.MkdirAll(path, os.FileMode(perm)); err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] mkdir failed\n" + err.Error()))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	L.Push(lua.LTrue)
 | 
					 | 
				
			||||||
	L.Push(lua.LNil)
 | 
					 | 
				
			||||||
	return 2
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func LuaCompile(L *lua.LState) int {
 | 
					 | 
				
			||||||
	lang := L.CheckString(1)
 | 
					 | 
				
			||||||
	args := []string{}
 | 
					 | 
				
			||||||
	for i := 2; i <= L.GetTop(); i++ {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if strings.Contains(L.CheckString(i), "/") {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			tryintoacess, err := filepath.Abs(filepath.Clean(filepath.Join(SandboxDir, L.CheckString(i))))
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
				L.Push(lua.LString("[packets] invalid filepath\n" + err.Error()))
 | 
					 | 
				
			||||||
				return 2
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			fmt.Printf("sandboxdir: (%s) acessto: (%s)\n", SandboxDir, tryintoacess)
 | 
					 | 
				
			||||||
			rel, err := filepath.Rel(SandboxDir, tryintoacess)
 | 
					 | 
				
			||||||
			if err != nil || strings.HasPrefix(rel, "..") {
 | 
					 | 
				
			||||||
				L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
				L.Push(lua.LString("[packets] unsafe filepath"))
 | 
					 | 
				
			||||||
				return 2
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		args = append(args, L.CheckString(i))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	bin, suc := AllowedCmds[lang]
 | 
					 | 
				
			||||||
	if !suc {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] unsupported language"))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	cmd := exec.Command(bin, args...)
 | 
					 | 
				
			||||||
	cmd.Dir = SandboxDir
 | 
					 | 
				
			||||||
	out, err := cmd.CombinedOutput()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] compile failed\n" + err.Error() + "\n" + string(out)))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if err := cmd.Run(); err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] compile failed\n" + err.Error()))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	L.Push(lua.LTrue)
 | 
					 | 
				
			||||||
	L.Push(lua.LString(string(out)))
 | 
					 | 
				
			||||||
	return 2
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func CompileRequirements(L *lua.LState) int {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	cmdLang := L.CheckString(1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if strings.Contains(L.CheckString(2), "/") {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		tryintoacess, err := filepath.Abs(filepath.Clean(L.CheckString(2)))
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
			L.Push(lua.LString("[packets] invalid filepath\n" + err.Error()))
 | 
					 | 
				
			||||||
			return 2
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if !strings.HasPrefix(tryintoacess, SandboxDir) {
 | 
					 | 
				
			||||||
			L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
			L.Push(lua.LString("[packets] unsafe filepath"))
 | 
					 | 
				
			||||||
			return 2
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	var err error
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	switch cmdLang {
 | 
					 | 
				
			||||||
	case "python":
 | 
					 | 
				
			||||||
		cmd := exec.Command("pip", "install", "--target", filepath.Join(SandboxDir, "tmp/build"), "-r", L.CheckString(2))
 | 
					 | 
				
			||||||
		cmd.Dir = filepath.Join(SandboxDir, "data")
 | 
					 | 
				
			||||||
		err = cmd.Run()
 | 
					 | 
				
			||||||
	case "java":
 | 
					 | 
				
			||||||
		cmd := exec.Command("mvn", "dependency:copy-dependencies", "-DoutputDirectory="+filepath.Join(SandboxDir, "tmp/build"))
 | 
					 | 
				
			||||||
		cmd.Dir = L.CheckString(2)
 | 
					 | 
				
			||||||
		err = cmd.Run()
 | 
					 | 
				
			||||||
	case "ruby":
 | 
					 | 
				
			||||||
		cmd := exec.Command("bundle", "install", "--path", filepath.Join(SandboxDir, "tmp/build"))
 | 
					 | 
				
			||||||
		cmd.Dir = L.CheckString(2)
 | 
					 | 
				
			||||||
		err = cmd.Run()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		L.Push(lua.LFalse)
 | 
					 | 
				
			||||||
		L.Push(lua.LString("[packets] requirements install failed\n" + err.Error()))
 | 
					 | 
				
			||||||
		return 2
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	L.Push(lua.LTrue)
 | 
					 | 
				
			||||||
	L.Push(lua.LNil)
 | 
					 | 
				
			||||||
	return 2
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										195
									
								
								internal/lua/luafunctions.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										195
									
								
								internal/lua/luafunctions.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,195 @@
 | 
				
			|||||||
 | 
					package lua
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						lua "github.com/yuin/gopher-lua"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func LRemove(L *lua.LState) int {
 | 
				
			||||||
 | 
						filename := L.CheckString(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err := os.RemoveAll(filename)
 | 
				
			||||||
 | 
						if 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 LRename(L *lua.LState) int {
 | 
				
			||||||
 | 
						oldname := L.CheckString(1)
 | 
				
			||||||
 | 
						newname := L.CheckString(2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := os.Rename(oldname, newname); err != nil {
 | 
				
			||||||
 | 
							L.Push(lua.LFalse)
 | 
				
			||||||
 | 
							L.Push(lua.LString(err.Error()))
 | 
				
			||||||
 | 
							return 2
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						L.Push(lua.LTrue)
 | 
				
			||||||
 | 
						return 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					func LCopy(L *lua.LState) int {
 | 
				
			||||||
 | 
						oldname := L.CheckString(1)
 | 
				
			||||||
 | 
						newname := L.CheckString(2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_ = os.MkdirAll(filepath.Dir(newname), 0755)
 | 
				
			||||||
 | 
						if err := copyDir(oldname, newname); 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 LSymlink(L *lua.LState) int {
 | 
				
			||||||
 | 
						fileName := L.CheckString(1)
 | 
				
			||||||
 | 
						destination := L.CheckString(2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_ = os.RemoveAll(destination)
 | 
				
			||||||
 | 
						if err := os.Symlink(fileName, destination); 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 Ljoin(L *lua.LState) int {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						n := L.GetTop()
 | 
				
			||||||
 | 
						parts := make([]string, 0, n)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i := 1; i <= n; i++ {
 | 
				
			||||||
 | 
							val := L.Get(i)
 | 
				
			||||||
 | 
							parts = append(parts, val.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						result := filepath.Join(parts...)
 | 
				
			||||||
 | 
						L.Push(lua.LString(result))
 | 
				
			||||||
 | 
						return 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func LMkdir(L *lua.LState) int {
 | 
				
			||||||
 | 
						path := L.CheckString(1)
 | 
				
			||||||
 | 
						perm := L.CheckInt(2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						modeStr := strconv.Itoa(perm)
 | 
				
			||||||
 | 
						modeUint, err := strconv.ParseUint(modeStr, 8, 32)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error parsing mode:", err)
 | 
				
			||||||
 | 
							L.Push(lua.LFalse)
 | 
				
			||||||
 | 
							L.Push(lua.LString(err.Error()))
 | 
				
			||||||
 | 
							return 2
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := os.MkdirAll(path, os.FileMode(modeUint)); err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error creating directory:", err)
 | 
				
			||||||
 | 
							L.Push(lua.LFalse)
 | 
				
			||||||
 | 
							L.Push(lua.LString(err.Error()))
 | 
				
			||||||
 | 
							return 2
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						L.Push(lua.LTrue)
 | 
				
			||||||
 | 
						L.Push(lua.LNil)
 | 
				
			||||||
 | 
						return 2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func LError(L *lua.LState) int {
 | 
				
			||||||
 | 
						n := L.GetTop()
 | 
				
			||||||
 | 
						parts := make([]any, 0, n)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i := 1; i <= n; i++ {
 | 
				
			||||||
 | 
							val := L.Get(i)
 | 
				
			||||||
 | 
							parts = append(parts, val.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llogger().Panic(parts...)
 | 
				
			||||||
 | 
						return 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func LSetEnv(L *lua.LState) int {
 | 
				
			||||||
 | 
						env := L.CheckString(1)
 | 
				
			||||||
 | 
						value := L.CheckString(2)
 | 
				
			||||||
 | 
						os.Setenv(env, value)
 | 
				
			||||||
 | 
						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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						modeStr := strconv.Itoa(mode)
 | 
				
			||||||
 | 
						modeUint, err := strconv.ParseUint(modeStr, 8, 32)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error parsing mode:", err)
 | 
				
			||||||
 | 
							L.Push(lua.LFalse)
 | 
				
			||||||
 | 
							L.Push(lua.LString(err.Error()))
 | 
				
			||||||
 | 
							return 2
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := os.Chmod(f, os.FileMode(modeUint)); err != nil {
 | 
				
			||||||
 | 
							L.Push(lua.LFalse)
 | 
				
			||||||
 | 
							L.Push(lua.LString(err.Error()))
 | 
				
			||||||
 | 
							return 2
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						L.Push(lua.LTrue)
 | 
				
			||||||
 | 
						L.Push(lua.LNil)
 | 
				
			||||||
 | 
						return 2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Flag struct {
 | 
				
			||||||
 | 
						Name     string
 | 
				
			||||||
 | 
						Path     string
 | 
				
			||||||
 | 
						FlagType string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Flags struct {
 | 
				
			||||||
 | 
						Flags []Flag
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (f *Flags) LSetFlag(L *lua.LState) int {
 | 
				
			||||||
 | 
						flagtype := L.CheckString(1)
 | 
				
			||||||
 | 
						name := L.CheckString(2)
 | 
				
			||||||
 | 
						flagPath := L.CheckString(3)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f.Flags = append(f.Flags, Flag{
 | 
				
			||||||
 | 
							Name:     name,
 | 
				
			||||||
 | 
							Path:     flagPath,
 | 
				
			||||||
 | 
							FlagType: flagtype,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func llogger() *log.Logger { return log.New(os.Stderr, "script error: ", 0) }
 | 
				
			||||||
							
								
								
									
										95
									
								
								internal/lua/utils.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								internal/lua/utils.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,95 @@
 | 
				
			|||||||
 | 
					package lua
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func copyDir(src string, dest string) error {
 | 
				
			||||||
 | 
						if stats, err := os.Stat(src); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							if stats.IsDir() {
 | 
				
			||||||
 | 
								files, err := os.ReadDir(src)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if err := os.MkdirAll(dest, 0755); err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								for _, file := range files {
 | 
				
			||||||
 | 
									if file.IsDir() {
 | 
				
			||||||
 | 
										copyDir(filepath.Join(src, file.Name()), filepath.Join(dest, file.Name()))
 | 
				
			||||||
 | 
										continue
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									srcFile := filepath.Join(src, file.Name())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									f, err := os.Create(filepath.Join(dest, file.Name()))
 | 
				
			||||||
 | 
									if err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									defer f.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									opennedSrcFile, err := os.Open(srcFile)
 | 
				
			||||||
 | 
									if err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									defer opennedSrcFile.Close()
 | 
				
			||||||
 | 
									if _, err := io.Copy(f, opennedSrcFile); err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								if err := copyFile(src, dest); 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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										10
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"runtime"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func main() {
 | 
				
			||||||
 | 
						fmt.Println(runtime.GOARCH)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										102
									
								
								pkg/install/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								pkg/install/main.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,102 @@
 | 
				
			|||||||
 | 
					package install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"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() {
 | 
				
			||||||
 | 
								tmp, err := walkAll(filepath.Join(dirToWalk, v.Name()))
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return []BasicFileStatus{}, err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								filesSlice = append(filesSlice, tmp...)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return filesSlice, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func InstallFiles(files []BasicFileStatus, packetDir string) error {
 | 
				
			||||||
 | 
						for _, v := range files {
 | 
				
			||||||
 | 
							sysPath, _ := strings.CutPrefix(v.Filepath, packetDir)
 | 
				
			||||||
 | 
							if v.IsDir {
 | 
				
			||||||
 | 
								if err := os.MkdirAll(sysPath, v.PermMode.Perm()); err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								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), 0755)
 | 
				
			||||||
 | 
						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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										354
									
								
								pkg/packet.lua.d/auxiliar_functions.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										354
									
								
								pkg/packet.lua.d/auxiliar_functions.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,354 @@
 | 
				
			|||||||
 | 
					package packet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						lua "github.com/yuin/gopher-lua"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getStringFromTable(table *lua.LTable, key string) string {
 | 
				
			||||||
 | 
						value := table.RawGetString(key)
 | 
				
			||||||
 | 
						if value.Type() == lua.LTString {
 | 
				
			||||||
 | 
							return value.String()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						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(table *lua.LTable, key string) []string {
 | 
				
			||||||
 | 
						value := table.RawGetString(key)
 | 
				
			||||||
 | 
						if value.Type() != lua.LTTable {
 | 
				
			||||||
 | 
							return []string{}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						arrayTable := value.(*lua.LTable)
 | 
				
			||||||
 | 
						var result []string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						arrayTable.ForEach(func(_, value lua.LValue) {
 | 
				
			||||||
 | 
							if value.Type() == lua.LTString {
 | 
				
			||||||
 | 
								result = append(result, value.String())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return result
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getFunctionFromTable(table *lua.LTable, key string) *lua.LFunction {
 | 
				
			||||||
 | 
						value := table.RawGetString(key)
 | 
				
			||||||
 | 
						if value.Type() == lua.LTFunction {
 | 
				
			||||||
 | 
							return value.(*lua.LFunction)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type version struct {
 | 
				
			||||||
 | 
						Name       string
 | 
				
			||||||
 | 
						Constraint VersionConstraint
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getDependenciesFromTable(table *lua.LTable, key string) *PkgDependencies {
 | 
				
			||||||
 | 
						value := table.RawGetString(key)
 | 
				
			||||||
 | 
						if value.Type() != lua.LTTable {
 | 
				
			||||||
 | 
							return &PkgDependencies{}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var pkgDeps PkgDependencies
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						depnTable := value.(*lua.LTable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pkgDeps.RuntimeDependencies = depsParse(depnTable, "runtime")
 | 
				
			||||||
 | 
						pkgDeps.BuildDependencies = depsParse(depnTable, "build")
 | 
				
			||||||
 | 
						pkgDeps.Conflicts = depsParse(depnTable, "conflicts")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return &pkgDeps
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getSourcesFromTable(table *lua.LTable, key string) *[]Source {
 | 
				
			||||||
 | 
						value := table.RawGetString(key)
 | 
				
			||||||
 | 
						if value.Type() != lua.LTTable {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var srcList []Source
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						srcTable := value.(*lua.LTable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						srcTable.ForEach(func(_, value lua.LValue) {
 | 
				
			||||||
 | 
							if value.Type() == lua.LTTable {
 | 
				
			||||||
 | 
								src := value.(*lua.LTable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var srcInfo Source
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								method := src.RawGetString("method")
 | 
				
			||||||
 | 
								if method.Type() == lua.LTString {
 | 
				
			||||||
 | 
									srcInfo.Method = method.String()
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								url := src.RawGetString("url")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if url.Type() == lua.LTString {
 | 
				
			||||||
 | 
									srcInfo.Url = url.String()
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							switchlabel:
 | 
				
			||||||
 | 
								switch srcInfo.Method {
 | 
				
			||||||
 | 
								case "GET":
 | 
				
			||||||
 | 
									var getSpecs GETSpecs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									getSpecs.SHA256 = new([]string)
 | 
				
			||||||
 | 
									sha256sumL := src.RawGetString("sha256")
 | 
				
			||||||
 | 
									if sha256sumL.Type() == lua.LTTable {
 | 
				
			||||||
 | 
										shatable := sha256sumL.(*lua.LTable)
 | 
				
			||||||
 | 
										shatable.ForEach(func(_, value lua.LValue) {
 | 
				
			||||||
 | 
											if value.Type() == lua.LTString {
 | 
				
			||||||
 | 
												*getSpecs.SHA256 = append(*getSpecs.SHA256, value.String())
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										})
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									headersLT := src.RawGetString("headers")
 | 
				
			||||||
 | 
									if headersLT.Type() == lua.LTTable {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										headers := headersLT.(*lua.LTable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										tmpMap := make(map[string]string)
 | 
				
			||||||
 | 
										headers.ForEach(func(headerKey, value lua.LValue) {
 | 
				
			||||||
 | 
											if value.Type() == lua.LTString {
 | 
				
			||||||
 | 
												tmpMap[headerKey.String()] = value.String()
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										getSpecs.Headers = &tmpMap
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									srcInfo.Specs = getSpecs
 | 
				
			||||||
 | 
									break switchlabel
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								case "git":
 | 
				
			||||||
 | 
									var gitSpecs GitSpecs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									branchL := src.RawGetString("branch")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if branchL.Type() == lua.LTString {
 | 
				
			||||||
 | 
										gitSpecs.Branch = branchL.String()
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									tagL := src.RawGetString("tag")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if tagL.Type() == lua.LTString {
 | 
				
			||||||
 | 
										*gitSpecs.Tag = tagL.String()
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									srcInfo.Specs = gitSpecs
 | 
				
			||||||
 | 
									break switchlabel
 | 
				
			||||||
 | 
								case "POST":
 | 
				
			||||||
 | 
									var postSpecs POSTSpecs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									sha256sumL := src.RawGetString("sha256")
 | 
				
			||||||
 | 
									if sha256sumL.Type() == lua.LTTable {
 | 
				
			||||||
 | 
										shatable := sha256sumL.(*lua.LTable)
 | 
				
			||||||
 | 
										shatable.ForEach(func(_, value lua.LValue) {
 | 
				
			||||||
 | 
											if value.Type() == lua.LTString {
 | 
				
			||||||
 | 
												*postSpecs.SHA256 = append(*postSpecs.SHA256, value.String())
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										})
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									headersLT := src.RawGetString("headers")
 | 
				
			||||||
 | 
									if headersLT.Type() == lua.LTTable {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										headers := headersLT.(*lua.LTable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										tmpMap := make(map[string]string)
 | 
				
			||||||
 | 
										headers.ForEach(func(headerKey, value lua.LValue) {
 | 
				
			||||||
 | 
											if value.Type() == lua.LTString {
 | 
				
			||||||
 | 
												tmpMap[headerKey.String()] = value.String()
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										postSpecs.Headers = &tmpMap
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									bodyLt := src.RawGetString("body")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if bodyLt.Type() == lua.LTString {
 | 
				
			||||||
 | 
										*postSpecs.Body = bodyLt.String()
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									srcInfo.Specs = postSpecs
 | 
				
			||||||
 | 
									break switchlabel
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								srcList = append(srcList, srcInfo)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return &srcList
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getPlataformsFromTable(table *lua.LTable, key string) *map[OperationalSystem]Plataform {
 | 
				
			||||||
 | 
						value := table.RawGetString(key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if value.Type() != lua.LTTable {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tmpMap := make(map[OperationalSystem]Plataform)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						plataform := value.(*lua.LTable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						plataform.ForEach(func(osString, value lua.LValue) {
 | 
				
			||||||
 | 
							if value.Type() != lua.LTTable {
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var plat Plataform
 | 
				
			||||||
 | 
							plat.Architetures = getStringArrayFromTable(value.(*lua.LTable), "arch")
 | 
				
			||||||
 | 
							plat.Name = osString.String()
 | 
				
			||||||
 | 
							plat.Sources = getSourcesFromTable(value.(*lua.LTable), "sources")
 | 
				
			||||||
 | 
							plat.Dependencies = getDependenciesFromTable(value.(*lua.LTable), "dependencies")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							tmpMap[OperationalSystem(osString.String())] = plat
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(tmpMap) == 0 {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return &tmpMap
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func depsParse(depnTable *lua.LTable, key string) *map[string]*VersionConstraint {
 | 
				
			||||||
 | 
						if runLTable := depnTable.RawGetString(key); runLTable.Type() == lua.LTTable {
 | 
				
			||||||
 | 
							runtimeTable := runLTable.(*lua.LTable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							mapTemp := make(map[string]*VersionConstraint)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var found bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							runtimeTable.ForEach(func(_, value lua.LValue) {
 | 
				
			||||||
 | 
								if value.Type() == lua.LTString {
 | 
				
			||||||
 | 
									version := parseVersionString(value.String())
 | 
				
			||||||
 | 
									mapTemp[version.Name] = &version.Constraint
 | 
				
			||||||
 | 
									found = true
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
							if !found {
 | 
				
			||||||
 | 
								return nil
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								return &mapTemp
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func parseVersionString(s string) version {
 | 
				
			||||||
 | 
						// >=go@1.25.3 | <=go@1.25.3 | go | >go@1.25.3 | <go@1.25.3 | go@1.25.3
 | 
				
			||||||
 | 
						if strings.ContainsAny(s, "@") {
 | 
				
			||||||
 | 
							slice := strings.Split(s, "@")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							switch {
 | 
				
			||||||
 | 
							case !strings.ContainsAny(s, "<=>"):
 | 
				
			||||||
 | 
								return version{
 | 
				
			||||||
 | 
									Name:       slice[0],
 | 
				
			||||||
 | 
									Constraint: VersionConstraint(slice[1]),
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case s[0] == '>' && s[1] == '=':
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return version{
 | 
				
			||||||
 | 
									Name:       slice[0][2:],
 | 
				
			||||||
 | 
									Constraint: VersionConstraint(">=" + slice[1]),
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case s[0] == '<' && s[1] == '=':
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return version{
 | 
				
			||||||
 | 
									Name:       slice[0][2:],
 | 
				
			||||||
 | 
									Constraint: VersionConstraint("<=" + slice[1]),
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							case s[0] == '>' && s[1] != '=':
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return version{
 | 
				
			||||||
 | 
									Name:       slice[0][1:],
 | 
				
			||||||
 | 
									Constraint: VersionConstraint(">" + slice[1]),
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case s[0] == '<' && s[1] != '=':
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return version{
 | 
				
			||||||
 | 
									Name:       slice[0][1:],
 | 
				
			||||||
 | 
									Constraint: VersionConstraint("<" + slice[1]),
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						} else if !strings.ContainsAny(s, "@=<>") {
 | 
				
			||||||
 | 
							return version{
 | 
				
			||||||
 | 
								Name:       s,
 | 
				
			||||||
 | 
								Constraint: VersionConstraint(0x000),
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return version{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func normalizeArch(arch string) string {
 | 
				
			||||||
 | 
						switch arch {
 | 
				
			||||||
 | 
						case "386":
 | 
				
			||||||
 | 
							return "i686"
 | 
				
			||||||
 | 
						case "amd64":
 | 
				
			||||||
 | 
							return "x86_64"
 | 
				
			||||||
 | 
						case "amd64p32":
 | 
				
			||||||
 | 
							return "x86_64"
 | 
				
			||||||
 | 
						case "arm":
 | 
				
			||||||
 | 
							return "arm"
 | 
				
			||||||
 | 
						case "arm64":
 | 
				
			||||||
 | 
							return "aarch64"
 | 
				
			||||||
 | 
						case "arm64be":
 | 
				
			||||||
 | 
							return "aarch64_be"
 | 
				
			||||||
 | 
						case "armbe":
 | 
				
			||||||
 | 
							return "armbe"
 | 
				
			||||||
 | 
						case "loong64":
 | 
				
			||||||
 | 
							return "loongarch64"
 | 
				
			||||||
 | 
						case "mips":
 | 
				
			||||||
 | 
							return "mips"
 | 
				
			||||||
 | 
						case "mips64":
 | 
				
			||||||
 | 
							return "mips64"
 | 
				
			||||||
 | 
						case "mips64le":
 | 
				
			||||||
 | 
							return "mips64el"
 | 
				
			||||||
 | 
						case "mips64p32":
 | 
				
			||||||
 | 
							return "mips64"
 | 
				
			||||||
 | 
						case "mips64p32le":
 | 
				
			||||||
 | 
							return "mips64el"
 | 
				
			||||||
 | 
						case "mipsle":
 | 
				
			||||||
 | 
							return "mipsel"
 | 
				
			||||||
 | 
						case "ppc":
 | 
				
			||||||
 | 
							return "powerpc"
 | 
				
			||||||
 | 
						case "ppc64":
 | 
				
			||||||
 | 
							return "ppc64"
 | 
				
			||||||
 | 
						case "ppc64le":
 | 
				
			||||||
 | 
							return "ppc64le"
 | 
				
			||||||
 | 
						case "riscv":
 | 
				
			||||||
 | 
							return "riscv"
 | 
				
			||||||
 | 
						case "riscv64":
 | 
				
			||||||
 | 
							return "riscv64"
 | 
				
			||||||
 | 
						case "s390":
 | 
				
			||||||
 | 
							return "s390"
 | 
				
			||||||
 | 
						case "s390x":
 | 
				
			||||||
 | 
							return "s390x"
 | 
				
			||||||
 | 
						case "sparc":
 | 
				
			||||||
 | 
							return "sparc"
 | 
				
			||||||
 | 
						case "sparc64":
 | 
				
			||||||
 | 
							return "sparc64"
 | 
				
			||||||
 | 
						case "wasm":
 | 
				
			||||||
 | 
							return "wasm"
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return arch
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										33
									
								
								pkg/packet.lua.d/config.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								pkg/packet.lua.d/config.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					package packet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "path/filepath"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Config struct {
 | 
				
			||||||
 | 
						BinDir     string
 | 
				
			||||||
 | 
						PacketDir  string
 | 
				
			||||||
 | 
						SourcesDir string
 | 
				
			||||||
 | 
						RootDir    string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const defaultBinDir = "/usr/bin"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func checkConfig(cfg *Config) *Config {
 | 
				
			||||||
 | 
						if cfg == nil {
 | 
				
			||||||
 | 
							bin := defaultBinDir
 | 
				
			||||||
 | 
							return &Config{
 | 
				
			||||||
 | 
								BinDir: bin,
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch {
 | 
				
			||||||
 | 
						case cfg.BinDir == "":
 | 
				
			||||||
 | 
							return &Config{
 | 
				
			||||||
 | 
								BinDir: defaultBinDir,
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						case cfg.PacketDir == "":
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							cfg.PacketDir = filepath.Join("/tmp", randStringBytes(12))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return cfg
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										386
									
								
								pkg/packet.lua.d/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										386
									
								
								pkg/packet.lua.d/main.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,386 @@
 | 
				
			|||||||
 | 
					package packet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"archive/tar"
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
 | 
						"crypto/sha256"
 | 
				
			||||||
 | 
						"encoding/hex"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"runtime"
 | 
				
			||||||
 | 
						"slices"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/go-git/go-git/v6"
 | 
				
			||||||
 | 
						"github.com/go-git/go-git/v6/plumbing"
 | 
				
			||||||
 | 
						"github.com/klauspost/compress/zstd"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						lua_utils "github.com/roboogg133/packets/internal/lua"
 | 
				
			||||||
 | 
						lua "github.com/yuin/gopher-lua"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type OperationalSystem string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PacketLua struct {
 | 
				
			||||||
 | 
						Name        string
 | 
				
			||||||
 | 
						Version     string
 | 
				
			||||||
 | 
						Maintainer  string
 | 
				
			||||||
 | 
						Description string
 | 
				
			||||||
 | 
						Serial      int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Plataforms         *map[OperationalSystem]Plataform
 | 
				
			||||||
 | 
						GlobalSources      *[]Source
 | 
				
			||||||
 | 
						GlobalDependencies *PkgDependencies
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Flags []lua_utils.Flag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Build    *lua.LFunction
 | 
				
			||||||
 | 
						Install  *lua.LFunction
 | 
				
			||||||
 | 
						LuaState *lua.LState
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Source struct {
 | 
				
			||||||
 | 
						Method string
 | 
				
			||||||
 | 
						Url    string
 | 
				
			||||||
 | 
						Specs  any
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type VersionConstraint string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PkgDependencies struct {
 | 
				
			||||||
 | 
						RuntimeDependencies *map[string]*VersionConstraint
 | 
				
			||||||
 | 
						BuildDependencies   *map[string]*VersionConstraint
 | 
				
			||||||
 | 
						Conflicts           *map[string]*VersionConstraint
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Plataform struct {
 | 
				
			||||||
 | 
						Name         string
 | 
				
			||||||
 | 
						Architetures []string
 | 
				
			||||||
 | 
						Sources      *[]Source
 | 
				
			||||||
 | 
						Dependencies *PkgDependencies
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GitSpecs struct {
 | 
				
			||||||
 | 
						Branch string
 | 
				
			||||||
 | 
						Tag    *string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type POSTSpecs struct {
 | 
				
			||||||
 | 
						SHA256  *[]string
 | 
				
			||||||
 | 
						Body    *string
 | 
				
			||||||
 | 
						Headers *map[string]string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GETSpecs struct {
 | 
				
			||||||
 | 
						SHA256  *[]string
 | 
				
			||||||
 | 
						Headers *map[string]string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var ErrCantFindPacketDotLua = errors.New("can't find Packet.lua in .tar.zst file")
 | 
				
			||||||
 | 
					var ErrFileDontReturnTable = errors.New("invalid Packet.lua format: the file do not return a table")
 | 
				
			||||||
 | 
					var ErrCannotFindPackageTable = errors.New("invalid Packet.lua format: can't find package table")
 | 
				
			||||||
 | 
					var ErrInstallFunctionDoesNotExist = errors.New("can not find install()")
 | 
				
			||||||
 | 
					var ErrSha256Sum = errors.New("false checksum")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ReadPacket read a Packet.lua and alredy set global vars
 | 
				
			||||||
 | 
					func ReadPacket(f []byte, cfg *Config) (PacketLua, error) {
 | 
				
			||||||
 | 
						cfg = checkConfig(cfg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						L := lua.NewState()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						L.SetGlobal("error", L.NewFunction(lua_utils.LError))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						osObject := L.GetGlobal("os").(*lua.LTable)
 | 
				
			||||||
 | 
						ioObject := L.GetGlobal("io").(*lua.LTable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						L.SetGlobal("os", lua.LNil)
 | 
				
			||||||
 | 
						L.SetGlobal("io", lua.LNil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var newFlags lua_utils.Flags
 | 
				
			||||||
 | 
						L.SetGlobal("setflags", L.NewFunction(newFlags.LSetFlag))
 | 
				
			||||||
 | 
						L.SetGlobal("pathjoin", L.NewFunction(lua_utils.Ljoin))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := L.DoString(string(f)); err != nil {
 | 
				
			||||||
 | 
							return PacketLua{}, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						L.SetGlobal("os", osObject)
 | 
				
			||||||
 | 
						L.SetGlobal("io", ioObject)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tableLua := L.Get(-1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if tableLua.Type() != lua.LTTable {
 | 
				
			||||||
 | 
							return PacketLua{}, ErrFileDontReturnTable
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						table := tableLua.(*lua.LTable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pkgTableLua := table.RawGetString("package")
 | 
				
			||||||
 | 
						if pkgTableLua.Type() != lua.LTTable {
 | 
				
			||||||
 | 
							return PacketLua{}, ErrCannotFindPackageTable
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						pkgTable := pkgTableLua.(*lua.LTable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						packetLua := &PacketLua{
 | 
				
			||||||
 | 
							Name:        getStringFromTable(pkgTable, "name"),
 | 
				
			||||||
 | 
							Version:     getStringFromTable(pkgTable, "version"),
 | 
				
			||||||
 | 
							Maintainer:  getStringFromTable(pkgTable, "maintainer"),
 | 
				
			||||||
 | 
							Description: getStringFromTable(pkgTable, "description"),
 | 
				
			||||||
 | 
							Serial:      getIntFromTable(pkgTable, "serial"),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Plataforms: getPlataformsFromTable(pkgTable, "plataforms"),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							GlobalDependencies: getDependenciesFromTable(pkgTable, "build_dependencies"),
 | 
				
			||||||
 | 
							GlobalSources:      getSourcesFromTable(pkgTable, "sources"),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Build:   getFunctionFromTable(table, "build"),
 | 
				
			||||||
 | 
							Install: getFunctionFromTable(table, "install"),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						packetLua.Flags = append(packetLua.Flags, newFlags.Flags...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						packetLua.LuaState = L
 | 
				
			||||||
 | 
						if packetLua.Install == nil {
 | 
				
			||||||
 | 
							return PacketLua{}, ErrInstallFunctionDoesNotExist
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return *packetLua, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ReadPacketFromZSTDF(file io.Reader, cfg *Config) (PacketLua, error) {
 | 
				
			||||||
 | 
						cfg = checkConfig(cfg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						zstdReader, err := zstd.NewReader(file)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return PacketLua{}, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer zstdReader.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tarReader := tar.NewReader(zstdReader)
 | 
				
			||||||
 | 
						for {
 | 
				
			||||||
 | 
							header, err := tarReader.Next()
 | 
				
			||||||
 | 
							if err == io.EOF {
 | 
				
			||||||
 | 
								break
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return PacketLua{}, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if filepath.Base(header.Name) == "Packet.lua" {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								packageLuaBlob, err := io.ReadAll(tarReader)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return PacketLua{}, err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return ReadPacket(packageLuaBlob, cfg)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return PacketLua{}, ErrCantFindPacketDotLua
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetSource returns file []byte if method is "GET" or "POST", if is "git" returns *git.CloneOptions{}
 | 
				
			||||||
 | 
					func GetSource(url, method string, info any, tryAttempts int) (any, error) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch method {
 | 
				
			||||||
 | 
						case "GET":
 | 
				
			||||||
 | 
							req, err := http.NewRequest("GET", url, nil)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							specs := info.(GETSpecs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if specs.Headers != nil {
 | 
				
			||||||
 | 
								for k, v := range *specs.Headers {
 | 
				
			||||||
 | 
									req.Header.Set(k, v)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							client := http.Client{Timeout: 5 * time.Minute}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var resp *http.Response
 | 
				
			||||||
 | 
							for range tryAttempts {
 | 
				
			||||||
 | 
								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()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							data, err := io.ReadAll(resp.Body)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if !verifySHA256(*specs.SHA256, data) {
 | 
				
			||||||
 | 
								return nil, ErrSha256Sum
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return data, nil
 | 
				
			||||||
 | 
						case "POST":
 | 
				
			||||||
 | 
							specs := info.(POSTSpecs)
 | 
				
			||||||
 | 
							var body *bytes.Reader
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if specs.Body != nil {
 | 
				
			||||||
 | 
								body = bytes.NewReader([]byte(*specs.Body))
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								body = nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							req, err := http.NewRequest("POST", url, body)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if specs.Headers != nil {
 | 
				
			||||||
 | 
								for k, v := range *specs.Headers {
 | 
				
			||||||
 | 
									req.Header.Set(k, v)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							client := http.Client{Timeout: 5 * time.Minute}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var resp *http.Response
 | 
				
			||||||
 | 
							for range tryAttempts {
 | 
				
			||||||
 | 
								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()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							data, err := io.ReadAll(resp.Body)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if !verifySHA256(*specs.SHA256, data) {
 | 
				
			||||||
 | 
								return nil, ErrSha256Sum
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							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")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func verifySHA256(checksum []string, src []byte) bool {
 | 
				
			||||||
 | 
						check := sha256.Sum256(src)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return slices.Contains(checksum, hex.EncodeToString(check[:]))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (pkg *PacketLua) ExecuteBuild(cfg *Config) {
 | 
				
			||||||
 | 
						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))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var newFlags lua_utils.Flags
 | 
				
			||||||
 | 
						L.SetGlobal("setflags", L.NewFunction(newFlags.LSetFlag))
 | 
				
			||||||
 | 
						L.SetGlobal("pathjoin", L.NewFunction(lua_utils.Ljoin))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						os.Chdir(cfg.RootDir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						os.Setenv("PATH", os.Getenv("PATH")+":"+cfg.BinDir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						L.Push(pkg.Build)
 | 
				
			||||||
 | 
						L.Call(0, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pkg.Flags = append(pkg.Flags, newFlags.Flags...)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (pkg *PacketLua) ExecuteInstall(cfg *Config) {
 | 
				
			||||||
 | 
						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))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var newFlags lua_utils.Flags
 | 
				
			||||||
 | 
						L.SetGlobal("setflags", L.NewFunction(newFlags.LSetFlag))
 | 
				
			||||||
 | 
						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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pkg.Flags = append(pkg.Flags, newFlags.Flags...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										25
									
								
								pkg/packet.lua.d/properties.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								pkg/packet.lua.d/properties.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					package packet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (pkg PacketLua) IsValid() bool {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var a, b int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, v := range *pkg.Plataforms {
 | 
				
			||||||
 | 
							a += len(*v.Sources)
 | 
				
			||||||
 | 
							b += len(v.Architetures)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						a += len(*pkg.GlobalSources)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if a < 1 || len(*pkg.Plataforms) > b {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch {
 | 
				
			||||||
 | 
						case pkg.Serial == -133:
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						case pkg.Description == "" || pkg.Maintainer == "" || pkg.Name == "" || pkg.Version == "":
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										34
									
								
								pkg/packet.lua.d/utils.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								pkg/packet.lua.d/utils.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
				
			|||||||
 | 
					package packet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"math/rand"
 | 
				
			||||||
 | 
						"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)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										65
									
								
								test/bat/Packet.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								test/bat/Packet.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,65 @@
 | 
				
			|||||||
 | 
					return {
 | 
				
			||||||
 | 
					    package = {
 | 
				
			||||||
 | 
					        name = "bat-bin",                                                             -- required
 | 
				
			||||||
 | 
					        version = "0.26.0",                                                           -- required
 | 
				
			||||||
 | 
					        maintainer = "robogg133",                                                     -- required
 | 
				
			||||||
 | 
					        description = "A cat(1) clone with syntax highlighting and Git integration.", -- required
 | 
				
			||||||
 | 
					        serial = 0,                                                                   -- required
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        plataforms = {
 | 
				
			||||||
 | 
					            windows = {
 | 
				
			||||||
 | 
					                arch = { "amd64" },
 | 
				
			||||||
 | 
					                sources = {
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        url = "https://github.com/sharkdp/bat/releases/download/v0.26.0/bat-v0.26.0-" ..
 | 
				
			||||||
 | 
					                            CURRENT_ARCH_NORMALIZED .. "-pc-windows-msvc.zip",
 | 
				
			||||||
 | 
					                        method = "GET",
 | 
				
			||||||
 | 
					                        sha256 = { "a8a6862f14698b45e101b0932c69bc47a007f4c0456f3a129fdcef54d443d501" }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                dependencies = {
 | 
				
			||||||
 | 
					                    build = {},
 | 
				
			||||||
 | 
					                    runtime = {},
 | 
				
			||||||
 | 
					                    conflicts = {}
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            linux = {
 | 
				
			||||||
 | 
					                arch = { "amd64" },
 | 
				
			||||||
 | 
					                sources = {
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        url = "https://github.com/sharkdp/bat/releases/download/v0.26.0/bat-v0.26.0-" ..
 | 
				
			||||||
 | 
					                            CURRENT_ARCH_NORMALIZED .. "-unknown-linux-gnu.tar.gz",
 | 
				
			||||||
 | 
					                        method = "GET",
 | 
				
			||||||
 | 
					                        sha256 = { "7efed0c768fae36f18ddbbb4a38f5c4b64db7c55a170dfc89fd380805809a44b" }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                dependencies = {
 | 
				
			||||||
 | 
					                    build = {},
 | 
				
			||||||
 | 
					                    runtime = {},
 | 
				
			||||||
 | 
					                    conflicts = {}
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        sources = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    build = function()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    end,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    install = function()
 | 
				
			||||||
 | 
					        os.chdir(pathjoin(SOURCESDIR, "bat-v0.26.0-" .. CURRENT_ARCH_NORMALIZED .. "-unknown-linux-gnu"))
 | 
				
			||||||
 | 
					        os.chmod("bat", 755)
 | 
				
			||||||
 | 
					        local suc, errmsg = os.copy("bat", pathjoin(PACKETDIR, BIN_DIR, "bat"))
 | 
				
			||||||
 | 
					        if not suc then
 | 
				
			||||||
 | 
					            error("failed to copy bat: " .. errmsg)
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("bat.1", pathjoin(PACKETDIR, "/usr/share/man/man1/bat.1"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        setflags("man", "manual", "/usr/share/man/man1/bat.1")
 | 
				
			||||||
 | 
					    end,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										65
									
								
								test/go/Packet.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								test/go/Packet.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,65 @@
 | 
				
			|||||||
 | 
					return {
 | 
				
			||||||
 | 
					    package = {
 | 
				
			||||||
 | 
					        name = "go",
 | 
				
			||||||
 | 
					        version = "1.25.3",
 | 
				
			||||||
 | 
					        maintainer = "robogg133",
 | 
				
			||||||
 | 
					        description = "A cat(1) clone with syntax highlighting and Git integration.",
 | 
				
			||||||
 | 
					        serial = 0,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        plataforms = {
 | 
				
			||||||
 | 
					            windows = {
 | 
				
			||||||
 | 
					                arch = { "amd64" },
 | 
				
			||||||
 | 
					                sources = {
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        url = "https://github.com/sharkdp/bat/releases/download/v0.26.0/bat-v0.26.0-" ..
 | 
				
			||||||
 | 
					                            CURRENT_ARCH_NORMALIZED .. "-pc-windows-msvc.zip",
 | 
				
			||||||
 | 
					                        method = "GET",
 | 
				
			||||||
 | 
					                        sha256 = "a8a6862f14698b45e101b0932c69bc47a007f4c0456f3a129fdcef54d443d501"
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                dependencies = {
 | 
				
			||||||
 | 
					                    build = {},
 | 
				
			||||||
 | 
					                    runtime = {},
 | 
				
			||||||
 | 
					                    conflicts = {}
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            linux = {
 | 
				
			||||||
 | 
					                arch = { "amd64" },
 | 
				
			||||||
 | 
					                sources = {
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        url = "https://github.com/sharkdp/bat/releases/download/v0.26.0/bat-v0.26.0-" ..
 | 
				
			||||||
 | 
					                            CURRENT_ARCH_NORMALIZED .. "-unknown-linux-gnu.tar.gz",
 | 
				
			||||||
 | 
					                        method = "GET",
 | 
				
			||||||
 | 
					                        sha256 = "7efed0c768fae36f18ddbbb4a38f5c4b64db7c55a170dfc89fd380805809a44b"
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                dependencies = {
 | 
				
			||||||
 | 
					                    build = {},
 | 
				
			||||||
 | 
					                    runtime = {},
 | 
				
			||||||
 | 
					                    conflicts = {}
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        sources = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    build = function()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    end,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    install = function()
 | 
				
			||||||
 | 
					        os.chdir(pathjoin(SOURCESDIR, "bat-v0.26.0-" .. CURRENT_ARCH_NORMALIZED .. "-unknown-linux-gnu"))
 | 
				
			||||||
 | 
					        os.chmod("bat", 755)
 | 
				
			||||||
 | 
					        local suc, errmsg = os.copy("bat", pathjoin(PACKETDIR, BIN_DIR, "bat"))
 | 
				
			||||||
 | 
					        if not suc then
 | 
				
			||||||
 | 
					            error("failed to copy bat: " .. errmsg)
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("bat.1", pathjoin(PACKETDIR, "/usr/share/man/man1/bat.1"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        setflags("man", "manual", "/usr/share/man/man1/bat.1")
 | 
				
			||||||
 | 
					    end,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										127
									
								
								test/nginx/Packet.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								test/nginx/Packet.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,127 @@
 | 
				
			|||||||
 | 
					-- https://nginx.org/download/nginx-1.29.3.tar.gz
 | 
				
			||||||
 | 
					return {
 | 
				
			||||||
 | 
					    package = {
 | 
				
			||||||
 | 
					        name = "nginx",
 | 
				
			||||||
 | 
					        version = "1.29.3",
 | 
				
			||||||
 | 
					        maintainer = "robogg133",
 | 
				
			||||||
 | 
					        description =
 | 
				
			||||||
 | 
					        [[nginx ("engine x") is an HTTP web server, reverse proxy, content cache, load balancer, TCP/UDP proxy server, and mail proxy server. Originally written by Igor Sysoev and distributed under the 2-clause BSD License. Enterprise distributions, commercial support and training are available from F5, Inc.]],
 | 
				
			||||||
 | 
					        serial = 0,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        plataforms = {
 | 
				
			||||||
 | 
					            windows = {
 | 
				
			||||||
 | 
					                arch = { "amd64" },
 | 
				
			||||||
 | 
					                sources = {
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        url = "https://nginx.org/download/nginx-1.29.3.zip",
 | 
				
			||||||
 | 
					                        method = "GET",
 | 
				
			||||||
 | 
					                        sha256 = { "afa2fde9fdf0ac64b91a17dcd34100ac557a3ff8e6154eeb0eeae7aa8e5bbc2d" }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                dependencies = {
 | 
				
			||||||
 | 
					                    build = {
 | 
				
			||||||
 | 
					                        "cc",
 | 
				
			||||||
 | 
					                        "cmake",
 | 
				
			||||||
 | 
					                        "make"
 | 
				
			||||||
 | 
					                    },
 | 
				
			||||||
 | 
					                    runtime = {},
 | 
				
			||||||
 | 
					                    conflicts = {}
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            linux = {
 | 
				
			||||||
 | 
					                arch = { "amd64" },
 | 
				
			||||||
 | 
					                sources = {
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        url = "https://nginx.org/download/nginx-1.29.3.tar.gz",
 | 
				
			||||||
 | 
					                        method = "GET",
 | 
				
			||||||
 | 
					                        sha256 = { "9befcced12ee09c2f4e1385d7e8e21c91f1a5a63b196f78f897c2d044b8c9312" }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                dependencies = {
 | 
				
			||||||
 | 
					                    build = {
 | 
				
			||||||
 | 
					                        "cc",
 | 
				
			||||||
 | 
					                        "cmake",
 | 
				
			||||||
 | 
					                        "make"
 | 
				
			||||||
 | 
					                    },
 | 
				
			||||||
 | 
					                    runtime = {},
 | 
				
			||||||
 | 
					                    conflicts = {}
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        sources = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    build = function()
 | 
				
			||||||
 | 
					        local uncompressedname = "nginx-1.29.3"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.chdir(pathjoin(SOURCESDIR, uncompressedname))
 | 
				
			||||||
 | 
					        os.chmod("configure", 0755)
 | 
				
			||||||
 | 
					        os.execute("./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --sbin-path=" ..
 | 
				
			||||||
 | 
					            pathjoin(BIN_DIR, "nginx"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        print("Build progress: executing Make...")
 | 
				
			||||||
 | 
					        local handle = io.popen("make", "r")
 | 
				
			||||||
 | 
					        local _ = handle:read("*a")
 | 
				
			||||||
 | 
					        local success, reason, exitcode = handle:close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if not success then
 | 
				
			||||||
 | 
					            error("make failed with code " .. tostring(exitcode) .. ": " .. tostring(reason))
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					        print("Build progress: Make completed!")
 | 
				
			||||||
 | 
					    end,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    install = function()
 | 
				
			||||||
 | 
					        local uncompressedname = "nginx-1.29.3"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("nginx.service", pathjoin(PACKETDIR, "/etc/systemd/system/nginx.service"))
 | 
				
			||||||
 | 
					        os.chdir(pathjoin(SOURCESDIR, uncompressedname))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.chmod("objs/nginx", 755)
 | 
				
			||||||
 | 
					        os.copy("objs/nginx", pathjoin(PACKETDIR, BIN_DIR, "nginx"))
 | 
				
			||||||
 | 
					        os.mkdir(pathjoin(PACKETDIR, "/usr/local/nginx"), 755)
 | 
				
			||||||
 | 
					        os.mkdir(pathjoin(PACKETDIR, "/etc/nginx"), 755)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("conf/koi-win", pathjoin(PACKETDIR, "/etc/nginx/koi-win"))
 | 
				
			||||||
 | 
					        os.copy("conf/koi-utf", pathjoin(PACKETDIR, "/etc/nginx/koi-utf"))
 | 
				
			||||||
 | 
					        os.copy("conf/win-utf", pathjoin(PACKETDIR, "/etc/nginx/win-utf"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("conf/mime.types", pathjoin(PACKETDIR, "/etc/nginx/mime.types"))
 | 
				
			||||||
 | 
					        os.copy("conf/mime.types", pathjoin(PACKETDIR, "/etc/nginx/mime.types.default"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("conf/fastcgi_params", pathjoin(PACKETDIR, "/etc/nginx/fastcgi_params"))
 | 
				
			||||||
 | 
					        os.copy("conf/fastcgi_params", pathjoin(PACKETDIR, "/etc/nginx/fastcgi_params.default"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("conf/fastcgi.conf", pathjoin(PACKETDIR, "/etc/nginx/fastcgi.conf"))
 | 
				
			||||||
 | 
					        os.copy("conf/fastcgi.conf", pathjoin(PACKETDIR, "/etc/nginx/fastcgi.conf.default"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("conf/uwsgi_params", pathjoin(PACKETDIR, "/etc/nginx/uwsgi_params"))
 | 
				
			||||||
 | 
					        os.copy("conf/uwsgi_params", pathjoin(PACKETDIR, "/etc/nginx/uwsgi_params.default"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("conf/scgi_params", pathjoin(PACKETDIR, "/etc/nginx/scgi_params"))
 | 
				
			||||||
 | 
					        os.copy("conf/scgi_params", pathjoin(PACKETDIR, "/etc/nginx/scgi_params.default"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("conf/nginx.conf", pathjoin(PACKETDIR, "/etc/nginx/nginx.conf"))
 | 
				
			||||||
 | 
					        os.copy("conf/nginx.conf", pathjoin(PACKETDIR, "/etc/nginx/nginx.conf.default"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("html", pathjoin(PACKETDIR, "/usr/share/nginx/html"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("LICENSE", pathjoin(PACKETDIR, "/usr/share/licenses/nginx/LICENSE"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.copy("man/nginx.8", pathjoin(PACKETDIR, "/usr/share/man/man8/nginx.8"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        os.mkdir(pathjoin(PACKETDIR, "/etc/nginx/logs"), 755)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        setflags("bin", "nginx", pathjoin(BIN_DIR, "nginx"))
 | 
				
			||||||
 | 
					        setflags("config", "main", "/etc/nginx/nginx.conf")
 | 
				
			||||||
 | 
					        setflags("config", "sites-available", "/etc/nginx/sites-available")
 | 
				
			||||||
 | 
					        setflags("config", "sites-enabled", "/etc/nginx/sites-enabled")
 | 
				
			||||||
 | 
					        setflags("man", "nginx.8", "/usr/share/man/man8/nginx.8")
 | 
				
			||||||
 | 
					        setflags("license", "license", "/usr/share/licenses/nginx/LICENSE")
 | 
				
			||||||
 | 
					        setflags("systemd", "nginx.service", "/etc/systemd/system/nginx.service")
 | 
				
			||||||
 | 
					    end,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										20
									
								
								test/nginx/nginx.service
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								test/nginx/nginx.service
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					[Unit]
 | 
				
			||||||
 | 
					 Description=nginx web server
 | 
				
			||||||
 | 
					 After=network-online.target remote-fs.target nss-lookup.target
 | 
				
			||||||
 | 
					 Wants=network-online.target
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Service]
 | 
				
			||||||
 | 
					 Type=forking
 | 
				
			||||||
 | 
					 PrivateDevices=yes
 | 
				
			||||||
 | 
					 PrivateTmp=true
 | 
				
			||||||
 | 
					 SyslogLevel=err
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 ExecStart=/usr/bin/nginx
 | 
				
			||||||
 | 
					 ExecReload=/usr/bin/nginx -s reload
 | 
				
			||||||
 | 
					 Restart=on-failure
 | 
				
			||||||
 | 
					 KillMode=mixed
 | 
				
			||||||
 | 
					 KillSignal=SIGQUIT
 | 
				
			||||||
 | 
					 TimeoutStopSec=5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Install]
 | 
				
			||||||
 | 
					 WantedBy=multi-user.target
 | 
				
			||||||
							
								
								
									
										40
									
								
								test/utctimerightnow/Packet.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								test/utctimerightnow/Packet.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
				
			|||||||
 | 
					return {
 | 
				
			||||||
 | 
					    package = {
 | 
				
			||||||
 | 
					        name = "utctimerightnow",       -- required
 | 
				
			||||||
 | 
					        version = "0.1.0",              -- required
 | 
				
			||||||
 | 
					        maintainer = "robogg133",       -- required
 | 
				
			||||||
 | 
					        description = "shows utc time", -- required
 | 
				
			||||||
 | 
					        serial = 0,                     -- required
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        dependencies = {
 | 
				
			||||||
 | 
					            build = { "go" },
 | 
				
			||||||
 | 
					            runtime = {},
 | 
				
			||||||
 | 
					            conflicts = {}
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        sources = {                                                            --optional
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                url = "https://git.opentty.xyz/robogg133/utctimerightnow.git", -- required
 | 
				
			||||||
 | 
					                method = "git",                                                -- required
 | 
				
			||||||
 | 
					                branch = "main"                                                -- required
 | 
				
			||||||
 | 
					                --  tag = ""
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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", 777)
 | 
				
			||||||
 | 
					    end,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    install = function() -- required
 | 
				
			||||||
 | 
					        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,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user