forked from Plemya-x/ALR
Compare commits
21 Commits
tests/add-
...
master
Author | SHA1 | Date | |
---|---|---|---|
c59ed6d505 | |||
2bbc308810 | |||
5ca34a572a | |||
67e63d1831 | |||
0bfe88beed | |||
3ce9f0db35 | |||
469a05105a | |||
70aca61750 | |||
4b35f5e4e6 | |||
7770675a8d | |||
bd79d56776 | |||
fff8b777fe | |||
6bee268ea9 | |||
4b53e819d8 | |||
6c0e8aeb3f | |||
cbc6b9f452 | |||
c705c25613 | |||
8f4b021a93 | |||
5e7d4033e4 | |||
4ac2432770 | |||
3c37310f0d |
1
Makefile
1
Makefile
@ -73,5 +73,6 @@ test-coverage:
|
||||
bash scripts/coverage-badge.sh
|
||||
|
||||
e2e-test: clean build
|
||||
rm -f ./e2e-tests/alr
|
||||
cp alr e2e-tests
|
||||
go test -tags=e2e ./...
|
@ -11,7 +11,7 @@
|
||||
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
||||
<text x="33.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
|
||||
<text x="33.5" y="14">coverage</text>
|
||||
<text x="86" y="15" fill="#010101" fill-opacity=".3">19.8%</text>
|
||||
<text x="86" y="14">19.8%</text>
|
||||
<text x="86" y="15" fill="#010101" fill-opacity=".3">19.0%</text>
|
||||
<text x="86" y="14">19.0%</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 926 B After Width: | Height: | Size: 926 B |
@ -12,7 +12,7 @@
|
||||
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
||||
<text x="37" y="15" fill="#010101" fill-opacity=".3">ru translate</text>
|
||||
<text x="37" y="14">ru translate</text>
|
||||
<text x="100" y="15" fill="#010101" fill-opacity=".3">100.00%</text>
|
||||
<text x="100" y="14">100.00%</text>
|
||||
<text x="100" y="15" fill="#010101" fill-opacity=".3">97.00%</text>
|
||||
<text x="100" y="14">97.00%</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 942 B After Width: | Height: | Size: 940 B |
14
build.go
14
build.go
@ -68,9 +68,15 @@ func BuildCmd() *cli.Command {
|
||||
Action: func(c *cli.Context) error {
|
||||
ctx := c.Context
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
rs := repos.New(cfg, db)
|
||||
err := db.Init(ctx)
|
||||
err = db.Init(ctx)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error initialization database"), "err", err)
|
||||
os.Exit(1)
|
||||
@ -80,7 +86,7 @@ func BuildCmd() *cli.Command {
|
||||
var packages []string
|
||||
repository := "default"
|
||||
|
||||
repoDir := cfg.GetPaths(ctx).RepoDir
|
||||
repoDir := cfg.GetPaths().RepoDir
|
||||
|
||||
switch {
|
||||
case c.IsSet("script"):
|
||||
@ -118,8 +124,8 @@ func BuildCmd() *cli.Command {
|
||||
}
|
||||
|
||||
// Проверка автоматического пулла репозиториев
|
||||
if cfg.AutoPull(ctx) {
|
||||
err := rs.Pull(ctx, cfg.Repos(ctx))
|
||||
if cfg.AutoPull() {
|
||||
err := rs.Pull(ctx, cfg.Repos())
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error pulling repositories"), "err", err)
|
||||
os.Exit(1)
|
||||
|
@ -19,33 +19,52 @@
|
||||
package e2etests_test
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"bytes"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/efficientgo/e2e"
|
||||
expect "github.com/tailscale/goexpect"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestE2EAlrAddRepo(t *testing.T) {
|
||||
dockerMultipleRun(
|
||||
t,
|
||||
"add-repo",
|
||||
"add-repo-remove-repo",
|
||||
COMMON_SYSTEMS,
|
||||
func(t *testing.T, r e2e.Runnable) {
|
||||
runTestCommands(t, r, time.Second*10, []expect.Batcher{
|
||||
&expect.BSnd{S: "alr addrepo --name alr-repo --url https://gitea.plemya-x.ru/Plemya-x/alr-repo.git ; echo ALR-ADD-REPO-RETURN-CODE $?\n"},
|
||||
&expect.BCas{C: []expect.Caser{
|
||||
&expect.Case{
|
||||
R: regexp.MustCompile(`ALR-ADD-REPO-RETURN-CODE 0\n$`),
|
||||
T: expect.OK(),
|
||||
},
|
||||
&expect.Case{
|
||||
R: regexp.MustCompile(`ALR-ADD-REPO-RETURN-CODE \d\n$`),
|
||||
T: expect.Fail(expect.NewStatus(expect.Internal, "Unexpected return code!")),
|
||||
},
|
||||
}},
|
||||
})
|
||||
err := r.Exec(e2e.NewCommand(
|
||||
"alr",
|
||||
"addrepo",
|
||||
"--name",
|
||||
"alr-repo",
|
||||
"--url",
|
||||
"https://gitea.plemya-x.ru/Plemya-x/alr-repo.git",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = r.Exec(e2e.NewCommand(
|
||||
"bash",
|
||||
"-c",
|
||||
"cat $HOME/.config/alr/alr.toml",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = r.Exec(e2e.NewCommand(
|
||||
"alr",
|
||||
"removerepo",
|
||||
"--name",
|
||||
"alr-repo",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
|
||||
var buf bytes.Buffer
|
||||
err = r.Exec(e2e.NewCommand(
|
||||
"bash",
|
||||
"-c",
|
||||
"cat $HOME/.config/alr/alr.toml",
|
||||
), e2e.WithExecOptionStdout(&buf))
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, buf.String(), "rootCmd")
|
||||
},
|
||||
)
|
||||
}
|
||||
|
40
e2e-tests/bash_completion_test.go
Normal file
40
e2e-tests/bash_completion_test.go
Normal file
@ -0,0 +1,40 @@
|
||||
// ALR - Any Linux Repository
|
||||
// Copyright (C) 2025 Евгений Храмов
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//go:build e2e
|
||||
|
||||
package e2etests_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/alecthomas/assert/v2"
|
||||
"github.com/efficientgo/e2e"
|
||||
)
|
||||
|
||||
func TestE2EBashCompletion(t *testing.T) {
|
||||
dockerMultipleRun(
|
||||
t,
|
||||
"bash-completion",
|
||||
COMMON_SYSTEMS,
|
||||
func(t *testing.T, r e2e.Runnable) {
|
||||
err := r.Exec(e2e.NewCommand(
|
||||
"alr", "install", "--generate-bash-completion",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
},
|
||||
)
|
||||
}
|
@ -101,10 +101,16 @@ func e2eSpawn(runnable e2e.Runnable, command e2e.Command, timeout time.Duration,
|
||||
var ALL_SYSTEMS []string = []string{
|
||||
"ubuntu-24.04",
|
||||
"alt-sisyphus",
|
||||
"archlinux",
|
||||
//"alpine",
|
||||
"opensuse-leap",
|
||||
"redos-8",
|
||||
"fedora-41",
|
||||
// "archlinux",
|
||||
// "alpine",
|
||||
// "opensuse-leap",
|
||||
// "redos-8",
|
||||
}
|
||||
|
||||
var AUTOREQ_AUTOPROV_SYSTEMS []string = []string{
|
||||
"alt-sisyphus",
|
||||
"fedora-41",
|
||||
}
|
||||
|
||||
var COMMON_SYSTEMS []string = []string{
|
||||
@ -155,6 +161,7 @@ func dockerMultipleRun(t *testing.T, name string, ids []string, f func(t *testin
|
||||
Volumes: []string{
|
||||
"./alr:/usr/bin/alr",
|
||||
},
|
||||
Privileged: true,
|
||||
},
|
||||
)
|
||||
assert.NoError(t, e2e.StartAndWaitReady(runnable))
|
||||
|
@ -1,5 +1,6 @@
|
||||
FROM registry.altlinux.org/sisyphus/alt:latest
|
||||
RUN apt-get update && apt-get install -y ca-certificates
|
||||
RUN apt-get update && apt-get install -y ca-certificates rpm-build
|
||||
RUN useradd -m -s /bin/bash alr-user
|
||||
USER alr-user
|
||||
WORKDIR /home/alr-user
|
||||
ENTRYPOINT ["tail", "-f", "/dev/null"]
|
8
e2e-tests/images/Dockerfile.fedora-41
Normal file
8
e2e-tests/images/Dockerfile.fedora-41
Normal file
@ -0,0 +1,8 @@
|
||||
FROM fedora:41
|
||||
RUN dnf install -y ca-certificates sudo rpm-build
|
||||
RUN useradd -m -s /bin/bash alr-user && \
|
||||
echo "alr-user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/alr-user && \
|
||||
chmod 0440 /etc/sudoers.d/alr-user
|
||||
USER alr-user
|
||||
WORKDIR /home/alr-user
|
||||
ENTRYPOINT ["tail", "-f", "/dev/null"]
|
@ -1,5 +1,7 @@
|
||||
FROM ubuntu:24.10
|
||||
RUN apt update && apt install -y ca-certificates
|
||||
RUN useradd -m -s /bin/bash alr-user
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates sudo
|
||||
RUN useradd -m -s /bin/bash alr-user && \
|
||||
echo "alr-user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/alr-user && \
|
||||
chmod 0440 /etc/sudoers.d/alr-user
|
||||
USER alr-user
|
||||
ENTRYPOINT ["tail", "-f", "/dev/null"]
|
40
e2e-tests/issue_32_interactive_test.go
Normal file
40
e2e-tests/issue_32_interactive_test.go
Normal file
@ -0,0 +1,40 @@
|
||||
// ALR - Any Linux Repository
|
||||
// Copyright (C) 2025 Евгений Храмов
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//go:build e2e
|
||||
|
||||
package e2etests_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/alecthomas/assert/v2"
|
||||
"github.com/efficientgo/e2e"
|
||||
)
|
||||
|
||||
func TestE2EIssue32Interactive(t *testing.T) {
|
||||
dockerMultipleRun(
|
||||
t,
|
||||
"issue-32-interactive",
|
||||
COMMON_SYSTEMS,
|
||||
func(t *testing.T, r e2e.Runnable) {
|
||||
err := r.Exec(e2e.NewCommand(
|
||||
"alr", "--interactive=false", "remove", "ca-certificates",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
},
|
||||
)
|
||||
}
|
80
e2e-tests/issue_41_autoreq_skiplist_test.go
Normal file
80
e2e-tests/issue_41_autoreq_skiplist_test.go
Normal file
@ -0,0 +1,80 @@
|
||||
// ALR - Any Linux Repository
|
||||
// Copyright (C) 2025 Евгений Храмов
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//go:build e2e
|
||||
|
||||
package e2etests_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/alecthomas/assert/v2"
|
||||
"github.com/efficientgo/e2e"
|
||||
)
|
||||
|
||||
func TestE2EIssue41AutoreqSkiplist(t *testing.T) {
|
||||
dockerMultipleRun(
|
||||
t,
|
||||
"issue-41-autoreq-skiplist",
|
||||
AUTOREQ_AUTOPROV_SYSTEMS,
|
||||
func(t *testing.T, r e2e.Runnable) {
|
||||
err := r.Exec(e2e.NewCommand(
|
||||
"alr",
|
||||
"addrepo",
|
||||
"--name",
|
||||
"alr-repo",
|
||||
"--url",
|
||||
"https://gitea.plemya-x.ru/Maks1mS/repo-for-tests.git",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = r.Exec(e2e.NewCommand(
|
||||
"alr",
|
||||
"ref",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = r.Exec(e2e.NewCommand(
|
||||
"alr",
|
||||
"build",
|
||||
"-p",
|
||||
"alr-repo/test-autoreq-autoprov",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = r.Exec(e2e.NewCommand(
|
||||
"sh",
|
||||
"-c",
|
||||
"rpm -qp --requires *.rpm | grep \"^/bin/sh$\"",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = r.Exec(e2e.NewCommand(
|
||||
"sh",
|
||||
"-c",
|
||||
"rpm -qp --requires *.rpm | grep \"^/bin/bash$\"",
|
||||
))
|
||||
assert.Error(t, err)
|
||||
|
||||
err = r.Exec(e2e.NewCommand(
|
||||
"sh",
|
||||
"-c",
|
||||
"rpm -qp --requires *.rpm | grep \"^/bin/zsh$\"",
|
||||
))
|
||||
assert.Error(t, err)
|
||||
},
|
||||
)
|
||||
}
|
55
e2e-tests/issue_50_install_multiple_test.go
Normal file
55
e2e-tests/issue_50_install_multiple_test.go
Normal file
@ -0,0 +1,55 @@
|
||||
// ALR - Any Linux Repository
|
||||
// Copyright (C) 2025 Евгений Храмов
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//go:build e2e
|
||||
|
||||
package e2etests_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/alecthomas/assert/v2"
|
||||
"github.com/efficientgo/e2e"
|
||||
)
|
||||
|
||||
func TestE2EIssue50InstallMultiple(t *testing.T) {
|
||||
dockerMultipleRun(
|
||||
t,
|
||||
"issue-50-install-multiple",
|
||||
COMMON_SYSTEMS,
|
||||
func(t *testing.T, r e2e.Runnable) {
|
||||
err := r.Exec(e2e.NewCommand(
|
||||
"alr",
|
||||
"addrepo",
|
||||
"--name",
|
||||
"alr-repo",
|
||||
"--url",
|
||||
"https://gitea.plemya-x.ru/Maks1mS/repo-for-tests.git",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = r.Exec(e2e.NewCommand(
|
||||
"alr", "in", "foo-pkg", "bar-pkg",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = r.Exec(e2e.NewCommand("cat", "/opt/foo"))
|
||||
assert.NoError(t, err)
|
||||
err = r.Exec(e2e.NewCommand("cat", "/opt/bar"))
|
||||
assert.NoError(t, err)
|
||||
},
|
||||
)
|
||||
}
|
52
e2e-tests/issue_53_lc_all_c_info_test.go
Normal file
52
e2e-tests/issue_53_lc_all_c_info_test.go
Normal file
@ -0,0 +1,52 @@
|
||||
// ALR - Any Linux Repository
|
||||
// Copyright (C) 2025 Евгений Храмов
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//go:build e2e
|
||||
|
||||
package e2etests_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/alecthomas/assert/v2"
|
||||
"github.com/efficientgo/e2e"
|
||||
)
|
||||
|
||||
func TestE2EIssue53LcAllCInfo(t *testing.T) {
|
||||
dockerMultipleRun(
|
||||
t,
|
||||
"issue-53-lc-all-c-info",
|
||||
COMMON_SYSTEMS,
|
||||
func(t *testing.T, r e2e.Runnable) {
|
||||
err := r.Exec(e2e.NewCommand(
|
||||
"alr",
|
||||
"addrepo",
|
||||
"--name",
|
||||
"alr-repo",
|
||||
"--url",
|
||||
"https://gitea.plemya-x.ru/Plemya-x/alr-repo.git",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = r.Exec(e2e.NewCommand(
|
||||
"bash",
|
||||
"-c",
|
||||
"LANG=C alr info alr-bin",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
},
|
||||
)
|
||||
}
|
57
e2e-tests/issue_59_rm_completion_test.go
Normal file
57
e2e-tests/issue_59_rm_completion_test.go
Normal file
@ -0,0 +1,57 @@
|
||||
// ALR - Any Linux Repository
|
||||
// Copyright (C) 2025 Евгений Храмов
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//go:build e2e
|
||||
|
||||
package e2etests_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/alecthomas/assert/v2"
|
||||
"github.com/efficientgo/e2e"
|
||||
)
|
||||
|
||||
func TestE2EIssue59RmCompletion(t *testing.T) {
|
||||
dockerMultipleRun(
|
||||
t,
|
||||
"issue-59-rm-completion",
|
||||
COMMON_SYSTEMS,
|
||||
func(t *testing.T, r e2e.Runnable) {
|
||||
err := r.Exec(e2e.NewCommand(
|
||||
"alr",
|
||||
"addrepo",
|
||||
"--name",
|
||||
"alr-repo",
|
||||
"--url",
|
||||
"https://gitea.plemya-x.ru/Maks1mS/repo-for-tests.git",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = r.Exec(e2e.NewCommand(
|
||||
"alr", "in", "foo-pkg", "bar-pkg",
|
||||
))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = r.Exec(e2e.NewCommand("sh", "-c", "alr rm --generate-bash-completion | grep ^foo-pkg$"))
|
||||
assert.NoError(t, err)
|
||||
err = r.Exec(e2e.NewCommand("sh", "-c", "alr rm --generate-bash-completion | grep ^bar-pkg$"))
|
||||
assert.NoError(t, err)
|
||||
err = r.Exec(e2e.NewCommand("sh", "-c", "alr rm --generate-bash-completion | grep ^test-autoreq-autoprov$"))
|
||||
assert.Error(t, err)
|
||||
},
|
||||
)
|
||||
}
|
18
fix.go
18
fix.go
@ -38,11 +38,17 @@ func FixCmd() *cli.Command {
|
||||
Action: func(c *cli.Context) error {
|
||||
ctx := c.Context
|
||||
cfg := config.New()
|
||||
paths := cfg.GetPaths(ctx)
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
paths := cfg.GetPaths()
|
||||
|
||||
slog.Info(gotext.Get("Removing cache directory"))
|
||||
|
||||
err := os.RemoveAll(paths.CacheDir)
|
||||
err = os.RemoveAll(paths.CacheDir)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Unable to remove cache directory"), "err", err)
|
||||
os.Exit(1)
|
||||
@ -57,6 +63,12 @@ func FixCmd() *cli.Command {
|
||||
}
|
||||
|
||||
cfg = config.New()
|
||||
err = cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
err = db.Init(ctx)
|
||||
if err != nil {
|
||||
@ -64,7 +76,7 @@ func FixCmd() *cli.Command {
|
||||
os.Exit(1)
|
||||
}
|
||||
rs := repos.New(cfg, db)
|
||||
err = rs.Pull(ctx, cfg.Repos(ctx))
|
||||
err = rs.Pull(ctx, cfg.Repos())
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error pulling repos"), "err", err)
|
||||
os.Exit(1)
|
||||
|
4
go.mod
4
go.mod
@ -8,7 +8,9 @@ require (
|
||||
gitea.plemya-x.ru/Plemya-x/fakeroot v0.0.1
|
||||
github.com/AlecAivazis/survey/v2 v2.3.7
|
||||
github.com/PuerkitoBio/purell v1.2.0
|
||||
github.com/alecthomas/assert/v2 v2.2.1
|
||||
github.com/alecthomas/chroma/v2 v2.9.1
|
||||
github.com/caarlos0/env v3.5.0+incompatible
|
||||
github.com/charmbracelet/bubbles v0.20.0
|
||||
github.com/charmbracelet/bubbletea v1.2.4
|
||||
github.com/charmbracelet/lipgloss v1.0.0
|
||||
@ -48,6 +50,7 @@ require (
|
||||
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
|
||||
github.com/Microsoft/go-winio v0.6.1 // indirect
|
||||
github.com/ProtonMail/go-crypto v1.0.0 // indirect
|
||||
github.com/alecthomas/repr v0.2.0 // indirect
|
||||
github.com/andybalholm/brotli v1.0.4 // indirect
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb // indirect
|
||||
@ -81,6 +84,7 @@ require (
|
||||
github.com/goreleaser/fileglob v1.3.0 // indirect
|
||||
github.com/hashicorp/errwrap v1.0.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/hexops/gotextdiff v1.0.3 // indirect
|
||||
github.com/huandu/xstrings v1.3.3 // indirect
|
||||
github.com/imdario/mergo v0.3.16 // indirect
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -72,6 +72,8 @@ github.com/bodgit/sevenzip v1.3.0/go.mod h1:omwNcgZTEooWM8gA/IJ2Nk/+ZQ94+GsytRzO
|
||||
github.com/bodgit/windows v1.0.0 h1:rLQ/XjsleZvx4fR1tB/UxQrK+SJ2OFHzfPjLWWOhDIA=
|
||||
github.com/bodgit/windows v1.0.0/go.mod h1:a6JLwrB4KrTR5hBpp8FI9/9W9jJfeQ2h4XDXU74ZCdM=
|
||||
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
||||
github.com/caarlos0/env v3.5.0+incompatible h1:Yy0UN8o9Wtr/jGHZDpCBLpNrzcFLLM2yixi/rBrKyJs=
|
||||
github.com/caarlos0/env v3.5.0+incompatible/go.mod h1:tdCsowwCzMLdkqRYDlHpZCp2UooDD3MspDBjZ2AD02Y=
|
||||
github.com/caarlos0/testfs v0.4.4 h1:3PHvzHi5Lt+g332CiShwS8ogTgS3HjrmzZxCm6JCDr8=
|
||||
github.com/caarlos0/testfs v0.4.4/go.mod h1:bRN55zgG4XCUVVHZCeU+/Tz1Q6AxEJOEJTliBy+1DMk=
|
||||
github.com/cavaliergopher/cpio v1.0.1 h1:KQFSeKmZhv0cr+kawA3a0xTQCU4QxXF1vhU7P7av2KM=
|
||||
|
23
info.go
23
info.go
@ -51,8 +51,14 @@ func InfoCmd() *cli.Command {
|
||||
BashComplete: func(c *cli.Context) {
|
||||
ctx := c.Context
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
err := db.Init(ctx)
|
||||
err = db.Init(ctx)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error initialization database"), "err", err)
|
||||
os.Exit(1)
|
||||
@ -80,8 +86,14 @@ func InfoCmd() *cli.Command {
|
||||
ctx := c.Context
|
||||
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
err := db.Init(ctx)
|
||||
err = db.Init(ctx)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error initialization database"), "err", err)
|
||||
os.Exit(1)
|
||||
@ -94,8 +106,8 @@ func InfoCmd() *cli.Command {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if cfg.AutoPull(ctx) {
|
||||
err := rs.Pull(ctx, cfg.Repos(ctx))
|
||||
if cfg.AutoPull() {
|
||||
err := rs.Pull(ctx, cfg.Repos())
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error pulling repos"), "err", err)
|
||||
os.Exit(1)
|
||||
@ -122,6 +134,9 @@ func InfoCmd() *cli.Command {
|
||||
slog.Error("Can't detect system language", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if systemLang == "" {
|
||||
systemLang = "en"
|
||||
}
|
||||
|
||||
if !all {
|
||||
info, err := distro.ParseOSRelease(ctx)
|
||||
|
83
install.go
83
install.go
@ -65,16 +65,22 @@ func InstallCmd() *cli.Command {
|
||||
}
|
||||
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
rs := repos.New(cfg, db)
|
||||
err := db.Init(ctx)
|
||||
err = db.Init(ctx)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error initialization database"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if cfg.AutoPull(ctx) {
|
||||
err := rs.Pull(ctx, cfg.Repos(ctx))
|
||||
if cfg.AutoPull() {
|
||||
err := rs.Pull(ctx, cfg.Repos())
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error pulling repositories"), "err", err)
|
||||
os.Exit(1)
|
||||
@ -118,8 +124,14 @@ func InstallCmd() *cli.Command {
|
||||
},
|
||||
BashComplete: func(c *cli.Context) {
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
err := db.Init(c.Context)
|
||||
err = db.Init(c.Context)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error initialization database"), "err", err)
|
||||
os.Exit(1)
|
||||
@ -150,6 +162,64 @@ func RemoveCmd() *cli.Command {
|
||||
Name: "remove",
|
||||
Usage: gotext.Get("Remove an installed package"),
|
||||
Aliases: []string{"rm"},
|
||||
BashComplete: func(c *cli.Context) {
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
err = db.Init(c.Context)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error initialization database"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
installedAlrPackages := map[string]string{}
|
||||
mgr := manager.Detect()
|
||||
if mgr == nil {
|
||||
slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
|
||||
os.Exit(1)
|
||||
}
|
||||
installed, err := mgr.ListInstalled(&manager.Opts{AsRoot: false})
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error listing installed packages"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for pkgName, version := range installed {
|
||||
matches := build.RegexpALRPackageName.FindStringSubmatch(pkgName)
|
||||
if matches != nil {
|
||||
packageName := matches[build.RegexpALRPackageName.SubexpIndex("package")]
|
||||
repoName := matches[build.RegexpALRPackageName.SubexpIndex("repo")]
|
||||
installedAlrPackages[fmt.Sprintf("%s/%s", repoName, packageName)] = version
|
||||
}
|
||||
}
|
||||
|
||||
result, err := db.GetPkgs(c.Context, "true")
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error getting packages"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer result.Close()
|
||||
|
||||
for result.Next() {
|
||||
var pkg database.Package
|
||||
err = result.StructScan(&pkg)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error iterating over packages"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
_, ok := installedAlrPackages[fmt.Sprintf("%s/%s", pkg.Repository, pkg.Name)]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Println(pkg.Name)
|
||||
}
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
args := c.Args()
|
||||
if args.Len() < 1 {
|
||||
@ -163,7 +233,10 @@ func RemoveCmd() *cli.Command {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err := mgr.Remove(nil, c.Args().Slice()...)
|
||||
err := mgr.Remove(&manager.Opts{
|
||||
AsRoot: true,
|
||||
NoConfirm: !c.Bool("interactive"),
|
||||
}, c.Args().Slice()...)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error removing packages"), "err", err)
|
||||
os.Exit(1)
|
||||
|
@ -20,15 +20,14 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
"reflect"
|
||||
|
||||
"github.com/caarlos0/env"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
|
||||
)
|
||||
@ -36,16 +35,13 @@ import (
|
||||
type ALRConfig struct {
|
||||
cfg *types.Config
|
||||
paths *Paths
|
||||
|
||||
cfgOnce sync.Once
|
||||
pathsOnce sync.Once
|
||||
}
|
||||
|
||||
var defaultConfig = &types.Config{
|
||||
RootCmd: "sudo",
|
||||
PagerStyle: "native",
|
||||
IgnorePkgUpdates: []string{},
|
||||
AutoPull: false,
|
||||
AutoPull: true,
|
||||
Repos: []types.Repo{},
|
||||
}
|
||||
|
||||
@ -53,147 +49,152 @@ func New() *ALRConfig {
|
||||
return &ALRConfig{}
|
||||
}
|
||||
|
||||
func (c *ALRConfig) Load(ctx context.Context) {
|
||||
cfgFl, err := os.Open(c.GetPaths(ctx).ConfigPath)
|
||||
func readConfig(path string) (*types.Config, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
slog.Warn(gotext.Get("Error opening config file, using defaults"), "err", err)
|
||||
c.cfg = defaultConfig
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
defer cfgFl.Close()
|
||||
defer file.Close()
|
||||
|
||||
// Copy the default configuration into config
|
||||
defCopy := *defaultConfig
|
||||
config := &defCopy
|
||||
config.Repos = nil
|
||||
config := types.Config{}
|
||||
|
||||
err = toml.NewDecoder(cfgFl).Decode(config)
|
||||
if err != nil {
|
||||
slog.Warn(gotext.Get("Error decoding config file, using defaults"), "err", err)
|
||||
c.cfg = defaultConfig
|
||||
return
|
||||
if err := toml.NewDecoder(file).Decode(&config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.cfg = config
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
func (c *ALRConfig) initPaths() {
|
||||
paths := &Paths{}
|
||||
func mergeStructs(dst, src interface{}) {
|
||||
srcVal := reflect.ValueOf(src)
|
||||
if srcVal.IsNil() {
|
||||
return
|
||||
}
|
||||
srcVal = srcVal.Elem()
|
||||
dstVal := reflect.ValueOf(dst).Elem()
|
||||
|
||||
for i := range srcVal.NumField() {
|
||||
srcField := srcVal.Field(i)
|
||||
srcFieldName := srcVal.Type().Field(i).Name
|
||||
|
||||
dstField := dstVal.FieldByName(srcFieldName)
|
||||
if dstField.IsValid() && dstField.CanSet() {
|
||||
dstField.Set(srcField)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const systemConfigPath = "/etc/alr/alr.toml"
|
||||
|
||||
func (c *ALRConfig) Load() error {
|
||||
systemConfig, err := readConfig(
|
||||
systemConfigPath,
|
||||
)
|
||||
if err != nil {
|
||||
slog.Debug("Cannot read system config", "err", err)
|
||||
}
|
||||
|
||||
cfgDir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Unable to detect user config directory"), "err", err)
|
||||
os.Exit(1)
|
||||
slog.Debug("Cannot read user config directory")
|
||||
}
|
||||
userConfigPath := filepath.Join(cfgDir, "alr", "alr.toml")
|
||||
|
||||
paths.ConfigDir = filepath.Join(cfgDir, "alr")
|
||||
|
||||
err = os.MkdirAll(paths.ConfigDir, 0o755)
|
||||
userConfig, err := readConfig(
|
||||
userConfigPath,
|
||||
)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Unable to create ALR config directory"), "err", err)
|
||||
os.Exit(1)
|
||||
slog.Debug("Cannot read user config")
|
||||
}
|
||||
|
||||
paths.ConfigPath = filepath.Join(paths.ConfigDir, "alr.toml")
|
||||
config := &types.Config{}
|
||||
|
||||
if _, err := os.Stat(paths.ConfigPath); err != nil {
|
||||
cfgFl, err := os.Create(paths.ConfigPath)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Unable to create ALR config file"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = toml.NewEncoder(cfgFl).Encode(&defaultConfig)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error encoding default configuration"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cfgFl.Close()
|
||||
mergeStructs(config, defaultConfig)
|
||||
mergeStructs(config, systemConfig)
|
||||
mergeStructs(config, userConfig)
|
||||
err = env.Parse(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.cfg = config
|
||||
|
||||
cacheDir, err := os.UserCacheDir()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Unable to detect cache directory"), "err", err)
|
||||
return err
|
||||
}
|
||||
c.paths = &Paths{}
|
||||
c.paths.UserConfigPath = userConfigPath
|
||||
c.paths.CacheDir = filepath.Join(cacheDir, "alr")
|
||||
c.paths.RepoDir = filepath.Join(c.paths.CacheDir, "repo")
|
||||
c.paths.PkgsDir = filepath.Join(c.paths.CacheDir, "pkgs")
|
||||
c.paths.DBPath = filepath.Join(c.paths.CacheDir, "db")
|
||||
c.initPaths()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ALRConfig) RootCmd() string {
|
||||
return c.cfg.RootCmd
|
||||
}
|
||||
|
||||
func (c *ALRConfig) PagerStyle() string {
|
||||
return c.cfg.PagerStyle
|
||||
}
|
||||
|
||||
func (c *ALRConfig) AutoPull() bool {
|
||||
return c.cfg.AutoPull
|
||||
}
|
||||
|
||||
func (c *ALRConfig) AllowRunAsRoot() bool {
|
||||
return c.cfg.Unsafe.AllowRunAsRoot
|
||||
}
|
||||
|
||||
func (c *ALRConfig) Repos() []types.Repo {
|
||||
return c.cfg.Repos
|
||||
}
|
||||
|
||||
func (c *ALRConfig) SetRepos(repos []types.Repo) {
|
||||
c.cfg.Repos = repos
|
||||
}
|
||||
|
||||
func (c *ALRConfig) IgnorePkgUpdates() []string {
|
||||
return c.cfg.IgnorePkgUpdates
|
||||
}
|
||||
|
||||
func (c *ALRConfig) LogLevel() string {
|
||||
return c.cfg.LogLevel
|
||||
}
|
||||
|
||||
func (c *ALRConfig) GetPaths() *Paths {
|
||||
return c.paths
|
||||
}
|
||||
|
||||
func (c *ALRConfig) initPaths() {
|
||||
err := os.MkdirAll(filepath.Dir(c.paths.UserConfigPath), 0o755)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Unable to create config directory"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
paths.CacheDir = filepath.Join(cacheDir, "alr")
|
||||
paths.RepoDir = filepath.Join(paths.CacheDir, "repo")
|
||||
paths.PkgsDir = filepath.Join(paths.CacheDir, "pkgs")
|
||||
|
||||
err = os.MkdirAll(paths.RepoDir, 0o755)
|
||||
err = os.MkdirAll(c.paths.RepoDir, 0o755)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Unable to create repo cache directory"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = os.MkdirAll(paths.PkgsDir, 0o755)
|
||||
err = os.MkdirAll(c.paths.PkgsDir, 0o755)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Unable to create package cache directory"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
paths.DBPath = filepath.Join(paths.CacheDir, "db")
|
||||
|
||||
c.paths = paths
|
||||
}
|
||||
|
||||
func (c *ALRConfig) GetPaths(ctx context.Context) *Paths {
|
||||
c.pathsOnce.Do(func() {
|
||||
c.initPaths()
|
||||
})
|
||||
return c.paths
|
||||
}
|
||||
func (c *ALRConfig) SaveUserConfig() error {
|
||||
f, err := os.Create(c.paths.UserConfigPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *ALRConfig) Repos(ctx context.Context) []types.Repo {
|
||||
c.cfgOnce.Do(func() {
|
||||
c.Load(ctx)
|
||||
})
|
||||
return c.cfg.Repos
|
||||
}
|
||||
|
||||
func (c *ALRConfig) SetRepos(ctx context.Context, repos []types.Repo) {
|
||||
c.cfgOnce.Do(func() {
|
||||
c.Load(ctx)
|
||||
})
|
||||
c.cfg.Repos = repos
|
||||
}
|
||||
|
||||
func (c *ALRConfig) IgnorePkgUpdates(ctx context.Context) []string {
|
||||
c.cfgOnce.Do(func() {
|
||||
c.Load(ctx)
|
||||
})
|
||||
return c.cfg.IgnorePkgUpdates
|
||||
}
|
||||
|
||||
func (c *ALRConfig) AutoPull(ctx context.Context) bool {
|
||||
c.cfgOnce.Do(func() {
|
||||
c.Load(ctx)
|
||||
})
|
||||
return c.cfg.AutoPull
|
||||
}
|
||||
|
||||
func (c *ALRConfig) PagerStyle(ctx context.Context) string {
|
||||
c.cfgOnce.Do(func() {
|
||||
c.Load(ctx)
|
||||
})
|
||||
return c.cfg.PagerStyle
|
||||
}
|
||||
|
||||
func (c *ALRConfig) AllowRunAsRoot(ctx context.Context) bool {
|
||||
c.cfgOnce.Do(func() {
|
||||
c.Load(ctx)
|
||||
})
|
||||
return c.cfg.Unsafe.AllowRunAsRoot
|
||||
}
|
||||
|
||||
func (c *ALRConfig) RootCmd(ctx context.Context) string {
|
||||
c.cfgOnce.Do(func() {
|
||||
c.Load(ctx)
|
||||
})
|
||||
return c.cfg.RootCmd
|
||||
}
|
||||
|
||||
func (c *ALRConfig) Save(f *os.File) error {
|
||||
return toml.NewEncoder(f).Encode(c.cfg)
|
||||
}
|
||||
|
@ -21,10 +21,9 @@ package config
|
||||
|
||||
// Paths contains various paths used by ALR
|
||||
type Paths struct {
|
||||
ConfigDir string
|
||||
ConfigPath string
|
||||
CacheDir string
|
||||
RepoDir string
|
||||
PkgsDir string
|
||||
DBPath string
|
||||
UserConfigPath string
|
||||
CacheDir string
|
||||
RepoDir string
|
||||
PkgsDir string
|
||||
DBPath string
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ type version struct {
|
||||
}
|
||||
|
||||
type Config interface {
|
||||
GetPaths(ctx context.Context) *config.Paths
|
||||
GetPaths() *config.Paths
|
||||
}
|
||||
|
||||
type Database struct {
|
||||
@ -82,7 +82,7 @@ func (d *Database) Init(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (d *Database) Connect(ctx context.Context) error {
|
||||
dsn := d.config.GetPaths(ctx).DBPath
|
||||
dsn := d.config.GetPaths().DBPath
|
||||
db, err := sqlx.Open("sqlite", dsn)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -33,7 +33,7 @@ import (
|
||||
|
||||
type TestALRConfig struct{}
|
||||
|
||||
func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
|
||||
func (c *TestALRConfig) GetPaths() *config.Paths {
|
||||
return &config.Paths{
|
||||
DBPath: ":memory:",
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ import (
|
||||
|
||||
type TestALRConfig struct{}
|
||||
|
||||
func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
|
||||
func (c *TestALRConfig) GetPaths() *config.Paths {
|
||||
return &config.Paths{
|
||||
CacheDir: "/tmp",
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
type Config interface {
|
||||
GetPaths(ctx context.Context) *config.Paths
|
||||
GetPaths() *config.Paths
|
||||
}
|
||||
|
||||
type DownloadCache struct {
|
||||
@ -43,7 +43,7 @@ func New(cfg Config) *DownloadCache {
|
||||
|
||||
func (dc *DownloadCache) BasePath(ctx context.Context) string {
|
||||
return filepath.Join(
|
||||
dc.cfg.GetPaths(ctx).CacheDir, "dl",
|
||||
dc.cfg.GetPaths().CacheDir, "dl",
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ type TestALRConfig struct {
|
||||
CacheDir string
|
||||
}
|
||||
|
||||
func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
|
||||
func (c *TestALRConfig) GetPaths() *config.Paths {
|
||||
return &config.Paths{
|
||||
CacheDir: c.CacheDir,
|
||||
}
|
||||
|
@ -62,6 +62,25 @@ func New() *Logger {
|
||||
}
|
||||
}
|
||||
|
||||
func slogLevelToLog(level slog.Level) log.Level {
|
||||
switch level {
|
||||
case slog.LevelDebug:
|
||||
return log.DebugLevel
|
||||
case slog.LevelInfo:
|
||||
return log.InfoLevel
|
||||
case slog.LevelWarn:
|
||||
return log.WarnLevel
|
||||
case slog.LevelError:
|
||||
return log.ErrorLevel
|
||||
}
|
||||
return log.FatalLevel
|
||||
}
|
||||
|
||||
func (l *Logger) SetLevel(level slog.Level) {
|
||||
l.lOut.(*log.Logger).SetLevel(slogLevelToLog(level))
|
||||
l.lErr.(*log.Logger).SetLevel(slogLevelToLog(level))
|
||||
}
|
||||
|
||||
func (l *Logger) Enabled(ctx context.Context, level slog.Level) bool {
|
||||
if level <= slog.LevelInfo {
|
||||
return l.lOut.Enabled(ctx, level)
|
||||
@ -90,7 +109,9 @@ func (l *Logger) WithGroup(name string) slog.Handler {
|
||||
return &sl
|
||||
}
|
||||
|
||||
func SetupDefault() {
|
||||
logger := slog.New(New())
|
||||
func SetupDefault() *Logger {
|
||||
l := New()
|
||||
logger := slog.New(l)
|
||||
slog.SetDefault(logger)
|
||||
return l
|
||||
}
|
||||
|
@ -123,15 +123,29 @@ func (d *Decoder) DecodeVars(val any) error {
|
||||
}
|
||||
|
||||
rVal := reflect.ValueOf(val).Elem()
|
||||
return d.decodeStruct(rVal)
|
||||
}
|
||||
|
||||
func (d *Decoder) decodeStruct(rVal reflect.Value) error {
|
||||
for i := 0; i < rVal.NumField(); i++ {
|
||||
field := rVal.Field(i)
|
||||
fieldType := rVal.Type().Field(i)
|
||||
|
||||
// Пропускаем неэкспортируемые поля
|
||||
if !fieldType.IsExported() {
|
||||
continue
|
||||
}
|
||||
|
||||
// Обрабатываем встроенные поля рекурсивно
|
||||
if fieldType.Anonymous {
|
||||
if field.Kind() == reflect.Struct {
|
||||
if err := d.decodeStruct(field); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
name := fieldType.Name
|
||||
tag := fieldType.Tag.Get("sh")
|
||||
required := false
|
||||
@ -160,7 +174,6 @@ func (d *Decoder) DecodeVars(val any) error {
|
||||
|
||||
field.Set(newVal.Elem())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -30,35 +30,39 @@ msgid ""
|
||||
"Build package from scratch even if there's an already built package available"
|
||||
msgstr ""
|
||||
|
||||
#: build.go:75
|
||||
#: build.go:73
|
||||
msgid "Error loading config"
|
||||
msgstr ""
|
||||
|
||||
#: build.go:81
|
||||
msgid "Error initialization database"
|
||||
msgstr ""
|
||||
|
||||
#: build.go:104
|
||||
#: build.go:110
|
||||
msgid "Package not found"
|
||||
msgstr ""
|
||||
|
||||
#: build.go:124
|
||||
#: build.go:130
|
||||
msgid "Error pulling repositories"
|
||||
msgstr ""
|
||||
|
||||
#: build.go:132
|
||||
#: build.go:138
|
||||
msgid "Unable to detect a supported package manager on the system"
|
||||
msgstr ""
|
||||
|
||||
#: build.go:138
|
||||
#: build.go:144
|
||||
msgid "Error parsing os release"
|
||||
msgstr ""
|
||||
|
||||
#: build.go:160
|
||||
#: build.go:166
|
||||
msgid "Error building package"
|
||||
msgstr ""
|
||||
|
||||
#: build.go:167
|
||||
#: build.go:173
|
||||
msgid "Error getting working directory"
|
||||
msgstr ""
|
||||
|
||||
#: build.go:176
|
||||
#: build.go:182
|
||||
msgid "Error moving the package"
|
||||
msgstr ""
|
||||
|
||||
@ -66,27 +70,27 @@ msgstr ""
|
||||
msgid "Attempt to fix problems with ALR"
|
||||
msgstr ""
|
||||
|
||||
#: fix.go:43
|
||||
#: fix.go:49
|
||||
msgid "Removing cache directory"
|
||||
msgstr ""
|
||||
|
||||
#: fix.go:47
|
||||
#: fix.go:53
|
||||
msgid "Unable to remove cache directory"
|
||||
msgstr ""
|
||||
|
||||
#: fix.go:51
|
||||
#: fix.go:57
|
||||
msgid "Rebuilding cache"
|
||||
msgstr ""
|
||||
|
||||
#: fix.go:55
|
||||
#: fix.go:61
|
||||
msgid "Unable to create new cache directory"
|
||||
msgstr ""
|
||||
|
||||
#: fix.go:69
|
||||
#: fix.go:81
|
||||
msgid "Error pulling repos"
|
||||
msgstr ""
|
||||
|
||||
#: fix.go:73
|
||||
#: fix.go:85
|
||||
msgid "Done"
|
||||
msgstr ""
|
||||
|
||||
@ -122,31 +126,31 @@ msgstr ""
|
||||
msgid "Show all information, not just for the current distro"
|
||||
msgstr ""
|
||||
|
||||
#: info.go:63
|
||||
#: info.go:69
|
||||
msgid "Error getting packages"
|
||||
msgstr ""
|
||||
|
||||
#: info.go:72
|
||||
#: info.go:78
|
||||
msgid "Error iterating over packages"
|
||||
msgstr ""
|
||||
|
||||
#: info.go:93
|
||||
#: info.go:105
|
||||
msgid "Command info expected at least 1 argument, got %d"
|
||||
msgstr ""
|
||||
|
||||
#: info.go:107
|
||||
#: info.go:119
|
||||
msgid "Error finding packages"
|
||||
msgstr ""
|
||||
|
||||
#: info.go:129
|
||||
#: info.go:144
|
||||
msgid "Error parsing os-release file"
|
||||
msgstr ""
|
||||
|
||||
#: info.go:138
|
||||
#: info.go:153
|
||||
msgid "Error resolving overrides"
|
||||
msgstr ""
|
||||
|
||||
#: info.go:147 info.go:153
|
||||
#: info.go:162 info.go:168
|
||||
msgid "Error encoding script variables"
|
||||
msgstr ""
|
||||
|
||||
@ -158,15 +162,19 @@ msgstr ""
|
||||
msgid "Command install expected at least 1 argument, got %d"
|
||||
msgstr ""
|
||||
|
||||
#: install.go:151
|
||||
#: install.go:163
|
||||
msgid "Remove an installed package"
|
||||
msgstr ""
|
||||
|
||||
#: install.go:156
|
||||
#: install.go:188
|
||||
msgid "Error listing installed packages"
|
||||
msgstr ""
|
||||
|
||||
#: install.go:226
|
||||
msgid "Command remove expected at least 1 argument, got %d"
|
||||
msgstr ""
|
||||
|
||||
#: install.go:168
|
||||
#: install.go:241
|
||||
msgid "Error removing packages"
|
||||
msgstr ""
|
||||
|
||||
@ -250,39 +258,15 @@ msgstr ""
|
||||
msgid "OPTIONS"
|
||||
msgstr ""
|
||||
|
||||
#: internal/config/config.go:59
|
||||
msgid "Error opening config file, using defaults"
|
||||
#: internal/config/config.go:176
|
||||
msgid "Unable to create config directory"
|
||||
msgstr ""
|
||||
|
||||
#: internal/config/config.go:72
|
||||
msgid "Error decoding config file, using defaults"
|
||||
msgstr ""
|
||||
|
||||
#: internal/config/config.go:84
|
||||
msgid "Unable to detect user config directory"
|
||||
msgstr ""
|
||||
|
||||
#: internal/config/config.go:92
|
||||
msgid "Unable to create ALR config directory"
|
||||
msgstr ""
|
||||
|
||||
#: internal/config/config.go:101
|
||||
msgid "Unable to create ALR config file"
|
||||
msgstr ""
|
||||
|
||||
#: internal/config/config.go:107
|
||||
msgid "Error encoding default configuration"
|
||||
msgstr ""
|
||||
|
||||
#: internal/config/config.go:116
|
||||
msgid "Unable to detect cache directory"
|
||||
msgstr ""
|
||||
|
||||
#: internal/config/config.go:126
|
||||
#: internal/config/config.go:182
|
||||
msgid "Unable to create repo cache directory"
|
||||
msgstr ""
|
||||
|
||||
#: internal/config/config.go:132
|
||||
#: internal/config/config.go:188
|
||||
msgid "Unable to create package cache directory"
|
||||
msgstr ""
|
||||
|
||||
@ -327,10 +311,6 @@ msgstr ""
|
||||
msgid "List ALR repo packages"
|
||||
msgstr ""
|
||||
|
||||
#: list.go:92
|
||||
msgid "Error listing installed packages"
|
||||
msgstr ""
|
||||
|
||||
#: main.go:45
|
||||
msgid "Print the current ALR version and exit"
|
||||
msgstr ""
|
||||
@ -343,106 +323,106 @@ msgstr ""
|
||||
msgid "Enable interactive questions and prompts"
|
||||
msgstr ""
|
||||
|
||||
#: main.go:92
|
||||
#: main.go:96
|
||||
msgid ""
|
||||
"Running ALR as root is forbidden as it may cause catastrophic damage to your "
|
||||
"system"
|
||||
msgstr ""
|
||||
|
||||
#: main.go:125
|
||||
#: main.go:154
|
||||
msgid "Show help"
|
||||
msgstr ""
|
||||
|
||||
#: main.go:129
|
||||
#: main.go:158
|
||||
msgid "Error while running app"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:156
|
||||
#: pkg/build/build.go:157
|
||||
msgid "Failed to prompt user to view build script"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:160
|
||||
#: pkg/build/build.go:161
|
||||
msgid "Building package"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:208
|
||||
#: pkg/build/build.go:209
|
||||
msgid "The checksums array must be the same length as sources"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:235
|
||||
#: pkg/build/build.go:238
|
||||
msgid "Downloading sources"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:257
|
||||
#: pkg/build/build.go:260
|
||||
msgid "Building package metadata"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:279
|
||||
#: pkg/build/build.go:282
|
||||
msgid "Compressing package"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:438
|
||||
#: pkg/build/build.go:441
|
||||
msgid ""
|
||||
"Your system's CPU architecture doesn't match this package. Do you want to "
|
||||
"build anyway?"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:452
|
||||
#: pkg/build/build.go:455
|
||||
msgid "This package is already installed"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:476
|
||||
#: pkg/build/build.go:479
|
||||
msgid "Installing build dependencies"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:517
|
||||
#: pkg/build/build.go:524
|
||||
msgid "Installing dependencies"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:598
|
||||
#: pkg/build/build.go:605
|
||||
msgid "Would you like to remove the build dependencies?"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:661
|
||||
#: pkg/build/build.go:668
|
||||
msgid "Executing prepare()"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:671
|
||||
#: pkg/build/build.go:678
|
||||
msgid "Executing build()"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:701 pkg/build/build.go:721
|
||||
#: pkg/build/build.go:708 pkg/build/build.go:728
|
||||
msgid "Executing %s()"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:780
|
||||
#: pkg/build/build.go:787
|
||||
msgid "Error installing native packages"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:804
|
||||
#: pkg/build/build.go:811
|
||||
msgid "Error installing package"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:863
|
||||
msgid "AutoProv is not implemented for this package format, so it's skipped"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/build.go:874
|
||||
msgid "AutoReq is not implemented for this package format, so it's skipped"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/findDeps.go:35
|
||||
#: pkg/build/find_deps/alt_linux.go:35
|
||||
msgid "Command not found on the system"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/findDeps.go:82
|
||||
#: pkg/build/find_deps/alt_linux.go:86
|
||||
msgid "Provided dependency found"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/findDeps.go:89
|
||||
#: pkg/build/find_deps/alt_linux.go:93
|
||||
msgid "Required dependency found"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/find_deps/empty.go:32
|
||||
msgid "AutoProv is not implemented for this package format, so it's skipped"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/build/find_deps/empty.go:37
|
||||
msgid "AutoReq is not implemented for this package format, so it's skipped"
|
||||
msgstr ""
|
||||
|
||||
#: pkg/repos/pull.go:79
|
||||
msgid "Pulling repository"
|
||||
msgstr ""
|
||||
@ -461,47 +441,43 @@ msgid ""
|
||||
"updating ALR if something doesn't work."
|
||||
msgstr ""
|
||||
|
||||
#: repo.go:41
|
||||
#: repo.go:40
|
||||
msgid "Add a new repository"
|
||||
msgstr ""
|
||||
|
||||
#: repo.go:48
|
||||
#: repo.go:47
|
||||
msgid "Name of the new repo"
|
||||
msgstr ""
|
||||
|
||||
#: repo.go:54
|
||||
#: repo.go:53
|
||||
msgid "URL of the new repo"
|
||||
msgstr ""
|
||||
|
||||
#: repo.go:82 repo.go:147
|
||||
msgid "Error opening config file"
|
||||
#: repo.go:86 repo.go:156
|
||||
msgid "Error saving config"
|
||||
msgstr ""
|
||||
|
||||
#: repo.go:88 repo.go:153
|
||||
msgid "Error encoding config"
|
||||
msgstr ""
|
||||
|
||||
#: repo.go:113
|
||||
#: repo.go:111
|
||||
msgid "Remove an existing repository"
|
||||
msgstr ""
|
||||
|
||||
#: repo.go:120
|
||||
#: repo.go:118
|
||||
msgid "Name of the repo to be deleted"
|
||||
msgstr ""
|
||||
|
||||
#: repo.go:139
|
||||
#: repo.go:142
|
||||
msgid "Repo does not exist"
|
||||
msgstr ""
|
||||
|
||||
#: repo.go:159
|
||||
#: repo.go:150
|
||||
msgid "Error removing repo directory"
|
||||
msgstr ""
|
||||
|
||||
#: repo.go:170
|
||||
#: repo.go:167
|
||||
msgid "Error removing packages from database"
|
||||
msgstr ""
|
||||
|
||||
#: repo.go:182
|
||||
#: repo.go:179
|
||||
msgid "Pull all repositories that have changed"
|
||||
msgstr ""
|
||||
|
||||
@ -529,11 +505,11 @@ msgstr ""
|
||||
msgid "Format output using a Go template"
|
||||
msgstr ""
|
||||
|
||||
#: search.go:82 search.go:99
|
||||
#: search.go:88 search.go:105
|
||||
msgid "Error parsing format template"
|
||||
msgstr ""
|
||||
|
||||
#: search.go:107
|
||||
#: search.go:113
|
||||
msgid "Error executing template"
|
||||
msgstr ""
|
||||
|
||||
@ -541,10 +517,10 @@ msgstr ""
|
||||
msgid "Upgrade all installed packages"
|
||||
msgstr ""
|
||||
|
||||
#: upgrade.go:90
|
||||
#: upgrade.go:96
|
||||
msgid "Error checking for updates"
|
||||
msgstr ""
|
||||
|
||||
#: upgrade.go:112
|
||||
#: upgrade.go:118
|
||||
msgid "There is nothing to do."
|
||||
msgstr ""
|
||||
|
@ -37,35 +37,40 @@ msgid ""
|
||||
"Build package from scratch even if there's an already built package available"
|
||||
msgstr "Создайте пакет с нуля, даже если уже имеется готовый пакет"
|
||||
|
||||
#: build.go:75
|
||||
#: build.go:73
|
||||
#, fuzzy
|
||||
msgid "Error loading config"
|
||||
msgstr "Ошибка при кодировании конфигурации"
|
||||
|
||||
#: build.go:81
|
||||
msgid "Error initialization database"
|
||||
msgstr "Ошибка инициализации базы данных"
|
||||
|
||||
#: build.go:104
|
||||
#: build.go:110
|
||||
msgid "Package not found"
|
||||
msgstr "Пакет не найден"
|
||||
|
||||
#: build.go:124
|
||||
#: build.go:130
|
||||
msgid "Error pulling repositories"
|
||||
msgstr "Ошибка при извлечении репозиториев"
|
||||
|
||||
#: build.go:132
|
||||
#: build.go:138
|
||||
msgid "Unable to detect a supported package manager on the system"
|
||||
msgstr "Не удалось обнаружить поддерживаемый менеджер пакетов в системе"
|
||||
|
||||
#: build.go:138
|
||||
#: build.go:144
|
||||
msgid "Error parsing os release"
|
||||
msgstr "Ошибка при разборе файла выпуска операционной системы"
|
||||
|
||||
#: build.go:160
|
||||
#: build.go:166
|
||||
msgid "Error building package"
|
||||
msgstr "Ошибка при сборке пакета"
|
||||
|
||||
#: build.go:167
|
||||
#: build.go:173
|
||||
msgid "Error getting working directory"
|
||||
msgstr "Ошибка при получении рабочего каталога"
|
||||
|
||||
#: build.go:176
|
||||
#: build.go:182
|
||||
msgid "Error moving the package"
|
||||
msgstr "Ошибка при перемещении пакета"
|
||||
|
||||
@ -73,27 +78,27 @@ msgstr "Ошибка при перемещении пакета"
|
||||
msgid "Attempt to fix problems with ALR"
|
||||
msgstr "Попытка устранить проблемы с ALR"
|
||||
|
||||
#: fix.go:43
|
||||
#: fix.go:49
|
||||
msgid "Removing cache directory"
|
||||
msgstr "Удаление каталога кэша"
|
||||
|
||||
#: fix.go:47
|
||||
#: fix.go:53
|
||||
msgid "Unable to remove cache directory"
|
||||
msgstr "Не удалось удалить каталог кэша"
|
||||
|
||||
#: fix.go:51
|
||||
#: fix.go:57
|
||||
msgid "Rebuilding cache"
|
||||
msgstr "Восстановление кэша"
|
||||
|
||||
#: fix.go:55
|
||||
#: fix.go:61
|
||||
msgid "Unable to create new cache directory"
|
||||
msgstr "Не удалось создать новый каталог кэша"
|
||||
|
||||
#: fix.go:69
|
||||
#: fix.go:81
|
||||
msgid "Error pulling repos"
|
||||
msgstr "Ошибка при извлечении репозиториев"
|
||||
|
||||
#: fix.go:73
|
||||
#: fix.go:85
|
||||
msgid "Done"
|
||||
msgstr "Сделано"
|
||||
|
||||
@ -129,31 +134,31 @@ msgstr "Отобразить информацию о пакете"
|
||||
msgid "Show all information, not just for the current distro"
|
||||
msgstr "Показывать всю информацию, не только для текущего дистрибутива"
|
||||
|
||||
#: info.go:63
|
||||
#: info.go:69
|
||||
msgid "Error getting packages"
|
||||
msgstr "Ошибка при получении пакетов"
|
||||
|
||||
#: info.go:72
|
||||
#: info.go:78
|
||||
msgid "Error iterating over packages"
|
||||
msgstr "Ошибка при переборе пакетов"
|
||||
|
||||
#: info.go:93
|
||||
#: info.go:105
|
||||
msgid "Command info expected at least 1 argument, got %d"
|
||||
msgstr "Для команды info ожидался хотя бы 1 аргумент, получено %d"
|
||||
|
||||
#: info.go:107
|
||||
#: info.go:119
|
||||
msgid "Error finding packages"
|
||||
msgstr "Ошибка при поиске пакетов"
|
||||
|
||||
#: info.go:129
|
||||
#: info.go:144
|
||||
msgid "Error parsing os-release file"
|
||||
msgstr "Ошибка при разборе файла выпуска операционной системы"
|
||||
|
||||
#: info.go:138
|
||||
#: info.go:153
|
||||
msgid "Error resolving overrides"
|
||||
msgstr "Ошибка устранения переорпеделений"
|
||||
|
||||
#: info.go:147 info.go:153
|
||||
#: info.go:162 info.go:168
|
||||
msgid "Error encoding script variables"
|
||||
msgstr "Ошибка кодирования переменных скрита"
|
||||
|
||||
@ -165,15 +170,19 @@ msgstr "Установить новый пакет"
|
||||
msgid "Command install expected at least 1 argument, got %d"
|
||||
msgstr "Для команды install ожидался хотя бы 1 аргумент, получено %d"
|
||||
|
||||
#: install.go:151
|
||||
#: install.go:163
|
||||
msgid "Remove an installed package"
|
||||
msgstr "Удалить установленный пакет"
|
||||
|
||||
#: install.go:156
|
||||
#: install.go:188
|
||||
msgid "Error listing installed packages"
|
||||
msgstr "Ошибка при составлении списка установленных пакетов"
|
||||
|
||||
#: install.go:226
|
||||
msgid "Command remove expected at least 1 argument, got %d"
|
||||
msgstr "Для команды remove ожидался хотя бы 1 аргумент, получено %d"
|
||||
|
||||
#: install.go:168
|
||||
#: install.go:241
|
||||
msgid "Error removing packages"
|
||||
msgstr "Ошибка при удалении пакетов"
|
||||
|
||||
@ -257,43 +266,16 @@ msgstr "КАТЕГОРИЯ"
|
||||
msgid "OPTIONS"
|
||||
msgstr "ПАРАМЕТРЫ"
|
||||
|
||||
#: internal/config/config.go:59
|
||||
msgid "Error opening config file, using defaults"
|
||||
msgstr ""
|
||||
"Ошибка при открытии конфигурационного файла, используются значения по "
|
||||
"умолчанию"
|
||||
|
||||
#: internal/config/config.go:72
|
||||
msgid "Error decoding config file, using defaults"
|
||||
msgstr ""
|
||||
"Ошибка при декодировании конфигурационного файла, используются значения по "
|
||||
"умолчанию"
|
||||
|
||||
#: internal/config/config.go:84
|
||||
msgid "Unable to detect user config directory"
|
||||
msgstr "Не удалось обнаружить каталог конфигурации пользователя"
|
||||
|
||||
#: internal/config/config.go:92
|
||||
msgid "Unable to create ALR config directory"
|
||||
#: internal/config/config.go:176
|
||||
#, fuzzy
|
||||
msgid "Unable to create config directory"
|
||||
msgstr "Не удалось создать каталог конфигурации ALR"
|
||||
|
||||
#: internal/config/config.go:101
|
||||
msgid "Unable to create ALR config file"
|
||||
msgstr "Не удалось создать конфигурационный файл ALR"
|
||||
|
||||
#: internal/config/config.go:107
|
||||
msgid "Error encoding default configuration"
|
||||
msgstr "Ошибка кодирования конфигурации по умолчанию"
|
||||
|
||||
#: internal/config/config.go:116
|
||||
msgid "Unable to detect cache directory"
|
||||
msgstr "Не удалось обнаружить каталог кэша"
|
||||
|
||||
#: internal/config/config.go:126
|
||||
#: internal/config/config.go:182
|
||||
msgid "Unable to create repo cache directory"
|
||||
msgstr "Не удалось создать каталог кэша репозитория"
|
||||
|
||||
#: internal/config/config.go:132
|
||||
#: internal/config/config.go:188
|
||||
msgid "Unable to create package cache directory"
|
||||
msgstr "Не удалось создать каталог кэша пакетов"
|
||||
|
||||
@ -339,10 +321,6 @@ msgstr "ОШИБКА"
|
||||
msgid "List ALR repo packages"
|
||||
msgstr "Список пакетов репозитория ALR"
|
||||
|
||||
#: list.go:92
|
||||
msgid "Error listing installed packages"
|
||||
msgstr "Ошибка при составлении списка установленных пакетов"
|
||||
|
||||
#: main.go:45
|
||||
msgid "Print the current ALR version and exit"
|
||||
msgstr "Показать текущую версию ALR и выйти"
|
||||
@ -355,7 +333,7 @@ msgstr "Аргументы, которые будут переданы мене
|
||||
msgid "Enable interactive questions and prompts"
|
||||
msgstr "Включение интерактивных вопросов и запросов"
|
||||
|
||||
#: main.go:92
|
||||
#: main.go:96
|
||||
msgid ""
|
||||
"Running ALR as root is forbidden as it may cause catastrophic damage to your "
|
||||
"system"
|
||||
@ -363,39 +341,39 @@ msgstr ""
|
||||
"Запуск ALR от имени root запрещён, так как это может привести к "
|
||||
"катастрофическому повреждению вашей системы"
|
||||
|
||||
#: main.go:125
|
||||
#: main.go:154
|
||||
msgid "Show help"
|
||||
msgstr "Показать справку"
|
||||
|
||||
#: main.go:129
|
||||
#: main.go:158
|
||||
msgid "Error while running app"
|
||||
msgstr "Ошибка при запуске приложения"
|
||||
|
||||
#: pkg/build/build.go:156
|
||||
#: pkg/build/build.go:157
|
||||
msgid "Failed to prompt user to view build script"
|
||||
msgstr "Не удалось предложить пользователю просмотреть скрипт сборки"
|
||||
|
||||
#: pkg/build/build.go:160
|
||||
#: pkg/build/build.go:161
|
||||
msgid "Building package"
|
||||
msgstr "Сборка пакета"
|
||||
|
||||
#: pkg/build/build.go:208
|
||||
#: pkg/build/build.go:209
|
||||
msgid "The checksums array must be the same length as sources"
|
||||
msgstr "Массив контрольных сумм должен быть той же длины, что и источники"
|
||||
|
||||
#: pkg/build/build.go:235
|
||||
#: pkg/build/build.go:238
|
||||
msgid "Downloading sources"
|
||||
msgstr "Скачивание источников"
|
||||
|
||||
#: pkg/build/build.go:257
|
||||
#: pkg/build/build.go:260
|
||||
msgid "Building package metadata"
|
||||
msgstr "Сборка метаданных пакета"
|
||||
|
||||
#: pkg/build/build.go:279
|
||||
#: pkg/build/build.go:282
|
||||
msgid "Compressing package"
|
||||
msgstr "Сжатие пакета"
|
||||
|
||||
#: pkg/build/build.go:438
|
||||
#: pkg/build/build.go:441
|
||||
msgid ""
|
||||
"Your system's CPU architecture doesn't match this package. Do you want to "
|
||||
"build anyway?"
|
||||
@ -403,64 +381,64 @@ msgstr ""
|
||||
"Архитектура процессора вашей системы не соответствует этому пакету. Вы все "
|
||||
"равно хотите выполнить сборку?"
|
||||
|
||||
#: pkg/build/build.go:452
|
||||
#: pkg/build/build.go:455
|
||||
msgid "This package is already installed"
|
||||
msgstr "Этот пакет уже установлен"
|
||||
|
||||
#: pkg/build/build.go:476
|
||||
#: pkg/build/build.go:479
|
||||
msgid "Installing build dependencies"
|
||||
msgstr "Установка зависимостей сборки"
|
||||
|
||||
#: pkg/build/build.go:517
|
||||
#: pkg/build/build.go:524
|
||||
msgid "Installing dependencies"
|
||||
msgstr "Установка зависимостей"
|
||||
|
||||
#: pkg/build/build.go:598
|
||||
#: pkg/build/build.go:605
|
||||
msgid "Would you like to remove the build dependencies?"
|
||||
msgstr "Хотели бы вы удалить зависимости сборки?"
|
||||
|
||||
#: pkg/build/build.go:661
|
||||
#: pkg/build/build.go:668
|
||||
msgid "Executing prepare()"
|
||||
msgstr "Исполнение prepare()"
|
||||
|
||||
#: pkg/build/build.go:671
|
||||
#: pkg/build/build.go:678
|
||||
msgid "Executing build()"
|
||||
msgstr "Исполнение build()"
|
||||
|
||||
#: pkg/build/build.go:701 pkg/build/build.go:721
|
||||
#: pkg/build/build.go:708 pkg/build/build.go:728
|
||||
msgid "Executing %s()"
|
||||
msgstr "Исполнение %s()"
|
||||
|
||||
#: pkg/build/build.go:780
|
||||
#: pkg/build/build.go:787
|
||||
msgid "Error installing native packages"
|
||||
msgstr "Ошибка при установке нативных пакетов"
|
||||
|
||||
#: pkg/build/build.go:804
|
||||
#: pkg/build/build.go:811
|
||||
msgid "Error installing package"
|
||||
msgstr "Ошибка при установке пакета"
|
||||
|
||||
#: pkg/build/build.go:863
|
||||
#: pkg/build/find_deps/alt_linux.go:35
|
||||
msgid "Command not found on the system"
|
||||
msgstr "Команда не найдена в системе"
|
||||
|
||||
#: pkg/build/find_deps/alt_linux.go:86
|
||||
msgid "Provided dependency found"
|
||||
msgstr "Найденная предоставленная зависимость"
|
||||
|
||||
#: pkg/build/find_deps/alt_linux.go:93
|
||||
msgid "Required dependency found"
|
||||
msgstr "Найдена требуемая зависимость"
|
||||
|
||||
#: pkg/build/find_deps/empty.go:32
|
||||
msgid "AutoProv is not implemented for this package format, so it's skipped"
|
||||
msgstr ""
|
||||
"AutoProv не реализовано для этого формата пакета, поэтому будет пропущено"
|
||||
|
||||
#: pkg/build/build.go:874
|
||||
#: pkg/build/find_deps/empty.go:37
|
||||
msgid "AutoReq is not implemented for this package format, so it's skipped"
|
||||
msgstr ""
|
||||
"AutoReq не реализовано для этого формата пакета, поэтому будет пропущено"
|
||||
|
||||
#: pkg/build/findDeps.go:35
|
||||
msgid "Command not found on the system"
|
||||
msgstr "Команда не найдена в системе"
|
||||
|
||||
#: pkg/build/findDeps.go:82
|
||||
msgid "Provided dependency found"
|
||||
msgstr "Найденная предоставленная зависимость"
|
||||
|
||||
#: pkg/build/findDeps.go:89
|
||||
msgid "Required dependency found"
|
||||
msgstr "Найдена требуемая зависимость"
|
||||
|
||||
#: pkg/repos/pull.go:79
|
||||
msgid "Pulling repository"
|
||||
msgstr "Скачивание репозитория"
|
||||
@ -481,47 +459,44 @@ msgstr ""
|
||||
"Минимальная версия ALR для ALR-репозитория выше текущей версии. Попробуйте "
|
||||
"обновить ALR, если что-то не работает."
|
||||
|
||||
#: repo.go:41
|
||||
#: repo.go:40
|
||||
msgid "Add a new repository"
|
||||
msgstr "Добавить новый репозиторий"
|
||||
|
||||
#: repo.go:48
|
||||
#: repo.go:47
|
||||
msgid "Name of the new repo"
|
||||
msgstr "Название нового репозитория"
|
||||
|
||||
#: repo.go:54
|
||||
#: repo.go:53
|
||||
msgid "URL of the new repo"
|
||||
msgstr "URL-адрес нового репозитория"
|
||||
|
||||
#: repo.go:82 repo.go:147
|
||||
msgid "Error opening config file"
|
||||
msgstr "Ошибка при открытии конфигурационного файла"
|
||||
|
||||
#: repo.go:88 repo.go:153
|
||||
msgid "Error encoding config"
|
||||
#: repo.go:86 repo.go:156
|
||||
#, fuzzy
|
||||
msgid "Error saving config"
|
||||
msgstr "Ошибка при кодировании конфигурации"
|
||||
|
||||
#: repo.go:113
|
||||
#: repo.go:111
|
||||
msgid "Remove an existing repository"
|
||||
msgstr "Удалить существующий репозиторий"
|
||||
|
||||
#: repo.go:120
|
||||
#: repo.go:118
|
||||
msgid "Name of the repo to be deleted"
|
||||
msgstr "Название репозитория удалён"
|
||||
|
||||
#: repo.go:139
|
||||
#: repo.go:142
|
||||
msgid "Repo does not exist"
|
||||
msgstr "Репозитория не существует"
|
||||
|
||||
#: repo.go:159
|
||||
#: repo.go:150
|
||||
msgid "Error removing repo directory"
|
||||
msgstr "Ошибка при удалении каталога репозитория"
|
||||
|
||||
#: repo.go:170
|
||||
#: repo.go:167
|
||||
msgid "Error removing packages from database"
|
||||
msgstr "Ошибка при удалении пакетов из базы данных"
|
||||
|
||||
#: repo.go:182
|
||||
#: repo.go:179
|
||||
msgid "Pull all repositories that have changed"
|
||||
msgstr "Скачать все изменённые репозитории"
|
||||
|
||||
@ -549,11 +524,11 @@ msgstr "Иcкать по provides"
|
||||
msgid "Format output using a Go template"
|
||||
msgstr "Формат выходных данных с использованием шаблона Go"
|
||||
|
||||
#: search.go:82 search.go:99
|
||||
#: search.go:88 search.go:105
|
||||
msgid "Error parsing format template"
|
||||
msgstr "Ошибка при разборе шаблона"
|
||||
|
||||
#: search.go:107
|
||||
#: search.go:113
|
||||
msgid "Error executing template"
|
||||
msgstr "Ошибка при выполнении шаблона"
|
||||
|
||||
@ -561,14 +536,39 @@ msgstr "Ошибка при выполнении шаблона"
|
||||
msgid "Upgrade all installed packages"
|
||||
msgstr "Обновить все установленные пакеты"
|
||||
|
||||
#: upgrade.go:90
|
||||
#: upgrade.go:96
|
||||
msgid "Error checking for updates"
|
||||
msgstr "Ошибка при проверке обновлений"
|
||||
|
||||
#: upgrade.go:112
|
||||
#: upgrade.go:118
|
||||
msgid "There is nothing to do."
|
||||
msgstr "Здесь нечего делать."
|
||||
|
||||
#~ msgid "Error opening config file, using defaults"
|
||||
#~ msgstr ""
|
||||
#~ "Ошибка при открытии конфигурационного файла, используются значения по "
|
||||
#~ "умолчанию"
|
||||
|
||||
#~ msgid "Error decoding config file, using defaults"
|
||||
#~ msgstr ""
|
||||
#~ "Ошибка при декодировании конфигурационного файла, используются значения "
|
||||
#~ "по умолчанию"
|
||||
|
||||
#~ msgid "Unable to detect user config directory"
|
||||
#~ msgstr "Не удалось обнаружить каталог конфигурации пользователя"
|
||||
|
||||
#~ msgid "Unable to create ALR config file"
|
||||
#~ msgstr "Не удалось создать конфигурационный файл ALR"
|
||||
|
||||
#~ msgid "Error encoding default configuration"
|
||||
#~ msgstr "Ошибка кодирования конфигурации по умолчанию"
|
||||
|
||||
#~ msgid "Unable to detect cache directory"
|
||||
#~ msgstr "Не удалось обнаружить каталог кэша"
|
||||
|
||||
#~ msgid "Error opening config file"
|
||||
#~ msgstr "Ошибка при открытии конфигурационного файла"
|
||||
|
||||
#~ msgid "Error parsing system language"
|
||||
#~ msgstr "Ошибка при парсинге языка системы"
|
||||
|
||||
|
@ -31,79 +31,44 @@ type BuildOpts struct {
|
||||
}
|
||||
|
||||
type BuildVarsPre struct {
|
||||
Version string `sh:"version,required"`
|
||||
Release int `sh:"release,required"`
|
||||
Epoch uint `sh:"epoch"`
|
||||
Description string `sh:"desc"`
|
||||
Homepage string `sh:"homepage"`
|
||||
Maintainer string `sh:"maintainer"`
|
||||
Architectures []string `sh:"architectures"`
|
||||
Licenses []string `sh:"license"`
|
||||
Provides []string `sh:"provides"`
|
||||
Conflicts []string `sh:"conflicts"`
|
||||
Depends []string `sh:"deps"`
|
||||
BuildDepends []string `sh:"build_deps"`
|
||||
OptDepends []string `sh:"opt_deps"`
|
||||
Replaces []string `sh:"replaces"`
|
||||
Sources []string `sh:"sources"`
|
||||
Checksums []string `sh:"checksums"`
|
||||
Backup []string `sh:"backup"`
|
||||
Scripts Scripts `sh:"scripts"`
|
||||
AutoReq []string `sh:"auto_req"`
|
||||
AutoProv []string `sh:"auto_prov"`
|
||||
Version string `sh:"version,required"`
|
||||
Release int `sh:"release,required"`
|
||||
Epoch uint `sh:"epoch"`
|
||||
Description string `sh:"desc"`
|
||||
Homepage string `sh:"homepage"`
|
||||
Maintainer string `sh:"maintainer"`
|
||||
Architectures []string `sh:"architectures"`
|
||||
Licenses []string `sh:"license"`
|
||||
Provides []string `sh:"provides"`
|
||||
Conflicts []string `sh:"conflicts"`
|
||||
Depends []string `sh:"deps"`
|
||||
BuildDepends []string `sh:"build_deps"`
|
||||
OptDepends []string `sh:"opt_deps"`
|
||||
Replaces []string `sh:"replaces"`
|
||||
Sources []string `sh:"sources"`
|
||||
Checksums []string `sh:"checksums"`
|
||||
Backup []string `sh:"backup"`
|
||||
Scripts Scripts `sh:"scripts"`
|
||||
AutoReq []string `sh:"auto_req"`
|
||||
AutoProv []string `sh:"auto_prov"`
|
||||
AutoReqSkipList []string `sh:"auto_req_skiplist"`
|
||||
AutoProvSkipList []string `sh:"auto_prov_skiplist"`
|
||||
}
|
||||
|
||||
func (bv *BuildVarsPre) ToBuildVars() BuildVars {
|
||||
return BuildVars{
|
||||
Name: "",
|
||||
Version: bv.Version,
|
||||
Release: bv.Release,
|
||||
Epoch: bv.Epoch,
|
||||
Description: bv.Description,
|
||||
Homepage: bv.Homepage,
|
||||
Maintainer: bv.Maintainer,
|
||||
Architectures: bv.Architectures,
|
||||
Licenses: bv.Licenses,
|
||||
Provides: bv.Provides,
|
||||
Conflicts: bv.Conflicts,
|
||||
Depends: bv.Depends,
|
||||
BuildDepends: bv.BuildDepends,
|
||||
OptDepends: bv.OptDepends,
|
||||
Replaces: bv.Replaces,
|
||||
Sources: bv.Sources,
|
||||
Checksums: bv.Checksums,
|
||||
Backup: bv.Backup,
|
||||
Scripts: bv.Scripts,
|
||||
AutoReq: bv.AutoReq,
|
||||
AutoProv: bv.AutoProv,
|
||||
Name: "",
|
||||
Base: "",
|
||||
BuildVarsPre: *bv,
|
||||
}
|
||||
}
|
||||
|
||||
// BuildVars represents the script variables required
|
||||
// to build a package
|
||||
type BuildVars struct {
|
||||
Name string `sh:"name,required"`
|
||||
Version string `sh:"version,required"`
|
||||
Release int `sh:"release,required"`
|
||||
Epoch uint `sh:"epoch"`
|
||||
Description string `sh:"desc"`
|
||||
Homepage string `sh:"homepage"`
|
||||
Maintainer string `sh:"maintainer"`
|
||||
Architectures []string `sh:"architectures"`
|
||||
Licenses []string `sh:"license"`
|
||||
Provides []string `sh:"provides"`
|
||||
Conflicts []string `sh:"conflicts"`
|
||||
Depends []string `sh:"deps"`
|
||||
BuildDepends []string `sh:"build_deps"`
|
||||
OptDepends []string `sh:"opt_deps"`
|
||||
Replaces []string `sh:"replaces"`
|
||||
Sources []string `sh:"sources"`
|
||||
Checksums []string `sh:"checksums"`
|
||||
Backup []string `sh:"backup"`
|
||||
Scripts Scripts `sh:"scripts"`
|
||||
AutoReq []string `sh:"auto_req"`
|
||||
AutoProv []string `sh:"auto_prov"`
|
||||
Base string
|
||||
Name string `sh:"name,required"`
|
||||
Base string
|
||||
BuildVarsPre
|
||||
}
|
||||
|
||||
type Scripts struct {
|
||||
|
@ -21,12 +21,13 @@ package types
|
||||
|
||||
// Config represents the ALR configuration file
|
||||
type Config struct {
|
||||
RootCmd string `toml:"rootCmd"`
|
||||
PagerStyle string `toml:"pagerStyle"`
|
||||
RootCmd string `toml:"rootCmd" env:"ALR_ROOT_CMD"`
|
||||
PagerStyle string `toml:"pagerStyle" env:"ALR_PAGER_STYLE"`
|
||||
IgnorePkgUpdates []string `toml:"ignorePkgUpdates"`
|
||||
Repos []Repo `toml:"repo"`
|
||||
Unsafe Unsafe `toml:"unsafe"`
|
||||
AutoPull bool `toml:"autoPull"`
|
||||
AutoPull bool `toml:"autoPull" env:"ALR_AUTOPULL"`
|
||||
LogLevel string `toml:"logLevel" env:"ALR_LOG_LEVEL"`
|
||||
}
|
||||
|
||||
// Repo represents a ALR repo within a configuration file
|
||||
@ -36,5 +37,5 @@ type Repo struct {
|
||||
}
|
||||
|
||||
type Unsafe struct {
|
||||
AllowRunAsRoot bool `toml:"allowRunAsRoot"`
|
||||
AllowRunAsRoot bool `toml:"allowRunAsRoot" env:"ALR_UNSAFE_ALLOW_RUN_AS_ROOT"`
|
||||
}
|
||||
|
14
list.go
14
list.go
@ -49,16 +49,22 @@ func ListCmd() *cli.Command {
|
||||
Action: func(c *cli.Context) error {
|
||||
ctx := c.Context
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
err := db.Init(ctx)
|
||||
err = db.Init(ctx)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error initialization database"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
rs := repos.New(cfg, db)
|
||||
|
||||
if cfg.AutoPull(ctx) {
|
||||
err = rs.Pull(ctx, cfg.Repos(ctx))
|
||||
if cfg.AutoPull() {
|
||||
err = rs.Pull(ctx, cfg.Repos())
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error pulling repositories"), "err", err)
|
||||
os.Exit(1)
|
||||
@ -110,7 +116,7 @@ func ListCmd() *cli.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
if slices.Contains(cfg.IgnorePkgUpdates(ctx), pkg.Name) {
|
||||
if slices.Contains(cfg.IgnorePkgUpdates(), pkg.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
47
main.go
47
main.go
@ -84,11 +84,15 @@ func GetApp() *cli.App {
|
||||
SearchCmd(),
|
||||
},
|
||||
Before: func(c *cli.Context) error {
|
||||
ctx := c.Context
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cmd := c.Args().First()
|
||||
if cmd != "helper" && !cfg.AllowRunAsRoot(ctx) && os.Geteuid() == 0 {
|
||||
if cmd != "helper" && !cfg.AllowRunAsRoot() && os.Geteuid() == 0 {
|
||||
slog.Error(gotext.Get("Running ALR as root is forbidden as it may cause catastrophic damage to your system"))
|
||||
os.Exit(1)
|
||||
}
|
||||
@ -104,17 +108,42 @@ func GetApp() *cli.App {
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
translations.Setup()
|
||||
logger.SetupDefault()
|
||||
func setLogLevel(newLevel string) {
|
||||
level := slog.LevelInfo
|
||||
switch newLevel {
|
||||
case "DEBUG":
|
||||
level = slog.LevelDebug
|
||||
case "INFO":
|
||||
level = slog.LevelInfo
|
||||
case "WARN":
|
||||
level = slog.LevelWarn
|
||||
case "ERROR":
|
||||
level = slog.LevelError
|
||||
}
|
||||
logger, ok := slog.Default().Handler().(*logger.Logger)
|
||||
if !ok {
|
||||
panic("unexpected")
|
||||
}
|
||||
logger.SetLevel(level)
|
||||
}
|
||||
|
||||
app := GetApp()
|
||||
cfg := config.New()
|
||||
func main() {
|
||||
logger.SetupDefault()
|
||||
setLogLevel(os.Getenv("ALR_LOG_LEVEL"))
|
||||
translations.Setup()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
app := GetApp()
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
setLogLevel(cfg.LogLevel())
|
||||
// Set the root command to the one set in the ALR config
|
||||
manager.DefaultRootCmd = cfg.RootCmd(ctx)
|
||||
manager.DefaultRootCmd = cfg.RootCmd()
|
||||
|
||||
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
@ -124,7 +153,7 @@ func main() {
|
||||
cli.CommandHelpTemplate = cliutils.GetCommandHelpTemplate()
|
||||
cli.HelpFlag.(*cli.BoolFlag).Usage = gotext.Get("Show help")
|
||||
|
||||
err := app.RunContext(ctx, os.Args)
|
||||
err = app.RunContext(ctx, os.Args)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error while running app"), "err", err)
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ import (
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/shutils/handlers"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/shutils/helpers"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
|
||||
finddeps "gitea.plemya-x.ru/Plemya-x/ALR/pkg/build/find_deps"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/manager"
|
||||
)
|
||||
@ -59,8 +60,8 @@ type PackageFinder interface {
|
||||
}
|
||||
|
||||
type Config interface {
|
||||
GetPaths(ctx context.Context) *config.Paths
|
||||
PagerStyle(ctx context.Context) string
|
||||
GetPaths() *config.Paths
|
||||
PagerStyle() string
|
||||
}
|
||||
|
||||
type Builder struct {
|
||||
@ -88,7 +89,7 @@ func NewBuilder(
|
||||
}
|
||||
|
||||
func (b *Builder) UpdateOptsFromPkg(pkg *db.Package, packages []string) {
|
||||
repodir := b.config.GetPaths(b.ctx).RepoDir
|
||||
repodir := b.config.GetPaths().RepoDir
|
||||
b.opts.Repository = pkg.Repository
|
||||
if pkg.BasePkgName != "" {
|
||||
b.opts.Script = filepath.Join(repodir, pkg.Repository, pkg.BasePkgName, "alr.sh")
|
||||
@ -149,7 +150,7 @@ func (b *Builder) BuildPackage(ctx context.Context) ([]string, []string, error)
|
||||
ctx,
|
||||
b.opts.Script,
|
||||
basePkg,
|
||||
b.config.PagerStyle(ctx),
|
||||
b.config.PagerStyle(),
|
||||
b.opts.Interactive,
|
||||
)
|
||||
if err != nil {
|
||||
@ -211,8 +212,10 @@ func (b *Builder) BuildPackage(ctx context.Context) ([]string, []string, error)
|
||||
sources, checksums = removeDuplicatesSources(sources, checksums)
|
||||
|
||||
mergedVars := types.BuildVars{
|
||||
Sources: sources,
|
||||
Checksums: checksums,
|
||||
BuildVarsPre: types.BuildVarsPre{
|
||||
Sources: sources,
|
||||
Checksums: checksums,
|
||||
},
|
||||
}
|
||||
|
||||
buildDeps, err := b.installBuildDeps(ctx, buildDepends) // Устанавливаем зависимости для сборки
|
||||
@ -392,7 +395,7 @@ func (b *Builder) getDirs(basePkg string) (types.Directories, error) {
|
||||
return types.Directories{}, err
|
||||
}
|
||||
|
||||
baseDir := filepath.Join(b.config.GetPaths(b.ctx).PkgsDir, basePkg) // Определяем базовую директорию
|
||||
baseDir := filepath.Join(b.config.GetPaths().PkgsDir, basePkg) // Определяем базовую директорию
|
||||
return types.Directories{
|
||||
BaseDir: baseDir,
|
||||
SrcDir: filepath.Join(baseDir, "src"),
|
||||
@ -489,13 +492,17 @@ func (b *Builder) getBuildersForPackages(pkgs []db.Package) []*Builder {
|
||||
}
|
||||
pkgsMap := make(map[string]*item)
|
||||
for _, pkg := range pkgs {
|
||||
if pkgsMap[pkg.BasePkgName] == nil {
|
||||
pkgsMap[pkg.BasePkgName] = &item{
|
||||
name := pkg.BasePkgName
|
||||
if name == "" {
|
||||
name = pkg.Name
|
||||
}
|
||||
if pkgsMap[name] == nil {
|
||||
pkgsMap[name] = &item{
|
||||
pkg: &pkg,
|
||||
}
|
||||
}
|
||||
pkgsMap[pkg.BasePkgName].packages = append(
|
||||
pkgsMap[pkg.BasePkgName].packages,
|
||||
pkgsMap[name].packages = append(
|
||||
pkgsMap[name].packages,
|
||||
pkg.Name,
|
||||
)
|
||||
}
|
||||
@ -854,24 +861,18 @@ func (b *Builder) buildPkgMetadata(
|
||||
pkgInfo.Overridables.Contents = contents
|
||||
|
||||
if len(vars.AutoProv) == 1 && decoder.IsTruthy(vars.AutoProv[0]) {
|
||||
if pkgFormat == "rpm" {
|
||||
err = rpmFindProvides(ctx, pkgInfo, dirs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
slog.Info(gotext.Get("AutoProv is not implemented for this package format, so it's skipped"))
|
||||
f := finddeps.New(b.info, pkgFormat)
|
||||
err = f.FindProvides(ctx, pkgInfo, dirs, vars.AutoProvSkipList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if len(vars.AutoReq) == 1 && decoder.IsTruthy(vars.AutoReq[0]) {
|
||||
if pkgFormat == "rpm" {
|
||||
err = rpmFindRequires(ctx, pkgInfo, dirs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
slog.Info(gotext.Get("AutoReq is not implemented for this package format, so it's skipped"))
|
||||
f := finddeps.New(b.info, pkgFormat)
|
||||
err = f.FindRequires(ctx, pkgInfo, dirs, vars.AutoReqSkipList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,11 +144,11 @@ func (m *TestManager) IsInstalled(pkg string) (bool, error) {
|
||||
|
||||
type TestConfig struct{}
|
||||
|
||||
func (c *TestConfig) PagerStyle(ctx context.Context) string {
|
||||
func (c *TestConfig) PagerStyle() string {
|
||||
return "native"
|
||||
}
|
||||
|
||||
func (c *TestConfig) GetPaths(ctx context.Context) *config.Paths {
|
||||
func (c *TestConfig) GetPaths() *config.Paths {
|
||||
return &config.Paths{
|
||||
CacheDir: "/tmp",
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package build
|
||||
package finddeps
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -30,7 +30,7 @@ import (
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
|
||||
)
|
||||
|
||||
func rpmFindDependencies(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, command string, updateFunc func(string)) error {
|
||||
func rpmFindDependenciesALTLinux(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, command string, envs []string, updateFunc func(string)) error {
|
||||
if _, err := exec.LookPath(command); err != nil {
|
||||
slog.Info(gotext.Get("Command not found on the system"), "command", command)
|
||||
return nil
|
||||
@ -49,8 +49,8 @@ func rpmFindDependencies(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Dir
|
||||
return nil
|
||||
}
|
||||
|
||||
cmd := exec.Command(command)
|
||||
cmd.Stdin = bytes.NewBufferString(strings.Join(paths, "\n"))
|
||||
cmd := exec.CommandContext(ctx, command)
|
||||
cmd.Stdin = bytes.NewBufferString(strings.Join(paths, "\n") + "\n")
|
||||
cmd.Env = append(cmd.Env,
|
||||
"RPM_BUILD_ROOT="+dirs.PkgDir,
|
||||
"RPM_FINDPROV_METHOD=",
|
||||
@ -58,6 +58,7 @@ func rpmFindDependencies(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Dir
|
||||
"RPM_DATADIR=",
|
||||
"RPM_SUBPACKAGE_NAME=",
|
||||
)
|
||||
cmd.Env = append(cmd.Env, envs...)
|
||||
var out bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
@ -66,6 +67,7 @@ func rpmFindDependencies(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Dir
|
||||
slog.Error(stderr.String())
|
||||
return err
|
||||
}
|
||||
slog.Debug(stderr.String())
|
||||
|
||||
dependencies := strings.Split(strings.TrimSpace(out.String()), "\n")
|
||||
for _, dep := range dependencies {
|
||||
@ -77,15 +79,17 @@ func rpmFindDependencies(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Dir
|
||||
return nil
|
||||
}
|
||||
|
||||
func rpmFindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories) error {
|
||||
return rpmFindDependencies(ctx, pkgInfo, dirs, "/usr/lib/rpm/find-provides", func(dep string) {
|
||||
type ALTLinuxFindProvReq struct{}
|
||||
|
||||
func (o *ALTLinuxFindProvReq) FindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error {
|
||||
return rpmFindDependenciesALTLinux(ctx, pkgInfo, dirs, "/usr/lib/rpm/find-provides", []string{"RPM_FINDPROV_SKIPLIST=" + strings.Join(skiplist, "\n")}, func(dep string) {
|
||||
slog.Info(gotext.Get("Provided dependency found"), "dep", dep)
|
||||
pkgInfo.Overridables.Provides = append(pkgInfo.Overridables.Provides, dep)
|
||||
})
|
||||
}
|
||||
|
||||
func rpmFindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories) error {
|
||||
return rpmFindDependencies(ctx, pkgInfo, dirs, "/usr/lib/rpm/find-requires", func(dep string) {
|
||||
func (o *ALTLinuxFindProvReq) FindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error {
|
||||
return rpmFindDependenciesALTLinux(ctx, pkgInfo, dirs, "/usr/lib/rpm/find-requires", []string{"RPM_FINDREQ_SKIPLIST=" + strings.Join(skiplist, "\n")}, func(dep string) {
|
||||
slog.Info(gotext.Get("Required dependency found"), "dep", dep)
|
||||
pkgInfo.Overridables.Depends = append(pkgInfo.Overridables.Depends, dep)
|
||||
})
|
39
pkg/build/find_deps/empty.go
Normal file
39
pkg/build/find_deps/empty.go
Normal file
@ -0,0 +1,39 @@
|
||||
// ALR - Any Linux Repository
|
||||
// Copyright (C) 2025 Евгений Храмов
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package finddeps
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/goreleaser/nfpm/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
|
||||
)
|
||||
|
||||
type EmptyFindProvReq struct{}
|
||||
|
||||
func (o *EmptyFindProvReq) FindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error {
|
||||
slog.Info(gotext.Get("AutoProv is not implemented for this package format, so it's skipped"))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *EmptyFindProvReq) FindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error {
|
||||
slog.Info(gotext.Get("AutoReq is not implemented for this package format, so it's skipped"))
|
||||
return nil
|
||||
}
|
118
pkg/build/find_deps/fedora.go
Normal file
118
pkg/build/find_deps/fedora.go
Normal file
@ -0,0 +1,118 @@
|
||||
// ALR - Any Linux Repository
|
||||
// Copyright (C) 2025 Евгений Храмов
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package finddeps
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/goreleaser/nfpm/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
|
||||
)
|
||||
|
||||
type FedoraFindProvReq struct{}
|
||||
|
||||
func rpmFindDependenciesFedora(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, command string, args []string, updateFunc func(string)) error {
|
||||
if _, err := exec.LookPath(command); err != nil {
|
||||
slog.Info(gotext.Get("Command not found on the system"), "command", command)
|
||||
return nil
|
||||
}
|
||||
|
||||
var paths []string
|
||||
for _, content := range pkgInfo.Contents {
|
||||
if content.Type != "dir" {
|
||||
paths = append(paths,
|
||||
path.Join(dirs.PkgDir, content.Destination),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if len(paths) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
cmd := exec.CommandContext(ctx, command, args...)
|
||||
cmd.Stdin = bytes.NewBufferString(strings.Join(paths, "\n") + "\n")
|
||||
cmd.Env = append(cmd.Env,
|
||||
"RPM_BUILD_ROOT="+dirs.PkgDir,
|
||||
)
|
||||
var out bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
cmd.Stderr = &stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
slog.Error(stderr.String())
|
||||
return err
|
||||
}
|
||||
slog.Debug(stderr.String())
|
||||
|
||||
dependencies := strings.Split(strings.TrimSpace(out.String()), "\n")
|
||||
for _, dep := range dependencies {
|
||||
if dep != "" {
|
||||
updateFunc(dep)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *FedoraFindProvReq) FindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error {
|
||||
return rpmFindDependenciesFedora(
|
||||
ctx,
|
||||
pkgInfo,
|
||||
dirs,
|
||||
"/usr/lib/rpm/rpmdeps",
|
||||
[]string{
|
||||
"--define=_use_internal_dependency_generator 1",
|
||||
"--provides",
|
||||
fmt.Sprintf(
|
||||
"--define=__provides_exclude_from %s\"",
|
||||
strings.Join(skiplist, "|"),
|
||||
),
|
||||
},
|
||||
func(dep string) {
|
||||
slog.Info(gotext.Get("Provided dependency found"), "dep", dep)
|
||||
pkgInfo.Overridables.Provides = append(pkgInfo.Overridables.Provides, dep)
|
||||
})
|
||||
}
|
||||
|
||||
func (o *FedoraFindProvReq) FindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error {
|
||||
return rpmFindDependenciesFedora(
|
||||
ctx,
|
||||
pkgInfo,
|
||||
dirs,
|
||||
"/usr/lib/rpm/rpmdeps",
|
||||
[]string{
|
||||
"--define=_use_internal_dependency_generator 1",
|
||||
"--requires",
|
||||
fmt.Sprintf(
|
||||
"--define=__requires_exclude_from %s",
|
||||
strings.Join(skiplist, "|"),
|
||||
),
|
||||
},
|
||||
func(dep string) {
|
||||
slog.Info(gotext.Get("Required dependency found"), "dep", dep)
|
||||
pkgInfo.Overridables.Depends = append(pkgInfo.Overridables.Depends, dep)
|
||||
})
|
||||
}
|
58
pkg/build/find_deps/find_deps.go
Normal file
58
pkg/build/find_deps/find_deps.go
Normal file
@ -0,0 +1,58 @@
|
||||
// ALR - Any Linux Repository
|
||||
// Copyright (C) 2025 Евгений Храмов
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package finddeps
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/goreleaser/nfpm/v2"
|
||||
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
|
||||
)
|
||||
|
||||
type ProvReqFinder interface {
|
||||
FindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error
|
||||
FindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error
|
||||
}
|
||||
|
||||
type ProvReqService struct {
|
||||
finder ProvReqFinder
|
||||
}
|
||||
|
||||
func New(info *distro.OSRelease, pkgFormat string) *ProvReqService {
|
||||
s := &ProvReqService{
|
||||
finder: &EmptyFindProvReq{},
|
||||
}
|
||||
if pkgFormat == "rpm" {
|
||||
switch info.ID {
|
||||
case "altlinux":
|
||||
s.finder = &ALTLinuxFindProvReq{}
|
||||
case "fedora":
|
||||
s.finder = &FedoraFindProvReq{}
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ProvReqService) FindProvides(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error {
|
||||
return s.finder.FindProvides(ctx, pkgInfo, dirs, skiplist)
|
||||
}
|
||||
|
||||
func (s *ProvReqService) FindRequires(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Directories, skiplist []string) error {
|
||||
return s.finder.FindRequires(ctx, pkgInfo, dirs, skiplist)
|
||||
}
|
@ -41,10 +41,10 @@ checksums=('blake2b-256:{{.SourceURL.Digests.blake2b_256}}')
|
||||
|
||||
build() {
|
||||
cd "$srcdir/{{.Info.Name}}-${version}"
|
||||
python3 -m build
|
||||
python -m build --wheel --no-isolation
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "$srcdir/{{.Info.Name}}-${version}"
|
||||
pip install --root="${pkgdir}/" . --no-deps --disable-pip-version-check
|
||||
pip install --root="${pkgdir}/" . --no-deps --ignore-installed --disable-pip-version-check
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ type action struct {
|
||||
// If repos is set to nil, the repos in the ALR config will be used.
|
||||
func (rs *Repos) Pull(ctx context.Context, repos []types.Repo) error {
|
||||
if repos == nil {
|
||||
repos = rs.cfg.Repos(ctx)
|
||||
repos = rs.cfg.Repos()
|
||||
}
|
||||
|
||||
for _, repo := range repos {
|
||||
@ -77,7 +77,7 @@ func (rs *Repos) Pull(ctx context.Context, repos []types.Repo) error {
|
||||
}
|
||||
|
||||
slog.Info(gotext.Get("Pulling repository"), "name", repo.Name)
|
||||
repoDir := filepath.Join(rs.cfg.GetPaths(ctx).RepoDir, repo.Name)
|
||||
repoDir := filepath.Join(rs.cfg.GetPaths().RepoDir, repo.Name)
|
||||
|
||||
var repoFS billy.Filesystem
|
||||
gitDir := filepath.Join(repoDir, ".git")
|
||||
|
@ -32,13 +32,13 @@ import (
|
||||
|
||||
type TestALRConfig struct{}
|
||||
|
||||
func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
|
||||
func (c *TestALRConfig) GetPaths() *config.Paths {
|
||||
return &config.Paths{
|
||||
DBPath: ":memory:",
|
||||
}
|
||||
}
|
||||
|
||||
func (c *TestALRConfig) Repos(ctx context.Context) []types.Repo {
|
||||
func (c *TestALRConfig) Repos() []types.Repo {
|
||||
return []types.Repo{
|
||||
{
|
||||
Name: "test",
|
||||
|
@ -44,7 +44,7 @@ type TestALRConfig struct {
|
||||
PkgsDir string
|
||||
}
|
||||
|
||||
func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
|
||||
func (c *TestALRConfig) GetPaths() *config.Paths {
|
||||
return &config.Paths{
|
||||
DBPath: ":memory:",
|
||||
CacheDir: c.CacheDir,
|
||||
@ -53,7 +53,7 @@ func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *TestALRConfig) Repos(ctx context.Context) []types.Repo {
|
||||
func (c *TestALRConfig) Repos() []types.Repo {
|
||||
return []types.Repo{}
|
||||
}
|
||||
|
||||
|
@ -17,16 +17,14 @@
|
||||
package repos
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
|
||||
database "gitea.plemya-x.ru/Plemya-x/ALR/internal/db"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
|
||||
)
|
||||
|
||||
type Config interface {
|
||||
GetPaths(ctx context.Context) *config.Paths
|
||||
Repos(ctx context.Context) []types.Repo
|
||||
GetPaths() *config.Paths
|
||||
Repos() []types.Repo
|
||||
}
|
||||
|
||||
type Repos struct {
|
||||
|
63
repo.go
63
repo.go
@ -25,7 +25,6 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
"github.com/urfave/cli/v2"
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
@ -61,7 +60,13 @@ func AddRepoCmd() *cli.Command {
|
||||
repoURL := c.String("url")
|
||||
|
||||
cfg := config.New()
|
||||
reposSlice := cfg.Repos(ctx)
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
reposSlice := cfg.Repos()
|
||||
|
||||
for _, repo := range reposSlice {
|
||||
if repo.URL == repoURL {
|
||||
@ -74,18 +79,11 @@ func AddRepoCmd() *cli.Command {
|
||||
Name: name,
|
||||
URL: repoURL,
|
||||
})
|
||||
cfg.SetRepos(reposSlice)
|
||||
|
||||
cfg.SetRepos(ctx, reposSlice)
|
||||
|
||||
cfgFl, err := os.Create(cfg.GetPaths(ctx).ConfigPath)
|
||||
err = cfg.SaveUserConfig()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error opening config file"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = cfg.Save(cfgFl)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error encoding config"), "err", err)
|
||||
slog.Error(gotext.Get("Error saving config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@ -96,7 +94,7 @@ func AddRepoCmd() *cli.Command {
|
||||
}
|
||||
|
||||
rs := repos.New(cfg, db)
|
||||
err = rs.Pull(ctx, cfg.Repos(ctx))
|
||||
err = rs.Pull(ctx, cfg.Repos())
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error pulling repos"), "err", err)
|
||||
os.Exit(1)
|
||||
@ -125,10 +123,15 @@ func RemoveRepoCmd() *cli.Command {
|
||||
|
||||
name := c.String("name")
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
found := false
|
||||
index := 0
|
||||
reposSlice := cfg.Repos(ctx)
|
||||
reposSlice := cfg.Repos()
|
||||
for i, repo := range reposSlice {
|
||||
if repo.Name == name {
|
||||
index = i
|
||||
@ -140,26 +143,20 @@ func RemoveRepoCmd() *cli.Command {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cfg.SetRepos(ctx, slices.Delete(reposSlice, index, index+1))
|
||||
cfg.SetRepos(slices.Delete(reposSlice, index, index+1))
|
||||
|
||||
cfgFl, err := os.Create(cfg.GetPaths(ctx).ConfigPath)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error opening config file"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = toml.NewEncoder(cfgFl).Encode(&cfg)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error encoding config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = os.RemoveAll(filepath.Join(cfg.GetPaths(ctx).RepoDir, name))
|
||||
err = os.RemoveAll(filepath.Join(cfg.GetPaths().RepoDir, name))
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error removing repo directory"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = cfg.SaveUserConfig()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error saving config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
err = db.Init(ctx)
|
||||
if err != nil {
|
||||
@ -184,13 +181,19 @@ func RefreshCmd() *cli.Command {
|
||||
Action: func(c *cli.Context) error {
|
||||
ctx := c.Context
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
err := db.Init(ctx)
|
||||
err = db.Init(ctx)
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
rs := repos.New(cfg, db)
|
||||
err = rs.Pull(ctx, cfg.Repos(ctx))
|
||||
err = rs.Pull(ctx, cfg.Repos())
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error pulling repos"), "err", err)
|
||||
os.Exit(1)
|
||||
|
@ -96,53 +96,52 @@ if [ -z "$noPkgMgr" ]; then
|
||||
|
||||
echo "Полученный список файлов:"
|
||||
echo "$fileList"
|
||||
|
||||
if [ "$pkgMgr" == "pacman" ]; then
|
||||
latestFile=$(echo "$fileList" | grep -E 'alr-bin-.*.pkg.tar.zst' | sort -V | tail -n 1)
|
||||
elif [ "$pkgMgr" == "apt" ]; then
|
||||
latestFile=$(echo "$fileList" | grep -E 'alr-bin-.*.amd64.deb' | sort -V | tail -n 1)
|
||||
elif [[ "$pkgMgr" == "dnf" || "$pkgMgr" == "yum" || "$pkgMgr" == "zypper" ]]; then
|
||||
if [ "$pkgMgr" == "pacman" ]; then
|
||||
latestFile=$(echo "$fileList" | grep -E 'alr-bin-.*\.pkg\.tar\.zst' | sort -V | tail -n 1)
|
||||
elif [ "$pkgMgr" == "apt" ]; then
|
||||
latestFile=$(echo "$fileList" | grep -E 'alr-bin-.*\.amd64\.deb' | sort -V | tail -n 1)
|
||||
elif [[ "$pkgMgr" == "dnf" || "$pkgMgr" == "yum" || "$pkgMgr" == "zypper" ]]; then
|
||||
latestFile=$(echo "$fileList" | grep -E 'alr-bin-.*\.x86_64\.rpm' | grep -v 'alt1' | sort -V | tail -n 1)
|
||||
elif [[ "$pkgMgr" == "apt-get" ]]; then
|
||||
latestFile=$(echo "$fileList" | grep -E 'alr-bin-.*alt1.x86_64.rpm' | sort -V | tail -n 1)
|
||||
|
||||
else
|
||||
error "Не поддерживаемый менеджер пакетов для автоматической установки"
|
||||
fi
|
||||
|
||||
if [ -z "$latestFile" ]; then
|
||||
error "Не удалось найти соответствующий пакет для $pkgMgr"
|
||||
fi
|
||||
|
||||
info "Найдена последняя версия ALR: $latestFile"
|
||||
|
||||
url="https://plemya-x.ru/$latestFile"
|
||||
fname="$(mktemp -u -p /tmp "alr.XXXXXXXXXX").${pkgFormat}"
|
||||
|
||||
info "Загрузка пакета ALR"
|
||||
curl -L $url -o $fname
|
||||
|
||||
if [ ! -f "$fname" ]; then
|
||||
error "Ошибка загрузки пакета ALR"
|
||||
fi
|
||||
|
||||
info "Установка пакета ALR"
|
||||
installPkg $pkgMgr $fname
|
||||
|
||||
info "Очистка"
|
||||
rm $fname
|
||||
|
||||
info "Готово!"
|
||||
elif [ "$pkgMgr" == "apt-get" ]; then
|
||||
latestFile=$(echo "$fileList" | grep -E 'alr-bin-.*-alt[0-9]+\.x86_64\.rpm' | sort -V | tail -n 1)
|
||||
else
|
||||
info "Клонирование репозитория ALR"
|
||||
git clone https://gitea.plemya-x.ru/xpamych/ALR.git /tmp/alr
|
||||
|
||||
info "Установка ALR"
|
||||
cd /tmp/alr
|
||||
sudo make install
|
||||
|
||||
info "Очистка репозитория ALR"
|
||||
rm -rf /tmp/alr
|
||||
|
||||
info "Все задачи выполнены!"
|
||||
error "Не поддерживаемый менеджер пакетов для автоматической установки"
|
||||
fi
|
||||
|
||||
if [ -z "$latestFile" ]; then
|
||||
error "Не удалось найти соответствующий пакет для $pkgMgr"
|
||||
fi
|
||||
|
||||
info "Найдена последняя версия ALR: $latestFile"
|
||||
|
||||
url="https://plemya-x.ru/$latestFile"
|
||||
fname="$(mktemp -u -p /tmp "alr.XXXXXXXXXX").${pkgFormat}"
|
||||
|
||||
info "Загрузка пакета ALR"
|
||||
curl -L $url -o $fname
|
||||
|
||||
if [ ! -f "$fname" ]; then
|
||||
error "Ошибка загрузки пакета ALR"
|
||||
fi
|
||||
|
||||
info "Установка пакета ALR"
|
||||
installPkg $pkgMgr $fname
|
||||
|
||||
info "Очистка"
|
||||
rm $fname
|
||||
|
||||
info "Готово!"
|
||||
|
||||
else
|
||||
info "Клонирование репозитория ALR"
|
||||
git clone https://gitea.plemya-x.ru/xpamych/ALR.git /tmp/alr
|
||||
|
||||
info "Установка ALR"
|
||||
cd /tmp/alr
|
||||
sudo make install
|
||||
|
||||
info "Очистка репозитория ALR"
|
||||
rm -rf /tmp/alr
|
||||
|
||||
info "Все задачи выполнены!"
|
||||
fi
|
||||
|
@ -65,8 +65,14 @@ func SearchCmd() *cli.Command {
|
||||
Action: func(c *cli.Context) error {
|
||||
ctx := c.Context
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
err := db.Init(ctx)
|
||||
err = db.Init(ctx)
|
||||
defer db.Close()
|
||||
|
||||
if err != nil {
|
||||
|
12
upgrade.go
12
upgrade.go
@ -57,9 +57,15 @@ func UpgradeCmd() *cli.Command {
|
||||
ctx := c.Context
|
||||
|
||||
cfg := config.New()
|
||||
err := cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
rs := repos.New(cfg, db)
|
||||
err := db.Init(ctx)
|
||||
err = db.Init(ctx)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error initialization database"), "err", err)
|
||||
os.Exit(1)
|
||||
@ -77,8 +83,8 @@ func UpgradeCmd() *cli.Command {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if cfg.AutoPull(ctx) {
|
||||
err = rs.Pull(ctx, cfg.Repos(ctx))
|
||||
if cfg.AutoPull() {
|
||||
err = rs.Pull(ctx, cfg.Repos())
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error pulling repos"), "err", err)
|
||||
os.Exit(1)
|
||||
|
Loading…
Reference in New Issue
Block a user