ебать крупнейшее обновление 1.0

This commit is contained in:
huker667 committed 2026-08-11 18:58:45 +03:00
1 parent 22359129af
commit d6ebd95cbd
6 files changed
+1788 -330

No files matched your search

+4 -1
View File
@@ -1,5 +1,8 @@
package paths
const ReposUrlsFile = "etc/qulay/repositories"
const ReposConfigDir = "etc/qulay/repos/"
const ReposDir = "var/lib/qulay/repos/"
const InstalledFile = "var/lib/qulay/installed"
const BuiltDir = "var/lib/qulay/built/"
const FilesDir = "var/lib/qulay/files/"
const BuildConfigFile = "etc/qulay/build"
+111 -54
View File
@@ -1,70 +1,112 @@
package database
import (
"fmt"
"os"
// "archive/tar"
"bufio"
"context"
"fmt"
"io"
"net/http"
"os"
"path"
"path/filepath"
"sync"
"time"
// "net/url"
"io"
"slices"
"strings"
"sync"
"qulay/config"
"codeberg.org/UzbekLinux/uzbekdb-go"
"qulay/helpers"
"codeberg.org/UzbekLinux/uzbekdb-go"
"github.com/codeclysm/extract/v3"
// "github.com/klauspost/compress/zstd"
)
var _name string = filepath.Base(os.Args[0])
func GetReposUrls(destDir string) []string {
f, err := os.Open(filepath.Join(destDir, paths.ReposUrlsFile))
if err != nil {
return []string{}
}
defer f.Close()
var urls []string
scanner := bufio.NewScanner(f)
for scanner.Scan() {
urls = append(urls, scanner.Text())
}
return urls
type Repo struct {
Name string
URL string
}
func DownloadRepos(urls []string, destDir string) {
var wg sync.WaitGroup
var links []string
func GetRepos(destDir string) []Repo {
dir := filepath.Join(destDir, paths.ReposConfigDir)
for _, link := range urls {
link = strings.TrimSpace(link)
if link == "" {
entries, err := os.ReadDir(dir)
if err != nil {
return nil
}
var repos []Repo
for _, entry := range entries {
if entry.IsDir() {
continue
}
links = append(links, link)
data, err := os.ReadFile(
filepath.Join(dir, entry.Name()),
)
if err != nil {
continue
}
m := uzbekdb.Loads(string(data), "map")
if m == nil {
continue
}
mp, ok := m.(map[interface{}][]interface{})
if !ok {
continue
}
repo := Repo{Name: entry.Name()}
if vals, ok := mp["url"]; ok && len(vals) > 0 {
repo.URL = fmt.Sprintf("%v", vals[0])
}
repos = append(repos, repo)
}
wg.Add(len(links))
for _, link := range links {
go func(link string) {
slices.SortFunc(repos, func(a, b Repo) int {
return strings.Compare(a.Name, b.Name)
})
return repos
}
func RepoURL(destDir, name string) string {
for _, repo := range GetRepos(destDir) {
if repo.Name == name {
return repo.URL
}
}
return ""
}
func DownloadRepos(destDir string) {
var wg sync.WaitGroup
for _, repo := range GetRepos(destDir) {
wg.Add(1)
go func(base, name string) {
defer wg.Done()
archiveName := path.Base(link)
repoName := strings.TrimSuffix(archiveName, ".tar.zst")
destArchivePath := filepath.Join(destDir, "tmp", archiveName)
destNArchivePath := filepath.Join(destDir, "tmp")
destPath := filepath.Join(destDir, paths.ReposDir)
fullDestPath := filepath.Join(destDir, paths.ReposDir, repoName)
os.MkdirAll(destNArchivePath, 0755)
client := &http.Client{
Timeout: 10 * time.Second,
link := base
if !strings.HasSuffix(link, "/") {
link += "/"
}
link += name + ".tar.zst"
archiveName := path.Base(link)
destArchivePath := filepath.Join(destDir, "tmp", archiveName)
destPath := filepath.Join(destDir, paths.ReposDir)
fullDestPath := filepath.Join(destPath, name)
os.MkdirAll(filepath.Dir(destArchivePath), 0755)
defer os.Remove(destArchivePath)
client := helpers.HTTPClient()
resp, err := client.Get(link)
if err != nil {
@@ -72,6 +114,10 @@ func DownloadRepos(urls []string, destDir string) {
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Println("!! http error", resp.StatusCode, link)
return
}
f, err := os.Create(destArchivePath)
if err != nil {
@@ -88,8 +134,8 @@ func DownloadRepos(urls []string, destDir string) {
fmt.Println(":: downloaded", archiveName, "to", destArchivePath)
err = os.RemoveAll(fullDestPath)
fmt.Println(":: removing old repo", fullDestPath)
err = os.RemoveAll(fullDestPath)
if err != nil {
fmt.Println("w! failed to delete old repo", fullDestPath, err)
}
@@ -99,13 +145,16 @@ func DownloadRepos(urls []string, destDir string) {
fmt.Println("!! failed to open archive file", destArchivePath, err)
return
}
err = extract.Zstd(context.TODO(), file, destPath, nil)
defer file.Close()
err = extract.Zstd(context.TODO(), file, fullDestPath, nil)
if err != nil {
fmt.Println("!! failed to extract", err)
return
}
}(link)
}(repo.URL, repo.Name)
}
wg.Wait()
fmt.Println(":: repo updating ended")
}
@@ -123,7 +172,7 @@ func ReadInstalled(destDir string) map[interface{}][]interface{} {
}
data := uzbekdb.Loads(string(text), "map")
if data == nil {
return map[interface{}][]interface{}{}
return map[interface{}][]interface{}{}
}
return data.(map[interface{}][]interface{})
}
@@ -150,12 +199,21 @@ func IsInstalled(name string, destDir string) bool {
func GetPackageVersion(name string, destDir string) string {
data := ReadInstalled(destDir)
if !strings.Contains(name, "/") {
for k := range data {
if kStr, ok := k.(string); ok {
if strings.HasSuffix(kStr, "/"+name) {
name = kStr
break
}
}
}
}
alo, _ := data[name]
if len(alo) > 0 {
return alo[0].(string)
} else {
return ""
return fmt.Sprintf("%v", alo[0])
}
return ""
}
func RegPackage(name string, version string, destDir string) error {
@@ -177,7 +235,7 @@ func UnRegPackage(name string, destDir string) error {
data := ReadInstalled(destDir)
_, ok := data[name]
if !ok {
return fmt.Errorf("cant unregister '%s': package is not installed", name)
return nil
}
delete(data, name)
return WriteInstalled(data, destDir)
@@ -185,13 +243,12 @@ func UnRegPackage(name string, destDir string) error {
func PurgeRepository(name string, destDir string) error {
dirPath := filepath.Join(destDir, paths.ReposDir, name)
if _, err := os.Stat(dirPath); err != nil {
return fmt.Errorf("repository '%s' not found", name)
}
err := os.RemoveAll(dirPath)
if err != nil {
return err
}
return nil
}
// func Ensure(args, destDir) error {
//
// }
+1 -1
View File
@@ -5,13 +5,13 @@ go 1.26.4
require (
codeberg.org/UzbekLinux/uzbekdb-go v0.0.0-20260509165828-8f8f4cbf599e
github.com/codeclysm/extract/v3 v3.1.1
github.com/klauspost/compress v1.15.13
)
require (
github.com/h2non/filetype v1.1.3 // indirect
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 // indirect
github.com/juju/loggo v1.0.0 // indirect
github.com/klauspost/compress v1.15.13 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
+17
View File
@@ -2,6 +2,8 @@ package helpers
import (
"fmt"
"net"
"net/http"
"strings"
"path/filepath"
"math/rand"
@@ -25,6 +27,18 @@ func Ask(str string) bool {
return true
}
func HTTPClient() *http.Client {
transport := &http.Transport{
DialContext: (&net.Dialer{
Timeout: 10 * time.Second,
}).DialContext,
TLSHandshakeTimeout: 10 * time.Second,
}
return &http.Client{
Transport: transport,
}
}
func ToString(v interface{}) string {
switch val := v.(type) {
case int:
@@ -67,6 +81,9 @@ func CopyDir(src, dst string) error {
if err != nil {
return err
}
if err := os.RemoveAll(target); err != nil {
return err
}
return os.Symlink(link, target)
case info.IsDir():
+75 -18
View File
@@ -13,29 +13,41 @@ import (
)
var _name string = filepath.Base(os.Args[0])
var _cmds = []string{"h", "+", "-", "g", "s", "p", "u", "r", "q", "f", "v"}
var _root_cmds = []string{"+", "-", "u", "i"}
var _cmds = []string{"h", "+", "-", "g", "s", "p", "u", "r", "q", "f", "v", "b", "o"}
const _version string = "0.7"
const _help string = `{_name}: command-line interface to the Qulay Package Manager
const _version string = "1.0"
const _help string = `{_name}: Qulay Package Manager
Usage:
{_name} h -> help menu
{_name} + pkg -> download and install package
{_name} + pkg -> download and install package (or .qpmp file path)
{_name} - pkg -> remove package
{_name} b pkg -> build package into .tar.zst (or .qpmp on :qpmp)
{_name} g pkg -> get package version
{_name} s pkg -> search packages by name
{_name} p repo -> purge local repo directory
{_name} u -> update all repositories
{_name} r -> get all repositories URLs
{_name} r -> get all repositories configs
{_name} o -> upgrade all installed packages
{_name} q -> get all installed packages
{_name} f -> get files path for destDir
{_name} v -> get {_name} version
Options:
:v -> verbose output
:a -> ask before doing
:nl -> disable recording in databases and logs
:nd -> do not download deps
:r -> reinstall already installed deps
:f -> force install (ignore conflicts)
:qpmp -> build a .qpmp archive instead of .tar.zst
Tags (for +, - , b and o):
@all -> apply to all packages
repo/@all -> apply to all packages in repo
@inst -> apply to installed (for b: built) packages
repo/@inst -> apply to installed (for b: built) packages in repo
@notinst -> apply to not installed (for b: not built) packages
repo/@notinst-> apply to not installed (for b: not built) packages in repo
@old -> apply to installed/built packages outdated by version
repo/@old -> apply to outdated packages in repo
o without tags applies @old automatically
Vars:
DESTDIR -> path where the package will be installed/removed`
@@ -86,7 +98,12 @@ func main() {
fmt.Println("!! no package(s) received")
os.Exit(1)
}
for _, n := range oths {
names, err := pkg.Expand("+", oths, absDestDir)
if err != nil {
fmt.Println("!!", err)
os.Exit(1)
}
for _, n := range names {
err := pkg.Install(n, opts, absDestDir)
if err != nil {
fmt.Println("!!", err)
@@ -98,7 +115,12 @@ func main() {
fmt.Println("!! no package(s) received")
os.Exit(1)
}
for _, n := range oths {
names, err := pkg.Expand("-", oths, absDestDir)
if err != nil {
fmt.Println("!!", err)
os.Exit(1)
}
for _, n := range names {
err := pkg.Remove(n, opts, absDestDir)
if err != nil {
fmt.Println("!!", err)
@@ -106,7 +128,24 @@ func main() {
}
}
} else if cmds[0] == "u" {
database.DownloadRepos(database.GetReposUrls(absDestDir), absDestDir)
database.DownloadRepos(absDestDir)
} else if cmds[0] == "b" {
if len(oths) < 1 {
fmt.Println("!! no package(s) received")
os.Exit(1)
}
names, err := pkg.Expand("b", oths, absDestDir)
if err != nil {
fmt.Println("!!", err)
os.Exit(1)
}
for _, n := range names {
err := pkg.Build(n, opts, absDestDir)
if err != nil {
fmt.Println("!!", err)
os.Exit(1)
}
}
} else if cmds[0] == "g" {
if len(oths) < 1 {
fmt.Println("!! no package(s) received")
@@ -116,21 +155,37 @@ func main() {
fmt.Println(database.GetPackageVersion(name, absDestDir))
}
} else if cmds[0] == "r" {
for _, url := range database.GetReposUrls(absDestDir) {
fmt.Println(url)
for _, repo := range database.GetRepos(absDestDir) {
fmt.Println(repo.Name, "url:", repo.URL)
}
} else if cmds[0] == "o" {
if len(oths) < 1 {
oths = []string{"@old"}
}
names, err := pkg.Expand("o", oths, absDestDir)
if err != nil {
fmt.Println("!!", err)
os.Exit(1)
}
err = pkg.Upgrade(names, opts, absDestDir)
if err != nil {
fmt.Println("!!", err)
os.Exit(1)
}
} else if cmds[0] == "q" {
for name, version := range database.ReadInstalled(absDestDir) {
fmt.Println(name, "-", version[0])
if len(version) > 0 {
fmt.Println(name, "-", version[0])
}
}
} else if cmds[0] == "s" {
if len(oths) < 1 {
pkgs := pkg.GetPackages(absDestDir)
for _, p := range pkgs {
if database.IsInstalled(p.Repo+"/"+p.Name, absDestDir) {
fmt.Printf("[+] %s/%s - %v - %v\n", p.Repo, p.Name, p.Data[0], p.Data[1])
fmt.Printf("[+] %s/%s - %v - %v\n", p.Repo, p.Name, p.Version, p.Desc)
} else {
fmt.Printf(" %s/%s - %v - %v\n", p.Repo, p.Name, p.Data[0], p.Data[1])
fmt.Printf(" %s/%s - %v - %v\n", p.Repo, p.Name, p.Version, p.Desc)
}
}
} else {
@@ -138,9 +193,9 @@ func main() {
pkgs := pkg.FindPackages(n, absDestDir)
for _, p := range pkgs {
if database.IsInstalled(p.Repo+"/"+p.Name, absDestDir) {
fmt.Printf("[+] %s/%s - %v - %v\n", p.Repo, p.Name, p.Data[0], p.Data[1])
fmt.Printf("[+] %s/%s - %v - %v\n", p.Repo, p.Name, p.Version, p.Desc)
} else {
fmt.Printf(" %s/%s - %v - %v\n", p.Repo, p.Name, p.Data[0], p.Data[1])
fmt.Printf(" %s/%s - %v - %v\n", p.Repo, p.Name, p.Version, p.Desc)
}
}
}
@@ -166,9 +221,11 @@ func main() {
fmt.Printf("dest dir: %v\n", destDir)
fmt.Printf("abs dest dir: %v\n", absDestDir)
fmt.Printf("is abs: %v\n", filepath.IsAbs(destDir))
fmt.Printf("repos urls file: %v\n", filepath.Join(absDestDir, paths.ReposUrlsFile))
fmt.Printf("repos config dir: %v\n", filepath.Join(absDestDir, paths.ReposConfigDir))
fmt.Printf("repos dir: %v\n", filepath.Join(absDestDir, paths.ReposDir))
fmt.Printf("installed pkgs database: %v\n", filepath.Join(absDestDir, paths.InstalledFile))
fmt.Printf("built pkgs dir: %v\n", filepath.Join(absDestDir, paths.BuiltDir))
fmt.Printf("build config file: %v\n", filepath.Join(absDestDir, paths.BuildConfigFile))
} else if cmds[0] == "v" {
fmt.Println(_version)
} else {
+1580 -256
View File
File diff suppressed because it is too large. Load diff