This commit is contained in:
2025-04-14 23:35:10 +03:00
parent e3aaa88822
commit 6d5016270f
21 changed files with 449 additions and 349 deletions

View File

@ -22,8 +22,8 @@ import (
"log/slog"
"github.com/leonelquinteros/gotext"
"github.com/urfave/cli/v2"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/db"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
@ -68,8 +68,7 @@ func (b *AppBuilder) WithConfig() *AppBuilder {
cfg := config.New()
if err := cfg.Load(); err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
b.err = cli.Exit("", 1)
b.err = cliutils.FormatCliExit(gotext.Get("Error loading config"), err)
return b
}
@ -90,8 +89,7 @@ func (b *AppBuilder) WithDB() *AppBuilder {
db := db.New(cfg)
if err := db.Init(b.ctx); err != nil {
slog.Error(gotext.Get("Error initialization database"), "err", err)
b.err = cli.Exit("", 1)
b.err = cliutils.FormatCliExit(gotext.Get("Error initialization database"), err)
return b
}
@ -130,8 +128,7 @@ func (b *AppBuilder) withRepos(enablePull, forcePull bool) *AppBuilder {
if enablePull && (forcePull || cfg.AutoPull()) {
if err := rs.Pull(b.ctx, cfg.Repos()); err != nil {
slog.Error(gotext.Get("Error pulling repositories"), "err", err)
b.err = cli.Exit("", 1)
b.err = cliutils.FormatCliExit(gotext.Get("Error pulling repositories"), err)
return b
}
}

View File

@ -28,6 +28,7 @@ import (
"github.com/caarlos0/env"
"github.com/pelletier/go-toml/v2"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/constants"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
)
@ -83,14 +84,9 @@ func mergeStructs(dst, src interface{}) {
}
}
const (
systemConfigPath = "/etc/alr/alr.toml"
systemCachePath = "/var/cache/alr"
)
func (c *ALRConfig) Load() error {
systemConfig, err := readConfig(
systemConfigPath,
constants.SystemConfigPath,
)
if err != nil {
slog.Debug("Cannot read system config", "err", err)
@ -108,8 +104,8 @@ func (c *ALRConfig) Load() error {
c.cfg = config
c.paths = &Paths{}
c.paths.UserConfigPath = systemConfigPath
c.paths.CacheDir = systemCachePath
c.paths.UserConfigPath = constants.SystemConfigPath
c.paths.CacheDir = constants.SystemCachePath
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")

View File

@ -0,0 +1,23 @@
// 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 constants
const (
SystemConfigPath = "/etc/alr/alr.toml"
SystemCachePath = "/var/cache/alr"
AlrRunDir = "/var/run/alr"
)

View File

@ -9,64 +9,52 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: build.go:48
#: build.go:44
msgid "Build a local package"
msgstr ""
#: build.go:54
#: build.go:50
msgid "Path to the build script"
msgstr ""
#: build.go:59
#: build.go:55
msgid "Specify subpackage in script (for multi package script only)"
msgstr ""
#: build.go:64
#: build.go:60
msgid "Name of the package to build and its repo (example: default/go-bin)"
msgstr ""
#: build.go:69
#: build.go:65
msgid ""
"Build package from scratch even if there's an already built package available"
msgstr ""
#: build.go:75 build.go:79 build.go:88
#: build.go:71
msgid "Error getting working directory"
msgstr ""
#: build.go:104 build.go:108
msgid "Error dropping capabilities"
msgstr ""
#: build.go:115
msgid "Error loading config"
msgstr ""
#: build.go:122
msgid "Error initialization database"
msgstr ""
#: build.go:131
#: build.go:99
msgid "Unable to detect a supported package manager on the system"
msgstr ""
#: build.go:137
#: build.go:105
msgid "Error parsing os release"
msgstr ""
#: build.go:168 build.go:209
#: build.go:143 build.go:184
msgid "Error building package"
msgstr ""
#: build.go:185
#: build.go:160
msgid "Package not found"
msgstr ""
#: build.go:212
#: build.go:187
msgid "Nothing to build"
msgstr ""
#: build.go:221
#: build.go:196
msgid "Error moving the package"
msgstr ""
@ -166,7 +154,7 @@ msgstr ""
msgid "Error encoding script variables"
msgstr ""
#: install.go:45
#: install.go:41
msgid "Install a new package"
msgstr ""
@ -174,11 +162,11 @@ msgstr ""
msgid "Command install expected at least 1 argument, got %d"
msgstr ""
#: install.go:95
#: install.go:88
msgid "Error pulling repositories"
msgstr ""
#: install.go:158
#: install.go:159
msgid "Remove an installed package"
msgstr ""
@ -194,6 +182,14 @@ msgstr ""
msgid "Error removing packages"
msgstr ""
#: internal/cliutils/app_builder/builder.go:71
msgid "Error loading config"
msgstr ""
#: internal/cliutils/app_builder/builder.go:92
msgid "Error initialization database"
msgstr ""
#: internal/cliutils/prompt.go:60
msgid "Would you like to view the build script for %s"
msgstr ""
@ -311,7 +307,11 @@ msgstr ""
msgid "ERROR"
msgstr ""
#: internal/utils/cmd.go:94
#: internal/utils/cmd.go:86
msgid "Error dropping capabilities"
msgstr ""
#: internal/utils/cmd.go:93
msgid "You need to be root to perform this action"
msgstr ""
@ -331,27 +331,27 @@ msgstr ""
msgid "Enable interactive questions and prompts"
msgstr ""
#: main.go:148
#: main.go:147
msgid "Show help"
msgstr ""
#: main.go:152
#: main.go:151
msgid "Error while running app"
msgstr ""
#: pkg/build/build.go:392
#: pkg/build/build.go:394
msgid "Building package"
msgstr ""
#: pkg/build/build.go:421
#: pkg/build/build.go:423
msgid "The checksums array must be the same length as sources"
msgstr ""
#: pkg/build/build.go:448
#: pkg/build/build.go:454
msgid "Downloading sources"
msgstr ""
#: pkg/build/build.go:535
#: pkg/build/build.go:543
msgid "Installing dependencies"
msgstr ""
@ -419,47 +419,47 @@ msgid ""
"updating ALR if something doesn't work."
msgstr ""
#: repo.go:40
#: repo.go:39
msgid "Add a new repository"
msgstr ""
#: repo.go:47
#: repo.go:46
msgid "Name of the new repo"
msgstr ""
#: repo.go:53
#: repo.go:52
msgid "URL of the new repo"
msgstr ""
#: repo.go:80
#: repo.go:79
msgid "Repo %s already exists"
msgstr ""
#: repo.go:91 repo.go:169
#: repo.go:90 repo.go:167
msgid "Error saving config"
msgstr ""
#: repo.go:117
#: repo.go:116
msgid "Remove an existing repository"
msgstr ""
#: repo.go:124
#: repo.go:123
msgid "Name of the repo to be deleted"
msgstr ""
#: repo.go:157
msgid "Repo does not exist"
#: repo.go:156
msgid "Repo \"%s\" does not exist"
msgstr ""
#: repo.go:165
#: repo.go:163
msgid "Error removing repo directory"
msgstr ""
#: repo.go:188
#: repo.go:186
msgid "Error removing packages from database"
msgstr ""
#: repo.go:199
#: repo.go:197
msgid "Pull all repositories that have changed"
msgstr ""
@ -503,14 +503,14 @@ msgstr ""
msgid "Upgrade all installed packages"
msgstr ""
#: upgrade.go:101
#: upgrade.go:103
msgid "Error pulling repos"
msgstr ""
#: upgrade.go:107 upgrade.go:124
#: upgrade.go:109 upgrade.go:126
msgid "Error checking for updates"
msgstr ""
#: upgrade.go:127
#: upgrade.go:129
msgid "There is nothing to do."
msgstr ""

View File

@ -16,67 +16,53 @@ msgstr ""
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"X-Generator: Gtranslator 47.1\n"
#: build.go:48
#: build.go:44
msgid "Build a local package"
msgstr "Сборка локального пакета"
#: build.go:54
#: build.go:50
msgid "Path to the build script"
msgstr "Путь к скрипту сборки"
#: build.go:59
#: build.go:55
msgid "Specify subpackage in script (for multi package script only)"
msgstr "Укажите подпакет в скрипте (только для многопакетного скрипта)"
#: build.go:64
#: build.go:60
msgid "Name of the package to build and its repo (example: default/go-bin)"
msgstr "Имя пакета для сборки и его репозиторий (пример: default/go-bin)"
#: build.go:69
#: build.go:65
msgid ""
"Build package from scratch even if there's an already built package available"
msgstr "Создайте пакет с нуля, даже если уже имеется готовый пакет"
#: build.go:75 build.go:79 build.go:88
#: build.go:71
msgid "Error getting working directory"
msgstr "Ошибка при получении рабочего каталога"
#: build.go:104 build.go:108
#, fuzzy
msgid "Error dropping capabilities"
msgstr "Ошибка при открытии базы данных"
#: build.go:115
#, fuzzy
msgid "Error loading config"
msgstr "Ошибка при кодировании конфигурации"
#: build.go:122
msgid "Error initialization database"
msgstr "Ошибка инициализации базы данных"
#: build.go:131
#: build.go:99
msgid "Unable to detect a supported package manager on the system"
msgstr "Не удалось обнаружить поддерживаемый менеджер пакетов в системе"
#: build.go:137
#: build.go:105
msgid "Error parsing os release"
msgstr "Ошибка при разборе файла выпуска операционной системы"
#: build.go:168 build.go:209
#: build.go:143 build.go:184
msgid "Error building package"
msgstr "Ошибка при сборке пакета"
#: build.go:185
#: build.go:160
msgid "Package not found"
msgstr "Пакет не найден"
#: build.go:212
#: build.go:187
#, fuzzy
msgid "Nothing to build"
msgstr "Исполнение build()"
#: build.go:221
#: build.go:196
msgid "Error moving the package"
msgstr "Ошибка при перемещении пакета"
@ -181,7 +167,7 @@ msgstr "Ошибка устранения переорпеделений"
msgid "Error encoding script variables"
msgstr "Ошибка кодирования переменных скрита"
#: install.go:45
#: install.go:41
msgid "Install a new package"
msgstr "Установить новый пакет"
@ -189,11 +175,11 @@ msgstr "Установить новый пакет"
msgid "Command install expected at least 1 argument, got %d"
msgstr "Для команды install ожидался хотя бы 1 аргумент, получено %d"
#: install.go:95
#: install.go:88
msgid "Error pulling repositories"
msgstr "Ошибка при извлечении репозиториев"
#: install.go:158
#: install.go:159
msgid "Remove an installed package"
msgstr "Удалить установленный пакет"
@ -209,6 +195,15 @@ msgstr "Для команды remove ожидался хотя бы 1 аргум
msgid "Error removing packages"
msgstr "Ошибка при удалении пакетов"
#: internal/cliutils/app_builder/builder.go:71
#, fuzzy
msgid "Error loading config"
msgstr "Ошибка при кодировании конфигурации"
#: internal/cliutils/app_builder/builder.go:92
msgid "Error initialization database"
msgstr "Ошибка инициализации базы данных"
#: internal/cliutils/prompt.go:60
msgid "Would you like to view the build script for %s"
msgstr "Показать скрипт для пакета %s"
@ -327,7 +322,12 @@ msgstr "%s %s загружается — %s/с\n"
msgid "ERROR"
msgstr "ОШИБКА"
#: internal/utils/cmd.go:94
#: internal/utils/cmd.go:86
#, fuzzy
msgid "Error dropping capabilities"
msgstr "Ошибка при открытии базы данных"
#: internal/utils/cmd.go:93
msgid "You need to be root to perform this action"
msgstr ""
@ -347,27 +347,27 @@ msgstr "Аргументы, которые будут переданы мене
msgid "Enable interactive questions and prompts"
msgstr "Включение интерактивных вопросов и запросов"
#: main.go:148
#: main.go:147
msgid "Show help"
msgstr "Показать справку"
#: main.go:152
#: main.go:151
msgid "Error while running app"
msgstr "Ошибка при запуске приложения"
#: pkg/build/build.go:392
#: pkg/build/build.go:394
msgid "Building package"
msgstr "Сборка пакета"
#: pkg/build/build.go:421
#: pkg/build/build.go:423
msgid "The checksums array must be the same length as sources"
msgstr "Массив контрольных сумм должен быть той же длины, что и источники"
#: pkg/build/build.go:448
#: pkg/build/build.go:454
msgid "Downloading sources"
msgstr "Скачивание источников"
#: pkg/build/build.go:535
#: pkg/build/build.go:543
msgid "Installing dependencies"
msgstr "Установка зависимостей"
@ -441,49 +441,50 @@ msgstr ""
"Минимальная версия ALR для ALR-репозитория выше текущей версии. Попробуйте "
"обновить ALR, если что-то не работает."
#: repo.go:40
#: repo.go:39
msgid "Add a new repository"
msgstr "Добавить новый репозиторий"
#: repo.go:47
#: repo.go:46
msgid "Name of the new repo"
msgstr "Название нового репозитория"
#: repo.go:53
#: repo.go:52
msgid "URL of the new repo"
msgstr "URL-адрес нового репозитория"
#: repo.go:80
#: repo.go:79
#, fuzzy
msgid "Repo %s already exists"
msgstr "Репозитория не существует"
#: repo.go:91 repo.go:169
#: repo.go:90 repo.go:167
#, fuzzy
msgid "Error saving config"
msgstr "Ошибка при кодировании конфигурации"
#: repo.go:117
#: repo.go:116
msgid "Remove an existing repository"
msgstr "Удалить существующий репозиторий"
#: repo.go:124
#: repo.go:123
msgid "Name of the repo to be deleted"
msgstr "Название репозитория удалён"
#: repo.go:157
msgid "Repo does not exist"
#: repo.go:156
#, fuzzy
msgid "Repo \"%s\" does not exist"
msgstr "Репозитория не существует"
#: repo.go:165
#: repo.go:163
msgid "Error removing repo directory"
msgstr "Ошибка при удалении каталога репозитория"
#: repo.go:188
#: repo.go:186
msgid "Error removing packages from database"
msgstr "Ошибка при удалении пакетов из базы данных"
#: repo.go:199
#: repo.go:197
msgid "Pull all repositories that have changed"
msgstr "Скачать все изменённые репозитории"
@ -528,18 +529,26 @@ msgstr "Ошибка при выполнении шаблона"
msgid "Upgrade all installed packages"
msgstr "Обновить все установленные пакеты"
#: upgrade.go:101
#: upgrade.go:103
msgid "Error pulling repos"
msgstr "Ошибка при извлечении репозиториев"
#: upgrade.go:107 upgrade.go:124
#: upgrade.go:109 upgrade.go:126
msgid "Error checking for updates"
msgstr "Ошибка при проверке обновлений"
#: upgrade.go:127
#: upgrade.go:129
msgid "There is nothing to do."
msgstr "Здесь нечего делать."
#, fuzzy
#~ msgid "Error getting current executable"
#~ msgstr "Ошибка при получении рабочего каталога"
#, fuzzy
#~ msgid "Error mounting"
#~ msgstr "Ошибка при кодировании конфигурации"
#, fuzzy
#~ msgid "Unable to create config directory"
#~ msgstr "Не удалось создать каталог конфигурации ALR"

View File

@ -80,7 +80,6 @@ func DropCapsToAlrUser() error {
return nil
}
// Returns cli.Exit to
func ExitIfCantDropCapsToAlrUser() cli.ExitCoder {
err := DropCapsToAlrUser()
if err != nil {
@ -95,3 +94,63 @@ func ExitIfNotRoot() error {
}
return nil
}
func EnuseIsAlrUser() error {
uid, gid, err := GetUidGidAlrUser()
if err != nil {
return err
}
newUid := syscall.Getuid()
if newUid != uid {
return errors.New("new uid don't matches requested")
}
newGid := syscall.Getgid()
if newGid != gid {
return errors.New("new gid don't matches requested")
}
return nil
}
func EnuseIsWheelMember() error {
currentUser, err := user.Current()
if err != nil {
return err
}
group, err := user.LookupGroup("wheel")
if err != nil {
return err
}
groups, err := currentUser.GroupIds()
if err != nil {
return err
}
for _, gid := range groups {
if gid == group.Gid {
return nil
}
}
return errors.New("looks like is not wheel member")
}
func EscalateToRootGid() error {
return syscall.Setgid(0)
}
func EscalateToRootUid() error {
return syscall.Setuid(0)
}
func EscalateToRoot() error {
err := EscalateToRootUid()
if err != nil {
return err
}
err = EscalateToRootGid()
if err != nil {
return err
}
return nil
}

23
internal/utils/utils.go Normal file
View File

@ -0,0 +1,23 @@
// 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 utils
import "golang.org/x/sys/unix"
func NoNewPrivs() error {
return unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)
}