forked from Plemya-x/ALR
refactor
This commit is contained in:
parent
b8cb7af3bb
commit
e3aaa88822
@ -12,7 +12,7 @@
|
|||||||
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
<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="15" fill="#010101" fill-opacity=".3">ru translate</text>
|
||||||
<text x="37" y="14">ru translate</text>
|
<text x="37" y="14">ru translate</text>
|
||||||
<text x="100" y="15" fill="#010101" fill-opacity=".3">98.00%</text>
|
<text x="100" y="15" fill="#010101" fill-opacity=".3">99.00%</text>
|
||||||
<text x="100" y="14">98.00%</text>
|
<text x="100" y="14">99.00%</text>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 940 B After Width: | Height: | Size: 940 B |
29
install.go
29
install.go
@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils"
|
||||||
|
appbuilder "gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils/app_builder"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
|
||||||
database "gitea.plemya-x.ru/Plemya-x/ALR/internal/db"
|
database "gitea.plemya-x.ru/Plemya-x/ALR/internal/db"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
|
||||||
@ -157,17 +158,17 @@ func RemoveCmd() *cli.Command {
|
|||||||
Usage: gotext.Get("Remove an installed package"),
|
Usage: gotext.Get("Remove an installed package"),
|
||||||
Aliases: []string{"rm"},
|
Aliases: []string{"rm"},
|
||||||
BashComplete: cliutils.BashCompleteWithError(func(c *cli.Context) error {
|
BashComplete: cliutils.BashCompleteWithError(func(c *cli.Context) error {
|
||||||
cfg := config.New()
|
ctx := c.Context
|
||||||
err := cfg.Load()
|
|
||||||
if err != nil {
|
|
||||||
return cliutils.FormatCliExit(gotext.Get("Error loading config"), err)
|
|
||||||
}
|
|
||||||
|
|
||||||
db := database.New(cfg)
|
deps, err := appbuilder.
|
||||||
err = db.Init(c.Context)
|
New(ctx).
|
||||||
|
WithConfig().
|
||||||
|
WithDB().
|
||||||
|
Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cliutils.FormatCliExit(gotext.Get("Error initialization database"), err)
|
return cli.Exit(err, 1)
|
||||||
}
|
}
|
||||||
|
defer deps.Defer()
|
||||||
|
|
||||||
installedAlrPackages := map[string]string{}
|
installedAlrPackages := map[string]string{}
|
||||||
mgr := manager.Detect()
|
mgr := manager.Detect()
|
||||||
@ -188,7 +189,7 @@ func RemoveCmd() *cli.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := db.GetPkgs(c.Context, "true")
|
result, err := deps.DB.GetPkgs(c.Context, "true")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cliutils.FormatCliExit(gotext.Get("Error getting packages"), err)
|
return cliutils.FormatCliExit(gotext.Get("Error getting packages"), err)
|
||||||
}
|
}
|
||||||
@ -212,16 +213,18 @@ func RemoveCmd() *cli.Command {
|
|||||||
return nil
|
return nil
|
||||||
}),
|
}),
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
if err := utils.ExitIfNotRoot(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
args := c.Args()
|
args := c.Args()
|
||||||
if args.Len() < 1 {
|
if args.Len() < 1 {
|
||||||
slog.Error(gotext.Get("Command remove expected at least 1 argument, got %d", args.Len()))
|
return cliutils.FormatCliExit(gotext.Get("Command remove expected at least 1 argument, got %d", args.Len()), nil)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mgr := manager.Detect()
|
mgr := manager.Detect()
|
||||||
if mgr == nil {
|
if mgr == nil {
|
||||||
slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
|
return cliutils.FormatCliExit(gotext.Get("Unable to detect a supported package manager on the system"), nil)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := mgr.Remove(&manager.Opts{
|
err := mgr.Remove(&manager.Opts{
|
||||||
|
@ -53,6 +53,14 @@ func New(ctx context.Context) *AppBuilder {
|
|||||||
return &AppBuilder{ctx: ctx}
|
return &AppBuilder{ctx: ctx}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *AppBuilder) UseConfig(cfg *config.ALRConfig) *AppBuilder {
|
||||||
|
if b.err != nil {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
b.deps.Cfg = cfg
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
func (b *AppBuilder) WithConfig() *AppBuilder {
|
func (b *AppBuilder) WithConfig() *AppBuilder {
|
||||||
if b.err != nil {
|
if b.err != nil {
|
||||||
return b
|
return b
|
||||||
@ -92,16 +100,21 @@ func (b *AppBuilder) WithDB() *AppBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *AppBuilder) WithRepos() *AppBuilder {
|
func (b *AppBuilder) WithRepos() *AppBuilder {
|
||||||
b.withRepos(false)
|
b.withRepos(true, false)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *AppBuilder) WithReposForcePull() *AppBuilder {
|
func (b *AppBuilder) WithReposForcePull() *AppBuilder {
|
||||||
b.withRepos(true)
|
b.withRepos(true, true)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *AppBuilder) withRepos(forcePull bool) *AppBuilder {
|
func (b *AppBuilder) WithReposNoPull() *AppBuilder {
|
||||||
|
b.withRepos(false, false)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *AppBuilder) withRepos(enablePull, forcePull bool) *AppBuilder {
|
||||||
if b.err != nil {
|
if b.err != nil {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
@ -115,7 +128,7 @@ func (b *AppBuilder) withRepos(forcePull bool) *AppBuilder {
|
|||||||
|
|
||||||
rs := repos.New(cfg, db)
|
rs := repos.New(cfg, db)
|
||||||
|
|
||||||
if forcePull || cfg.AutoPull() {
|
if enablePull && (forcePull || cfg.AutoPull()) {
|
||||||
if err := rs.Pull(b.ctx, cfg.Repos()); err != nil {
|
if err := rs.Pull(b.ctx, cfg.Repos()); err != nil {
|
||||||
slog.Error(gotext.Get("Error pulling repositories"), "err", err)
|
slog.Error(gotext.Get("Error pulling repositories"), "err", err)
|
||||||
b.err = cli.Exit("", 1)
|
b.err = cli.Exit("", 1)
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package cliutils
|
package cliutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
@ -52,5 +53,8 @@ func FormatCliExit(msg string, err error) cli.ExitCoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FormatCliExitWithCode(msg string, err error, exitCode int) cli.ExitCoder {
|
func FormatCliExitWithCode(msg string, err error, exitCode int) cli.ExitCoder {
|
||||||
|
if err == nil {
|
||||||
|
return cli.Exit(errors.New(msg), exitCode)
|
||||||
|
}
|
||||||
return cli.Exit(fmt.Errorf("%s: %w", msg, err), exitCode)
|
return cli.Exit(fmt.Errorf("%s: %w", msg, err), exitCode)
|
||||||
}
|
}
|
||||||
|
@ -166,31 +166,31 @@ msgstr ""
|
|||||||
msgid "Error encoding script variables"
|
msgid "Error encoding script variables"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: install.go:44
|
#: install.go:45
|
||||||
msgid "Install a new package"
|
msgid "Install a new package"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: install.go:58
|
#: install.go:59
|
||||||
msgid "Command install expected at least 1 argument, got %d"
|
msgid "Command install expected at least 1 argument, got %d"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: install.go:94
|
#: install.go:95
|
||||||
msgid "Error pulling repositories"
|
msgid "Error pulling repositories"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: install.go:157
|
#: install.go:158
|
||||||
msgid "Remove an installed package"
|
msgid "Remove an installed package"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: install.go:180
|
#: install.go:181
|
||||||
msgid "Error listing installed packages"
|
msgid "Error listing installed packages"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: install.go:217
|
#: install.go:222
|
||||||
msgid "Command remove expected at least 1 argument, got %d"
|
msgid "Command remove expected at least 1 argument, got %d"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: install.go:232
|
#: install.go:235
|
||||||
msgid "Error removing packages"
|
msgid "Error removing packages"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@ -419,51 +419,47 @@ msgid ""
|
|||||||
"updating ALR if something doesn't work."
|
"updating ALR if something doesn't work."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: repo.go:43
|
#: repo.go:40
|
||||||
msgid "Add a new repository"
|
msgid "Add a new repository"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: repo.go:50
|
#: repo.go:47
|
||||||
msgid "Name of the new repo"
|
msgid "Name of the new repo"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: repo.go:56
|
#: repo.go:53
|
||||||
msgid "URL of the new repo"
|
msgid "URL of the new repo"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: repo.go:93 repo.go:169
|
#: repo.go:80
|
||||||
|
msgid "Repo %s already exists"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: repo.go:91 repo.go:169
|
||||||
msgid "Error saving config"
|
msgid "Error saving config"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: repo.go:97
|
#: repo.go:117
|
||||||
msgid "Can't drop privileges"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: repo.go:104 repo.go:110
|
|
||||||
msgid "Error pulling repos"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: repo.go:121
|
|
||||||
msgid "Remove an existing repository"
|
msgid "Remove an existing repository"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: repo.go:128
|
#: repo.go:124
|
||||||
msgid "Name of the repo to be deleted"
|
msgid "Name of the repo to be deleted"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: repo.go:156
|
#: repo.go:157
|
||||||
msgid "Repo does not exist"
|
msgid "Repo does not exist"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: repo.go:164
|
#: repo.go:165
|
||||||
msgid "Error removing repo directory"
|
msgid "Error removing repo directory"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: repo.go:179
|
#: repo.go:188
|
||||||
msgid "Error removing packages from database"
|
msgid "Error removing packages from database"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: repo.go:190
|
#: repo.go:199
|
||||||
msgid "Pull all repositories that have changed"
|
msgid "Pull all repositories that have changed"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@ -507,6 +503,10 @@ msgstr ""
|
|||||||
msgid "Upgrade all installed packages"
|
msgid "Upgrade all installed packages"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: upgrade.go:101
|
||||||
|
msgid "Error pulling repos"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: upgrade.go:107 upgrade.go:124
|
#: upgrade.go:107 upgrade.go:124
|
||||||
msgid "Error checking for updates"
|
msgid "Error checking for updates"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -181,31 +181,31 @@ msgstr "Ошибка устранения переорпеделений"
|
|||||||
msgid "Error encoding script variables"
|
msgid "Error encoding script variables"
|
||||||
msgstr "Ошибка кодирования переменных скрита"
|
msgstr "Ошибка кодирования переменных скрита"
|
||||||
|
|
||||||
#: install.go:44
|
#: install.go:45
|
||||||
msgid "Install a new package"
|
msgid "Install a new package"
|
||||||
msgstr "Установить новый пакет"
|
msgstr "Установить новый пакет"
|
||||||
|
|
||||||
#: install.go:58
|
#: install.go:59
|
||||||
msgid "Command install expected at least 1 argument, got %d"
|
msgid "Command install expected at least 1 argument, got %d"
|
||||||
msgstr "Для команды install ожидался хотя бы 1 аргумент, получено %d"
|
msgstr "Для команды install ожидался хотя бы 1 аргумент, получено %d"
|
||||||
|
|
||||||
#: install.go:94
|
#: install.go:95
|
||||||
msgid "Error pulling repositories"
|
msgid "Error pulling repositories"
|
||||||
msgstr "Ошибка при извлечении репозиториев"
|
msgstr "Ошибка при извлечении репозиториев"
|
||||||
|
|
||||||
#: install.go:157
|
#: install.go:158
|
||||||
msgid "Remove an installed package"
|
msgid "Remove an installed package"
|
||||||
msgstr "Удалить установленный пакет"
|
msgstr "Удалить установленный пакет"
|
||||||
|
|
||||||
#: install.go:180
|
#: install.go:181
|
||||||
msgid "Error listing installed packages"
|
msgid "Error listing installed packages"
|
||||||
msgstr "Ошибка при составлении списка установленных пакетов"
|
msgstr "Ошибка при составлении списка установленных пакетов"
|
||||||
|
|
||||||
#: install.go:217
|
#: install.go:222
|
||||||
msgid "Command remove expected at least 1 argument, got %d"
|
msgid "Command remove expected at least 1 argument, got %d"
|
||||||
msgstr "Для команды remove ожидался хотя бы 1 аргумент, получено %d"
|
msgstr "Для команды remove ожидался хотя бы 1 аргумент, получено %d"
|
||||||
|
|
||||||
#: install.go:232
|
#: install.go:235
|
||||||
msgid "Error removing packages"
|
msgid "Error removing packages"
|
||||||
msgstr "Ошибка при удалении пакетов"
|
msgstr "Ошибка при удалении пакетов"
|
||||||
|
|
||||||
@ -441,52 +441,49 @@ msgstr ""
|
|||||||
"Минимальная версия ALR для ALR-репозитория выше текущей версии. Попробуйте "
|
"Минимальная версия ALR для ALR-репозитория выше текущей версии. Попробуйте "
|
||||||
"обновить ALR, если что-то не работает."
|
"обновить ALR, если что-то не работает."
|
||||||
|
|
||||||
#: repo.go:43
|
#: repo.go:40
|
||||||
msgid "Add a new repository"
|
msgid "Add a new repository"
|
||||||
msgstr "Добавить новый репозиторий"
|
msgstr "Добавить новый репозиторий"
|
||||||
|
|
||||||
#: repo.go:50
|
#: repo.go:47
|
||||||
msgid "Name of the new repo"
|
msgid "Name of the new repo"
|
||||||
msgstr "Название нового репозитория"
|
msgstr "Название нового репозитория"
|
||||||
|
|
||||||
#: repo.go:56
|
#: repo.go:53
|
||||||
msgid "URL of the new repo"
|
msgid "URL of the new repo"
|
||||||
msgstr "URL-адрес нового репозитория"
|
msgstr "URL-адрес нового репозитория"
|
||||||
|
|
||||||
#: repo.go:93 repo.go:169
|
#: repo.go:80
|
||||||
|
#, fuzzy
|
||||||
|
msgid "Repo %s already exists"
|
||||||
|
msgstr "Репозитория не существует"
|
||||||
|
|
||||||
|
#: repo.go:91 repo.go:169
|
||||||
#, fuzzy
|
#, fuzzy
|
||||||
msgid "Error saving config"
|
msgid "Error saving config"
|
||||||
msgstr "Ошибка при кодировании конфигурации"
|
msgstr "Ошибка при кодировании конфигурации"
|
||||||
|
|
||||||
#: repo.go:97
|
#: repo.go:117
|
||||||
msgid "Can't drop privileges"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: repo.go:104 repo.go:110
|
|
||||||
msgid "Error pulling repos"
|
|
||||||
msgstr "Ошибка при извлечении репозиториев"
|
|
||||||
|
|
||||||
#: repo.go:121
|
|
||||||
msgid "Remove an existing repository"
|
msgid "Remove an existing repository"
|
||||||
msgstr "Удалить существующий репозиторий"
|
msgstr "Удалить существующий репозиторий"
|
||||||
|
|
||||||
#: repo.go:128
|
#: repo.go:124
|
||||||
msgid "Name of the repo to be deleted"
|
msgid "Name of the repo to be deleted"
|
||||||
msgstr "Название репозитория удалён"
|
msgstr "Название репозитория удалён"
|
||||||
|
|
||||||
#: repo.go:156
|
#: repo.go:157
|
||||||
msgid "Repo does not exist"
|
msgid "Repo does not exist"
|
||||||
msgstr "Репозитория не существует"
|
msgstr "Репозитория не существует"
|
||||||
|
|
||||||
#: repo.go:164
|
#: repo.go:165
|
||||||
msgid "Error removing repo directory"
|
msgid "Error removing repo directory"
|
||||||
msgstr "Ошибка при удалении каталога репозитория"
|
msgstr "Ошибка при удалении каталога репозитория"
|
||||||
|
|
||||||
#: repo.go:179
|
#: repo.go:188
|
||||||
msgid "Error removing packages from database"
|
msgid "Error removing packages from database"
|
||||||
msgstr "Ошибка при удалении пакетов из базы данных"
|
msgstr "Ошибка при удалении пакетов из базы данных"
|
||||||
|
|
||||||
#: repo.go:190
|
#: repo.go:199
|
||||||
msgid "Pull all repositories that have changed"
|
msgid "Pull all repositories that have changed"
|
||||||
msgstr "Скачать все изменённые репозитории"
|
msgstr "Скачать все изменённые репозитории"
|
||||||
|
|
||||||
@ -531,6 +528,10 @@ msgstr "Ошибка при выполнении шаблона"
|
|||||||
msgid "Upgrade all installed packages"
|
msgid "Upgrade all installed packages"
|
||||||
msgstr "Обновить все установленные пакеты"
|
msgstr "Обновить все установленные пакеты"
|
||||||
|
|
||||||
|
#: upgrade.go:101
|
||||||
|
msgid "Error pulling repos"
|
||||||
|
msgstr "Ошибка при извлечении репозиториев"
|
||||||
|
|
||||||
#: upgrade.go:107 upgrade.go:124
|
#: upgrade.go:107 upgrade.go:124
|
||||||
msgid "Error checking for updates"
|
msgid "Error checking for updates"
|
||||||
msgstr "Ошибка при проверке обновлений"
|
msgstr "Ошибка при проверке обновлений"
|
||||||
|
@ -18,7 +18,6 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log/slog"
|
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -26,6 +25,8 @@ import (
|
|||||||
|
|
||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetUidGidAlrUserString() (string, string, error) {
|
func GetUidGidAlrUserString() (string, string, error) {
|
||||||
@ -83,8 +84,7 @@ func DropCapsToAlrUser() error {
|
|||||||
func ExitIfCantDropCapsToAlrUser() cli.ExitCoder {
|
func ExitIfCantDropCapsToAlrUser() cli.ExitCoder {
|
||||||
err := DropCapsToAlrUser()
|
err := DropCapsToAlrUser()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Debug("dropping capabilities error", "err", err)
|
return cliutils.FormatCliExit(gotext.Get("Error dropping capabilities"), err)
|
||||||
return cli.Exit(gotext.Get("Error dropping capabilities"), 1)
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
83
repo.go
83
repo.go
@ -30,11 +30,8 @@ import (
|
|||||||
|
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils"
|
||||||
appbuilder "gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils/app_builder"
|
appbuilder "gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils/app_builder"
|
||||||
"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"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/utils"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/utils"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddRepoCmd() *cli.Command {
|
func AddRepoCmd() *cli.Command {
|
||||||
@ -57,31 +54,32 @@ func AddRepoCmd() *cli.Command {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
err := utils.ExitIfNotRoot()
|
if err := utils.ExitIfNotRoot(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := c.Context
|
|
||||||
|
|
||||||
name := c.String("name")
|
name := c.String("name")
|
||||||
repoURL := c.String("url")
|
repoURL := c.String("url")
|
||||||
|
|
||||||
cfg := config.New()
|
ctx := c.Context
|
||||||
err = cfg.Load()
|
|
||||||
|
deps, err := appbuilder.
|
||||||
|
New(ctx).
|
||||||
|
WithConfig().
|
||||||
|
Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cliutils.FormatCliExit(gotext.Get("Error loading config"), err)
|
return err
|
||||||
}
|
}
|
||||||
|
defer deps.Defer()
|
||||||
|
|
||||||
|
cfg := deps.Cfg
|
||||||
|
|
||||||
reposSlice := cfg.Repos()
|
reposSlice := cfg.Repos()
|
||||||
|
|
||||||
for _, repo := range reposSlice {
|
for _, repo := range reposSlice {
|
||||||
if repo.URL == repoURL {
|
if repo.URL == repoURL {
|
||||||
slog.Error("Repo already exists", "name", repo.Name)
|
return cliutils.FormatCliExit(gotext.Get("Repo %s already exists", repo.Name), nil)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reposSlice = append(reposSlice, types.Repo{
|
reposSlice = append(reposSlice, types.Repo{
|
||||||
Name: name,
|
Name: name,
|
||||||
URL: repoURL,
|
URL: repoURL,
|
||||||
@ -93,22 +91,20 @@ func AddRepoCmd() *cli.Command {
|
|||||||
return cliutils.FormatCliExit(gotext.Get("Error saving config"), err)
|
return cliutils.FormatCliExit(gotext.Get("Error saving config"), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if utils.DropCapsToAlrUser() != nil {
|
if err := utils.ExitIfCantDropCapsToAlrUser(); err != nil {
|
||||||
slog.Error(gotext.Get("Can't drop privileges"))
|
return err
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
db := database.New(cfg)
|
deps, err = appbuilder.
|
||||||
err = db.Init(ctx)
|
New(ctx).
|
||||||
|
UseConfig(cfg).
|
||||||
|
WithDB().
|
||||||
|
WithReposForcePull().
|
||||||
|
Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error(gotext.Get("Error pulling repos"), "err", err)
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
rs := repos.New(cfg, db)
|
|
||||||
err = rs.Pull(ctx, cfg.Repos())
|
|
||||||
if err != nil {
|
|
||||||
return cliutils.FormatCliExit(gotext.Get("Error pulling repos"), err)
|
|
||||||
}
|
}
|
||||||
|
defer deps.Defer()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@ -129,19 +125,24 @@ func RemoveRepoCmd() *cli.Command {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
err := utils.ExitIfNotRoot()
|
if err := utils.ExitIfNotRoot(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := c.Context
|
ctx := c.Context
|
||||||
|
|
||||||
name := c.String("name")
|
name := c.String("name")
|
||||||
cfg := config.New()
|
|
||||||
err = cfg.Load()
|
deps, err := appbuilder.
|
||||||
|
New(ctx).
|
||||||
|
WithConfig().
|
||||||
|
Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cliutils.FormatCliExit(gotext.Get("Error loading config"), err)
|
return err
|
||||||
}
|
}
|
||||||
|
defer deps.Defer()
|
||||||
|
|
||||||
|
cfg := deps.Cfg
|
||||||
|
|
||||||
found := false
|
found := false
|
||||||
index := 0
|
index := 0
|
||||||
@ -163,18 +164,26 @@ func RemoveRepoCmd() *cli.Command {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return cliutils.FormatCliExit(gotext.Get("Error removing repo directory"), err)
|
return cliutils.FormatCliExit(gotext.Get("Error removing repo directory"), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = cfg.SaveUserConfig()
|
err = cfg.SaveUserConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cliutils.FormatCliExit(gotext.Get("Error saving config"), err)
|
return cliutils.FormatCliExit(gotext.Get("Error saving config"), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
db := database.New(cfg)
|
if err := utils.ExitIfCantDropCapsToAlrUser(); err != nil {
|
||||||
err = db.Init(ctx)
|
return err
|
||||||
if err != nil {
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
err = db.DeletePkgs(ctx, "repository = ?", name)
|
|
||||||
|
deps, err = appbuilder.
|
||||||
|
New(ctx).
|
||||||
|
UseConfig(cfg).
|
||||||
|
WithDB().
|
||||||
|
Build()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer deps.Defer()
|
||||||
|
|
||||||
|
err = deps.DB.DeletePkgs(ctx, "repository = ?", name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cliutils.FormatCliExit(gotext.Get("Error removing packages from database"), err)
|
return cliutils.FormatCliExit(gotext.Get("Error removing packages from database"), err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user