init commit da
This commit is contained in:
1 parent
d64b4f3983
commit
22359129af
5 files changed
+300
-35
No files matched your search
@@ -1,9 +1,9 @@
|
|||||||
module qulay
|
module qulay
|
||||||
|
|
||||||
go 1.25.8
|
go 1.26.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
codeberg.org/UzbekLinux/uzbekdb-go v0.0.0-20260324144756-3e62f214b3bb
|
codeberg.org/UzbekLinux/uzbekdb-go v0.0.0-20260509165828-8f8f4cbf599e
|
||||||
github.com/codeclysm/extract/v3 v3.1.1
|
github.com/codeclysm/extract/v3 v3.1.1
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ require (
|
|||||||
github.com/h2non/filetype v1.1.3 // indirect
|
github.com/h2non/filetype v1.1.3 // indirect
|
||||||
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 // indirect
|
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 // indirect
|
||||||
github.com/juju/loggo v1.0.0 // indirect
|
github.com/juju/loggo v1.0.0 // indirect
|
||||||
github.com/klauspost/compress v1.18.5 // indirect
|
github.com/klauspost/compress v1.15.13 // indirect
|
||||||
github.com/kr/text v0.2.0 // indirect
|
github.com/kr/text v0.2.0 // indirect
|
||||||
github.com/ulikunitz/xz v0.5.11 // indirect
|
github.com/ulikunitz/xz v0.5.11 // indirect
|
||||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
|
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
codeberg.org/UzbekLinux/uzbekdb-go v0.0.0-20260324144756-3e62f214b3bb h1:iUv2IrVCC3MrUy5Q/4kPIk/X5npUCZn1zQe4cUgh6Vk=
|
codeberg.org/UzbekLinux/uzbekdb-go v0.0.0-20260509165828-8f8f4cbf599e h1:CgMXKGmi0xnhKkQz/aiOKFpGF0RTn7Wc765ZKzymL+E=
|
||||||
codeberg.org/UzbekLinux/uzbekdb-go v0.0.0-20260324144756-3e62f214b3bb/go.mod h1:1npzE6+Q2MW4RuDTFcL+V9REv0o9k8LlTRW8jgGqeGA=
|
codeberg.org/UzbekLinux/uzbekdb-go v0.0.0-20260509165828-8f8f4cbf599e/go.mod h1:1npzE6+Q2MW4RuDTFcL+V9REv0o9k8LlTRW8jgGqeGA=
|
||||||
github.com/arduino/go-paths-helper v1.2.0 h1:qDW93PR5IZUN/jzO4rCtexiwF8P4OIcOmcSgAYLZfY4=
|
github.com/arduino/go-paths-helper v1.2.0 h1:qDW93PR5IZUN/jzO4rCtexiwF8P4OIcOmcSgAYLZfY4=
|
||||||
github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
|
github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
|
||||||
github.com/codeclysm/extract/v3 v3.1.1 h1:iHZtdEAwSTqPrd+1n4jfhr1qBhUWtHlMTjT90+fJVXg=
|
github.com/codeclysm/extract/v3 v3.1.1 h1:iHZtdEAwSTqPrd+1n4jfhr1qBhUWtHlMTjT90+fJVXg=
|
||||||
@@ -16,8 +16,8 @@ github.com/juju/loggo v1.0.0 h1:Y6ZMQOGR9Aj3BGkiWx7HBbIx6zNwNkxhVNOHU2i1bl0=
|
|||||||
github.com/juju/loggo v1.0.0/go.mod h1:NIXFioti1SmKAlKNuUwbMenNdef59IF52+ZzuOmHYkg=
|
github.com/juju/loggo v1.0.0/go.mod h1:NIXFioti1SmKAlKNuUwbMenNdef59IF52+ZzuOmHYkg=
|
||||||
github.com/juju/testing v0.0.0-20200510222523-6c8c298c77a0 h1:+WWUkhnTjV6RNOxkcwk79qrjeyHEHvBzlneueBsatX4=
|
github.com/juju/testing v0.0.0-20200510222523-6c8c298c77a0 h1:+WWUkhnTjV6RNOxkcwk79qrjeyHEHvBzlneueBsatX4=
|
||||||
github.com/juju/testing v0.0.0-20200510222523-6c8c298c77a0/go.mod h1:hpGvhGHPVbNBraRLZEhoQwFLMrjK8PSlO4D3nDjKYXo=
|
github.com/juju/testing v0.0.0-20200510222523-6c8c298c77a0/go.mod h1:hpGvhGHPVbNBraRLZEhoQwFLMrjK8PSlO4D3nDjKYXo=
|
||||||
github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE=
|
github.com/klauspost/compress v1.15.13 h1:NFn1Wr8cfnenSJSA46lLq4wHCcBzKTSjnBIexDMMOV0=
|
||||||
github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
github.com/klauspost/compress v1.15.13/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/lunixbochs/vtclean v0.0.0-20160125035106-4fbf7632a2c6/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
|
github.com/lunixbochs/vtclean v0.0.0-20160125035106-4fbf7632a2c6/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
|
||||||
|
|||||||
@@ -3,9 +3,12 @@ package helpers
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"path/filepath"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"os"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
var r = rand.New(rand.NewSource(time.Now().UnixNano()))
|
var r = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
@@ -42,3 +45,60 @@ func RandStr(n int) string {
|
|||||||
}
|
}
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CopyDir(src, dst string) error {
|
||||||
|
return filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rel, err := filepath.Rel(src, path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
target := filepath.Join(dst, rel)
|
||||||
|
|
||||||
|
mode := info.Mode()
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case mode&os.ModeSymlink != 0:
|
||||||
|
link, err := os.Readlink(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return os.Symlink(link, target)
|
||||||
|
|
||||||
|
case info.IsDir():
|
||||||
|
return os.MkdirAll(target, 0755)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return CopyFile(path, target)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func CopyFile(src, dst string) error {
|
||||||
|
in, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer in.Close()
|
||||||
|
|
||||||
|
out, err := os.Create(dst)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer out.Close()
|
||||||
|
|
||||||
|
_, err = io.Copy(out, in)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
si, err := os.Stat(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return os.Chmod(dst, si.Mode())
|
||||||
|
}
|
||||||
@@ -35,7 +35,6 @@ Options:
|
|||||||
:a -> ask before doing
|
:a -> ask before doing
|
||||||
:nl -> disable recording in databases and logs
|
:nl -> disable recording in databases and logs
|
||||||
:nd -> do not download deps
|
:nd -> do not download deps
|
||||||
:nrc -> disable uid 0 (root) checks
|
|
||||||
:r -> reinstall already installed deps
|
:r -> reinstall already installed deps
|
||||||
Vars:
|
Vars:
|
||||||
DESTDIR -> path where the package will be installed/removed`
|
DESTDIR -> path where the package will be installed/removed`
|
||||||
@@ -79,11 +78,6 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if os.Getuid() != 0 && slices.Contains(_root_cmds, cmds[0]) && !slices.Contains(opts, ":nrc") {
|
|
||||||
fmt.Println("!! this command is root-only. run this with root privileges")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// fmt.Println(cmds, oths, opts)
|
// fmt.Println(cmds, oths, opts)
|
||||||
if cmds[0] == "h" {
|
if cmds[0] == "h" {
|
||||||
printHelp()
|
printHelp()
|
||||||
|
|||||||
+233
-22
@@ -16,11 +16,19 @@ import (
|
|||||||
"qulay/database"
|
"qulay/database"
|
||||||
"qulay/helpers"
|
"qulay/helpers"
|
||||||
|
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
"io"
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/codeclysm/extract/v3"
|
||||||
"codeberg.org/UzbekLinux/uzbekdb-go"
|
"codeberg.org/UzbekLinux/uzbekdb-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _name string = filepath.Base(os.Args[0])
|
var _name string = filepath.Base(os.Args[0])
|
||||||
|
|
||||||
|
var installing = map[string]bool{}
|
||||||
|
|
||||||
type Package struct {
|
type Package struct {
|
||||||
Name string
|
Name string
|
||||||
Repo string
|
Repo string
|
||||||
@@ -34,28 +42,36 @@ func randomTempDir(destDir string) string {
|
|||||||
return tempDirPath
|
return tempDirPath
|
||||||
}
|
}
|
||||||
|
|
||||||
func readDepends(path string) []string {
|
func readPackage(path string) ([]string, string, string, string, string) {
|
||||||
dependsPath := filepath.Join(path, "depends")
|
pkgPath := filepath.Join(path, "pkg")
|
||||||
dependsPath2 := filepath.Join(path, "depends.uz")
|
|
||||||
f, err := os.Open(dependsPath)
|
f, err := os.Open(pkgPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f, err = os.Open(dependsPath2)
|
return []string{}, "", "", "", ""
|
||||||
if err != nil {
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
var depends []string
|
var depends []string
|
||||||
|
var taip = ""
|
||||||
|
var url = ""
|
||||||
|
var afterScript = ""
|
||||||
|
var removeScript = ""
|
||||||
|
|
||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
depends = append(depends, scanner.Text())
|
line := scanner.Text()
|
||||||
|
if strings.HasPrefix(line, "deps: ") {
|
||||||
|
depends = append(depends, strings.Fields(strings.TrimPrefix(line, "deps: "))...)
|
||||||
|
} else if strings.HasPrefix(line, "type: ") {
|
||||||
|
taip = strings.TrimPrefix(line, "type: ")
|
||||||
|
} else if strings.HasPrefix(line, "url: ") {
|
||||||
|
url = strings.TrimPrefix(line, "url: ")
|
||||||
|
} else if strings.HasPrefix(line, "after: ") {
|
||||||
|
afterScript = strings.TrimPrefix(line, "after: ")
|
||||||
|
} else if strings.HasPrefix(line, "remove: ") {
|
||||||
|
removeScript = strings.TrimPrefix(line, "remove: ")
|
||||||
}
|
}
|
||||||
return depends
|
}
|
||||||
}
|
return depends, taip, url, afterScript, removeScript
|
||||||
|
|
||||||
func isNewFormat(path string) bool {
|
|
||||||
_, err := os.Stat(filepath.Join(path, "data"))
|
|
||||||
return !os.IsNotExist(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPackages(destDir string) []Package {
|
func GetPackages(destDir string) []Package {
|
||||||
@@ -157,13 +173,24 @@ func Install(name string, args []string, destDir string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pkgPath := filepath.Join(destDir, paths.ReposDir, pkg.Repo, "packages", pkg.Name)
|
pkgPath := filepath.Join(destDir, paths.ReposDir, pkg.Repo, "packages", pkg.Name)
|
||||||
depends := readDepends(pkgPath)
|
depends, taip, url, afterScript, _ := readPackage(pkgPath)
|
||||||
|
|
||||||
|
key := pkg.Repo + "/" + pkg.Name
|
||||||
|
|
||||||
|
if installing[key] {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
installing[key] = true
|
||||||
|
defer func() {
|
||||||
|
installing[key] = false
|
||||||
|
}()
|
||||||
|
|
||||||
if !disableDeps {
|
if !disableDeps {
|
||||||
if len(depends) != 0 {
|
if len(depends) != 0 {
|
||||||
fmt.Println(helpers.ToString(len(depends)) + " depends for " + pkg.Repo + "/" + pkg.Name + ":")
|
fmt.Println(helpers.ToString(len(depends)) + " deps for " + pkg.Repo + "/" + pkg.Name + ":")
|
||||||
for i, n := range depends {
|
for i, n := range depends {
|
||||||
if n == pkg.Name || n == pkg.Repo+"/"+pkg.Name {
|
if n == pkg.Name || n == pkg.Repo+"/"+pkg.Name {
|
||||||
return errors.New("broken depends in package " + n)
|
return errors.New("broken deps in package " + n)
|
||||||
}
|
}
|
||||||
|
|
||||||
depPkgs := FindPackages(n, destDir)
|
depPkgs := FindPackages(n, destDir)
|
||||||
@@ -176,11 +203,13 @@ func Install(name string, args []string, destDir string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(args, ":a") {
|
if slices.Contains(args, ":a") {
|
||||||
if !helpers.Ask("install " + pkg.Repo + "/" + pkg.Name + " with version " + helpers.ToString(pkg.Data[1])) {
|
if !helpers.Ask("install " + pkg.Repo + "/" + pkg.Name + " with version " + helpers.ToString(pkg.Data[1])) {
|
||||||
return errors.New("canceled by user")
|
return errors.New("canceled by user")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !disableDeps {
|
if !disableDeps {
|
||||||
for _, dep := range depends {
|
for _, dep := range depends {
|
||||||
depPkg, err := getPackage(dep, destDir)
|
depPkg, err := getPackage(dep, destDir)
|
||||||
@@ -199,7 +228,107 @@ func Install(name string, args []string, destDir string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isNewFormat(pkgPath) {
|
fmt.Println(":: installing " + pkg.Name + " from repo " + pkg.Repo)
|
||||||
|
|
||||||
|
if taip == "arch" {
|
||||||
|
destArchivePath := filepath.Join(destDir, "tmp", pkg.Name + pkg.Repo + ".tar.zst")
|
||||||
|
fullDestPath := filepath.Join(pkgPath, "arch")
|
||||||
|
|
||||||
|
os.MkdirAll(fullDestPath, 0755)
|
||||||
|
os.MkdirAll(filepath.Dir(destArchivePath), 0755)
|
||||||
|
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: 10 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("!! failed to download", url, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
f, err := os.Create(destArchivePath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("!! failed to create file", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
_, err = io.Copy(f, resp.Body)
|
||||||
|
f.Close()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("!! failed to copy", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(":: downloaded", url, "to", destArchivePath)
|
||||||
|
|
||||||
|
_ = os.RemoveAll(fullDestPath)
|
||||||
|
|
||||||
|
file, err := os.Open(destArchivePath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("!! failed to open archive file", destArchivePath, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
err = extract.Zstd(context.TODO(), file, fullDestPath, nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("!! failed to extract", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(":: removing govnofiles from package...")
|
||||||
|
|
||||||
|
_ = os.Remove(filepath.Join(fullDestPath, ".BUILDINFO"))
|
||||||
|
_ = os.Remove(filepath.Join(fullDestPath, ".MTREE"))
|
||||||
|
_ = os.Remove(filepath.Join(fullDestPath, ".PKGINFO"))
|
||||||
|
_ = os.Remove(filepath.Join(fullDestPath, ".INSTALL"))
|
||||||
|
|
||||||
|
fmt.Println(":: copying files to / ...")
|
||||||
|
|
||||||
|
err = helpers.CopyDir(fullDestPath, filepath.Join(destDir, "/"))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("!! failed to copy files to /:", err)
|
||||||
|
} else {
|
||||||
|
fmt.Println(":: successfully copied to /")
|
||||||
|
}
|
||||||
|
|
||||||
|
outputFilePath := filepath.Join(pkgPath, "files")
|
||||||
|
outputFile, err := os.Create(outputFilePath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("!! failed to create files list:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer outputFile.Close()
|
||||||
|
|
||||||
|
err = filepath.WalkDir(fullDestPath, func(path string, d os.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
relPath, err := filepath.Rel(fullDestPath, path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
formattedPath := "/" + filepath.ToSlash(relPath)
|
||||||
|
|
||||||
|
_, err = outputFile.WriteString(formattedPath + "\n")
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("!! failed to index files:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if taip == "script" {
|
||||||
cmd := exec.Command("sh", "install.sh")
|
cmd := exec.Command("sh", "install.sh")
|
||||||
cmd.Dir = pkgPath
|
cmd.Dir = pkgPath
|
||||||
cmd.Env = append(os.Environ(), "DESTDIR="+destDir)
|
cmd.Env = append(os.Environ(), "DESTDIR="+destDir)
|
||||||
@@ -209,6 +338,49 @@ func Install(name string, args []string, destDir string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else if taip == "binary" {
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: 10 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
outPath := filepath.Join(destDir, "/usr/bin", pkg.Name)
|
||||||
|
|
||||||
|
f, err := os.Create(outPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(f, resp.Body)
|
||||||
|
f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Chmod(outPath, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return errors.New("package err maybe old format")
|
||||||
|
}
|
||||||
|
|
||||||
|
if afterScript != "" {
|
||||||
|
fmt.Println(":: running after installation script " + afterScript + " ...")
|
||||||
|
cmd := exec.Command("sh", afterScript)
|
||||||
|
cmd.Dir = pkgPath
|
||||||
|
cmd.Env = append(os.Environ(), "DESTDIR="+destDir)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = database.RegPackage(pkg.Repo+"/"+pkg.Name, helpers.ToString(pkg.Data[1]), destDir)
|
err = database.RegPackage(pkg.Repo+"/"+pkg.Name, helpers.ToString(pkg.Data[1]), destDir)
|
||||||
@@ -234,18 +406,57 @@ func Remove(name string, args []string, destDir string) error {
|
|||||||
|
|
||||||
pkgPath := filepath.Join(destDir, paths.ReposDir, pkg.Repo, "packages", pkg.Name)
|
pkgPath := filepath.Join(destDir, paths.ReposDir, pkg.Repo, "packages", pkg.Name)
|
||||||
|
|
||||||
if !isNewFormat(pkgPath) {
|
_, _, _, _, removeScript := readPackage(pkgPath)
|
||||||
cmd := exec.Command("sh", "remove.sh")
|
|
||||||
|
if removeScript != "" {
|
||||||
|
fmt.Println(":: running remove script " + removeScript + " ...")
|
||||||
|
cmd := exec.Command("sh", removeScript)
|
||||||
cmd.Dir = pkgPath
|
cmd.Dir = pkgPath
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
err := cmd.Run()
|
err = cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat("files"); err == nil {
|
||||||
|
f, _ := os.Open("files")
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
for scanner.Scan() {
|
||||||
|
file := scanner.Text()
|
||||||
|
|
||||||
|
if file == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
path := filepath.Join(destDir, file)
|
||||||
|
|
||||||
|
if _, err := os.Stat(path); err == nil {
|
||||||
|
fmt.Printf("removing %s\n", path)
|
||||||
|
|
||||||
|
if err := os.RemoveAll(path); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "failed to remove %s: %v\n", path, err)
|
||||||
|
}
|
||||||
|
} else if !os.IsNotExist(err) {
|
||||||
|
fmt.Fprintf(os.Stderr, "failed to stat %s: %v\n", path, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "failed to read files: %v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if removeScript == "" {
|
||||||
|
if _, err := os.Stat("files"); os.IsNotExist(err) {
|
||||||
|
return errors.New("failed to remove package file (no remove script and paths file)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = database.UnRegPackage(pkg.Repo+"/"+pkg.Name, destDir)
|
err = database.UnRegPackage(pkg.Repo+"/"+pkg.Name, destDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in new issue
Block a user