32 Commits

Author SHA1 Message Date
3d9f4a0985 Улучшения обработки зависимостей и фильтрации установленных пакетов
- Добавлена поддержка версионных ограничений при установке пакетов
- Улучшена логика фильтрации уже установленных пакетов
- Добавлен метод GetInstalledVersion для всех менеджеров пакетов
- Активированы тесты для систем archlinux, alpine, opensuse-leap
- Улучшена обработка переменных в скриптах

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-01-16 01:01:01 +03:00
b649a459b8 Merge pull request 'Исправлен ключ дефолтного репозитория в конфигурации' (#139) from fix/default-repo-config-key into master
All checks were successful
Pre-commit / pre-commit (push) Successful in 4m3s
Create Release / changelog (push) Successful in 2m38s
Reviewed-on: #139
2025-12-15 20:28:51 +00:00
e8c20bad25 Исправлен ключ дефолтного репозитория в конфигурации
All checks were successful
Pre-commit / pre-commit (pull_request) Successful in 3m51s
Ключ "repos" изменён на "repo" для соответствия тегу koanf в структуре Config.
Это исправляет проблему, когда дефолтный репозиторий alr-default не загружался.
2025-12-15 23:22:15 +03:00
df69f3dcab Merge pull request 'Исправлена повторная сборка подпакетов мультипакета' (#138) from fix/multipackage-dependencies into master
All checks were successful
Pre-commit / pre-commit (push) Successful in 4m8s
Create Release / changelog (push) Successful in 2m43s
Reviewed-on: #138
2025-12-15 19:42:57 +00:00
a44da806d4 Исправлена повторная сборка подпакетов мультипакета
All checks were successful
Pre-commit / pre-commit (pull_request) Successful in 4m37s
При установке пакета с зависимостями на другие подпакеты того же
мультипакета теперь каждый подпакет собирается только один раз.
2025-12-15 22:36:49 +03:00
6567f8a71f Merge pull request 'Извлечение имени репозитория из пути к скрипту при сборке через -s' (#137) from fix/repository-name-from-path into master
All checks were successful
Pre-commit / pre-commit (push) Successful in 3m42s
Create Release / changelog (push) Successful in 2m26s
Reviewed-on: #137
2025-12-09 08:38:45 +00:00
7448d91817 Извлечение имени репозитория из пути к скрипту при сборке через -s
All checks were successful
Pre-commit / pre-commit (pull_request) Successful in 3m47s
2025-12-09 11:33:14 +03:00
f775641cb7 Обновлён сгенерированный package_gen.go с лицензией
All checks were successful
Pre-commit / pre-commit (push) Successful in 3m34s
2025-12-08 22:26:00 +00:00
e05396f214 Добавлен лицензионный заголовок в генератор package_gen.go
Some checks failed
Pre-commit / pre-commit (push) Failing after 3m12s
2025-12-08 22:19:07 +00:00
5e094fa69f gitignore
Some checks failed
Pre-commit / pre-commit (push) Failing after 3m16s
2025-12-08 21:59:20 +00:00
d7e910c06c Оптимизация сборки зависимостей и исправление кеширования
All checks were successful
Create Release / changelog (push) Successful in 2m26s
- Добавлено полное разрешение дерева зависимостей перед сборкой
- Общие зависимости теперь собираются только один раз
- Исправлена работа кеша для подпакетов
- Исправлена обработка системных зависимостей
2025-12-08 21:58:41 +00:00
6529094fa7 Добавлен go-generate hook в pre-commit и лицензионные заголовки в автогенерируемые файлы
Some checks failed
Pre-commit / pre-commit (push) Failing after 3m21s
Изменения:
- Добавлен hook go-generate перед update-license в .pre-commit-config.yaml
- Добавлены лицензионные заголовки в pkg/alrsh/package_gen.go
2025-12-07 11:19:42 +03:00
c2d48c1a13 Исправлена проблема дублирования обновлений пакетов с подпакетами
Some checks failed
Pre-commit / pre-commit (push) Failing after 8m9s
Create Release / changelog (push) Successful in 3m30s
Изменения:
- Заменён вызов InstallALRPackages на InstallPkgs в upgrade.go
- Переименована функция mapUptatesInfoToPackages в mapUpdatesToPackageNames
- Добавлена дедупликация подпакетов по полному имени (package+repo)
- Теперь возвращаются строки с именами пакетов вместо объектов Package
2025-12-06 13:08:13 +03:00
72cdfcaa4b Замена vercmp и оптимизация сборки зависимостей с полной русификацией интерфейса
All checks were successful
Pre-commit / pre-commit (push) Successful in 6m13s
Create Release / changelog (push) Successful in 2m58s
- Заменен vercmp с go.elara.ws/vercmp на gitea.plemya-x.ru/xpamych/vercmp v0.0.1
- Добавлена функция FilterPackagesByVersion для проверки версий установленных
  пакетов перед пересборкой зависимостей (учитывает version-release и epoch)
- Исправлена инициализация переводов в плагинах: добавлены вызовы translations.Setup()
  во всех plugin subcommands (_internal-safe-script-executor, _internal-installer,
  _internal-repos)
- Добавлен GetSubcommandHelpTemplate для корректного отображения справки команд
  с подкомандами на русском языке
- Добавлены кастомные help команды для config, repo, helper и mirror
- Добавлены русские переводы для всех пользовательских сообщений:
  * Сообщения о создании пакетов (Creating package file, Packaging with nfpm и др.)
  * Сообщения команды fix (Clearing cache, Fixing permissions и др.)
  * Сообщения обновления (Updating system packages, System packages updated)
  * Сообщения о версиях пакетов (Package is installed with older/newer version)
  * Заголовки справки (NAME, USAGE, COMMANDS, OPTIONS)
  * Справочные сообщения (Shows a list of commands or help for one command)
- Оптимизирован assets/logo.png (уменьшен с 37KB до 17KB)
2025-11-29 19:32:13 +03:00
c9c8397856 Исправлена проблема, когда при первом запуске ALR требовалось вручную
All checks were successful
Pre-commit / pre-commit (push) Successful in 6m30s
Create Release / changelog (push) Successful in 3m31s
выполнять 'sudo alr fix' для создания необходимых директорий. Теперь
  директории /var/cache/alr и /tmp/alr создаются автоматически при первом
  использовании с правильными правами доступа.
2025-11-23 15:16:22 +03:00
107075e8ef Исправлен dlcache_prod
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m46s
2025-10-12 19:11:15 +03:00
41e3d8119f Добавлены files-find: systemd, systemd-user, license
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m33s
Create Release / changelog (push) Successful in 3m12s
2025-09-25 22:10:47 +03:00
cf804ec66b Исправлена проблема с перемещением готового пакета из временной дирректории сборки (в случае зависимости)
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m12s
Create Release / changelog (push) Successful in 3m6s
2025-09-21 17:50:31 +03:00
6773d51caf Добавление функций обработки files
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m8s
Create Release / changelog (push) Successful in 3m5s
2025-09-21 16:42:04 +03:00
4a616f2137 Исправление функционала создания дирректорий для работы ALR
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m23s
Create Release / changelog (push) Successful in 3m3s
2025-09-21 16:21:23 +03:00
9efebbc02a Исправление функционала создания дирректорий для работы ALR
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m11s
Create Release / changelog (push) Successful in 3m11s
2025-09-21 15:31:51 +03:00
ef41d682a1 Исправление функционала повышения привилегий
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m12s
Create Release / changelog (push) Successful in 3m8s
2025-09-21 15:04:42 +03:00
42f0d5e575 Исправление дублирования "alr" в названии пакета
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m6s
Create Release / changelog (push) Successful in 3m7s
2025-09-21 13:43:36 +03:00
7b9404a058 Исправление обработки зависимостей на debian-based
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m28s
Create Release / changelog (push) Successful in 3m6s
2025-09-21 12:36:48 +03:00
18e8dc3fbf Исправление логики определения привилегированной группы для debian производных дистрибутивов
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m28s
Create Release / changelog (push) Successful in 3m10s
2025-09-21 01:08:26 +03:00
9c0af83a20 Добавление вычисления SHA256 для архива и обновление версии и чексуммы
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m33s
2025-09-19 23:13:32 +03:00
4bd20d84ef Добавление логики поиска пакета с noarch
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m28s
2025-09-16 23:44:23 +03:00
8dea5e1e7f Улучшена логика создания конфига при новом запуске и при появлении новых опций (миграция)
All checks were successful
Pre-commit / pre-commit (push) Successful in 6m38s
Create Release / changelog (push) Successful in 3m4s
2025-09-11 23:29:24 +03:00
86a982478e Исправление PrepareDirs вызывался только если пакет действительно нужно собирать
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m43s
Create Release / changelog (push) Successful in 3m8s
2025-09-08 22:31:43 +03:00
8bc82cb95c Добавление статистики
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m56s
Create Release / changelog (push) Successful in 3m27s
Исправление работы с мультипакетами
2025-09-01 01:32:43 +03:00
9783ce37de Добавление возможности обновления системным пакетным менеджером при alr up
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m39s
2025-08-28 12:03:14 +03:00
b852688ab0 Исправление фильтрации имён пакетов в скрипте установки
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m27s
2025-08-27 12:49:03 +03:00
67 changed files with 3888 additions and 547 deletions

View File

@@ -78,12 +78,31 @@ jobs:
token: ${{ secrets.GITEAPUBLIC }}
path: alr-default
- name: Update version in alr-bin
- name: Calculate checksum
run: |
# Замените значения в файле с конфигурацией
# Вычисляем SHA256 контрольную сумму архива
CHECKSUM=$(sha256sum alr-${{ env.VERSION }}-linux-x86_64.tar.gz | awk '{print $1}')
echo "Archive checksum: $CHECKSUM"
echo "CHECKSUM=$CHECKSUM" >> $GITHUB_ENV
- name: Update version and checksum in alr-bin
run: |
# Обновляем версию
sed -i "s/version='[0-9]\+\.[0-9]\+\.[0-9]\+'/version='${{ env.VERSION }}'/g" alr-default/alr-bin/alr.sh
sed -i "s/release='[0-9]\+'/release='1'/g" alr-default/alr-bin/alr.sh
# Обновляем контрольную сумму
sed -i "s/checksums=('[^']*')/checksums=('${{ env.CHECKSUM }}')/g" alr-default/alr-bin/alr.sh
- name: Commit and push changes to alr-default
run: |
cd alr-default
git config user.name "gitea"
git config user.email "admin@plemya-x.ru"
git add alr-bin/alr.sh
git commit -m "Обновление alr-bin до версии ${{ env.VERSION }}"
git push
- name: Install alr
env:
CREATE_SYSTEM_RESOURCES: 0

4
.gitignore vendored
View File

@@ -12,3 +12,7 @@
e2e-tests/alr
CLAUDE.md
commit_msg.txt
/scripts/.claude/settings.local.json
/ALR
.claude/settings.local.json
.directory

View File

@@ -0,0 +1,49 @@
# ALR - Any Linux Repository
# Copyright (C) 2025 The ALR Authors
#
# 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/>.
name: E2E
# on:
# push:
# branches: [ main ]
# pull_request:
on:
workflow_dispatch:
jobs:
tests:
runs-on: ubuntu-latest
container:
image: altlinux.space/maks1ms/actions-container-runner:latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
cache: false
- name: Run E2E tests
env:
IGNORE_ROOT_CHECK: 1
run: |
make e2e-test

View File

@@ -0,0 +1,49 @@
# ALR - Any Linux Repository
# Copyright (C) 2025 The ALR Authors
#
# 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/>.
name: Pre-commit
on:
push:
branches: [ master ]
pull_request:
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
- name: Set up Python for pre-commit
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install deps
run: apt-get update && apt-get install -y gettext bc
- run: pip install pre-commit
- run: pre-commit install
- run: pre-commit run --all-files

View File

@@ -0,0 +1,185 @@
# ALR - Any Linux Repository
# Copyright (C) 2025 The ALR Authors
#
# 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/>.
name: Create Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout this repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
- name: Get Changes between Tags
id: changes
run: |
# Получаем текущий и предыдущий теги
CURRENT_TAG=${GITHUB_REF##*/}
PREVIOUS_TAG=$(git describe --tags --abbrev=0 ${CURRENT_TAG}^ 2>/dev/null || echo "")
if [ -n "$PREVIOUS_TAG" ]; then
CHANGES=$(git log ${PREVIOUS_TAG}..${CURRENT_TAG} --pretty=format:"- %s" --no-merges)
else
CHANGES=$(git log ${CURRENT_TAG} --pretty=format:"- %s" --no-merges)
fi
# Экранируем для использования в GitHub Actions
CHANGES="${CHANGES//'%'/'%25'}"
CHANGES="${CHANGES//$'\n'/'%0A'}"
CHANGES="${CHANGES//$'\r'/'%0D'}"
echo "changes=$CHANGES" >> $GITHUB_OUTPUT
- name: Set version
run: |
version=$(echo "${GITHUB_REF##*/}" | sed 's/^v//')
echo "Version - $version"
echo "VERSION=$version" >> $GITHUB_ENV
- name: Prepare for install
run: |
apt-get update
- name: Build alr
env:
IGNORE_ROOT_CHECK: 1
run: |
make build
- name: Create tar.gz
run: |
mkdir -p ./out/completion
cp alr ./out
cp scripts/completion/bash ./out/completion/alr
cp scripts/completion/zsh ./out/completion/_alr
( cd out && tar -czvf ../alr-${{ env.VERSION }}-linux-x86_64.tar.gz * )
- name: Create Release via GitVerse API
env:
GITVERSE_TOKEN: ${{ secrets.GITVERSE_TOKEN }}
run: |
TAG_NAME=${GITHUB_REF##*/}
RELEASE_NAME="ALR ${{ env.VERSION }}"
BODY="${{ steps.changes.outputs.changes }}"
# Создаём релиз через GitVerse API
RELEASE_RESPONSE=$(curl -s -X POST \
"https://gitverse.ru/api/v1/repos/${{ gitverse.repository_owner }}/${{ gitverse.repository }}/releases" \
-H "Authorization: token ${GITVERSE_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"tag_name\": \"${TAG_NAME}\",
\"name\": \"${RELEASE_NAME}\",
\"body\": \"${BODY}\",
\"draft\": false,
\"prerelease\": false
}")
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | jq -r '.id')
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV
echo "Created release with ID: $RELEASE_ID"
- name: Upload tar.gz asset
env:
GITVERSE_TOKEN: ${{ secrets.GITVERSE_TOKEN }}
run: |
curl -s -X POST \
"https://gitverse.ru/api/v1/repos/${{ gitverse.repository_owner }}/${{ gitverse.repository }}/releases/${{ env.RELEASE_ID }}/assets?name=alr-${{ env.VERSION }}-linux-x86_64.tar.gz" \
-H "Authorization: token ${GITVERSE_TOKEN}" \
-H "Content-Type: application/octet-stream" \
--data-binary "@alr-${{ env.VERSION }}-linux-x86_64.tar.gz"
- name: Checkout alr-default repository
uses: actions/checkout@v4
with:
repository: ${{ gitverse.repository_owner }}/alr-default
token: ${{ secrets.GITVERSE_PUBLIC_TOKEN }}
path: alr-default
- name: Calculate checksum
run: |
# Вычисляем SHA256 контрольную сумму архива
CHECKSUM=$(sha256sum alr-${{ env.VERSION }}-linux-x86_64.tar.gz | awk '{print $1}')
echo "Archive checksum: $CHECKSUM"
echo "CHECKSUM=$CHECKSUM" >> $GITHUB_ENV
- name: Update version and checksum in alr-bin
run: |
# Обновляем версию
sed -i "s/version='[0-9]\+\.[0-9]\+\.[0-9]\+'/version='${{ env.VERSION }}'/g" alr-default/alr-bin/alr.sh
sed -i "s/release='[0-9]\+'/release='1'/g" alr-default/alr-bin/alr.sh
# Обновляем контрольную сумму
sed -i "s/checksums=('[^']*')/checksums=('${{ env.CHECKSUM }}')/g" alr-default/alr-bin/alr.sh
- name: Commit and push changes to alr-default
run: |
cd alr-default
git config user.name "gitverse"
git config user.email "admin@plemya-x.ru"
git add alr-bin/alr.sh
git commit -m "Обновление alr-bin до версии ${{ env.VERSION }}"
git push
- name: Install alr
env:
CREATE_SYSTEM_RESOURCES: 0
run: |
make install
- name: Prepare directories for ALR
run: |
# Создаём необходимые директории для работы alr build
mkdir -p /tmp/alr/dl /tmp/alr/pkgs /var/cache/alr
chmod -R 777 /tmp/alr
chmod -R 755 /var/cache/alr
- name: Build packages
run: |
SCRIPT_PATH=alr-default/alr-bin/alr.sh
ALR_DISTRO=altlinux ALR_PKG_FORMAT=rpm alr build -s "$SCRIPT_PATH"
ALR_PKG_FORMAT=rpm alr build -s "$SCRIPT_PATH"
ALR_PKG_FORMAT=deb alr build -s "$SCRIPT_PATH"
ALR_PKG_FORMAT=archlinux alr build -s "$SCRIPT_PATH"
- name: Upload package assets
env:
GITVERSE_TOKEN: ${{ secrets.GITVERSE_TOKEN }}
run: |
# Загружаем все собранные пакеты
for file in alr-bin*.deb alr-bin*.rpm alr-bin*.pkg.tar.zst; do
if [ -f "$file" ]; then
echo "Uploading $file..."
curl -s -X POST \
"https://gitverse.ru/api/v1/repos/${{ gitverse.repository_owner }}/${{ gitverse.repository }}/releases/${{ env.RELEASE_ID }}/assets?name=${file}" \
-H "Authorization: token ${GITVERSE_TOKEN}" \
-H "Content-Type: application/octet-stream" \
--data-binary "@${file}"
fi
done

View File

@@ -29,6 +29,12 @@ repos:
language: system
pass_filenames: false
- id: go-generate
name: Run go generate
entry: bash -c 'go generate ./...'
language: system
pass_filenames: false
- id: update-license
name: Update license
entry: make update-license

View File

@@ -1,2 +1 @@
Евгений Храмов
Maxim Slipenko

View File

@@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -63,7 +63,7 @@ func BuildCmd() *cli.Command {
},
},
Action: func(c *cli.Context) error {
if err := utils.EnuseIsPrivilegedGroupMember(); err != nil {
if err := utils.CheckUserPrivileges(); err != nil {
return err
}
@@ -197,6 +197,13 @@ func BuildCmd() *cli.Command {
for _, pkg := range res {
name := filepath.Base(pkg.Path)
// Проверяем, существует ли файл перед перемещением
if _, err := os.Stat(pkg.Path); os.IsNotExist(err) {
slog.Info(gotext.Get("Package file already moved or removed, skipping"), "path", pkg.Path)
continue
}
err = osutils.Move(pkg.Path, filepath.Join(wd, name))
if err != nil {
return cliutils.FormatCliExit(gotext.Get("Error moving the package"), err)

View File

@@ -38,6 +38,24 @@ func ConfigCmd() *cli.Command {
ShowCmd(),
SetConfig(),
GetConfig(),
ConfigHelpCmd(),
},
}
}
func ConfigHelpCmd() *cli.Command {
return &cli.Command{
Name: "help",
Aliases: []string{"h"},
Usage: gotext.Get("Shows a list of commands or help for one command"),
ArgsUsage: "[command]",
Action: func(cCtx *cli.Context) error {
args := cCtx.Args()
if args.Present() {
return cli.ShowCommandHelp(cCtx, args.First())
}
cli.ShowSubcommandHelp(cCtx)
return nil
},
}
}
@@ -76,6 +94,7 @@ var configKeys = []string{
"autoPull",
"logLevel",
"ignorePkgUpdates",
"updateSystemOnUpgrade",
}
func SetConfig() *cli.Command {
@@ -137,6 +156,12 @@ func SetConfig() *cli.Command {
}
}
deps.Cfg.System.SetIgnorePkgUpdates(updates)
case "updateSystemOnUpgrade":
boolValue, err := strconv.ParseBool(value)
if err != nil {
return cliutils.FormatCliExit(gotext.Get("invalid boolean value for %s: %s", key, value), err)
}
deps.Cfg.System.SetUpdateSystemOnUpgrade(boolValue)
case "repo", "repos":
return cliutils.FormatCliExit(gotext.Get("use 'repo add/remove' commands to manage repositories"), nil)
default:
@@ -206,6 +231,8 @@ func GetConfig() *cli.Command {
} else {
fmt.Println(strings.Join(updates, ", "))
}
case "updateSystemOnUpgrade":
fmt.Println(deps.Cfg.UpdateSystemOnUpgrade())
case "repo", "repos":
repos := deps.Cfg.Repos()
if len(repos) == 0 {

View File

@@ -30,19 +30,21 @@ var ALL_SYSTEMS []string = []string{
"ubuntu-24.04",
"alt-sisyphus",
"fedora-41",
// "archlinux",
// "alpine",
// "opensuse-leap",
// "redos-8",
"archlinux",
"alpine",
"opensuse-leap",
}
var AUTOREQ_AUTOPROV_SYSTEMS []string = []string{
// "alt-sisyphus",
"alt-sisyphus",
"fedora-41",
"opensuse-leap",
}
var RPM_SYSTEMS []string = []string{
"alt-sisyphus",
"fedora-41",
"opensuse-leap",
}
var COMMON_SYSTEMS []string = []string{

View File

@@ -45,17 +45,17 @@ func TestE2EIssue130Install(t *testing.T) {
)
runMatrixSuite(
t,
"alr install {package}+alr-{repo}",
"alr install {package}+{repo}",
COMMON_SYSTEMS,
func(t *testing.T, r capytest.Runner) {
t.Parallel()
defaultPrepare(t, r)
r.Command("sudo", "alr", "in", fmt.Sprintf("foo-pkg+alr-%s", REPO_NAME_FOR_E2E_TESTS)).
r.Command("sudo", "alr", "in", fmt.Sprintf("foo-pkg+%s", REPO_NAME_FOR_E2E_TESTS)).
ExpectSuccess().
Run(t)
r.Command("sudo", "alr", "in", fmt.Sprintf("bar-pkg+alr-%s", "NOT_REPO_NAME_FOR_E2E_TESTS")).
r.Command("sudo", "alr", "in", fmt.Sprintf("bar-pkg+%s", "NOT_REPO_NAME_FOR_E2E_TESTS")).
ExpectFailure().
Run(t)
},

32
fix.go
View File

@@ -131,22 +131,22 @@ func FixCmd() *cli.Command {
}
}
// Создаем базовый каталог /tmp/alr с владельцем root:wheel и правами 775
err = utils.EnsureTempDirWithRootOwner(tmpDir, 0o775)
// Создаем базовый каталог /tmp/alr с владельцем root:wheel и правами 2775
err = utils.EnsureTempDirWithRootOwner(tmpDir, 0o2775)
if err != nil {
slog.Warn(gotext.Get("Unable to create temporary directory"), "error", err)
}
// Создаем каталог dl с правами для группы wheel
dlDir := filepath.Join(tmpDir, "dl")
err = utils.EnsureTempDirWithRootOwner(dlDir, 0o775)
err = utils.EnsureTempDirWithRootOwner(dlDir, 0o2775)
if err != nil {
slog.Warn(gotext.Get("Unable to create download directory"), "error", err)
}
// Создаем каталог pkgs с правами для группы wheel
pkgsDir := filepath.Join(tmpDir, "pkgs")
err = utils.EnsureTempDirWithRootOwner(pkgsDir, 0o775)
err = utils.EnsureTempDirWithRootOwner(pkgsDir, 0o2775)
if err != nil {
slog.Warn(gotext.Get("Unable to create packages directory"), "error", err)
}
@@ -158,7 +158,8 @@ func FixCmd() *cli.Command {
// Проверяем, есть ли файлы в директории
entries, err := os.ReadDir(tmpDir)
if err == nil && len(entries) > 0 {
fixCmd := execWithPrivileges("chown", "-R", "root:wheel", tmpDir)
group := utils.GetPrivilegedGroup()
fixCmd := execWithPrivileges("chown", "-R", "root:"+group, tmpDir)
if fixErr := fixCmd.Run(); fixErr != nil {
slog.Warn(gotext.Get("Unable to fix file ownership"), "error", fixErr)
}
@@ -172,28 +173,13 @@ func FixCmd() *cli.Command {
slog.Info(gotext.Get("Rebuilding cache"))
// Пробуем создать директорию кэша
err = os.MkdirAll(paths.CacheDir, 0o775)
// Создаем директорию кэша с правильными правами
slog.Info(gotext.Get("Creating cache directory"))
err = utils.EnsureTempDirWithRootOwner(paths.CacheDir, 0o2775)
if err != nil {
// Если не получилось, пробуем через sudo с правильными правами для группы wheel
slog.Info(gotext.Get("Creating cache directory with sudo"))
sudoCmd := execWithPrivileges("mkdir", "-p", paths.CacheDir)
if sudoErr := sudoCmd.Run(); sudoErr != nil {
return cliutils.FormatCliExit(gotext.Get("Unable to create new cache directory"), err)
}
// Устанавливаем права 775 и группу wheel
chmodCmd := execWithPrivileges("chmod", "775", paths.CacheDir)
if chmodErr := chmodCmd.Run(); chmodErr != nil {
return cliutils.FormatCliExit(gotext.Get("Unable to set cache directory permissions"), chmodErr)
}
chgrpCmd := execWithPrivileges("chgrp", "wheel", paths.CacheDir)
if chgrpErr := chgrpCmd.Run(); chgrpErr != nil {
return cliutils.FormatCliExit(gotext.Get("Unable to set cache directory group"), chgrpErr)
}
}
deps, err = appbuilder.
New(ctx).
WithConfig().

View File

@@ -202,6 +202,23 @@ func main() {
var buf bytes.Buffer
buf.WriteString(`// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// 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/>.
`)
buf.WriteString("// DO NOT EDIT MANUALLY. This file is generated.\n")
buf.WriteString("package alrsh")

2
go.mod
View File

@@ -4,6 +4,7 @@ go 1.24.4
require (
gitea.plemya-x.ru/Plemya-x/fakeroot v0.0.2-0.20250408104831-427aaa7713c3
gitea.plemya-x.ru/xpamych/vercmp v0.0.1
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/PuerkitoBio/purell v1.2.0
github.com/alecthomas/chroma/v2 v2.9.1
@@ -36,7 +37,6 @@ require (
github.com/vmihailenco/msgpack/v5 v5.3.5
go.alt-gnome.ru/capytest v0.0.3-0.20250706082755-f20413e052f9
go.alt-gnome.ru/capytest/providers/podman v0.0.3-0.20250706082755-f20413e052f9
go.elara.ws/vercmp v0.0.0-20230622214216-0b2b067575c4
golang.org/x/crypto v0.36.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/sys v0.33.0

6
go.sum
View File

@@ -21,6 +21,8 @@ gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGq
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
gitea.plemya-x.ru/Plemya-x/fakeroot v0.0.2-0.20250408104831-427aaa7713c3 h1:56BjRJJ2Sv50DfSvNUydUMJwwFuiBMWC1uYtH2GYjk8=
gitea.plemya-x.ru/Plemya-x/fakeroot v0.0.2-0.20250408104831-427aaa7713c3/go.mod h1:iKQM6uttMJgE5CFrPw6SQqAV7TKtlJNICRAie/dTciw=
gitea.plemya-x.ru/xpamych/vercmp v0.0.1 h1:tFQzsPfnQQDQ3jrqW0UwUSbK+HwJuq0sA0GfnvIkatw=
gitea.plemya-x.ru/xpamych/vercmp v0.0.1/go.mod h1:z9qQ4QJDou1AULVKPIW5blu/jT+O3O5HpTV8aujWSIM=
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
github.com/AlekSi/pointer v1.2.0 h1:glcy/gc4h8HnG2Z3ZECSzZ1IX1x2JxRVuDzaJwQE0+w=
@@ -432,14 +434,10 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsr
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
gitlab.com/digitalxero/go-conventional-commit v1.0.7 h1:8/dO6WWG+98PMhlZowt/YjuiKhqhGlOCwlIV8SqqGh8=
gitlab.com/digitalxero/go-conventional-commit v1.0.7/go.mod h1:05Xc2BFsSyC5tKhK0y+P3bs0AwUtNuTp+mTpbCU/DZ0=
go.alt-gnome.ru/capytest v0.0.2 h1:clmvIqmYS86hhA1rsvivSSPpfOFkJTpbn38EQP7I3E8=
go.alt-gnome.ru/capytest v0.0.2/go.mod h1:lvxPx3H6h+LPnStBFblgoT2wkjv0wbug3S14troykEg=
go.alt-gnome.ru/capytest v0.0.3-0.20250706082755-f20413e052f9 h1:NST+V5LV/eLgs0p6PsuvfHiZ4UrIWqftCdifO8zgg0g=
go.alt-gnome.ru/capytest v0.0.3-0.20250706082755-f20413e052f9/go.mod h1:qiM8LARP+JBZr5mrDoVylOoqjrN0MAzvZ21NR9qMc0Y=
go.alt-gnome.ru/capytest/providers/podman v0.0.3-0.20250706082755-f20413e052f9 h1:VZclgdJxARvhZ6PIWWW2hQ6Ge4XeE36pzUr/U/y62bE=
go.alt-gnome.ru/capytest/providers/podman v0.0.3-0.20250706082755-f20413e052f9/go.mod h1:Wpq1Ny3eMzADJpMJArA2TZGZbsviUBmawtEPcxnoerg=
go.elara.ws/vercmp v0.0.0-20230622214216-0b2b067575c4 h1:Ep54XceQlKhcCHl9awG+wWP4kz4kIP3c3Lzw/Gc/zwY=
go.elara.ws/vercmp v0.0.0-20230622214216-0b2b067575c4/go.mod h1:/7PNW7nFnDR5W7UXZVc04gdVLR/wBNgkm33KgIz0OBk=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=

View File

@@ -49,11 +49,26 @@ func HelperCmd() *cli.Command {
},
}
helperHelpCmd := &cli.Command{
Name: "help",
Aliases: []string{"h"},
Usage: gotext.Get("Shows a list of commands or help for one command"),
ArgsUsage: "[command]",
Action: func(cCtx *cli.Context) error {
args := cCtx.Args()
if args.Present() {
return cli.ShowCommandHelp(cCtx, args.First())
}
cli.ShowSubcommandHelp(cCtx)
return nil
},
}
return &cli.Command{
Name: "helper",
Usage: gotext.Get("Run a ALR helper command"),
ArgsUsage: `<helper_name|"list">`,
Subcommands: []*cli.Command{helperListCmd},
Subcommands: []*cli.Command{helperListCmd, helperHelpCmd},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "dest-dir",
@@ -100,7 +115,6 @@ func HelperCmd() *cli.Command {
return helper(hc, c.Args().First(), c.Args().Slice()[1:])
},
CustomHelpTemplate: cli.CommandHelpTemplate,
BashComplete: func(ctx *cli.Context) {
for name := range helpers.Helpers {
fmt.Println(name)

View File

@@ -32,6 +32,7 @@ import (
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/logger"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/translations"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/utils"
)
@@ -42,6 +43,7 @@ func InternalBuildCmd() *cli.Command {
Hidden: true,
Action: func(c *cli.Context) error {
logger.SetupForGoPlugin()
translations.Setup()
slog.Debug("start _internal-safe-script-executor", "uid", syscall.Getuid(), "gid", syscall.Getgid())
@@ -81,7 +83,7 @@ func InternalReposCmd() *cli.Command {
Hidden: true,
Action: utils.RootNeededAction(func(ctx *cli.Context) error {
logger.SetupForGoPlugin()
translations.Setup()
deps, err := appbuilder.
New(ctx.Context).
@@ -115,6 +117,7 @@ func InternalInstallCmd() *cli.Command {
Hidden: true,
Action: func(c *cli.Context) error {
logger.SetupForGoPlugin()
translations.Setup()
// Запуск от текущего пользователя, повышение прав будет через sudo при необходимости

View File

@@ -32,6 +32,7 @@ import (
"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/manager"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/stats"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/types"
@@ -44,6 +45,7 @@ type BuildInput struct {
script string
repository string
packages []string
skipDepsBuilding bool // Пропустить сборку зависимостей (используется при вызове из BuildALRDeps)
}
func (bi *BuildInput) GobEncode() ([]byte, error) {
@@ -244,6 +246,7 @@ type BuildArgs struct {
Opts *types.BuildOpts
Info *distro.OSRelease
PkgFormat_ string
SkipDepsBuilding bool // Пропустить сборку зависимостей (используется при вызове из BuildALRDeps)
}
func (b *BuildArgs) BuildOpts() *types.BuildOpts {
@@ -283,6 +286,7 @@ func (b *Builder) BuildPackageFromDb(
pkgFormat: args.PkgFormat(),
opts: args.Opts,
info: args.Info,
skipDepsBuilding: args.SkipDepsBuilding,
})
}
@@ -292,7 +296,7 @@ func (b *Builder) BuildPackageFromScript(
) ([]*BuiltDep, error) {
return b.BuildPackage(ctx, &BuildInput{
script: args.Script,
repository: "default",
repository: ExtractRepoNameFromPath(args.Script),
packages: args.Packages,
pkgFormat: args.PkgFormat(),
opts: args.Opts,
@@ -319,9 +323,9 @@ func (b *Builder) BuildPackage(
}
var builtDeps []*BuiltDep
var remainingVars []*alrsh.Package
if !input.opts.Clean {
var remainingVars []*alrsh.Package
for _, vars := range varsOfPackages {
builtPkgPath, ok, err := b.cacheExecutor.CheckForBuiltPackage(ctx, input, vars)
if err != nil {
@@ -330,6 +334,7 @@ func (b *Builder) BuildPackage(
if ok {
builtDeps = append(builtDeps, &BuiltDep{
Path: builtPkgPath,
Name: vars.Name,
})
} else {
remainingVars = append(remainingVars, vars)
@@ -337,8 +342,12 @@ func (b *Builder) BuildPackage(
}
if len(remainingVars) == 0 {
slog.Info(gotext.Get("Using cached package"), "name", basePkg)
return builtDeps, nil
}
// Обновляем varsOfPackages только теми пакетами, которые нужно собрать
varsOfPackages = remainingVars
}
slog.Debug("ViewScript")
@@ -401,17 +410,34 @@ func (b *Builder) BuildPackage(
// We filter so as not to re-build what has already been built at the `installBuildDeps` stage.
var filteredDepends []string
// Создаем набор подпакетов текущего мультипакета для исключения циклических зависимостей
// Используем имена из varsOfPackages, так как input.packages может быть пустым
currentPackageNames := make(map[string]struct{})
for _, vars := range varsOfPackages {
currentPackageNames[vars.Name] = struct{}{}
}
for _, d := range depends {
if _, found := depNames[d]; !found {
// Исключаем зависимости, которые являются подпакетами текущего мультипакета
if _, isCurrentPackage := currentPackageNames[d]; !isCurrentPackage {
filteredDepends = append(filteredDepends, d)
}
}
}
var newBuiltDeps []*BuiltDep
var repoDeps []string
// Пропускаем сборку зависимостей если флаг установлен (вызов из BuildALRDeps)
if !input.skipDepsBuilding {
slog.Debug("BuildALRDeps")
newBuiltDeps, repoDeps, err := b.BuildALRDeps(ctx, input, filteredDepends)
newBuiltDeps, repoDeps, err = b.BuildALRDeps(ctx, input, filteredDepends)
if err != nil {
return nil, err
}
}
slog.Debug("PrepareDirs")
err = b.scriptExecutor.PrepareDirs(ctx, input, basePkg)
@@ -528,6 +554,13 @@ func (b *Builder) InstallALRPackages(
if err != nil {
return err
}
// Отслеживание установки ALR пакетов
for _, dep := range res {
if stats.ShouldTrackPackage(dep.Name) {
stats.TrackInstallation(ctx, dep.Name, "upgrade")
}
}
}
return nil
@@ -542,54 +575,137 @@ func (b *Builder) BuildALRDeps(
},
depends []string,
) (buildDeps []*BuiltDep, repoDeps []string, err error) {
if len(depends) > 0 {
if len(depends) == 0 {
return nil, nil, nil
}
slog.Info(gotext.Get("Installing dependencies"))
found, notFound, err := b.repos.FindPkgs(ctx, depends) // Поиск зависимостей
// Шаг 1: Рекурсивно разрешаем ВСЕ зависимости
depTree, systemDeps, err := b.ResolveDependencyTree(ctx, input, depends)
if err != nil {
return nil, nil, fmt.Errorf("failed FindPkgs: %w", err)
}
repoDeps = notFound
// Если для некоторых пакетов есть несколько опций, упрощаем их все в один срез
pkgs := cliutils.FlattenPkgs(
ctx,
found,
"install",
input.BuildOpts().Interactive,
)
type item struct {
pkg *alrsh.Package
packages []string
}
pkgsMap := make(map[string]*item)
for _, pkg := range pkgs {
name := pkg.BasePkgName
if name == "" {
name = pkg.Name
}
if pkgsMap[name] == nil {
pkgsMap[name] = &item{
pkg: &pkg,
}
}
pkgsMap[name].packages = append(
pkgsMap[name].packages,
pkg.Name,
)
return nil, nil, fmt.Errorf("failed to resolve dependency tree: %w", err)
}
for basePkgName := range pkgsMap {
pkg := pkgsMap[basePkgName].pkg
// Системные зависимости возвращаем как repoDeps
repoDeps = systemDeps
// Шаг 2: Топологическая сортировка (от корней к листьям)
sortedPkgs, err := TopologicalSort(depTree)
if err != nil {
return nil, nil, fmt.Errorf("failed to sort dependencies: %w", err)
}
// Шаг 2.5: Фильтруем уже установленные пакеты
// Собираем пакеты вместе с их ключами (именами поиска)
type pkgWithKey struct {
key string
pkg alrsh.Package
}
var allPkgsWithKeys []pkgWithKey
for key, node := range depTree {
if node.Package != nil {
allPkgsWithKeys = append(allPkgsWithKeys, pkgWithKey{key: key, pkg: *node.Package})
}
}
var allPkgs []alrsh.Package
for _, p := range allPkgsWithKeys {
allPkgs = append(allPkgs, p.pkg)
}
slog.Info("DEBUG: allPkgs count", "count", len(allPkgs))
for _, p := range allPkgsWithKeys {
slog.Info("DEBUG: package in depTree", "key", p.key, "name", p.pkg.Name, "repo", p.pkg.Repository)
}
needBuildPkgs, err := b.installerExecutor.FilterPackagesByVersion(ctx, allPkgs, input.OSRelease())
if err != nil {
return nil, nil, fmt.Errorf("failed to filter packages: %w", err)
}
// Создаём множество имён пакетов, которые нужно собрать
needBuildNames := make(map[string]bool)
for _, pkg := range needBuildPkgs {
needBuildNames[pkg.Name] = true
}
slog.Info("DEBUG: needBuildPkgs count", "count", len(needBuildPkgs))
for _, pkg := range needBuildPkgs {
slog.Info("DEBUG: package needs build", "name", pkg.Name)
}
// Строим needBuildSet по КЛЮЧАМ depTree, а не по pkg.Name
// Это важно, т.к. ключ может быть именем из Provides (python3-pyside6),
// а pkg.Name - фактическое имя пакета (python3-shiboken6)
needBuildSet := make(map[string]bool)
for _, p := range allPkgsWithKeys {
if needBuildNames[p.pkg.Name] {
needBuildSet[p.key] = true
}
}
// Шаг 3: Группируем подпакеты по basePkgName для оптимизации сборки
// Если несколько подпакетов из одного мультипакета, собираем их вместе
slog.Info("DEBUG: sortedPkgs", "pkgs", sortedPkgs)
// Шаг 4: Собираем пакеты в правильном порядке, проверяя кеш
for _, pkgName := range sortedPkgs {
node := depTree[pkgName]
if node == nil {
slog.Info("DEBUG: node is nil", "pkgName", pkgName)
continue
}
pkg := node.Package
basePkgName := node.BasePkgName
// Пропускаем уже установленные пакеты
if !needBuildSet[pkgName] {
slog.Info("DEBUG: skipping (not in needBuildSet)", "pkgName", pkgName)
continue
}
// Собираем только запрошенный подпакет (или все, если запрошен basePkgName)
packagesToBuilt := []string{pkgName}
// Проверяем кеш для запрошенного подпакета
scriptInfo := b.scriptResolver.ResolveScript(ctx, pkg)
buildInput := &BuildInput{
script: scriptInfo.Script,
repository: scriptInfo.Repository,
packages: packagesToBuilt,
pkgFormat: input.PkgFormat(),
opts: input.BuildOpts(),
info: input.OSRelease(),
}
cachedDeps, allInCache, err := b.checkCacheForAllSubpackages(ctx, buildInput, basePkgName, packagesToBuilt)
if err != nil {
return nil, nil, err
}
if allInCache {
// Подпакет в кеше, используем его
slog.Info("DEBUG: using cached package", "pkgName", pkgName)
buildDeps = append(buildDeps, cachedDeps...)
continue
}
slog.Info("DEBUG: building package", "pkgName", pkgName)
// Собираем только запрошенный подпакет
// SkipDepsBuilding: true предотвращает рекурсивный вызов BuildALRDeps
res, err := b.BuildPackageFromDb(
ctx,
&BuildPackageFromDbArgs{
Package: pkg,
Packages: pkgsMap[basePkgName].packages,
Packages: packagesToBuilt,
BuildArgs: BuildArgs{
Opts: input.BuildOpts(),
Info: input.OSRelease(),
PkgFormat_: input.PkgFormat(),
SkipDepsBuilding: true,
},
},
)
@@ -599,14 +715,90 @@ func (b *Builder) BuildALRDeps(
buildDeps = append(buildDeps, res...)
}
}
repoDeps = removeDuplicates(repoDeps)
buildDeps = removeDuplicates(buildDeps)
return buildDeps, repoDeps, nil
}
// findAllSubpackages находит все подпакеты для базового пакета
func (b *Builder) findAllSubpackages(ctx context.Context, basePkgName, repository string) ([]string, error) {
// Запрашиваем все пакеты с этим basepkg_name
pkgs, _, err := b.repos.FindPkgs(ctx, []string{basePkgName})
if err != nil {
return nil, err
}
var subpkgs []string
seen := make(map[string]bool)
for _, pkgList := range pkgs {
for _, pkg := range pkgList {
// Проверяем, что это пакет из нужного репозитория
if pkg.Repository == repository {
pkgBase := pkg.BasePkgName
if pkgBase == "" {
pkgBase = pkg.Name
}
// Добавляем только если это пакет с нужным BasePkgName
if pkgBase == basePkgName && !seen[pkg.Name] {
subpkgs = append(subpkgs, pkg.Name)
seen[pkg.Name] = true
}
}
}
}
return subpkgs, nil
}
// checkCacheForAllSubpackages проверяет кеш для всех подпакетов
func (b *Builder) checkCacheForAllSubpackages(
ctx context.Context,
buildInput *BuildInput,
basePkgName string,
subpkgs []string,
) ([]*BuiltDep, bool, error) {
var cachedDeps []*BuiltDep
allInCache := true
// Получаем информацию обо всех подпакетах
pkgsInfo, _, err := b.repos.FindPkgs(ctx, subpkgs)
if err != nil {
return nil, false, fmt.Errorf("failed to find subpackages info: %w", err)
}
for _, pkgName := range subpkgs {
var pkgForCheck *alrsh.Package
// Находим Package для подпакета
if pkgList, ok := pkgsInfo[pkgName]; ok && len(pkgList) > 0 {
pkgForCheck = &pkgList[0]
}
if pkgForCheck != nil {
pkgPath, found, err := b.cacheExecutor.CheckForBuiltPackage(ctx, buildInput, pkgForCheck)
if err != nil {
return nil, false, fmt.Errorf("failed to check cache: %w", err)
}
if found {
slog.Info(gotext.Get("Using cached package"), "name", pkgName, "path", pkgPath)
cachedDeps = append(cachedDeps, &BuiltDep{
Name: pkgName,
Path: pkgPath,
})
} else {
allInCache = false
break
}
}
}
return cachedDeps, allInCache && len(cachedDeps) > 0, nil
}
func (i *Builder) installBuildDeps(
ctx context.Context,
input interface {
@@ -691,6 +883,13 @@ func (i *Builder) InstallPkgs(
if err != nil {
return nil, err
}
// Отслеживание установки локальных пакетов
for _, dep := range builtDeps {
if stats.ShouldTrackPackage(dep.Name) {
stats.TrackInstallation(ctx, dep.Name, "install")
}
}
}
if len(repoDeps) > 0 {
@@ -700,6 +899,14 @@ func (i *Builder) InstallPkgs(
if err != nil {
return nil, err
}
_ = i.installerExecutor.CheckVersionsAfterInstall(ctx, repoDeps)
for _, pkg := range repoDeps {
if stats.ShouldTrackPackage(pkg) {
stats.TrackInstallation(ctx, pkg, "install")
}
}
}
return builtDeps, nil

View File

@@ -40,7 +40,12 @@ func (c *Cache) CheckForBuiltPackage(
return "", false, err
}
pkgPath := filepath.Join(getBaseDir(c.cfg, vars.Name), filename)
// Для подпакетов используем BasePkgName, чтобы искать в правильной директории
baseName := vars.BasePkgName
if baseName == "" {
baseName = vars.Name
}
pkgPath := filepath.Join(getBaseDir(c.cfg, baseName), filename)
_, err = os.Stat(pkgPath)
if err != nil {

View File

@@ -0,0 +1,190 @@
// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// 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 build
import (
"context"
"fmt"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/overrides"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
)
// DependencyNode представляет узел в дереве зависимостей
type DependencyNode struct {
Package *alrsh.Package
BasePkgName string
PkgName string // Имя конкретного подпакета (может отличаться от BasePkgName)
Dependencies []string // Имена зависимостей
}
// ResolveDependencyTree рекурсивно разрешает все зависимости и возвращает
// плоский список всех уникальных пакетов, необходимых для сборки
// и список системных зависимостей (не найденных в ALR-репозиториях)
func (b *Builder) ResolveDependencyTree(
ctx context.Context,
input interface {
OsInfoProvider
PkgFormatProvider
},
initialPkgs []string,
) (map[string]*DependencyNode, []string, error) {
resolved := make(map[string]*DependencyNode)
visited := make(map[string]bool)
systemDeps := make(map[string]bool)
overrideNames, err := overrides.Resolve(input.OSRelease(), overrides.DefaultOpts)
if err != nil {
return nil, nil, fmt.Errorf("failed to resolve overrides: %w", err)
}
var resolve func(pkgNames []string) error
resolve = func(pkgNames []string) error {
if len(pkgNames) == 0 {
return nil
}
// Находим пакеты
found, notFound, err := b.repos.FindPkgs(ctx, pkgNames)
if err != nil {
return fmt.Errorf("failed to find packages: %w", err)
}
// Собираем системные зависимости (не найденные в ALR)
for _, pkgName := range notFound {
systemDeps[pkgName] = true
}
// Обрабатываем найденные пакеты
for pkgName, pkgList := range found {
if visited[pkgName] {
continue
}
visited[pkgName] = true
// Берем первый пакет из списка (или можно добавить выбор пользователя)
if len(pkgList) == 0 {
continue
}
pkg := pkgList[0]
alrsh.ResolvePackage(&pkg, overrideNames)
baseName := pkg.BasePkgName
if baseName == "" {
baseName = pkg.Name
}
if resolved[pkgName] != nil {
continue
}
deps := pkg.Depends.Resolved()
buildDeps := pkg.BuildDepends.Resolved()
// Объединяем зависимости
allDeps := append([]string{}, deps...)
allDeps = append(allDeps, buildDeps...)
// Добавляем узел в resolved с ключом = имя подпакета
resolved[pkgName] = &DependencyNode{
Package: &pkg,
BasePkgName: baseName,
PkgName: pkgName,
Dependencies: allDeps,
}
// Рекурсивно разрешаем зависимости
if len(allDeps) > 0 {
if err := resolve(allDeps); err != nil {
return err
}
}
}
return nil
}
// Начинаем разрешение с начальных пакетов
if err := resolve(initialPkgs); err != nil {
return nil, nil, err
}
// Преобразуем map в слайс для системных зависимостей
var systemDepsList []string
for dep := range systemDeps {
systemDepsList = append(systemDepsList, dep)
}
return resolved, systemDepsList, nil
}
// TopologicalSort выполняет топологическую сортировку пакетов по зависимостям
// Возвращает список имен подпакетов в порядке сборки (от корней к листьям)
func TopologicalSort(nodes map[string]*DependencyNode) ([]string, error) {
// Список для результата
var result []string
// Множество посещенных узлов
visited := make(map[string]bool)
// Множество узлов в текущем пути (для обнаружения циклов)
inStack := make(map[string]bool)
var visit func(pkgName string) error
visit = func(pkgName string) error {
if visited[pkgName] {
return nil
}
if inStack[pkgName] {
return fmt.Errorf("circular dependency detected: %s", pkgName)
}
node := nodes[pkgName]
if node == nil {
// Это системный пакет или пакет не в дереве, игнорируем
return nil
}
inStack[pkgName] = true
// Посещаем все зависимости
for _, dep := range node.Dependencies {
// Используем имя зависимости напрямую (это имя подпакета)
if err := visit(dep); err != nil {
return err
}
}
inStack[pkgName] = false
visited[pkgName] = true
result = append(result, pkgName)
return nil
}
// Посещаем все узлы
for pkgName := range nodes {
if err := visit(pkgName); err != nil {
return nil, err
}
}
return result, nil
}

View File

@@ -42,6 +42,15 @@ func getDirs(
cfg Config,
scriptPath string,
basePkg string,
) (types.Directories, error) {
return getDirsForPackage(cfg, scriptPath, basePkg, "")
}
func getDirsForPackage(
cfg Config,
scriptPath string,
basePkg string,
packageName string,
) (types.Directories, error) {
pkgsDir := cfg.GetPaths().PkgsDir
@@ -50,10 +59,18 @@ func getDirs(
return types.Directories{}, err
}
baseDir := filepath.Join(pkgsDir, basePkg)
// Для подпакетов используем отдельную директорию pkg_<имя_подпакета>
// Для обычных пакетов используем просто pkg
pkgDirName := "pkg"
if packageName != "" {
pkgDirName = "pkg_" + packageName
}
return types.Directories{
BaseDir: getBaseDir(cfg, basePkg),
SrcDir: getSrcDir(cfg, basePkg),
PkgDir: filepath.Join(baseDir, "pkg"),
PkgDir: filepath.Join(baseDir, pkgDirName),
ScriptDir: getScriptDir(scriptPath),
}, nil
}

View File

@@ -18,6 +18,8 @@ package finddeps
import (
"context"
"os"
"os/exec"
"github.com/goreleaser/nfpm/v2"
@@ -39,10 +41,9 @@ func New(info *distro.OSRelease, pkgFormat string) *ProvReqService {
finder: &EmptyFindProvReq{},
}
if pkgFormat == "rpm" {
switch info.ID {
case "altlinux":
if _, err := os.Stat("/usr/lib/rpm/find-provides"); err == nil {
s.finder = &ALTLinuxFindProvReq{}
case "fedora":
} else if _, err := exec.LookPath("/usr/lib/rpm/rpmdeps"); err == nil {
s.finder = &FedoraFindProvReq{}
}
}

View File

@@ -18,8 +18,17 @@ package build
import (
"context"
"fmt"
"log/slog"
"github.com/leonelquinteros/gotext"
"gitea.plemya-x.ru/xpamych/vercmp"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/overrides"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/depver"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
)
func NewInstaller(mgr manager.Manager) *Installer {
@@ -35,7 +44,14 @@ func (i *Installer) InstallLocal(ctx context.Context, paths []string, opts *mana
}
func (i *Installer) Install(ctx context.Context, pkgs []string, opts *manager.Opts) error {
return i.mgr.Install(opts, pkgs...)
// Convert dependencies to manager-specific format
converted := make([]string, len(pkgs))
for idx, pkg := range pkgs {
dep := depver.Parse(pkg)
converted[idx] = dep.ForManager(i.mgr.Name())
}
return i.mgr.Install(opts, converted...)
}
func (i *Installer) Remove(ctx context.Context, pkgs []string, opts *manager.Opts) error {
@@ -46,15 +62,108 @@ func (i *Installer) RemoveAlreadyInstalled(ctx context.Context, pkgs []string) (
filteredPackages := []string{}
for _, dep := range pkgs {
installed, err := i.mgr.IsInstalled(dep)
parsed := depver.Parse(dep)
// Check if package is installed
installed, err := i.mgr.IsInstalled(parsed.Name)
if err != nil {
return nil, err
}
if installed {
if !installed {
filteredPackages = append(filteredPackages, dep)
continue
}
// If there's a version constraint, check if installed version satisfies it
if parsed.HasVersionConstraint() {
installedVer, err := i.mgr.GetInstalledVersion(parsed.Name)
if err != nil {
return nil, err
}
if !parsed.Satisfies(installedVer) {
// Installed version doesn't satisfy constraint - need to upgrade
slog.Debug("installed version doesn't satisfy constraint",
"package", parsed.Name,
"required", dep,
"installed", installedVer)
filteredPackages = append(filteredPackages, dep)
}
}
}
return filteredPackages, nil
}
func (i *Installer) CheckVersionsAfterInstall(ctx context.Context, pkgs []string) error {
for _, pkg := range pkgs {
parsed := depver.Parse(pkg)
if !parsed.HasVersionConstraint() {
continue
}
installedVer, err := i.mgr.GetInstalledVersion(parsed.Name)
if err != nil {
slog.Warn(gotext.Get("Failed to get installed version"),
"package", parsed.Name,
"error", err)
continue
}
if installedVer == "" {
slog.Warn(gotext.Get("Package was not installed"),
"package", parsed.Name)
continue
}
if !parsed.Satisfies(installedVer) {
slog.Warn(gotext.Get("Installed version doesn't satisfy requirement"),
"package", parsed.Name,
"required", pkg,
"installed", installedVer)
}
}
return nil
}
func (i *Installer) FilterPackagesByVersion(ctx context.Context, packages []alrsh.Package, osRelease *distro.OSRelease) ([]alrsh.Package, error) {
installedPkgs, err := i.mgr.ListInstalled(nil)
if err != nil {
return nil, fmt.Errorf("failed to list installed packages: %w", err)
}
var filteredPackages []alrsh.Package
for _, pkg := range packages {
alrPkgName := fmt.Sprintf("%s+%s", pkg.Name, pkg.Repository)
installedVer, isInstalled := installedPkgs[alrPkgName]
if !isInstalled {
filteredPackages = append(filteredPackages, pkg)
continue
}
repoVer := pkg.Version
releaseStr := overrides.ReleasePlatformSpecific(pkg.Release, osRelease)
if pkg.Release != 0 && pkg.Epoch == 0 {
repoVer = fmt.Sprintf("%s-%s", pkg.Version, releaseStr)
} else if pkg.Release != 0 && pkg.Epoch != 0 {
repoVer = fmt.Sprintf("%d:%s-%s", pkg.Epoch, pkg.Version, releaseStr)
}
cmp := vercmp.Compare(repoVer, installedVer)
if cmp > 0 {
slog.Info(gotext.Get("Package %s is installed with older version %s, will rebuild with version %s", alrPkgName, installedVer, repoVer))
filteredPackages = append(filteredPackages, pkg)
} else if cmp == 0 {
slog.Info(gotext.Get("Package %s is already installed with version %s, skipping build", alrPkgName, installedVer))
} else {
slog.Info(gotext.Get("Package %s is installed with newer version %s (repo has %s), skipping build", alrPkgName, installedVer, repoVer))
}
}
return filteredPackages, nil
}

View File

@@ -21,6 +21,7 @@ import (
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/types"
)
@@ -34,6 +35,8 @@ type InstallerExecutor interface {
Install(ctx context.Context, pkgs []string, opts *manager.Opts) error
Remove(ctx context.Context, pkgs []string, opts *manager.Opts) error
RemoveAlreadyInstalled(ctx context.Context, pkgs []string) ([]string, error)
FilterPackagesByVersion(ctx context.Context, packages []alrsh.Package, osRelease *distro.OSRelease) ([]alrsh.Package, error)
CheckVersionsAfterInstall(ctx context.Context, pkgs []string) error
}
type ScriptExecutor interface {

View File

@@ -24,6 +24,7 @@ import (
"context"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/types"
"github.com/hashicorp/go-plugin"
)
@@ -205,6 +206,65 @@ func (s *InstallerExecutorRPCServer) RemoveAlreadyInstalled(args *InstallerExecu
return nil
}
type InstallerExecutorFilterPackagesByVersionArgs struct {
Packages []alrsh.Package
OsRelease *distro.OSRelease
}
type InstallerExecutorFilterPackagesByVersionResp struct {
Result0 []alrsh.Package
}
func (s *InstallerExecutorRPC) FilterPackagesByVersion(ctx context.Context, packages []alrsh.Package, osRelease *distro.OSRelease) ([]alrsh.Package, error) {
var resp *InstallerExecutorFilterPackagesByVersionResp
err := s.client.Call("Plugin.FilterPackagesByVersion", &InstallerExecutorFilterPackagesByVersionArgs{
Packages: packages,
OsRelease: osRelease,
}, &resp)
if err != nil {
return nil, err
}
return resp.Result0, nil
}
func (s *InstallerExecutorRPCServer) FilterPackagesByVersion(args *InstallerExecutorFilterPackagesByVersionArgs, resp *InstallerExecutorFilterPackagesByVersionResp) error {
result0, err := s.Impl.FilterPackagesByVersion(context.Background(), args.Packages, args.OsRelease)
if err != nil {
return err
}
*resp = InstallerExecutorFilterPackagesByVersionResp{
Result0: result0,
}
return nil
}
type InstallerExecutorCheckVersionsAfterInstallArgs struct {
Pkgs []string
}
type InstallerExecutorCheckVersionsAfterInstallResp struct {
}
func (s *InstallerExecutorRPC) CheckVersionsAfterInstall(ctx context.Context, pkgs []string) error {
var resp *InstallerExecutorCheckVersionsAfterInstallResp
err := s.client.Call("Plugin.CheckVersionsAfterInstall", &InstallerExecutorCheckVersionsAfterInstallArgs{
Pkgs: pkgs,
}, &resp)
if err != nil {
return err
}
return nil
}
func (s *InstallerExecutorRPCServer) CheckVersionsAfterInstall(args *InstallerExecutorCheckVersionsAfterInstallArgs, resp *InstallerExecutorCheckVersionsAfterInstallResp) error {
err := s.Impl.CheckVersionsAfterInstall(context.Background(), args.Pkgs)
if err != nil {
return err
}
*resp = InstallerExecutorCheckVersionsAfterInstallResp{}
return nil
}
type ScriptExecutorReadScriptArgs struct {
ScriptPath string
}

View File

@@ -130,12 +130,34 @@ func (e *LocalScriptExecutor) ExecuteSecondPass(
packageName = vars.Name
}
// Для каждого подпакета создаём отдельную директорию
pkgDirs, err := getDirsForPackage(e.cfg, sf.Path(), basePkg, packageName)
if err != nil {
return nil, err
}
// Создаём директорию для подпакета
if err := os.MkdirAll(pkgDirs.PkgDir, 0o755); err != nil {
return nil, err
}
// Обновляем переменную окружения $pkgdir для текущего подпакета
setPkgdirCmd := fmt.Sprintf("pkgdir='%s'", pkgDirs.PkgDir)
setPkgdirScript, err := syntax.NewParser().Parse(strings.NewReader(setPkgdirCmd), "")
if err != nil {
return nil, err
}
err = runner.Run(ctx, setPkgdirScript)
if err != nil {
return nil, err
}
pkgFormat := input.pkgFormat
funcOut, err := e.ExecutePackageFunctions(
ctx,
dec,
dirs,
pkgDirs,
packageName,
)
if err != nil {
@@ -148,7 +170,7 @@ func (e *LocalScriptExecutor) ExecuteSecondPass(
ctx,
input,
vars,
dirs,
pkgDirs,
append(
repoDeps,
GetBuiltName(builtDeps)...,
@@ -165,17 +187,32 @@ func (e *LocalScriptExecutor) ExecuteSecondPass(
}
pkgName := packager.ConventionalFileName(pkgInfo) // Получаем имя файла пакета
pkgPath := filepath.Join(dirs.BaseDir, pkgName) // Определяем путь к пакету
pkgPath := filepath.Join(pkgDirs.BaseDir, pkgName) // Определяем путь к пакету
slog.Info(gotext.Get("Creating package file"), "path", pkgPath, "name", pkgName)
pkgFile, err := os.Create(pkgPath)
if err != nil {
slog.Error(gotext.Get("Failed to create package file"), "path", pkgPath, "error", err)
return nil, err
}
defer pkgFile.Close()
slog.Info(gotext.Get("Packaging with nfpm"), "format", pkgFormat)
err = packager.Package(pkgInfo, pkgFile)
if err != nil {
slog.Error(gotext.Get("Failed to create package"), "path", pkgPath, "error", err)
return nil, err
}
err = packager.Package(pkgInfo, pkgFile)
if err != nil {
slog.Info(gotext.Get("Package created successfully"), "path", pkgPath)
// Проверяем, что файл действительно существует
if _, err := os.Stat(pkgPath); err != nil {
slog.Error(gotext.Get("Package file not found after creation"), "path", pkgPath, "error", err)
return nil, err
}
slog.Info(gotext.Get("Package file verified to exist"), "path", pkgPath)
builtDeps = append(builtDeps, &BuiltDep{
Name: vars.Name,

View File

@@ -49,12 +49,21 @@ import (
// Функция prepareDirs подготавливает директории для сборки.
func prepareDirs(dirs types.Directories) error {
// Пробуем удалить базовую директорию, если она существует
err := os.RemoveAll(dirs.BaseDir)
// Удаляем только директории источников и упаковки, не трогаем файлы пакетов в BaseDir
err := os.RemoveAll(dirs.SrcDir)
if err != nil {
// Если не можем удалить (например, принадлежит root), логируем и продолжаем
// Новые директории будут созданы или перезаписаны
slog.Debug("Failed to remove base directory", "path", dirs.BaseDir, "error", err)
slog.Debug("Failed to remove src directory", "path", dirs.SrcDir, "error", err)
}
err = os.RemoveAll(dirs.PkgDir)
if err != nil {
slog.Debug("Failed to remove pkg directory", "path", dirs.PkgDir, "error", err)
}
// Создаем базовую директорию для пакета с setgid битом
err = utils.EnsureTempDirWithRootOwner(dirs.BaseDir, 0o2775)
if err != nil {
return err
}
// Создаем директории с правильным владельцем для /tmp/alr с setgid битом
@@ -169,15 +178,16 @@ func normalizeContents(contents []*files.Content) {
}
}
var RegexpALRPackageName = regexp.MustCompile(`^(?P<package>[^+]+)\+alr-(?P<repo>.+)$`)
var RegexpALRPackageName = regexp.MustCompile(`^(?P<package>[^+]+)\+(?P<repo>.+)$`)
func getBasePkgInfo(vars *alrsh.Package, input interface {
RepositoryProvider
OsInfoProvider
},
) *nfpm.Info {
repo := input.Repository()
return &nfpm.Info{
Name: fmt.Sprintf("%s+alr-%s", vars.Name, input.Repository()),
Name: fmt.Sprintf("%s+%s", vars.Name, repo),
Arch: cpu.Arch(),
Version: vars.Version,
Release: overrides.ReleasePlatformSpecific(vars.Release, input.OSRelease()),
@@ -321,3 +331,29 @@ func removeDuplicatesSources(sources, checksums []string) ([]string, []string) {
}
return newSources, newChecksums
}
// ExtractRepoNameFromPath извлекает имя репозитория из пути к скрипту.
// Ожидаемый формат: repo-name/package-name/alr.sh или /abs/path/repo-name/package-name/alr.sh
// Возвращает "default", если не удалось извлечь имя.
func ExtractRepoNameFromPath(scriptPath string) string {
// Нормализуем путь
cleanPath := filepath.Clean(scriptPath)
// Разбиваем путь на компоненты
dir := filepath.Dir(cleanPath) // package-name
if dir == "." || dir == "/" {
return "default"
}
repoDir := filepath.Dir(dir) // repo-name
if repoDir == "." || repoDir == "/" {
return "default"
}
repoName := filepath.Base(repoDir)
if repoName == "." || repoName == "/" || repoName == "" {
return "default"
}
return repoName
}

View File

@@ -0,0 +1,211 @@
// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// 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 build
import (
"testing"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
)
type mockInput struct {
repo string
osInfo *distro.OSRelease
}
func (m *mockInput) Repository() string {
return m.repo
}
func (m *mockInput) OSRelease() *distro.OSRelease {
return m.osInfo
}
func TestGetBasePkgInfo(t *testing.T) {
tests := []struct {
name string
packageName string
repoName string
expectedName string
}{
{
name: "обычный репозиторий",
packageName: "test-package",
repoName: "default",
expectedName: "test-package+default",
},
{
name: "репозиторий с alr- префиксом",
packageName: "test-package",
repoName: "alr-default",
expectedName: "test-package+alr-default",
},
{
name: "репозиторий с двойным alr- префиксом",
packageName: "test-package",
repoName: "alr-alr-repo",
expectedName: "test-package+alr-alr-repo",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pkg := &alrsh.Package{
Name: tt.packageName,
Version: "1.0.0",
Release: 1,
}
input := &mockInput{
repo: tt.repoName,
osInfo: &distro.OSRelease{
ID: "test",
},
}
info := getBasePkgInfo(pkg, input)
if info.Name != tt.expectedName {
t.Errorf("getBasePkgInfo() имя пакета = %v, ожидается %v", info.Name, tt.expectedName)
}
})
}
}
func TestRegexpALRPackageName(t *testing.T) {
tests := []struct {
name string
packageName string
expectedPkg string
expectedRepo string
shouldMatch bool
}{
{
name: "новый формат - обычный репозиторий",
packageName: "test-package+default",
expectedPkg: "test-package",
expectedRepo: "default",
shouldMatch: true,
},
{
name: "новый формат - alr-default репозиторий",
packageName: "test-package+alr-default",
expectedPkg: "test-package",
expectedRepo: "alr-default",
shouldMatch: true,
},
{
name: "новый формат - двойной alr- префикс",
packageName: "test-package+alr-alr-repo",
expectedPkg: "test-package",
expectedRepo: "alr-alr-repo",
shouldMatch: true,
},
{
name: "некорректный формат - без плюса",
packageName: "test-package",
shouldMatch: false,
},
{
name: "некорректный формат - пустое имя пакета",
packageName: "+repo",
shouldMatch: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
matches := RegexpALRPackageName.FindStringSubmatch(tt.packageName)
if tt.shouldMatch {
if matches == nil {
t.Errorf("RegexpALRPackageName должен найти совпадение для %q", tt.packageName)
return
}
packageName := matches[RegexpALRPackageName.SubexpIndex("package")]
repoName := matches[RegexpALRPackageName.SubexpIndex("repo")]
if packageName != tt.expectedPkg {
t.Errorf("RegexpALRPackageName извлеченное имя пакета = %v, ожидается %v", packageName, tt.expectedPkg)
}
if repoName != tt.expectedRepo {
t.Errorf("RegexpALRPackageName извлеченное имя репозитория = %v, ожидается %v", repoName, tt.expectedRepo)
}
} else {
if matches != nil {
t.Errorf("RegexpALRPackageName не должен найти совпадение для %q", tt.packageName)
}
}
})
}
}
func TestExtractRepoNameFromPath(t *testing.T) {
tests := []struct {
name string
scriptPath string
expectedRepo string
}{
{
name: "относительный путь - стандартная структура",
scriptPath: "alr-default/alr-bin/alr.sh",
expectedRepo: "alr-default",
},
{
name: "абсолютный путь",
scriptPath: "/home/user/repos/alr-default/alr-bin/alr.sh",
expectedRepo: "alr-default",
},
{
name: "репозиторий без префикса alr-",
scriptPath: "my-repo/my-package/alr.sh",
expectedRepo: "my-repo",
},
{
name: "только имя файла",
scriptPath: "alr.sh",
expectedRepo: "default",
},
{
name: "один уровень директории",
scriptPath: "package/alr.sh",
expectedRepo: "default",
},
{
name: "путь с точками",
scriptPath: "./alr-default/alr-bin/alr.sh",
expectedRepo: "alr-default",
},
{
name: "путь с двойными точками",
scriptPath: "../alr-default/alr-bin/alr.sh",
expectedRepo: "alr-default",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := ExtractRepoNameFromPath(tt.scriptPath)
if result != tt.expectedRepo {
t.Errorf("ExtractRepoNameFromPath(%q) = %q, ожидается %q", tt.scriptPath, result, tt.expectedRepo)
}
})
}
}

View File

@@ -42,7 +42,7 @@ type AppDeps struct {
func (d *AppDeps) Defer() {
if d.DB != nil {
if err := d.DB.Close(); err != nil {
slog.Warn("failed to close db", "err", err)
slog.Warn(gotext.Get("failed to close db"), "err", err)
}
}
}

View File

@@ -103,22 +103,62 @@ func ShowScript(path, name, style string) error {
// FlattenPkgs attempts to flatten the a map of slices of packages into a single slice
// of packages by prompting the user if multiple packages match.
func FlattenPkgs(ctx context.Context, found map[string][]alrsh.Package, verb string, interactive bool) []alrsh.Package {
return FlattenPkgsWithContext(ctx, found, verb, interactive, false)
}
// FlattenPkgsWithContext расширенная версия FlattenPkgs с контекстом обработки зависимостей
func FlattenPkgsWithContext(ctx context.Context, found map[string][]alrsh.Package, verb string, interactive bool, isDependency bool) []alrsh.Package {
var outPkgs []alrsh.Package
for _, pkgs := range found {
if len(pkgs) > 1 && interactive {
if len(pkgs) > 1 {
// Проверяем, являются ли пакеты подпакетами одного мультипакета
if isMultiPackage(pkgs) && verb == "install" {
// Для мультипакетов при установке ВСЕГДА берем все подпакеты без выбора
// Это правильное поведение как для прямой установки, так и для зависимостей
outPkgs = append(outPkgs, pkgs...)
} else if interactive {
// Для разных пакетов с одинаковым именем - показываем меню выбора
choice, err := PkgPrompt(ctx, pkgs, verb, interactive)
if err != nil {
slog.Error(gotext.Get("Error prompting for choice of package"))
os.Exit(1)
}
outPkgs = append(outPkgs, choice)
} else if len(pkgs) == 1 || !interactive {
} else {
// Если не интерактивный режим - берем первый
outPkgs = append(outPkgs, pkgs[0])
}
} else {
// Если только один пакет - берем его
outPkgs = append(outPkgs, pkgs[0])
}
}
return outPkgs
}
// isMultiPackage проверяет, являются ли пакеты подпакетами одного мультипакета
func isMultiPackage(pkgs []alrsh.Package) bool {
if len(pkgs) <= 1 {
return false
}
// Проверяем, что у всех пакетов одинаковый BasePkgName и Repository
firstBasePkg := pkgs[0].BasePkgName
firstRepo := pkgs[0].Repository
if firstBasePkg == "" {
return false // Не мультипакет
}
for _, pkg := range pkgs[1:] {
if pkg.BasePkgName != firstBasePkg || pkg.Repository != firstRepo {
return false
}
}
return true
}
// PkgPrompt asks the user to choose between multiple packages.
func PkgPrompt(ctx context.Context, options []alrsh.Package, verb string, interactive bool) (alrsh.Package, error) {
if !interactive {

View File

@@ -100,3 +100,28 @@ func GetCommandHelpTemplate() string {
gotext.Get("OPTIONS"),
)
}
func GetSubcommandHelpTemplate() string {
return fmt.Sprintf(`%s:
{{template "helpNameTemplate" .}}
%s:
{{.HelpName}} %s [%s] {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[%s...]{{end}}
{{if .Description}}
%s:
{{template "descriptionTemplate" .}}{{end}}
{{- if len .Authors}}
%s{{template "authorsTemplate" .}}{{end}}{{if .VisibleCommands}}
%s:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
%s:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
%s:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}}
%s:
{{template "copyrightTemplate" .}}{{end}}
`, gotext.Get("NAME"), gotext.Get("USAGE"), gotext.Get("command"), gotext.Get("command options"), gotext.Get("arguments"), gotext.Get("DESCRIPTION"), gotext.Get("AUTHOR"), gotext.Get("COMMANDS"), gotext.Get("OPTIONS"), gotext.Get("OPTIONS"), gotext.Get("COPYRIGHT"))
}

View File

@@ -22,11 +22,13 @@ package config
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/goccy/go-yaml"
"github.com/knadh/koanf/providers/confmap"
"github.com/knadh/koanf/v2"
ktoml "github.com/knadh/koanf/parsers/toml/v2"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/constants"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/types"
@@ -56,7 +58,8 @@ func defaultConfigKoanf() *koanf.Koanf {
"ignorePkgUpdates": []string{},
"logLevel": "info",
"autoPull": true,
"repos": []types.Repo{
"updateSystemOnUpgrade": false,
"repo": []types.Repo{
{
Name: "alr-default",
URL: "https://gitea.plemya-x.ru/Plemya-x/alr-default.git",
@@ -114,6 +117,11 @@ func (c *ALRConfig) Load() error {
}
}
// Выполняем миграцию конфигурации при необходимости
if err := c.migrateConfig(); err != nil {
return fmt.Errorf("failed to migrate config: %w", err)
}
return nil
}
@@ -125,6 +133,126 @@ func (c *ALRConfig) ToYAML() (string, error) {
return string(data), nil
}
func (c *ALRConfig) migrateConfig() error {
// Проверяем, существует ли конфигурационный файл
if _, err := os.Stat(constants.SystemConfigPath); os.IsNotExist(err) {
// Если файла нет, создаем полный конфигурационный файл с дефолтными значениями
if err := c.createDefaultConfig(); err != nil {
// Если не удается создать конфиг, это не критично - продолжаем работу
// но выводим предупреждение
fmt.Fprintf(os.Stderr, "Предупреждение: не удалось создать конфигурационный файл %s: %v\n", constants.SystemConfigPath, err)
return nil
}
} else {
// Если файл существует, проверяем, есть ли в нем новая опция
if !c.System.k.Exists("updateSystemOnUpgrade") {
// Если опции нет, добавляем ее со значением по умолчанию
c.System.SetUpdateSystemOnUpgrade(false)
// Сохраняем обновленную конфигурацию
if err := c.System.Save(); err != nil {
// Если не удается сохранить - это не критично, продолжаем работу
return nil
}
}
}
return nil
}
func (c *ALRConfig) createDefaultConfig() error {
// Проверяем, запущен ли процесс от root
if os.Getuid() != 0 {
// Если не root, пытаемся запустить создание конфига с повышением привилегий
return c.createDefaultConfigWithPrivileges()
}
// Если уже root, создаем конфиг напрямую
return c.doCreateDefaultConfig()
}
func (c *ALRConfig) createDefaultConfigWithPrivileges() error {
// Если useRootCmd отключен, просто пытаемся создать без повышения привилегий
if !c.cfg.UseRootCmd {
return c.doCreateDefaultConfig()
}
// Определяем команду для повышения привилегий
rootCmd := c.cfg.RootCmd
if rootCmd == "" {
rootCmd = "sudo" // fallback
}
// Создаем временный файл с дефолтной конфигурацией
tmpFile, err := os.CreateTemp("", "alr-config-*.toml")
if err != nil {
return fmt.Errorf("не удалось создать временный файл: %w", err)
}
defer os.Remove(tmpFile.Name())
defer tmpFile.Close()
// Генерируем дефолтную конфигурацию во временный файл
defaults := defaultConfigKoanf()
tempSystemConfig := &SystemConfig{k: defaults}
bytes, err := tempSystemConfig.k.Marshal(ktoml.Parser())
if err != nil {
return fmt.Errorf("не удалось сериализовать конфигурацию: %w", err)
}
if _, err := tmpFile.Write(bytes); err != nil {
return fmt.Errorf("не удалось записать во временный файл: %w", err)
}
tmpFile.Close()
// Используем команду повышения привилегий для создания директории и копирования файла
// Создаем директорию с правами
configDir := filepath.Dir(constants.SystemConfigPath)
mkdirCmd := exec.Command(rootCmd, "mkdir", "-p", configDir)
if err := mkdirCmd.Run(); err != nil {
return fmt.Errorf("не удалось создать директорию %s: %w", configDir, err)
}
// Копируем файл в нужное место
cpCmd := exec.Command(rootCmd, "cp", tmpFile.Name(), constants.SystemConfigPath)
if err := cpCmd.Run(); err != nil {
return fmt.Errorf("не удалось скопировать конфигурацию в %s: %w", constants.SystemConfigPath, err)
}
// Устанавливаем правильные права доступа
chmodCmd := exec.Command(rootCmd, "chmod", "644", constants.SystemConfigPath)
if err := chmodCmd.Run(); err != nil {
// Не критично, продолжаем
fmt.Fprintf(os.Stderr, "Предупреждение: не удалось установить права доступа для %s: %v\n", constants.SystemConfigPath, err)
}
return nil
}
func (c *ALRConfig) doCreateDefaultConfig() error {
// Проверяем, существует ли директория для конфига
configDir := filepath.Dir(constants.SystemConfigPath)
if _, err := os.Stat(configDir); os.IsNotExist(err) {
// Пытаемся создать директорию
if err := os.MkdirAll(configDir, 0755); err != nil {
return fmt.Errorf("не удалось создать директорию %s: %w", configDir, err)
}
}
// Загружаем дефолтную конфигурацию
defaults := defaultConfigKoanf()
// Копируем все дефолтные значения в системную конфигурацию
c.System.k = defaults
// Сохраняем конфигурацию в файл
if err := c.System.Save(); err != nil {
return fmt.Errorf("не удалось сохранить конфигурацию в %s: %w", constants.SystemConfigPath, err)
}
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 }
@@ -133,4 +261,5 @@ func (c *ALRConfig) SetRepos(repos []types.Repo) { c.System.SetRepos(repos) }
func (c *ALRConfig) IgnorePkgUpdates() []string { return c.cfg.IgnorePkgUpdates }
func (c *ALRConfig) LogLevel() string { return c.cfg.LogLevel }
func (c *ALRConfig) UseRootCmd() bool { return c.cfg.UseRootCmd }
func (c *ALRConfig) UpdateSystemOnUpgrade() bool { return c.cfg.UpdateSystemOnUpgrade }
func (c *ALRConfig) GetPaths() *Paths { return c.paths }

View File

@@ -142,3 +142,10 @@ func (c *SystemConfig) SetRepos(v []types.Repo) {
panic(err)
}
}
func (c *SystemConfig) SetUpdateSystemOnUpgrade(v bool) {
err := c.k.Set("updateSystemOnUpgrade", v)
if err != nil {
panic(err)
}
}

View File

@@ -20,5 +20,6 @@ const (
SystemConfigPath = "/etc/alr/alr.toml"
SystemCachePath = "/var/cache/alr"
TempDir = "/tmp/alr"
PrivilegedGroup = "wheel"
// PrivilegedGroup - устарело, используйте GetPrivilegedGroup()
PrivilegedGroup = "wheel" // оставлено для обратной совместимости
)

View File

@@ -31,6 +31,7 @@ import (
"xorm.io/xorm"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/fsutils"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
)
@@ -62,10 +63,10 @@ func (d *Database) Connect() error {
dbDir := filepath.Dir(dsn)
if _, err := os.Stat(dbDir); err != nil {
if os.IsNotExist(err) {
// Директория не существует - пытаемся создать
if mkErr := os.MkdirAll(dbDir, 0775); mkErr != nil {
// Не смогли создать - вернём ошибку, пользователь должен использовать alr fix
return fmt.Errorf("cache directory does not exist, please run 'alr fix' to create it: %w", mkErr)
// Директория не существует - создаем автоматически
slog.Info(gotext.Get("Cache directory does not exist, creating it"))
if err := fsutils.EnsureTempDirWithRootOwner(dbDir, 0o2775); err != nil {
return fmt.Errorf("failed to create cache directory: %w", err)
}
} else {
return fmt.Errorf("failed to check database directory: %w", err)

100
internal/fsutils/dirs.go Normal file
View File

@@ -0,0 +1,100 @@
// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// 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 fsutils
import (
"fmt"
"os"
"os/exec"
"strings"
)
// EnsureTempDirWithRootOwner создает каталог в /tmp/alr или /var/cache/alr с правами для привилегированной группы
// Все каталоги в /tmp/alr и /var/cache/alr принадлежат root:привилегированная_группа с правами 2775
// Для других каталогов использует стандартные права
func EnsureTempDirWithRootOwner(path string, mode os.FileMode) error {
needsElevation := strings.HasPrefix(path, "/tmp/alr") || strings.HasPrefix(path, "/var/cache/alr")
if needsElevation {
// В CI или если мы уже root, не нужно использовать sudo
isRoot := os.Geteuid() == 0
isCI := os.Getenv("CI") == "true"
// В CI создаем директории с обычными правами
if isCI {
err := os.MkdirAll(path, mode)
if err != nil {
return err
}
// В CI не используем группу wheel и не меняем права
// Устанавливаем базовые права 777 для временных каталогов
chmodCmd := exec.Command("chmod", "777", path)
chmodCmd.Run() // Игнорируем ошибки
return nil
}
// Для обычной работы устанавливаем права и привилегированную группу
permissions := "2775"
group := GetPrivilegedGroup()
var mkdirCmd, chmodCmd, chownCmd *exec.Cmd
if isRoot {
// Выполняем команды напрямую без sudo
mkdirCmd = exec.Command("mkdir", "-p", path)
chmodCmd = exec.Command("chmod", permissions, path)
chownCmd = exec.Command("chown", "root:"+group, path)
} else {
// Используем sudo для всех операций с привилегированными каталогами
mkdirCmd = exec.Command("sudo", "mkdir", "-p", path)
chmodCmd = exec.Command("sudo", "chmod", permissions, path)
chownCmd = exec.Command("sudo", "chown", "root:"+group, path)
}
// Создаем директорию через sudo если нужно
err := mkdirCmd.Run()
if err != nil {
// Игнорируем ошибку если директория уже существует
if !isRoot {
// Проверяем существует ли директория
if _, statErr := os.Stat(path); statErr != nil {
return fmt.Errorf("не удалось создать директорию %s: %w", path, err)
}
}
}
// Устанавливаем права с setgid битом для наследования группы
err = chmodCmd.Run()
if err != nil {
if !isRoot {
return fmt.Errorf("не удалось установить права на %s: %w", path, err)
}
}
// Устанавливаем владельца root:группа
err = chownCmd.Run()
if err != nil {
if !isRoot {
return fmt.Errorf("не удалось установить владельца на %s: %w", path, err)
}
}
return nil
}
// Для остальных каталогов обычное создание
return os.MkdirAll(path, mode)
}

View File

@@ -0,0 +1,76 @@
// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// 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 fsutils
import (
"context"
"os/user"
"sync"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
)
var (
privilegedGroupCache string
privilegedGroupOnce sync.Once
)
// GetPrivilegedGroup определяет правильную привилегированную группу для текущего дистрибутива.
// Дистрибутивы на базе Debian/Ubuntu используют группу "sudo", остальные - "wheel".
func GetPrivilegedGroup() string {
privilegedGroupOnce.Do(func() {
privilegedGroupCache = detectPrivilegedGroup()
})
return privilegedGroupCache
}
func detectPrivilegedGroup() string {
// Попробуем определить дистрибутив
ctx := context.Background()
osInfo, err := distro.ParseOSRelease(ctx)
if err != nil {
// Если не можем определить дистрибутив, проверяем какие группы существуют
return detectGroupByAvailability()
}
// Проверяем ID и семейство дистрибутива
// Debian и его производные (Ubuntu, Mint, PopOS и т.д.) используют sudo
if osInfo.ID == "debian" || osInfo.ID == "ubuntu" {
return "sudo"
}
// Проверяем семейство дистрибутива через ID_LIKE
for _, like := range osInfo.Like {
if like == "debian" || like == "ubuntu" {
return "sudo"
}
}
// Для остальных дистрибутивов (Fedora, RHEL, Arch, openSUSE, ALT Linux) используется wheel
return "wheel"
}
// detectGroupByAvailability проверяет существование групп в системе
func detectGroupByAvailability() string {
// Сначала проверяем группу sudo (более распространена)
if _, err := user.LookupGroup("sudo"); err == nil {
return "sudo"
}
// Если sudo не найдена, возвращаем wheel
return "wheel"
}

View File

@@ -167,3 +167,33 @@ func (a *APK) IsInstalled(pkg string) (bool, error) {
}
return true, nil
}
func (a *APK) GetInstalledVersion(pkg string) (string, error) {
cmd := exec.Command("apk", "info", "--installed", pkg)
output, err := cmd.CombinedOutput()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
// Exit code 1 means the package is not installed
if exitErr.ExitCode() == 1 {
return "", nil
}
}
return "", fmt.Errorf("apk: getinstalledversion: %w, output: %s", err, output)
}
// Output format: "package-version" (e.g., "curl-8.5.0-r0")
// We need to extract just the version part
line := strings.TrimSpace(string(output))
if line == "" {
return "", nil
}
// Find the last hyphen that separates name from version
// Alpine package names can contain hyphens, version starts after last one
lastDash := strings.LastIndex(line, "-")
if lastDash == -1 {
return "", nil
}
return line[lastDash+1:], nil
}

View File

@@ -82,8 +82,15 @@ func (a *APT) InstallLocal(opts *Opts, pkgs ...string) error {
func (a *APT) Remove(opts *Opts, pkgs ...string) error {
opts = ensureOpts(opts)
resolvedPkgs := make([]string, 0, len(pkgs))
for _, pkg := range pkgs {
resolved := a.resolvePackageName(pkg)
resolvedPkgs = append(resolvedPkgs, resolved)
}
cmd := a.getCmd(opts, "apt", "remove")
cmd.Args = append(cmd.Args, pkgs...)
cmd.Args = append(cmd.Args, resolvedPkgs...)
setCmdEnv(cmd)
err := cmd.Run()
if err != nil {
@@ -92,6 +99,39 @@ func (a *APT) Remove(opts *Opts, pkgs ...string) error {
return nil
}
func (a *APT) resolvePackageName(pkg string) string {
cmd := exec.Command("dpkg-query", "-f", "${Status}", "-W", pkg)
output, err := cmd.Output()
if err == nil && strings.Contains(string(output), "install ok installed") {
return pkg
}
cmd = exec.Command("dpkg-query", "-W", "-f", "${Package}\t${Provides}\n")
output, err = cmd.Output()
if err != nil {
return pkg
}
for _, line := range strings.Split(string(output), "\n") {
parts := strings.SplitN(line, "\t", 2)
if len(parts) != 2 {
continue
}
pkgName := parts[0]
provides := parts[1]
for _, p := range strings.Split(provides, ", ") {
p = strings.TrimSpace(p)
provName := strings.Split(p, " ")[0]
if provName == pkg {
return pkgName
}
}
}
return pkg
}
func (a *APT) Upgrade(opts *Opts, pkgs ...string) error {
opts = ensureOpts(opts)
return a.Install(opts, pkgs...)
@@ -140,16 +180,34 @@ func (a *APT) ListInstalled(opts *Opts) (map[string]string, error) {
}
func (a *APT) IsInstalled(pkg string) (bool, error) {
cmd := exec.Command("dpkg-query", "-l", pkg)
resolved := a.resolvePackageName(pkg)
cmd := exec.Command("dpkg-query", "-f", "${Status}", "-W", resolved)
output, err := cmd.CombinedOutput()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
// Exit code 1 means the package is not installed
if exitErr.ExitCode() == 1 {
return false, nil
}
}
return false, fmt.Errorf("apt: isinstalled: %w, output: %s", err, output)
}
return true, nil
status := strings.TrimSpace(string(output))
return strings.Contains(status, "install ok installed"), nil
}
func (a *APT) GetInstalledVersion(pkg string) (string, error) {
resolved := a.resolvePackageName(pkg)
cmd := exec.Command("dpkg-query", "-f", "${Version}", "-W", resolved)
output, err := cmd.CombinedOutput()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
if exitErr.ExitCode() == 1 {
return "", nil
}
}
return "", fmt.Errorf("apt: getinstalledversion: %w, output: %s", err, output)
}
return strings.TrimSpace(string(output)), nil
}

View File

@@ -70,3 +70,21 @@ func (a *CommonRPM) IsInstalled(pkg string) (bool, error) {
}
return true, nil
}
func (a *CommonRPM) GetInstalledVersion(pkg string) (string, error) {
cmd := exec.Command("rpm", "-q", "--queryformat", "%|EPOCH?{%{EPOCH}:}:{}|%{VERSION}-%{RELEASE}", pkg)
output, err := cmd.CombinedOutput()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
if exitErr.ExitCode() == 1 {
return "", nil
}
}
return "", fmt.Errorf("rpm: getinstalledversion: %w, output: %s", err, output)
}
version := strings.TrimSpace(string(output))
// Remove epoch 0: prefix if present
version = strings.TrimPrefix(version, "0:")
return version, nil
}

View File

@@ -0,0 +1,59 @@
// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// 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 manager
import (
"testing"
)
func TestNewZypperReturnsCorrectType(t *testing.T) {
z := NewZypper()
if z == nil {
t.Fatal("NewZypper() returned nil")
}
if z.Name() != "zypper" {
t.Errorf("Expected name 'zypper', got '%s'", z.Name())
}
if z.Format() != "rpm" {
t.Errorf("Expected format 'rpm', got '%s'", z.Format())
}
}
func TestManagersOrder(t *testing.T) {
// Проверяем, что APT-RPM идёт раньше APT в списке менеджеров
aptRpmIndex := -1
aptIndex := -1
for i, m := range managers {
switch m.Name() {
case "apt-rpm":
aptRpmIndex = i
case "apt":
aptIndex = i
}
}
if aptRpmIndex == -1 {
t.Fatal("APT-RPM not found in managers list")
}
if aptIndex == -1 {
t.Fatal("APT not found in managers list")
}
if aptRpmIndex >= aptIndex {
t.Errorf("APT-RPM (index %d) should come before APT (index %d)", aptRpmIndex, aptIndex)
}
}

View File

@@ -37,12 +37,12 @@ var DefaultOpts = &Opts{
var managers = []Manager{
NewPacman(),
NewAPTRpm(), // APT-RPM должен проверяться раньше APT, т.к. на ALT Linux есть оба
NewAPT(),
NewDNF(),
NewYUM(),
NewAPK(),
NewZypper(),
NewAPTRpm(),
}
// Register registers a new package manager
@@ -74,8 +74,11 @@ type Manager interface {
UpgradeAll(*Opts) error
// ListInstalled returns all installed packages mapped to their versions
ListInstalled(*Opts) (map[string]string, error)
//
// IsInstalled checks if a package is installed
IsInstalled(string) (bool, error)
// GetInstalledVersion returns the version of an installed package.
// Returns empty string and no error if package is not installed.
GetInstalledVersion(string) (string, error)
}
// Detect returns the package manager detected on the system

View File

@@ -160,3 +160,24 @@ func (p *Pacman) IsInstalled(pkg string) (bool, error) {
}
return true, nil
}
func (p *Pacman) GetInstalledVersion(pkg string) (string, error) {
cmd := exec.Command("pacman", "-Q", pkg)
output, err := cmd.CombinedOutput()
if err != nil {
// Pacman returns exit code 1 if the package is not found
if exitErr, ok := err.(*exec.ExitError); ok {
if exitErr.ExitCode() == 1 {
return "", nil
}
}
return "", fmt.Errorf("pacman: getinstalledversion: %w, output: %s", err, output)
}
// Output format: "package-name version"
_, version, ok := strings.Cut(strings.TrimSpace(string(output)), " ")
if !ok {
return "", nil
}
return version, nil
}

View File

@@ -30,8 +30,8 @@ type Zypper struct {
CommonRPM
}
func NewZypper() *YUM {
return &YUM{
func NewZypper() *Zypper {
return &Zypper{
CommonPackageManager: CommonPackageManager{
noConfirmArg: "-y",
},

View File

@@ -25,6 +25,7 @@ import (
"strings"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/depver"
)
func (rs *Repos) FindPkgs(ctx context.Context, pkgs []string) (map[string][]alrsh.Package, []string, error) {
@@ -36,32 +37,49 @@ func (rs *Repos) FindPkgs(ctx context.Context, pkgs []string) (map[string][]alrs
continue
}
// Parse version constraint from package name
dep := depver.Parse(pkgName)
searchName := dep.Name
var result []alrsh.Package
var err error
switch {
case strings.Contains(pkgName, "/"):
case strings.Contains(searchName, "/"):
// repo/pkg
parts := strings.SplitN(pkgName, "/", 2)
parts := strings.SplitN(searchName, "/", 2)
repo := parts[0]
name := parts[1]
result, err = rs.db.GetPkgs(ctx, "name = ? AND repository = ?", name, repo)
case strings.Contains(pkgName, "+alr-"):
// pkg+alr-repo
parts := strings.SplitN(pkgName, "+alr-", 2)
case strings.Contains(searchName, "+"):
// pkg+repo
parts := strings.SplitN(searchName, "+", 2)
name := parts[0]
repo := parts[1]
result, err = rs.db.GetPkgs(ctx, "name = ? AND repository = ?", name, repo)
default:
result, err = rs.db.GetPkgs(ctx, "json_array_contains(provides, ?)", pkgName)
// Сначала ищем по точному имени пакета
result, err = rs.db.GetPkgs(ctx, "name = ?", searchName)
if err != nil {
return nil, nil, fmt.Errorf("FindPkgs: get by name: %w", err)
}
// Затем по provides
if len(result) == 0 {
result, err = rs.db.GetPkgs(ctx, "json_array_contains(provides, ?)", searchName)
if err != nil {
return nil, nil, fmt.Errorf("FindPkgs: get by provides: %w", err)
}
}
// В последнюю очередь по basepkg_name (для мультипакетов)
if len(result) == 0 {
result, err = rs.db.GetPkgs(ctx, "name LIKE ?", pkgName)
result, err = rs.db.GetPkgs(ctx, "basepkg_name = ?", searchName)
if err != nil {
return nil, nil, fmt.Errorf("FindPkgs: get by basepkg_name: %w", err)
}
}
}
@@ -69,6 +87,11 @@ func (rs *Repos) FindPkgs(ctx context.Context, pkgs []string) (map[string][]alrs
return nil, nil, fmt.Errorf("FindPkgs: lookup for %q failed: %w", pkgName, err)
}
// Filter by version if constraint is specified
if dep.HasVersionConstraint() && len(result) > 0 {
result = filterByVersion(result, dep)
}
if len(result) == 0 {
notFound = append(notFound, pkgName)
} else {
@@ -78,3 +101,14 @@ func (rs *Repos) FindPkgs(ctx context.Context, pkgs []string) (map[string][]alrs
return found, notFound, nil
}
// filterByVersion filters packages by version constraint.
func filterByVersion(pkgs []alrsh.Package, dep depver.Dependency) []alrsh.Package {
var filtered []alrsh.Package
for _, pkg := range pkgs {
if dep.Satisfies(pkg.Version) {
filtered = append(filtered, pkg)
}
}
return filtered
}

View File

@@ -36,7 +36,7 @@ import (
"github.com/go-git/go-git/v5/plumbing"
"github.com/leonelquinteros/gotext"
"github.com/pelletier/go-toml/v2"
"go.elara.ws/vercmp"
"gitea.plemya-x.ru/xpamych/vercmp"
"mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/interp"
"mvdan.cc/sh/v3/syntax"
@@ -420,13 +420,13 @@ func (rs *Repos) processRepoChanges(ctx context.Context, repo types.Repo, r *git
case actionDelete:
scriptFl, err := oldCommit.File(action.File)
if err != nil {
slog.Warn("Failed to get deleted file from old commit", "file", action.File, "error", err)
slog.Warn(gotext.Get("Failed to get deleted file from old commit"), "file", action.File, "error", err)
continue
}
r, err := scriptFl.Reader()
if err != nil {
slog.Warn("Failed to read deleted file", "file", action.File, "error", err)
slog.Warn(gotext.Get("Failed to read deleted file"), "file", action.File, "error", err)
continue
}
@@ -445,13 +445,13 @@ func (rs *Repos) processRepoChanges(ctx context.Context, repo types.Repo, r *git
case actionUpdate:
scriptFl, err := newCommit.File(action.File)
if err != nil {
slog.Warn("Failed to get updated file from new commit", "file", action.File, "error", err)
slog.Warn(gotext.Get("Failed to get updated file from new commit"), "file", action.File, "error", err)
continue
}
r, err := scriptFl.Reader()
if err != nil {
slog.Warn("Failed to read updated file", "file", action.File, "error", err)
slog.Warn(gotext.Get("Failed to read updated file"), "file", action.File, "error", err)
continue
}
@@ -505,7 +505,7 @@ func (rs *Repos) processRepoFull(ctx context.Context, repo types.Repo, repoDir s
}
if len(matches) == 0 {
slog.Warn("No alr.sh files found in repository", "repo", repo.Name)
slog.Warn(gotext.Get("No alr.sh files found in repository"), "repo", repo.Name)
return nil
}

View File

@@ -71,6 +71,10 @@ func New(info *distro.OSRelease, runner *interp.Runner) *Decoder {
return &Decoder{info, runner, true, len(info.Like) > 0}
}
func (d *Decoder) Info() *distro.OSRelease {
return d.info
}
// DecodeVar decodes a variable to val using reflection.
// Structs should use the "sh" struct tag.
func (d *Decoder) DecodeVar(name string, val any) error {

View File

@@ -177,3 +177,333 @@ func filesFindCmd(hc interp.HandlerContext, cmd string, args []string) error {
return outputFiles(hc, foundFiles)
}
func filesFindBinCmd(hc interp.HandlerContext, cmd string, args []string) error {
namePattern := "*"
if len(args) > 0 {
namePattern = args[0]
}
binPath := "./usr/bin/"
realPath := path.Join(hc.Dir, binPath)
if err := validateDir(realPath, "files-find-bin"); err != nil {
return err
}
var binFiles []string
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
relPath, relErr := makeRelativePath(hc.Dir, p)
if relErr != nil {
return relErr
}
binFiles = append(binFiles, relPath)
}
return nil
})
if err != nil {
return fmt.Errorf("files-find-bin: %w", err)
}
return outputFiles(hc, binFiles)
}
func filesFindLibCmd(hc interp.HandlerContext, cmd string, args []string) error {
namePattern := "*"
if len(args) > 0 {
namePattern = args[0]
}
libPaths := []string{"./usr/lib/", "./usr/lib64/"}
var libFiles []string
for _, libPath := range libPaths {
realPath := path.Join(hc.Dir, libPath)
if _, err := os.Stat(realPath); os.IsNotExist(err) {
continue
}
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
relPath, relErr := makeRelativePath(hc.Dir, p)
if relErr != nil {
return relErr
}
libFiles = append(libFiles, relPath)
}
return nil
})
if err != nil {
return fmt.Errorf("files-find-lib: %w", err)
}
}
return outputFiles(hc, libFiles)
}
func filesFindIncludeCmd(hc interp.HandlerContext, cmd string, args []string) error {
namePattern := "*"
if len(args) > 0 {
namePattern = args[0]
}
includePath := "./usr/include/"
realPath := path.Join(hc.Dir, includePath)
if err := validateDir(realPath, "files-find-include"); err != nil {
return err
}
var includeFiles []string
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
relPath, relErr := makeRelativePath(hc.Dir, p)
if relErr != nil {
return relErr
}
includeFiles = append(includeFiles, relPath)
}
return nil
})
if err != nil {
return fmt.Errorf("files-find-include: %w", err)
}
return outputFiles(hc, includeFiles)
}
func filesFindShareCmd(hc interp.HandlerContext, cmd string, args []string) error {
namePattern := "*"
sharePath := "./usr/share/"
if len(args) > 0 {
if len(args) == 1 {
sharePath = "./usr/share/" + args[0] + "/"
} else {
sharePath = "./usr/share/" + args[0] + "/"
namePattern = args[1]
}
}
realPath := path.Join(hc.Dir, sharePath)
if err := validateDir(realPath, "files-find-share"); err != nil {
return err
}
var shareFiles []string
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
relPath, relErr := makeRelativePath(hc.Dir, p)
if relErr != nil {
return relErr
}
shareFiles = append(shareFiles, relPath)
}
return nil
})
if err != nil {
return fmt.Errorf("files-find-share: %w", err)
}
return outputFiles(hc, shareFiles)
}
func filesFindManCmd(hc interp.HandlerContext, cmd string, args []string) error {
namePattern := "*"
manSection := "*"
if len(args) > 0 {
if len(args) == 1 {
manSection = args[0]
} else {
manSection = args[0]
namePattern = args[1]
}
}
manPath := "./usr/share/man/man" + manSection + "/"
realPath := path.Join(hc.Dir, manPath)
if err := validateDir(realPath, "files-find-man"); err != nil {
return err
}
var manFiles []string
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
relPath, relErr := makeRelativePath(hc.Dir, p)
if relErr != nil {
return relErr
}
manFiles = append(manFiles, relPath)
}
return nil
})
if err != nil {
return fmt.Errorf("files-find-man: %w", err)
}
return outputFiles(hc, manFiles)
}
func filesFindConfigCmd(hc interp.HandlerContext, cmd string, args []string) error {
namePattern := "*"
if len(args) > 0 {
namePattern = args[0]
}
configPath := "./etc/"
realPath := path.Join(hc.Dir, configPath)
if err := validateDir(realPath, "files-find-config"); err != nil {
return err
}
var configFiles []string
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
relPath, relErr := makeRelativePath(hc.Dir, p)
if relErr != nil {
return relErr
}
configFiles = append(configFiles, relPath)
}
return nil
})
if err != nil {
return fmt.Errorf("files-find-config: %w", err)
}
return outputFiles(hc, configFiles)
}
func filesFindSystemdCmd(hc interp.HandlerContext, cmd string, args []string) error {
namePattern := "*"
if len(args) > 0 {
namePattern = args[0]
}
systemdPath := "./usr/lib/systemd/system/"
realPath := path.Join(hc.Dir, systemdPath)
if err := validateDir(realPath, "files-find-systemd"); err != nil {
return err
}
var systemdFiles []string
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
relPath, relErr := makeRelativePath(hc.Dir, p)
if relErr != nil {
return relErr
}
systemdFiles = append(systemdFiles, relPath)
}
return nil
})
if err != nil {
return fmt.Errorf("files-find-systemd: %w", err)
}
return outputFiles(hc, systemdFiles)
}
func filesFindSystemdUserCmd(hc interp.HandlerContext, cmd string, args []string) error {
namePattern := "*"
if len(args) > 0 {
namePattern = args[0]
}
systemdUserPath := "./usr/lib/systemd/user/"
realPath := path.Join(hc.Dir, systemdUserPath)
if err := validateDir(realPath, "files-find-systemd-user"); err != nil {
return err
}
var systemdUserFiles []string
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
relPath, relErr := makeRelativePath(hc.Dir, p)
if relErr != nil {
return relErr
}
systemdUserFiles = append(systemdUserFiles, relPath)
}
return nil
})
if err != nil {
return fmt.Errorf("files-find-systemd-user: %w", err)
}
return outputFiles(hc, systemdUserFiles)
}
func filesFindLicenseCmd(hc interp.HandlerContext, cmd string, args []string) error {
namePattern := "*"
if len(args) > 0 {
namePattern = args[0]
}
licensePath := "./usr/share/licenses/"
realPath := path.Join(hc.Dir, licensePath)
if err := validateDir(realPath, "files-find-license"); err != nil {
return err
}
var licenseFiles []string
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
relPath, relErr := makeRelativePath(hc.Dir, p)
if relErr != nil {
return relErr
}
licenseFiles = append(licenseFiles, relPath)
}
return nil
})
if err != nil {
return fmt.Errorf("files-find-license: %w", err)
}
return outputFiles(hc, licenseFiles)
}

View File

@@ -59,6 +59,15 @@ var Helpers = handlers.ExecFuncs{
"files-find": filesFindCmd,
"files-find-lang": filesFindLangCmd,
"files-find-doc": filesFindDocCmd,
"files-find-bin": filesFindBinCmd,
"files-find-lib": filesFindLibCmd,
"files-find-include": filesFindIncludeCmd,
"files-find-share": filesFindShareCmd,
"files-find-man": filesFindManCmd,
"files-find-config": filesFindConfigCmd,
"files-find-systemd": filesFindSystemdCmd,
"files-find-systemd-user": filesFindSystemdUserCmd,
"files-find-license": filesFindLicenseCmd,
}
// Restricted contains restricted read-only helper commands
@@ -68,6 +77,15 @@ var Restricted = handlers.ExecFuncs{
"files-find": filesFindCmd,
"files-find-lang": filesFindLangCmd,
"files-find-doc": filesFindDocCmd,
"files-find-bin": filesFindBinCmd,
"files-find-lib": filesFindLibCmd,
"files-find-include": filesFindIncludeCmd,
"files-find-share": filesFindShareCmd,
"files-find-man": filesFindManCmd,
"files-find-config": filesFindConfigCmd,
"files-find-systemd": filesFindSystemdCmd,
"files-find-systemd-user": filesFindSystemdUserCmd,
"files-find-license": filesFindLicenseCmd,
}
func installHelperCmd(prefix string, perms os.FileMode) handlers.ExecFunc {

106
internal/stats/tracker.go Normal file
View File

@@ -0,0 +1,106 @@
// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// 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 stats
import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"net/http"
"os"
"strings"
"time"
)
type InstallationData struct {
PackageName string `json:"packageName"`
Version string `json:"version,omitempty"`
InstallType string `json:"installType"` // "install" or "upgrade"
UserAgent string `json:"userAgent"`
Fingerprint string `json:"fingerprint,omitempty"`
}
var (
apiEndpoints = []string{
"https://alr.plemya-x.ru/api/packages/track-install",
"http://localhost:3001/api/packages/track-install",
}
userAgent = "ALR-CLI/1.0"
)
func generateFingerprint(packageName string) string {
hostname, _ := os.Hostname()
data := fmt.Sprintf("%s_%s_%s", hostname, packageName, time.Now().Format("2006-01-02"))
hash := sha256.Sum256([]byte(data))
return hex.EncodeToString(hash[:])
}
// TrackInstallation отправляет статистику установки пакета
func TrackInstallation(ctx context.Context, packageName string, installType string) {
// Запускаем в отдельной горутине, чтобы не блокировать основной процесс
go func() {
data := InstallationData{
PackageName: packageName,
InstallType: installType,
UserAgent: userAgent,
Fingerprint: generateFingerprint(packageName),
}
jsonData, err := json.Marshal(data)
if err != nil {
return // Тихо игнорируем ошибки - статистика не критична
}
// Пробуем отправить запрос к разным endpoint-ам
for _, endpoint := range apiEndpoints {
if sendRequest(endpoint, jsonData) {
return // Если хотя бы один запрос прошёл успешно, выходим
}
}
}()
}
func sendRequest(endpoint string, data []byte) bool {
client := &http.Client{
Timeout: 5 * time.Second,
}
req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(data))
if err != nil {
return false
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", userAgent)
resp, err := client.Do(req)
if err != nil {
return false
}
defer resp.Body.Close()
return resp.StatusCode >= 200 && resp.StatusCode < 300
}
// ShouldTrackPackage проверяет, нужно ли отслеживать установку этого пакета
func ShouldTrackPackage(packageName string) bool {
// Отслеживаем только alr-bin
return strings.Contains(packageName, "alr-bin")
}

View File

@@ -34,27 +34,31 @@ msgstr ""
msgid "Error getting working directory"
msgstr ""
#: build.go:117
#: build.go:111
msgid "Cannot get absolute script path"
msgstr ""
#: build.go:143
#: build.go:137
msgid "Package not found"
msgstr ""
#: build.go:156
#: build.go:150
msgid "Nothing to build"
msgstr ""
#: build.go:213
#: build.go:195
msgid "Error building package"
msgstr ""
#: build.go:220
#: build.go:203
msgid "Package file already moved or removed, skipping"
msgstr ""
#: build.go:209
msgid "Error moving the package"
msgstr ""
#: build.go:224
#: build.go:213
msgid "Done"
msgstr ""
@@ -62,71 +66,123 @@ msgstr ""
msgid "Manage config"
msgstr ""
#: config.go:48
#: config.go:50
msgid "Shows a list of commands or help for one command"
msgstr ""
#: config.go:66
msgid "Show config"
msgstr ""
#: config.go:84
#: config.go:103
msgid "Set config value"
msgstr ""
#: config.go:85
#: config.go:104
msgid "<key> <value>"
msgstr ""
#: config.go:118 config.go:126
#: config.go:137 config.go:145 config.go:162
msgid "invalid boolean value for %s: %s"
msgstr ""
#: config.go:141
#: config.go:166
msgid "use 'repo add/remove' commands to manage repositories"
msgstr ""
#: config.go:143 config.go:221
#: config.go:168 config.go:248
msgid "unknown config key: %s"
msgstr ""
#: config.go:147
#: config.go:172
msgid "failed to save config"
msgstr ""
#: config.go:150
#: config.go:175
msgid "Successfully set %s = %s"
msgstr ""
#: config.go:159
#: config.go:184
msgid "Get config value"
msgstr ""
#: config.go:160
#: config.go:185
msgid "<key>"
msgstr ""
#: fix.go:39
#: fix.go:55
msgid "Attempt to fix problems with ALR"
msgstr ""
#: fix.go:60
msgid "Clearing cache directory"
msgstr ""
#: fix.go:64
msgid "Unable to open cache directory"
msgstr ""
#: fix.go:70
msgid "Unable to read cache directory contents"
#: fix.go:75
msgid "Clearing cache and temporary directories"
msgstr ""
#: fix.go:82
msgid "Cache directory does not exist, will create it"
msgstr ""
#: fix.go:84
msgid "Unable to open cache directory"
msgstr ""
#: fix.go:91
msgid "Unable to read cache directory contents"
msgstr ""
#: fix.go:106
msgid "Unable to remove cache item (%s) as current user, trying with sudo"
msgstr ""
#: fix.go:111
msgid "Unable to remove cache item (%s)"
msgstr ""
#: fix.go:86
#: fix.go:119
msgid "Clearing temporary directory"
msgstr ""
#: fix.go:126
msgid "Unable to remove temporary directory as current user, trying with sudo"
msgstr ""
#: fix.go:129
msgid "Unable to remove temporary directory"
msgstr ""
#: fix.go:137
msgid "Unable to create temporary directory"
msgstr ""
#: fix.go:144
msgid "Unable to create download directory"
msgstr ""
#: fix.go:151
msgid "Unable to create packages directory"
msgstr ""
#: fix.go:156
msgid "Fixing permissions on temporary files"
msgstr ""
#: fix.go:164
msgid "Unable to fix file ownership"
msgstr ""
#: fix.go:169
msgid "Unable to fix file permissions"
msgstr ""
#: fix.go:174
msgid "Rebuilding cache"
msgstr ""
#: fix.go:90
#: fix.go:177
msgid "Creating cache directory"
msgstr ""
#: fix.go:180
msgid "Unable to create new cache directory"
msgstr ""
@@ -138,55 +194,67 @@ msgstr ""
msgid "Generate a ALR script for a pip module"
msgstr ""
#: gen.go:66
msgid "Generate a ALR script for an AUR package"
msgstr ""
#: gen.go:72
msgid "Name of the AUR package"
msgstr ""
#: gen.go:77
msgid "Version of the package (optional, uses latest if not specified)"
msgstr ""
#: helper.go:42
msgid "List all the available helper commands"
msgstr ""
#: helper.go:54
#: helper.go:69
msgid "Run a ALR helper command"
msgstr ""
#: helper.go:61
#: helper.go:76
msgid "The directory that the install commands will install to"
msgstr ""
#: helper.go:74 helper.go:75
#: helper.go:89 helper.go:90
msgid "No such helper command"
msgstr ""
#: helper.go:85
#: helper.go:100
msgid "Error parsing os-release file"
msgstr ""
#: info.go:42
#: info.go:41
msgid "Print information about a package"
msgstr ""
#: info.go:47
#: info.go:46
msgid "Show all information, not just for the current distro"
msgstr ""
#: info.go:68
#: info.go:64
msgid "Error getting packages"
msgstr ""
#: info.go:83
#: info.go:77
msgid "Command info expected at least 1 argument, got %d"
msgstr ""
#: info.go:104
#: info.go:98
msgid "Error finding packages"
msgstr ""
#: info.go:118
#: info.go:112
msgid "Can't detect system language"
msgstr ""
#: info.go:134
#: info.go:128
msgid "Error resolving overrides"
msgstr ""
#: info.go:143
#: info.go:137
msgid "Error encoding script variables"
msgstr ""
@@ -198,43 +266,47 @@ msgstr ""
msgid "Command install expected at least 1 argument, got %d"
msgstr ""
#: install.go:113
#: install.go:107
msgid "Error when installing the package"
msgstr ""
#: install.go:151
#: install.go:142
msgid "Remove an installed package"
msgstr ""
#: install.go:170
#: install.go:161
msgid "Error listing installed packages"
msgstr ""
#: install.go:199
#: install.go:190
msgid "Command remove expected at least 1 argument, got %d"
msgstr ""
#: install.go:214
#: install.go:205
msgid "Error removing packages"
msgstr ""
#: internal/build/build.go:351
#: internal/build/build.go:342 internal/build/build.go:653
msgid "Using cached package"
msgstr ""
#: internal/build/build.go:357
msgid "Building package"
msgstr ""
#: internal/build/build.go:380
#: internal/build/build.go:386
msgid "The checksums array must be the same length as sources"
msgstr ""
#: internal/build/build.go:422
#: internal/build/build.go:438
msgid "Downloading sources"
msgstr ""
#: internal/build/build.go:468
#: internal/build/build.go:484
msgid "Would you like to remove the build dependencies?"
msgstr ""
#: internal/build/build.go:546
#: internal/build/build.go:569
msgid "Installing dependencies"
msgstr ""
@@ -272,22 +344,68 @@ msgstr ""
msgid "Applying FireJail integration"
msgstr ""
#: internal/build/script_executor.go:145
#: internal/build/installer.go:99
msgid ""
"Package %s is installed with older version %s, will rebuild with version %s"
msgstr ""
#: internal/build/installer.go:102
msgid "Package %s is already installed with version %s, skipping build"
msgstr ""
#: internal/build/installer.go:104
msgid ""
"Package %s is installed with newer version %s (repo has %s), skipping build"
msgstr ""
#: internal/build/script_executor.go:167
msgid "Building package metadata"
msgstr ""
#: internal/build/script_executor.go:285
#: internal/build/script_executor.go:192
msgid "Creating package file"
msgstr ""
#: internal/build/script_executor.go:196
msgid "Failed to create package file"
msgstr ""
#: internal/build/script_executor.go:201
msgid "Packaging with nfpm"
msgstr ""
#: internal/build/script_executor.go:204
msgid "Failed to create package"
msgstr ""
#: internal/build/script_executor.go:208
msgid "Package created successfully"
msgstr ""
#: internal/build/script_executor.go:212
msgid "Package file not found after creation"
msgstr ""
#: internal/build/script_executor.go:215
msgid "Package file verified to exist"
msgstr ""
#: internal/build/script_executor.go:322
msgid "Executing prepare()"
msgstr ""
#: internal/build/script_executor.go:294
#: internal/build/script_executor.go:331
msgid "Executing build()"
msgstr ""
#: internal/build/script_executor.go:323 internal/build/script_executor.go:343
#: internal/build/script_executor.go:360 internal/build/script_executor.go:380
msgid "Executing %s()"
msgstr ""
#: internal/cliutils/app_builder/builder.go:45
msgid "failed to close db"
msgstr ""
#: internal/cliutils/app_builder/builder.go:75
msgid "Error loading config"
msgstr ""
@@ -320,23 +438,25 @@ msgstr ""
msgid "User chose not to continue after reading script"
msgstr ""
#: internal/cliutils/prompt.go:111
#: internal/cliutils/prompt.go:123
msgid "Error prompting for choice of package"
msgstr ""
#: internal/cliutils/prompt.go:135
#: internal/cliutils/prompt.go:175
msgid "Choose which package to %s"
msgstr ""
#: internal/cliutils/prompt.go:156
#: internal/cliutils/prompt.go:196
msgid "Choose which optional package(s) to install"
msgstr ""
#: internal/cliutils/template.go:74 internal/cliutils/template.go:93
#: internal/cliutils/template.go:126
msgid "NAME"
msgstr ""
#: internal/cliutils/template.go:74 internal/cliutils/template.go:94
#: internal/cliutils/template.go:126
msgid "USAGE"
msgstr ""
@@ -344,15 +464,17 @@ msgstr ""
msgid "global options"
msgstr ""
#: internal/cliutils/template.go:74
#: internal/cliutils/template.go:74 internal/cliutils/template.go:126
msgid "command"
msgstr ""
#: internal/cliutils/template.go:74 internal/cliutils/template.go:95
#: internal/cliutils/template.go:126
msgid "command options"
msgstr ""
#: internal/cliutils/template.go:74 internal/cliutils/template.go:96
#: internal/cliutils/template.go:126
msgid "arguments"
msgstr ""
@@ -361,14 +483,15 @@ msgid "VERSION"
msgstr ""
#: internal/cliutils/template.go:74 internal/cliutils/template.go:98
#: internal/cliutils/template.go:126
msgid "DESCRIPTION"
msgstr ""
#: internal/cliutils/template.go:74
#: internal/cliutils/template.go:74 internal/cliutils/template.go:126
msgid "AUTHOR"
msgstr ""
#: internal/cliutils/template.go:74
#: internal/cliutils/template.go:74 internal/cliutils/template.go:126
msgid "COMMANDS"
msgstr ""
@@ -376,7 +499,7 @@ msgstr ""
msgid "GLOBAL OPTIONS"
msgstr ""
#: internal/cliutils/template.go:74
#: internal/cliutils/template.go:74 internal/cliutils/template.go:126
msgid "COPYRIGHT"
msgstr ""
@@ -385,6 +508,7 @@ msgid "CATEGORY"
msgstr ""
#: internal/cliutils/template.go:99 internal/cliutils/template.go:100
#: internal/cliutils/template.go:126
msgid "OPTIONS"
msgstr ""
@@ -394,11 +518,15 @@ msgid ""
"instead!"
msgstr ""
#: internal/db/db.go:76
#: internal/db/db.go:67
msgid "Cache directory does not exist, creating it"
msgstr ""
#: internal/db/db.go:95
msgid "Database version mismatch; resetting"
msgstr ""
#: internal/db/db.go:82
#: internal/db/db.go:101
msgid ""
"Database version does not exist. Run alr fix if something isn't working."
msgstr ""
@@ -433,43 +561,55 @@ msgid ""
"updating ALR if something doesn't work."
msgstr ""
#: internal/utils/cmd.go:97
msgid "Error on dropping capabilities"
#: internal/repos/pull.go:423
msgid "Failed to get deleted file from old commit"
msgstr ""
#: internal/utils/cmd.go:164
msgid "You need to be a %s member to perform this action"
#: internal/repos/pull.go:429
msgid "Failed to read deleted file"
msgstr ""
#: internal/utils/cmd.go:200
#: internal/repos/pull.go:448
msgid "Failed to get updated file from new commit"
msgstr ""
#: internal/repos/pull.go:454
msgid "Failed to read updated file"
msgstr ""
#: internal/repos/pull.go:508
msgid "No alr.sh files found in repository"
msgstr ""
#: internal/utils/cmd.go:54
msgid "You need to be root to perform this action"
msgstr ""
#: list.go:45
#: list.go:44
msgid "List ALR repo packages"
msgstr ""
#: list.go:59
#: list.go:58
msgid "Format output using a Go template"
msgstr ""
#: list.go:91
#: list.go:87
msgid "Error getting packages for upgrade"
msgstr ""
#: list.go:94
#: list.go:90
msgid "No packages for upgrade"
msgstr ""
#: list.go:104 list.go:201
#: list.go:100 list.go:197
msgid "Error parsing format template"
msgstr ""
#: list.go:110 list.go:205
#: list.go:106 list.go:201
msgid "Error executing template"
msgstr ""
#: list.go:164
#: list.go:160
msgid "Failed to parse release"
msgstr ""
@@ -477,19 +617,19 @@ msgstr ""
msgid "Print the current ALR version and exit"
msgstr ""
#: main.go:61
#: main.go:77
msgid "Arguments to be passed on to the package manager"
msgstr ""
#: main.go:67
#: main.go:83
msgid "Enable interactive questions and prompts"
msgstr ""
#: main.go:148
#: main.go:165
msgid "Show help"
msgstr ""
#: main.go:152
#: main.go:169
msgid "Error while running app"
msgstr ""
@@ -525,124 +665,124 @@ msgstr ""
msgid "Manage repos"
msgstr ""
#: repo.go:56 repo.go:625
#: repo.go:74 repo.go:658
msgid "Remove an existing repository"
msgstr ""
#: repo.go:58 repo.go:521
#: repo.go:76 repo.go:554
msgid "<name>"
msgstr ""
#: repo.go:103 repo.go:465 repo.go:568
#: repo.go:121 repo.go:498 repo.go:601
msgid "Repo \"%s\" does not exist"
msgstr ""
#: repo.go:110
#: repo.go:128
msgid "Error removing repo directory"
msgstr ""
#: repo.go:114 repo.go:195 repo.go:253 repo.go:316 repo.go:389 repo.go:504
#: repo.go:576
#: repo.go:132 repo.go:210 repo.go:268 repo.go:331 repo.go:422 repo.go:537
#: repo.go:609
msgid "Error saving config"
msgstr ""
#: repo.go:133
#: repo.go:148
msgid "Error removing packages from database"
msgstr ""
#: repo.go:144 repo.go:595
#: repo.go:159 repo.go:628
msgid "Add a new repository"
msgstr ""
#: repo.go:145 repo.go:270 repo.go:345 repo.go:402
#: repo.go:160 repo.go:285 repo.go:378 repo.go:435
msgid "<name> <url>"
msgstr ""
#: repo.go:170
#: repo.go:185
msgid "Repo \"%s\" already exists"
msgstr ""
#: repo.go:206
#: repo.go:221
msgid "Set the reference of the repository"
msgstr ""
#: repo.go:207
#: repo.go:222
msgid "<name> <ref>"
msgstr ""
#: repo.go:269
#: repo.go:284
msgid "Set the main url of the repository"
msgstr ""
#: repo.go:332
#: repo.go:347
msgid "Manage mirrors of repos"
msgstr ""
#: repo.go:344
#: repo.go:377
msgid "Add a mirror URL to repository"
msgstr ""
#: repo.go:401
#: repo.go:434
msgid "Remove mirror from the repository"
msgstr ""
#: repo.go:420
#: repo.go:453
msgid "Ignore if mirror does not exist"
msgstr ""
#: repo.go:425
#: repo.go:458
msgid "Match partial URL (e.g., github.com instead of full URL)"
msgstr ""
#: repo.go:490
#: repo.go:523
msgid "No mirrors containing \"%s\" found in repo \"%s\""
msgstr ""
#: repo.go:492
#: repo.go:525
msgid "URL \"%s\" does not exist in repo \"%s\""
msgstr ""
#: repo.go:508 repo.go:580
#: repo.go:541 repo.go:613
msgid "Removed %d mirrors from repo \"%s\"\n"
msgstr ""
#: repo.go:520
#: repo.go:553
msgid "Remove all mirrors from the repository"
msgstr ""
#: repo.go:602
#: repo.go:635
msgid "Name of the new repo"
msgstr ""
#: repo.go:608
#: repo.go:641
msgid "URL of the new repo"
msgstr ""
#: repo.go:632
#: repo.go:665
msgid "Name of the repo to be deleted"
msgstr ""
#: search.go:40
#: search.go:39
msgid "Search packages"
msgstr ""
#: search.go:51
#: search.go:50
msgid "Search by name"
msgstr ""
#: search.go:56
#: search.go:55
msgid "Search by description"
msgstr ""
#: search.go:61
#: search.go:60
msgid "Search by repository"
msgstr ""
#: search.go:66
#: search.go:65
msgid "Search by provides"
msgstr ""
#: search.go:130
#: search.go:126
msgid "Error while executing search"
msgstr ""
@@ -650,10 +790,22 @@ msgstr ""
msgid "Upgrade all installed packages"
msgstr ""
#: upgrade.go:106 upgrade.go:123
#: upgrade.go:89
msgid "Updating system packages..."
msgstr ""
#: upgrade.go:95
msgid "Error updating system packages"
msgstr ""
#: upgrade.go:97
msgid "System packages updated successfully"
msgstr ""
#: upgrade.go:113 upgrade.go:130
msgid "Error checking for updates"
msgstr ""
#: upgrade.go:126
#: upgrade.go:133
msgid "There is nothing to do."
msgstr ""

View File

@@ -41,27 +41,31 @@ msgstr "Создайте пакет с нуля, даже если уже име
msgid "Error getting working directory"
msgstr "Ошибка при получении рабочего каталога"
#: build.go:117
#: build.go:111
msgid "Cannot get absolute script path"
msgstr "Невозможно получить абсолютный путь к скрипту"
#: build.go:143
#: build.go:137
msgid "Package not found"
msgstr "Пакет не найден"
#: build.go:156
#: build.go:150
msgid "Nothing to build"
msgstr "Нечего собирать"
#: build.go:213
#: build.go:195
msgid "Error building package"
msgstr "Ошибка при сборке пакета"
#: build.go:220
#: build.go:203
msgid "Package file already moved or removed, skipping"
msgstr "Файл пакета уже перемещён или удалён, пропускаем"
#: build.go:209
msgid "Error moving the package"
msgstr "Ошибка при перемещении пакета"
#: build.go:224
#: build.go:213
msgid "Done"
msgstr "Сделано"
@@ -69,71 +73,132 @@ msgstr "Сделано"
msgid "Manage config"
msgstr "Управление конфигурацией"
#: config.go:48
#: config.go:50
msgid "Shows a list of commands or help for one command"
msgstr "Показывает список команд или справку по одной команде"
#: config.go:66
msgid "Show config"
msgstr "Показать конфигурацию"
#: config.go:84
#: config.go:103
msgid "Set config value"
msgstr "Установить значение в конфигурации"
#: config.go:85
#: config.go:104
msgid "<key> <value>"
msgstr "<ключ> <значение>"
#: config.go:118 config.go:126
#: config.go:137 config.go:145 config.go:162
msgid "invalid boolean value for %s: %s"
msgstr "неверное булево значение для %s: %s"
#: config.go:141
#: config.go:166
msgid "use 'repo add/remove' commands to manage repositories"
msgstr "используйте команды 'repo add/remove' для управления репозиториями"
#: config.go:143 config.go:221
#: config.go:168 config.go:248
msgid "unknown config key: %s"
msgstr "неизвестный ключ конфигурации: %s"
#: config.go:147
#: config.go:172
msgid "failed to save config"
msgstr "не удалось сохранить конфигурацию"
#: config.go:150
#: config.go:175
msgid "Successfully set %s = %s"
msgstr "Успешно установлено %s = %s"
#: config.go:159
#: config.go:184
msgid "Get config value"
msgstr "Получить значение из конфигурации"
#: config.go:160
#: config.go:185
msgid "<key>"
msgstr "<ключ>"
#: fix.go:39
#: fix.go:55
msgid "Attempt to fix problems with ALR"
msgstr "Попытка устранить проблемы с ALR"
#: fix.go:60
msgid "Clearing cache directory"
msgstr "Очистка каталога кэша"
#: fix.go:75
msgid "Clearing cache and temporary directories"
msgstr "Очистка кэша и временных директорий"
#: fix.go:64
#: fix.go:82
msgid "Cache directory does not exist, will create it"
msgstr ""
#: fix.go:84
msgid "Unable to open cache directory"
msgstr "Невозможно открыть каталог кэша"
#: fix.go:70
#: fix.go:91
msgid "Unable to read cache directory contents"
msgstr "Невозможно прочитать содержимое каталога кэша"
#: fix.go:82
#: fix.go:106
#, fuzzy
msgid "Unable to remove cache item (%s) as current user, trying with sudo"
msgstr ""
"Невозможно удалить временную директорию от текущего пользователя, попытка "
"через sudo"
#: fix.go:111
msgid "Unable to remove cache item (%s)"
msgstr "Невозможно удалить элемент кэша (%s)"
#: fix.go:86
#: fix.go:119
msgid "Clearing temporary directory"
msgstr "Очистка временной директории"
#: fix.go:126
msgid "Unable to remove temporary directory as current user, trying with sudo"
msgstr ""
"Невозможно удалить временную директорию от текущего пользователя, попытка "
"через sudo"
#: fix.go:129
#, fuzzy
msgid "Unable to remove temporary directory"
msgstr "Невозможно открыть каталог кэша"
#: fix.go:137
#, fuzzy
msgid "Unable to create temporary directory"
msgstr "Не удалось создать каталог конфигурации ALR"
#: fix.go:144
#, fuzzy
msgid "Unable to create download directory"
msgstr "Не удалось создать каталог конфигурации ALR"
#: fix.go:151
#, fuzzy
msgid "Unable to create packages directory"
msgstr "Не удалось создать каталог кэша пакетов"
#: fix.go:156
msgid "Fixing permissions on temporary files"
msgstr "Исправление прав доступа к временным файлам"
#: fix.go:164
msgid "Unable to fix file ownership"
msgstr ""
#: fix.go:169
msgid "Unable to fix file permissions"
msgstr ""
#: fix.go:174
msgid "Rebuilding cache"
msgstr "Восстановление кэша"
#: fix.go:90
#: fix.go:177
msgid "Creating cache directory"
msgstr "Создание директории кэша"
#: fix.go:180
msgid "Unable to create new cache directory"
msgstr "Не удалось создать новый каталог кэша"
@@ -145,55 +210,69 @@ msgstr "Генерация скрипта ALR из шаблона"
msgid "Generate a ALR script for a pip module"
msgstr "Генерация скрипта ALR для модуля pip"
#: gen.go:66
#, fuzzy
msgid "Generate a ALR script for an AUR package"
msgstr "Генерация скрипта ALR из шаблона"
#: gen.go:72
#, fuzzy
msgid "Name of the AUR package"
msgstr "Название нового репозитория"
#: gen.go:77
msgid "Version of the package (optional, uses latest if not specified)"
msgstr ""
#: helper.go:42
msgid "List all the available helper commands"
msgstr "Список всех доступных вспомогательных команды"
#: helper.go:54
#: helper.go:69
msgid "Run a ALR helper command"
msgstr "Запустить вспомогательную команду ALR"
#: helper.go:61
#: helper.go:76
msgid "The directory that the install commands will install to"
msgstr "Каталог, в который будут устанавливать команды установки"
#: helper.go:74 helper.go:75
#: helper.go:89 helper.go:90
msgid "No such helper command"
msgstr "Такой вспомогательной команды нет"
#: helper.go:85
#: helper.go:100
msgid "Error parsing os-release file"
msgstr "Ошибка при разборе файла выпуска операционной системы"
#: info.go:42
#: info.go:41
msgid "Print information about a package"
msgstr "Отобразить информацию о пакете"
#: info.go:47
#: info.go:46
msgid "Show all information, not just for the current distro"
msgstr "Показывать всю информацию, не только для текущего дистрибутива"
#: info.go:68
#: info.go:64
msgid "Error getting packages"
msgstr "Ошибка при получении пакетов"
#: info.go:83
#: info.go:77
msgid "Command info expected at least 1 argument, got %d"
msgstr "Для команды info ожидался хотя бы 1 аргумент, получено %d"
#: info.go:104
#: info.go:98
msgid "Error finding packages"
msgstr "Ошибка при поиске пакетов"
#: info.go:118
#: info.go:112
msgid "Can't detect system language"
msgstr "Ошибка при определении языка системы"
#: info.go:134
#: info.go:128
msgid "Error resolving overrides"
msgstr "Ошибка устранения переорпеделений"
#: info.go:143
#: info.go:137
msgid "Error encoding script variables"
msgstr "Ошибка кодирования переменных скрита"
@@ -205,43 +284,47 @@ msgstr "Установить новый пакет"
msgid "Command install expected at least 1 argument, got %d"
msgstr "Для команды install ожидался хотя бы 1 аргумент, получено %d"
#: install.go:113
#: install.go:107
msgid "Error when installing the package"
msgstr "Ошибка при установке пакета"
#: install.go:151
#: install.go:142
msgid "Remove an installed package"
msgstr "Удалить установленный пакет"
#: install.go:170
#: install.go:161
msgid "Error listing installed packages"
msgstr "Ошибка при составлении списка установленных пакетов"
#: install.go:199
#: install.go:190
msgid "Command remove expected at least 1 argument, got %d"
msgstr "Для команды remove ожидался хотя бы 1 аргумент, получено %d"
#: install.go:214
#: install.go:205
msgid "Error removing packages"
msgstr "Ошибка при удалении пакетов"
#: internal/build/build.go:351
#: internal/build/build.go:342 internal/build/build.go:653
msgid "Using cached package"
msgstr "Используется кешированный пакет"
#: internal/build/build.go:357
msgid "Building package"
msgstr "Сборка пакета"
#: internal/build/build.go:380
#: internal/build/build.go:386
msgid "The checksums array must be the same length as sources"
msgstr "Массив контрольных сумм должен быть той же длины, что и источники"
#: internal/build/build.go:422
#: internal/build/build.go:438
msgid "Downloading sources"
msgstr "Скачивание источников"
#: internal/build/build.go:468
#: internal/build/build.go:484
msgid "Would you like to remove the build dependencies?"
msgstr "Хотели бы вы удалить зависимости сборки?"
#: internal/build/build.go:546
#: internal/build/build.go:569
msgid "Installing dependencies"
msgstr "Установка зависимостей"
@@ -283,22 +366,71 @@ msgstr ""
msgid "Applying FireJail integration"
msgstr "Применение интеграции FireJail"
#: internal/build/script_executor.go:145
#: internal/build/installer.go:99
msgid ""
"Package %s is installed with older version %s, will rebuild with version %s"
msgstr ""
"Пакет %s установлен с устаревшей версией %s, будет пересобран с версией %s"
#: internal/build/installer.go:102
msgid "Package %s is already installed with version %s, skipping build"
msgstr "Пакет %s уже установлен с версией %s, пропуск сборки"
#: internal/build/installer.go:104
msgid ""
"Package %s is installed with newer version %s (repo has %s), skipping build"
msgstr ""
"Пакет %s установлен с более новой версией %s (в репозитории %s), пропуск "
"сборки"
#: internal/build/script_executor.go:167
msgid "Building package metadata"
msgstr "Сборка метаданных пакета"
#: internal/build/script_executor.go:285
#: internal/build/script_executor.go:192
msgid "Creating package file"
msgstr "Создание файла пакета"
#: internal/build/script_executor.go:196
msgid "Failed to create package file"
msgstr "Не удалось создать файл пакета"
#: internal/build/script_executor.go:201
msgid "Packaging with nfpm"
msgstr "Упаковка с помощью nfpm"
#: internal/build/script_executor.go:204
msgid "Failed to create package"
msgstr "Не удалось создать пакет"
#: internal/build/script_executor.go:208
msgid "Package created successfully"
msgstr "Пакет успешно создан"
#: internal/build/script_executor.go:212
msgid "Package file not found after creation"
msgstr "Файл пакета не найден после создания"
#: internal/build/script_executor.go:215
msgid "Package file verified to exist"
msgstr "Наличие файла пакета подтверждено"
#: internal/build/script_executor.go:322
msgid "Executing prepare()"
msgstr "Выполнение prepare()"
#: internal/build/script_executor.go:294
#: internal/build/script_executor.go:331
msgid "Executing build()"
msgstr "Выполнение build()"
#: internal/build/script_executor.go:323 internal/build/script_executor.go:343
#: internal/build/script_executor.go:360 internal/build/script_executor.go:380
msgid "Executing %s()"
msgstr "Выполнение %s()"
#: internal/cliutils/app_builder/builder.go:45
msgid "failed to close db"
msgstr "не удалось закрыть БД"
#: internal/cliutils/app_builder/builder.go:75
msgid "Error loading config"
msgstr "Ошибка при загрузке"
@@ -331,23 +463,25 @@ msgstr "Продолжить?"
msgid "User chose not to continue after reading script"
msgstr "Пользователь решил не продолжать после просмотра скрипта"
#: internal/cliutils/prompt.go:111
#: internal/cliutils/prompt.go:123
msgid "Error prompting for choice of package"
msgstr "Ошибка при запросе выбора пакета"
#: internal/cliutils/prompt.go:135
#: internal/cliutils/prompt.go:175
msgid "Choose which package to %s"
msgstr "Выберите, какой пакет использовать для %s"
#: internal/cliutils/prompt.go:156
#: internal/cliutils/prompt.go:196
msgid "Choose which optional package(s) to install"
msgstr "Выберите, какой дополнительный пакет(ы) следует установить"
msgstr "Выберите дополнительные пакеты для установки"
#: internal/cliutils/template.go:74 internal/cliutils/template.go:93
#: internal/cliutils/template.go:126
msgid "NAME"
msgstr "НАЗВАНИЕ"
#: internal/cliutils/template.go:74 internal/cliutils/template.go:94
#: internal/cliutils/template.go:126
msgid "USAGE"
msgstr "ИСПОЛЬЗОВАНИЕ"
@@ -355,15 +489,17 @@ msgstr "ИСПОЛЬЗОВАНИЕ"
msgid "global options"
msgstr "глобальные опции"
#: internal/cliutils/template.go:74
#: internal/cliutils/template.go:74 internal/cliutils/template.go:126
msgid "command"
msgstr "команда"
#: internal/cliutils/template.go:74 internal/cliutils/template.go:95
#: internal/cliutils/template.go:126
msgid "command options"
msgstr "опции команды"
#: internal/cliutils/template.go:74 internal/cliutils/template.go:96
#: internal/cliutils/template.go:126
msgid "arguments"
msgstr "аргументы"
@@ -372,14 +508,15 @@ msgid "VERSION"
msgstr "ВЕРСИЯ"
#: internal/cliutils/template.go:74 internal/cliutils/template.go:98
#: internal/cliutils/template.go:126
msgid "DESCRIPTION"
msgstr "ОПИСАНИЕ"
#: internal/cliutils/template.go:74
#: internal/cliutils/template.go:74 internal/cliutils/template.go:126
msgid "AUTHOR"
msgstr "АВТОР"
#: internal/cliutils/template.go:74
#: internal/cliutils/template.go:74 internal/cliutils/template.go:126
msgid "COMMANDS"
msgstr "КОМАНДЫ"
@@ -387,7 +524,7 @@ msgstr "КОМАНДЫ"
msgid "GLOBAL OPTIONS"
msgstr "ГЛОБАЛЬНЫЕ ОПЦИИ"
#: internal/cliutils/template.go:74
#: internal/cliutils/template.go:74 internal/cliutils/template.go:126
msgid "COPYRIGHT"
msgstr "АВТОРСКОЕ ПРАВО"
@@ -396,6 +533,7 @@ msgid "CATEGORY"
msgstr "КАТЕГОРИЯ"
#: internal/cliutils/template.go:99 internal/cliutils/template.go:100
#: internal/cliutils/template.go:126
msgid "OPTIONS"
msgstr "ПАРАМЕТРЫ"
@@ -407,11 +545,15 @@ msgstr ""
"Эта команда устарела и будет удалена в будущем, используйте вместо нее "
"\"%s\"!"
#: internal/db/db.go:76
#: internal/db/db.go:67
msgid "Cache directory does not exist, creating it"
msgstr ""
#: internal/db/db.go:95
msgid "Database version mismatch; resetting"
msgstr "Несоответствие версий базы данных; сброс настроек"
#: internal/db/db.go:82
#: internal/db/db.go:101
msgid ""
"Database version does not exist. Run alr fix if something isn't working."
msgstr ""
@@ -449,43 +591,55 @@ msgstr ""
"Минимальная версия ALR для ALR-репозитория выше текущей версии. Попробуйте "
"обновить ALR, если что-то не работает."
#: internal/utils/cmd.go:97
msgid "Error on dropping capabilities"
msgstr "Ошибка при понижении привилегий"
#: internal/repos/pull.go:423
msgid "Failed to get deleted file from old commit"
msgstr "Не удалось получить удалённый файл из старого коммита"
#: internal/utils/cmd.go:164
msgid "You need to be a %s member to perform this action"
msgstr "Вы должны быть членом %s чтобы выполнить это"
#: internal/repos/pull.go:429
msgid "Failed to read deleted file"
msgstr "Не удалось прочитать удалённый файл"
#: internal/utils/cmd.go:200
#: internal/repos/pull.go:448
msgid "Failed to get updated file from new commit"
msgstr "Не удалось получить обновлённый файл из нового коммита"
#: internal/repos/pull.go:454
msgid "Failed to read updated file"
msgstr "Не удалось прочитать обновлённый файл"
#: internal/repos/pull.go:508
msgid "No alr.sh files found in repository"
msgstr "Файлы alr.sh не найдены в репозитории"
#: internal/utils/cmd.go:54
msgid "You need to be root to perform this action"
msgstr "Вы должны быть root чтобы выполнить это"
#: list.go:45
#: list.go:44
msgid "List ALR repo packages"
msgstr "Список пакетов репозитория ALR"
#: list.go:59
#: list.go:58
msgid "Format output using a Go template"
msgstr "Формат выходных данных с использованием шаблона Go"
#: list.go:91
#: list.go:87
msgid "Error getting packages for upgrade"
msgstr "Ошибка при получении пакетов для обновления"
#: list.go:94
#: list.go:90
msgid "No packages for upgrade"
msgstr "Нет пакетов к обновлению"
#: list.go:104 list.go:201
#: list.go:100 list.go:197
msgid "Error parsing format template"
msgstr "Ошибка при разборе шаблона"
#: list.go:110 list.go:205
#: list.go:106 list.go:201
msgid "Error executing template"
msgstr "Ошибка при выполнении шаблона"
#: list.go:164
#: list.go:160
msgid "Failed to parse release"
msgstr "Не удалось разобрать релиз"
@@ -493,19 +647,19 @@ msgstr "Не удалось разобрать релиз"
msgid "Print the current ALR version and exit"
msgstr "Показать текущую версию ALR и выйти"
#: main.go:61
#: main.go:77
msgid "Arguments to be passed on to the package manager"
msgstr "Аргументы, которые будут переданы менеджеру пакетов"
#: main.go:67
#: main.go:83
msgid "Enable interactive questions and prompts"
msgstr "Включение интерактивных вопросов и запросов"
#: main.go:148
#: main.go:165
msgid "Show help"
msgstr "Показать справку"
#: main.go:152
#: main.go:169
msgid "Error while running app"
msgstr "Ошибка при запуске приложения"
@@ -541,124 +695,124 @@ msgstr "Скачать все изменённые репозитории"
msgid "Manage repos"
msgstr "Управление репозиториями"
#: repo.go:56 repo.go:625
#: repo.go:74 repo.go:658
msgid "Remove an existing repository"
msgstr "Удалить существующий репозиторий"
#: repo.go:58 repo.go:521
#: repo.go:76 repo.go:554
msgid "<name>"
msgstr "<имя>"
#: repo.go:103 repo.go:465 repo.go:568
#: repo.go:121 repo.go:498 repo.go:601
msgid "Repo \"%s\" does not exist"
msgstr "Репозитория \"%s\" не существует"
msgstr "Репозиторий \"%s\" не существует"
#: repo.go:110
#: repo.go:128
msgid "Error removing repo directory"
msgstr "Ошибка при удалении каталога репозитория"
#: repo.go:114 repo.go:195 repo.go:253 repo.go:316 repo.go:389 repo.go:504
#: repo.go:576
#: repo.go:132 repo.go:210 repo.go:268 repo.go:331 repo.go:422 repo.go:537
#: repo.go:609
msgid "Error saving config"
msgstr "Ошибка при сохранении конфигурации"
#: repo.go:133
#: repo.go:148
msgid "Error removing packages from database"
msgstr "Ошибка при удалении пакетов из базы данных"
#: repo.go:144 repo.go:595
#: repo.go:159 repo.go:628
msgid "Add a new repository"
msgstr "Добавить новый репозиторий"
#: repo.go:145 repo.go:270 repo.go:345 repo.go:402
#: repo.go:160 repo.go:285 repo.go:378 repo.go:435
msgid "<name> <url>"
msgstr "<имя> <url>"
#: repo.go:170
#: repo.go:185
msgid "Repo \"%s\" already exists"
msgstr "Репозиторий \"%s\" уже существует"
#: repo.go:206
#: repo.go:221
msgid "Set the reference of the repository"
msgstr "Установить ссылку на версию репозитория"
#: repo.go:207
#: repo.go:222
msgid "<name> <ref>"
msgstr "<имя> <ссылкааерсию>"
#: repo.go:269
#: repo.go:284
msgid "Set the main url of the repository"
msgstr "Установить главный URL репозитория"
#: repo.go:332
#: repo.go:347
msgid "Manage mirrors of repos"
msgstr "Управление зеркалами репозитория"
#: repo.go:344
#: repo.go:377
msgid "Add a mirror URL to repository"
msgstr "Добавить зеркало репозитория"
#: repo.go:401
#: repo.go:434
msgid "Remove mirror from the repository"
msgstr "Удалить зеркало из репозитория"
#: repo.go:420
#: repo.go:453
msgid "Ignore if mirror does not exist"
msgstr "Игнорировать, если зеркала не существует"
#: repo.go:425
#: repo.go:458
msgid "Match partial URL (e.g., github.com instead of full URL)"
msgstr "Соответствует частичному URL (например, github.com вместо полного URL)"
#: repo.go:490
#: repo.go:523
msgid "No mirrors containing \"%s\" found in repo \"%s\""
msgstr "В репозитории \"%s\" не найдено зеркал, содержащих \"%s\""
#: repo.go:492
#: repo.go:525
msgid "URL \"%s\" does not exist in repo \"%s\""
msgstr "URL \"%s\" не существует в репозитории \"%s\""
#: repo.go:508 repo.go:580
#: repo.go:541 repo.go:613
msgid "Removed %d mirrors from repo \"%s\"\n"
msgstr "Удалены зеркала %d из репозитория \"%s\"\n"
msgstr "Удалено %d зеркал из репозитория \"%s\"\n"
#: repo.go:520
#: repo.go:553
msgid "Remove all mirrors from the repository"
msgstr "Удалить все зеркала из репозитория"
#: repo.go:602
#: repo.go:635
msgid "Name of the new repo"
msgstr "Название нового репозитория"
#: repo.go:608
#: repo.go:641
msgid "URL of the new repo"
msgstr "URL-адрес нового репозитория"
#: repo.go:632
#: repo.go:665
msgid "Name of the repo to be deleted"
msgstr "Название репозитория удалён"
msgstr "Название репозитория для удаления"
#: search.go:40
#: search.go:39
msgid "Search packages"
msgstr "Поиск пакетов"
#: search.go:51
#: search.go:50
msgid "Search by name"
msgstr "Искать по имени"
#: search.go:56
#: search.go:55
msgid "Search by description"
msgstr "Искать по описанию"
#: search.go:61
#: search.go:60
msgid "Search by repository"
msgstr "Искать по репозиторию"
#: search.go:66
#: search.go:65
msgid "Search by provides"
msgstr "Иcкать по provides"
msgstr "Искать по provides"
#: search.go:130
#: search.go:126
msgid "Error while executing search"
msgstr "Ошибка при выполнении поиска"
@@ -666,13 +820,35 @@ msgstr "Ошибка при выполнении поиска"
msgid "Upgrade all installed packages"
msgstr "Обновить все установленные пакеты"
#: upgrade.go:106 upgrade.go:123
#: upgrade.go:89
msgid "Updating system packages..."
msgstr "Обновление системных пакетов..."
#: upgrade.go:95
#, fuzzy
msgid "Error updating system packages"
msgstr "Обновление системных пакетов..."
#: upgrade.go:97
msgid "System packages updated successfully"
msgstr "Системные пакеты успешно обновлены"
#: upgrade.go:113 upgrade.go:130
msgid "Error checking for updates"
msgstr "Ошибка при проверке обновлений"
#: upgrade.go:126
#: upgrade.go:133
msgid "There is nothing to do."
msgstr "Здесь нечего делать."
msgstr "Действия не требуются."
#~ msgid "Clearing cache directory"
#~ msgstr "Очистка каталога кэша"
#~ msgid "Error on dropping capabilities"
#~ msgstr "Ошибка при понижении привилегий"
#~ msgid "You need to be a %s member to perform this action"
#~ msgstr "Вы должны быть членом %s чтобы выполнить это"
#, fuzzy
#~ msgid "Failed to clear contents of cache directory"
@@ -692,13 +868,6 @@ msgstr "Здесь нечего делать."
#~ msgid "Error mounting"
#~ msgstr "Ошибка при кодировании конфигурации"
#, fuzzy
#~ msgid "Unable to create config directory"
#~ msgstr "Не удалось создать каталог конфигурации ALR"
#~ msgid "Unable to create package cache directory"
#~ msgstr "Не удалось создать каталог кэша пакетов"
#~ msgid ""
#~ "Running ALR as root is forbidden as it may cause catastrophic damage to "
#~ "your system"

View File

@@ -19,14 +19,12 @@ package utils
import (
"os"
"os/exec"
"os/user"
"github.com/leonelquinteros/gotext"
"github.com/urfave/cli/v2"
"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/constants"
)
// IsNotRoot проверяет, что текущий пользователь не является root
@@ -34,39 +32,10 @@ func IsNotRoot() bool {
return os.Getuid() != 0
}
// EnuseIsPrivilegedGroupMember проверяет, что пользователь является членом привилегированной группы (wheel)
// EnuseIsPrivilegedGroupMember проверяет, что пользователь является членом привилегированной группы (wheel/sudo)
// DEPRECATED: используйте CheckUserPrivileges() из utils.go
func EnuseIsPrivilegedGroupMember() error {
// В CI пропускаем проверку группы wheel
if os.Getenv("CI") == "true" {
return nil
}
// Если пользователь root, пропускаем проверку
if os.Geteuid() == 0 {
return nil
}
currentUser, err := user.Current()
if err != nil {
return err
}
group, err := user.LookupGroup(constants.PrivilegedGroup)
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 cliutils.FormatCliExit(gotext.Get("You need to be a %s member to perform this action", constants.PrivilegedGroup), nil)
return CheckUserPrivileges()
}
func RootNeededAction(f cli.ActionFunc) cli.ActionFunc {

View File

@@ -17,10 +17,11 @@
package utils
import (
"fmt"
"os"
"os/exec"
"strings"
"os/user"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/fsutils"
"golang.org/x/sys/unix"
)
@@ -28,66 +29,71 @@ func NoNewPrivs() error {
return unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)
}
// EnsureTempDirWithRootOwner создает каталог в /tmp/alr с правами для группы wheel
// Все каталоги в /tmp/alr принадлежат root:wheel с правами 775
// Для других каталогов использует стандартные права
// EnsureTempDirWithRootOwner создает каталог в /tmp/alr или /var/cache/alr с правами для привилегированной группы
// Обёртка для обратной совместимости, делегирует вызов в fsutils
func EnsureTempDirWithRootOwner(path string, mode os.FileMode) error {
if strings.HasPrefix(path, "/tmp/alr") {
// Сначала создаем директорию обычным способом
err := os.MkdirAll(path, mode)
if err != nil {
return err
}
// В CI или если мы уже root, не нужно использовать sudo
isRoot := os.Geteuid() == 0
isCI := os.Getenv("CI") == "true"
// В CI создаем директории с обычными правами
if isCI {
// В CI не используем группу wheel и не меняем права
// Устанавливаем базовые права 777 для временных каталогов
chmodCmd := exec.Command("chmod", "777", path)
chmodCmd.Run() // Игнорируем ошибки
return nil
}
// Для обычной работы устанавливаем права и группу wheel
permissions := "2775"
group := "wheel"
var chmodCmd, chownCmd *exec.Cmd
if isRoot {
// Выполняем команды напрямую без sudo
chmodCmd = exec.Command("chmod", permissions, path)
chownCmd = exec.Command("chown", "root:"+group, path)
} else {
// Используем sudo для обычных пользователей
chmodCmd = exec.Command("sudo", "chmod", permissions, path)
chownCmd = exec.Command("sudo", "chown", "root:"+group, path)
}
// Устанавливаем права с setgid битом
err = chmodCmd.Run()
if err != nil {
// Для root игнорируем ошибки, если группа wheel не существует
if !isRoot {
return err
}
}
// Устанавливаем владельца root:wheel
err = chownCmd.Run()
if err != nil {
// Для root игнорируем ошибки, если группа wheel не существует
if !isRoot {
return err
}
}
return nil
}
// Для остальных каталогов обычное создание
return os.MkdirAll(path, mode)
return fsutils.EnsureTempDirWithRootOwner(path, mode)
}
// GetPrivilegedGroup возвращает привилегированную группу для текущей системы
// Обёртка для обратной совместимости, делегирует вызов в fsutils
func GetPrivilegedGroup() string {
return fsutils.GetPrivilegedGroup()
}
// IsUserInGroup проверяет, состоит ли пользователь в указанной группе
func IsUserInGroup(username, groupname string) bool {
u, err := user.Lookup(username)
if err != nil {
return false
}
groups, err := u.GroupIds()
if err != nil {
return false
}
targetGroup, err := user.LookupGroup(groupname)
if err != nil {
return false
}
for _, gid := range groups {
if gid == targetGroup.Gid {
return true
}
}
return false
}
// CheckUserPrivileges проверяет, что пользователь имеет необходимые привилегии для работы с ALR
// Пользователь должен быть root или состоять в группе wheel/sudo
func CheckUserPrivileges() error {
// Если пользователь root - все в порядке
if os.Geteuid() == 0 {
return nil
}
// В CI не проверяем привилегии
if os.Getenv("CI") == "true" {
return nil
}
currentUser, err := user.Current()
if err != nil {
return fmt.Errorf("не удалось получить информацию о текущем пользователе: %w", err)
}
privilegedGroup := fsutils.GetPrivilegedGroup()
// Проверяем членство в привилегированной группе
if !IsUserInGroup(currentUser.Username, privilegedGroup) {
return fmt.Errorf("пользователь %s не имеет необходимых привилегий для работы с ALR.\n"+
"Для работы с ALR необходимо быть пользователем root или состоять в группе %s.\n"+
"Выполните команду: sudo usermod -a -G %s %s\n"+
"Затем перезайдите в систему или выполните: newgrp %s",
currentUser.Username, privilegedGroup, privilegedGroup, currentUser.Username, privilegedGroup)
}
return nil
}

23
main.go
View File

@@ -50,6 +50,22 @@ func VersionCmd() *cli.Command {
}
}
func HelpCmd() *cli.Command {
return &cli.Command{
Name: "help",
Aliases: []string{"h"},
Usage: gotext.Get("Shows a list of commands or help for one command"),
ArgsUsage: "[command]",
Action: func(cCtx *cli.Context) error {
args := cCtx.Args()
if args.Present() {
return cli.ShowCommandHelp(cCtx, args.First())
}
return cli.ShowAppHelp(cCtx)
},
}
}
func GetApp() *cli.App {
return &cli.App{
Name: "alr",
@@ -88,6 +104,7 @@ func GetApp() *cli.App {
InternalBuildCmd(),
InternalInstallCmd(),
InternalReposCmd(),
HelpCmd(),
},
Before: func(c *cli.Context) error {
if trimmed := strings.TrimSpace(c.String("pm-args")); trimmed != "" {
@@ -124,7 +141,6 @@ func setLogLevel(newLevel string) {
func main() {
logger.SetupDefault()
setLogLevel(os.Getenv("ALR_LOG_LEVEL"))
translations.Setup()
ctx := context.Background()
@@ -137,6 +153,10 @@ func main() {
os.Exit(1)
}
setLogLevel(cfg.LogLevel())
// Переменная окружения имеет приоритет над конфигом
if envLevel := os.Getenv("ALR_LOG_LEVEL"); envLevel != "" {
setLogLevel(envLevel)
}
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
defer cancel()
@@ -144,6 +164,7 @@ func main() {
// Make the application more internationalized
cli.AppHelpTemplate = cliutils.GetAppCliTemplate()
cli.CommandHelpTemplate = cliutils.GetCommandHelpTemplate()
cli.SubcommandHelpTemplate = cliutils.GetSubcommandHelpTemplate()
cli.HelpFlag.(*cli.BoolFlag).Usage = gotext.Get("Show help")
err = app.RunContext(ctx, os.Args)

View File

@@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"log/slog"
"os"
"path/filepath"
"runtime"
@@ -171,7 +172,25 @@ func (s *ScriptFile) createPackageFromMeta(
return nil, err
}
metaDecoder := decoder.New(&distro.OSRelease{}, metaRunner)
// DEBUG: Выводим что в metaRunner.Vars и dec.Runner.Vars для deps_debian
if depsDebianMeta, ok := metaRunner.Vars["deps_debian"]; ok {
slog.Info("DEBUG createPackageFromMeta: metaRunner.Vars[deps_debian]", "value", depsDebianMeta.String(), "list", depsDebianMeta.List)
} else {
slog.Info("DEBUG createPackageFromMeta: metaRunner.Vars[deps_debian] NOT FOUND")
}
if depsDebianParent, ok := dec.Runner.Vars["deps_debian"]; ok {
slog.Info("DEBUG createPackageFromMeta: parent Vars[deps_debian]", "value", depsDebianParent.String(), "list", depsDebianParent.List)
}
// Сливаем переменные родительского runner'а с переменными мета-функции.
// Переменные мета-функции имеют приоритет (для случаев переопределения).
for name, val := range dec.Runner.Vars {
if _, exists := metaRunner.Vars[name]; !exists {
metaRunner.Vars[name] = val
}
}
metaDecoder := decoder.New(dec.Info(), metaRunner)
var vars Package
if err := metaDecoder.DecodeVars(&vars); err != nil {

137
pkg/depver/depver.go Normal file
View File

@@ -0,0 +1,137 @@
// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// 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 depver provides parsing and comparison of versioned dependencies
// in PKGBUILD-style format (e.g., "gcc>=5.0", "openssl>=1.1.0").
package depver
import (
"strings"
"gitea.plemya-x.ru/xpamych/vercmp"
)
// Operator represents a version comparison operator.
type Operator string
const (
OpNone Operator = "" // No version constraint
OpEq Operator = "=" // Equal to
OpGt Operator = ">" // Greater than
OpGe Operator = ">=" // Greater than or equal to
OpLt Operator = "<" // Less than
OpLe Operator = "<=" // Less than or equal to
)
// Dependency represents a package dependency with optional version constraint.
type Dependency struct {
Name string // Package name (e.g., "gcc")
Operator Operator // Comparison operator (e.g., OpGe for ">=")
Version string // Version string (e.g., "5.0")
}
// operators lists all supported operators in order of decreasing length
// (to ensure ">=" is matched before ">").
var operators = []Operator{OpGe, OpLe, OpGt, OpLt, OpEq}
// Parse parses a dependency string in PKGBUILD format.
// Examples:
// - "gcc>=5.0" -> Dependency{Name: "gcc", Operator: OpGe, Version: "5.0"}
// - "openssl" -> Dependency{Name: "openssl", Operator: OpNone, Version: ""}
// - "cmake>=3.10" -> Dependency{Name: "cmake", Operator: OpGe, Version: "3.10"}
func Parse(dep string) Dependency {
dep = strings.TrimSpace(dep)
if dep == "" {
return Dependency{}
}
// Try each operator (longer ones first)
for _, op := range operators {
if idx := strings.Index(dep, string(op)); idx > 0 {
return Dependency{
Name: strings.TrimSpace(dep[:idx]),
Operator: op,
Version: strings.TrimSpace(dep[idx+len(op):]),
}
}
}
// No operator found - just a package name
return Dependency{
Name: dep,
Operator: OpNone,
Version: "",
}
}
// ParseMultiple parses multiple dependency strings.
func ParseMultiple(deps []string) []Dependency {
result := make([]Dependency, 0, len(deps))
for _, dep := range deps {
if dep != "" {
result = append(result, Parse(dep))
}
}
return result
}
// String returns the dependency in PKGBUILD format.
func (d Dependency) String() string {
if d.Operator == OpNone || d.Version == "" {
return d.Name
}
return d.Name + string(d.Operator) + d.Version
}
// Satisfies checks if the given version satisfies the dependency constraint.
// Returns true if:
// - The dependency has no version constraint (OpNone)
// - The installed version satisfies the operator/version requirement
func (d Dependency) Satisfies(installedVersion string) bool {
if d.Operator == OpNone || d.Version == "" {
return true
}
if installedVersion == "" {
return false
}
// vercmp.Compare returns:
// -1 if installedVersion < d.Version
// 0 if installedVersion == d.Version
// 1 if installedVersion > d.Version
cmp := vercmp.Compare(installedVersion, d.Version)
switch d.Operator {
case OpEq:
return cmp == 0
case OpGt:
return cmp > 0
case OpGe:
return cmp >= 0
case OpLt:
return cmp < 0
case OpLe:
return cmp <= 0
default:
return true
}
}
// HasVersionConstraint returns true if the dependency has a version constraint.
func (d Dependency) HasVersionConstraint() bool {
return d.Operator != OpNone && d.Version != ""
}

347
pkg/depver/depver_test.go Normal file
View File

@@ -0,0 +1,347 @@
// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// 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 depver
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParse(t *testing.T) {
tests := []struct {
name string
input string
expected Dependency
}{
{
name: "simple package name",
input: "gcc",
expected: Dependency{
Name: "gcc",
Operator: OpNone,
Version: "",
},
},
{
name: "greater or equal",
input: "gcc>=5.0",
expected: Dependency{
Name: "gcc",
Operator: OpGe,
Version: "5.0",
},
},
{
name: "less or equal",
input: "openssl<=1.1.0",
expected: Dependency{
Name: "openssl",
Operator: OpLe,
Version: "1.1.0",
},
},
{
name: "greater than",
input: "cmake>3.10",
expected: Dependency{
Name: "cmake",
Operator: OpGt,
Version: "3.10",
},
},
{
name: "less than",
input: "python<4.0",
expected: Dependency{
Name: "python",
Operator: OpLt,
Version: "4.0",
},
},
{
name: "equal",
input: "nodejs=18.0.0",
expected: Dependency{
Name: "nodejs",
Operator: OpEq,
Version: "18.0.0",
},
},
{
name: "with spaces around",
input: " gcc>=5.0 ",
expected: Dependency{
Name: "gcc",
Operator: OpGe,
Version: "5.0",
},
},
{
name: "complex version",
input: "glibc>=2.17-326",
expected: Dependency{
Name: "glibc",
Operator: OpGe,
Version: "2.17-326",
},
},
{
name: "empty string",
input: "",
expected: Dependency{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := Parse(tt.input)
assert.Equal(t, tt.expected, result)
})
}
}
func TestParseMultiple(t *testing.T) {
input := []string{"gcc>=5.0", "openssl", "cmake>=3.10", ""}
expected := []Dependency{
{Name: "gcc", Operator: OpGe, Version: "5.0"},
{Name: "openssl", Operator: OpNone, Version: ""},
{Name: "cmake", Operator: OpGe, Version: "3.10"},
}
result := ParseMultiple(input)
assert.Equal(t, expected, result)
}
func TestDependency_String(t *testing.T) {
tests := []struct {
name string
dep Dependency
expected string
}{
{
name: "no version",
dep: Dependency{Name: "gcc", Operator: OpNone, Version: ""},
expected: "gcc",
},
{
name: "with version",
dep: Dependency{Name: "gcc", Operator: OpGe, Version: "5.0"},
expected: "gcc>=5.0",
},
{
name: "equal operator",
dep: Dependency{Name: "python", Operator: OpEq, Version: "3.11"},
expected: "python=3.11",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.dep.String()
assert.Equal(t, tt.expected, result)
})
}
}
func TestDependency_Satisfies(t *testing.T) {
tests := []struct {
name string
dep Dependency
installedVersion string
expected bool
}{
{
name: "no constraint - always satisfied",
dep: Dependency{Name: "gcc", Operator: OpNone, Version: ""},
installedVersion: "5.0",
expected: true,
},
{
name: "ge - satisfied",
dep: Dependency{Name: "gcc", Operator: OpGe, Version: "5.0"},
installedVersion: "5.0",
expected: true,
},
{
name: "ge - greater version satisfied",
dep: Dependency{Name: "gcc", Operator: OpGe, Version: "5.0"},
installedVersion: "6.0",
expected: true,
},
{
name: "ge - not satisfied",
dep: Dependency{Name: "gcc", Operator: OpGe, Version: "5.0"},
installedVersion: "4.9",
expected: false,
},
{
name: "gt - satisfied",
dep: Dependency{Name: "gcc", Operator: OpGt, Version: "5.0"},
installedVersion: "5.1",
expected: true,
},
{
name: "gt - equal not satisfied",
dep: Dependency{Name: "gcc", Operator: OpGt, Version: "5.0"},
installedVersion: "5.0",
expected: false,
},
{
name: "le - satisfied",
dep: Dependency{Name: "gcc", Operator: OpLe, Version: "5.0"},
installedVersion: "5.0",
expected: true,
},
{
name: "le - lesser satisfied",
dep: Dependency{Name: "gcc", Operator: OpLe, Version: "5.0"},
installedVersion: "4.9",
expected: true,
},
{
name: "le - not satisfied",
dep: Dependency{Name: "gcc", Operator: OpLe, Version: "5.0"},
installedVersion: "5.1",
expected: false,
},
{
name: "lt - satisfied",
dep: Dependency{Name: "gcc", Operator: OpLt, Version: "5.0"},
installedVersion: "4.9",
expected: true,
},
{
name: "lt - equal not satisfied",
dep: Dependency{Name: "gcc", Operator: OpLt, Version: "5.0"},
installedVersion: "5.0",
expected: false,
},
{
name: "eq - satisfied",
dep: Dependency{Name: "gcc", Operator: OpEq, Version: "5.0"},
installedVersion: "5.0",
expected: true,
},
{
name: "eq - not satisfied",
dep: Dependency{Name: "gcc", Operator: OpEq, Version: "5.0"},
installedVersion: "5.1",
expected: false,
},
{
name: "empty installed version",
dep: Dependency{Name: "gcc", Operator: OpGe, Version: "5.0"},
installedVersion: "",
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.dep.Satisfies(tt.installedVersion)
assert.Equal(t, tt.expected, result)
})
}
}
func TestDependency_ForManager(t *testing.T) {
dep := Dependency{Name: "gcc", Operator: OpGe, Version: "5.0"}
tests := []struct {
manager string
expected string
}{
{"pacman", "gcc>=5.0"},
{"apt", "gcc"},
{"dnf", "gcc >= 5.0"},
{"yum", "gcc >= 5.0"},
{"apk", "gcc>=5.0"},
{"zypper", "gcc >= 5.0"},
{"apt-rpm", "gcc >= 5.0"},
{"unknown", "gcc>=5.0"},
}
for _, tt := range tests {
t.Run(tt.manager, func(t *testing.T) {
result := dep.ForManager(tt.manager)
assert.Equal(t, tt.expected, result)
})
}
// Test without version constraint
depNoVersion := Dependency{Name: "gcc", Operator: OpNone, Version: ""}
for _, tt := range tests {
t.Run(tt.manager+"_no_version", func(t *testing.T) {
result := depNoVersion.ForManager(tt.manager)
assert.Equal(t, "gcc", result)
})
}
}
func TestDependency_ForNfpm(t *testing.T) {
dep := Dependency{Name: "gcc", Operator: OpGe, Version: "5.0"}
tests := []struct {
format string
expected string
}{
{"deb", "gcc (>= 5.0)"},
{"rpm", "gcc >= 5.0"},
{"apk", "gcc>=5.0"},
{"archlinux", "gcc>=5.0"},
{"unknown", "gcc>=5.0"},
}
for _, tt := range tests {
t.Run(tt.format, func(t *testing.T) {
result := dep.ForNfpm(tt.format)
assert.Equal(t, tt.expected, result)
})
}
}
func TestHasVersionConstraint(t *testing.T) {
tests := []struct {
name string
dep Dependency
expected bool
}{
{
name: "has constraint",
dep: Dependency{Name: "gcc", Operator: OpGe, Version: "5.0"},
expected: true,
},
{
name: "no operator",
dep: Dependency{Name: "gcc", Operator: OpNone, Version: ""},
expected: false,
},
{
name: "operator but no version",
dep: Dependency{Name: "gcc", Operator: OpGe, Version: ""},
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.dep.HasVersionConstraint()
assert.Equal(t, tt.expected, result)
})
}
}

132
pkg/depver/format.go Normal file
View File

@@ -0,0 +1,132 @@
// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// 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 depver
import "fmt"
// ForManager formats the dependency for a specific package manager.
// Different package managers have different syntax for version constraints:
//
// pacman (Arch): "gcc>=5.0" (no changes)
// apt (Debian): "gcc" (version ignored for install command)
// dnf/yum (Fedora): "gcc >= 5.0" (with spaces)
// apk (Alpine): "gcc>=5.0" (no changes)
// zypper (openSUSE): "gcc >= 5.0" (with spaces)
// apt-rpm (ALT): "gcc >= 5.0" (with spaces)
func (d Dependency) ForManager(managerName string) string {
if d.Name == "" {
return ""
}
// No version constraint - just return the name
if d.Operator == OpNone || d.Version == "" {
return d.Name
}
switch managerName {
case "apt":
// APT doesn't support version constraints in 'apt install' command
// Versions are checked after installation
return d.Name
case "pacman":
// Pacman uses PKGBUILD-style: package>=version (no spaces)
return fmt.Sprintf("%s%s%s", d.Name, d.Operator, d.Version)
case "apk":
// Alpine APK uses similar syntax to pacman
return fmt.Sprintf("%s%s%s", d.Name, d.Operator, d.Version)
case "dnf", "yum":
// DNF/YUM use RPM-style: "package >= version" (with spaces)
return fmt.Sprintf("%s %s %s", d.Name, d.Operator, d.Version)
case "zypper":
// Zypper uses RPM-style with spaces
return fmt.Sprintf("%s %s %s", d.Name, d.Operator, d.Version)
case "apt-rpm":
// ALT Linux apt-rpm uses RPM-style
return fmt.Sprintf("%s %s %s", d.Name, d.Operator, d.Version)
default:
// Default: PKGBUILD-style (no spaces)
return fmt.Sprintf("%s%s%s", d.Name, d.Operator, d.Version)
}
}
// ForManagerMultiple formats multiple dependencies for a specific package manager.
func ForManagerMultiple(deps []Dependency, managerName string) []string {
result := make([]string, 0, len(deps))
for _, dep := range deps {
if formatted := dep.ForManager(managerName); formatted != "" {
result = append(result, formatted)
}
}
return result
}
// ForNfpm formats the dependency for nfpm package building.
// Different package formats have different dependency syntax:
//
// deb: "package (>= version)"
// rpm: "package >= version"
// apk: "package>=version"
// archlinux: "package>=version"
func (d Dependency) ForNfpm(pkgFormat string) string {
if d.Name == "" {
return ""
}
// No version constraint - just return the name
if d.Operator == OpNone || d.Version == "" {
return d.Name
}
switch pkgFormat {
case "deb":
// Debian uses: package (>= version)
return fmt.Sprintf("%s (%s %s)", d.Name, d.Operator, d.Version)
case "rpm":
// RPM uses: package >= version
return fmt.Sprintf("%s %s %s", d.Name, d.Operator, d.Version)
case "apk":
// Alpine uses: package>=version
return fmt.Sprintf("%s%s%s", d.Name, d.Operator, d.Version)
case "archlinux":
// Arch uses: package>=version
return fmt.Sprintf("%s%s%s", d.Name, d.Operator, d.Version)
default:
// Default: no spaces
return fmt.Sprintf("%s%s%s", d.Name, d.Operator, d.Version)
}
}
// ForNfpmMultiple formats multiple dependencies for nfpm.
func ForNfpmMultiple(deps []Dependency, pkgFormat string) []string {
result := make([]string, 0, len(deps))
for _, dep := range deps {
if formatted := dep.ForNfpm(pkgFormat); formatted != "" {
result = append(result, formatted)
}
}
return result
}

View File

@@ -27,9 +27,9 @@ import (
// createDir создает директорию с правильными правами для production
func createDir(itemPath string, mode os.FileMode) error {
// Используем специальную функцию для создания каталогов с setgid битом только для /tmp/alr
// В остальных случаях используем обычное создание директории
if strings.HasPrefix(itemPath, "/tmp/alr") {
// Используем специальную функцию для создания каталогов с setgid битом только для /tmp/alr/ и /var/cache/alr/
// Проверяем с слешем в конце, чтобы исключить тестовые директории вроде /tmp/alr-test-XXX
if strings.HasPrefix(itemPath, "/tmp/alr/") || strings.HasPrefix(itemPath, "/var/cache/alr/") {
return utils.EnsureTempDirWithRootOwner(itemPath, mode)
} else {
return os.MkdirAll(itemPath, mode)

View File

@@ -28,6 +28,7 @@ type Config struct {
Repos []Repo `json:"repo" koanf:"repo"`
AutoPull bool `json:"autoPull" koanf:"autoPull"`
LogLevel string `json:"logLevel" koanf:"logLevel"`
UpdateSystemOnUpgrade bool `json:"updateSystemOnUpgrade" koanf:"updateSystemOnUpgrade"`
}
// Repo represents a ALR repo within a configuration file

View File

@@ -21,6 +21,7 @@ import (
"github.com/urfave/cli/v2"
appbuilder "gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils/app_builder"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/utils"
)
func RefreshCmd() *cli.Command {
@@ -29,6 +30,9 @@ func RefreshCmd() *cli.Command {
Usage: gotext.Get("Pull all repositories that have changed"),
Aliases: []string{"ref"},
Action: func(c *cli.Context) error {
if err := utils.CheckUserPrivileges(); err != nil {
return err
}
ctx := c.Context

36
repo.go
View File

@@ -46,6 +46,24 @@ func RepoCmd() *cli.Command {
SetRepoRefCmd(),
RepoMirrorCmd(),
SetUrlCmd(),
RepoHelpCmd(),
},
}
}
func RepoHelpCmd() *cli.Command {
return &cli.Command{
Name: "help",
Aliases: []string{"h"},
Usage: gotext.Get("Shows a list of commands or help for one command"),
ArgsUsage: "[command]",
Action: func(cCtx *cli.Context) error {
args := cCtx.Args()
if args.Present() {
return cli.ShowCommandHelp(cCtx, args.First())
}
cli.ShowSubcommandHelp(cCtx)
return nil
},
}
}
@@ -331,6 +349,24 @@ func RepoMirrorCmd() *cli.Command {
AddMirror(),
RemoveMirror(),
ClearMirrors(),
MirrorHelpCmd(),
},
}
}
func MirrorHelpCmd() *cli.Command {
return &cli.Command{
Name: "help",
Aliases: []string{"h"},
Usage: gotext.Get("Shows a list of commands or help for one command"),
ArgsUsage: "[command]",
Action: func(cCtx *cli.Context) error {
args := cCtx.Args()
if args.Present() {
return cli.ShowCommandHelp(cCtx, args.First())
}
cli.ShowSubcommandHelp(cCtx)
return nil
},
}
}

View File

@@ -56,6 +56,31 @@ installPkg() {
esac
}
trackInstallation() {
# Отправить статистику установки (не критично если не получится)
if command -v curl &>/dev/null; then
# Генерируем уникальный отпечаток на основе hostname и даты
fingerprint=$(echo "$(hostname)_$(date +%Y-%m-%d)" | sha256sum 2>/dev/null | cut -d' ' -f1 || echo "$(hostname)_$(date +%Y-%m-%d)")
# Пробуем разные домены/порты для отправки статистики
for api_url in "https://alr.plemya-x.ru/api/packages/track-install" "http://localhost:3001/api/packages/track-install"; do
curl -s -m 5 -X POST "$api_url" \
-H "Content-Type: application/json" \
-H "User-Agent: ALR-InstallScript/1.0" \
-d "{
\"packageName\": \"alr-bin\",
\"installType\": \"script\",
\"userAgent\": \"ALR-InstallScript/1.0\",
\"fingerprint\": \"$fingerprint\"
}" >/dev/null 2>&1
# Если один запрос удался, не пробуем остальные
if [ $? -eq 0 ]; then
break
fi
done
fi
}
if ! command -v curl &>/dev/null; then
error "Этот скрипт требует команду curl. Пожалуйста, установите её и запустите снова."
fi
@@ -142,16 +167,15 @@ if [ -z "$noPkgMgr" ]; then
info "Получен список файлов релиза"
if [ "$pkgMgr" == "pacman" ]; then
latestFile=$(echo "$fileList" | grep -E "alr-bin-.*\.pkg\.tar\.zst" | sort -V | tail -n 1)
latestFile=$(echo "$fileList" | grep -E "alr-bin.*-(${arch}|any)\.pkg\.tar\.zst" | sort -V | tail -n 1)
elif [ "$pkgMgr" == "apt" ]; then
latestFile=$(echo "$fileList" | grep -E "alr-bin-.*\.${debArch}\.deb" | sort -V | tail -n 1)
latestFile=$(echo "$fileList" | grep -E "alr-bin.*_(${debArch}|all)\.deb" | sort -V | tail -n 1)
elif [[ "$pkgMgr" == "dnf" || "$pkgMgr" == "yum" || "$pkgMgr" == "zypper" ]]; then
latestFile=$(echo "$fileList" | grep -E "alr-bin-.*\.${rpmArch}\.rpm" | grep -v 'alt[0-9]*' | sort -V | tail -n 1)
latestFile=$(echo "$fileList" | grep -E "alr-bin.*\.(${rpmArch}|noarch)\.rpm" | grep -v 'alt[0-9]*' | sort -V | tail -n 1)
elif [ "$pkgMgr" == "apt-get" ]; then
# ALT Linux использует RPM с особой маркировкой
latestFile=$(echo "$fileList" | grep -E "alr-bin-.*-alt[0-9]+\.${rpmArch}\.rpm" | sort -V | tail -n 1)
latestFile=$(echo "$fileList" | grep -E "alr-bin.*-alt[0-9]+\.(${rpmArch}|noarch)\.rpm" | sort -V | tail -n 1)
elif [ "$pkgMgr" == "apk" ]; then
latestFile=$(echo "$fileList" | grep -E "alr-bin-.*\.apk" | sort -V | tail -n 1)
latestFile=$(echo "$fileList" | grep -E "alr-bin.*\.apk" | sort -V | tail -n 1)
else
error "Не поддерживаемый менеджер пакетов для автоматической установки"
fi
@@ -187,6 +211,9 @@ if [ -z "$noPkgMgr" ]; then
info "Установка пакета ALR"
installPkg "$pkgMgr" "$fname"
# Отправляем статистику установки
trackInstallation
info "Очистка"
rm -f "$fname"
trap - EXIT

View File

@@ -26,7 +26,7 @@ import (
"github.com/leonelquinteros/gotext"
"github.com/urfave/cli/v2"
"go.elara.ws/vercmp"
"gitea.plemya-x.ru/xpamych/vercmp"
"golang.org/x/exp/maps"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/build"
@@ -84,6 +84,19 @@ func UpgradeCmd() *cli.Command {
}
defer deps.Defer()
// Обновляем систему, если это включено в конфигурации
if deps.Cfg.UpdateSystemOnUpgrade() {
slog.Info(gotext.Get("Updating system packages..."))
err = deps.Manager.UpgradeAll(&manager.Opts{
NoConfirm: !c.Bool("interactive"),
Args: manager.Args,
})
if err != nil {
return cliutils.FormatCliExit(gotext.Get("Error updating system packages"), err)
}
slog.Info(gotext.Get("System packages updated successfully"))
}
builder, err := build.NewMainBuilder(
deps.Cfg,
deps.Manager,
@@ -101,7 +114,7 @@ func UpgradeCmd() *cli.Command {
}
if len(updates) > 0 {
err = builder.InstallALRPackages(
_, err = builder.InstallPkgs(
ctx,
&build.BuildArgs{
Opts: &types.BuildOpts{
@@ -111,7 +124,7 @@ func UpgradeCmd() *cli.Command {
Info: deps.Info,
PkgFormat_: build.GetPkgFormat(deps.Manager),
},
mapUptatesInfoToPackages(updates),
mapUpdatesToPackageNames(updates),
)
if err != nil {
return cliutils.FormatCliExit(gotext.Get("Error checking for updates"), err)
@@ -125,12 +138,19 @@ func UpgradeCmd() *cli.Command {
}
}
func mapUptatesInfoToPackages(updates []UpdateInfo) []alrsh.Package {
var pkgs []alrsh.Package
func mapUpdatesToPackageNames(updates []UpdateInfo) []string {
seen := make(map[string]bool)
var pkgNames []string
for _, info := range updates {
pkgs = append(pkgs, *info.Package)
fullName := fmt.Sprintf("%s+%s", info.Package.Name, info.Package.Repository)
if !seen[fullName] {
seen[fullName] = true
pkgNames = append(pkgNames, fullName)
}
return pkgs
}
return pkgNames
}
type UpdateInfo struct {