// This file was originally part of the project "LURE - Linux User REpository", created by Elara Musayelyan. // It has been modified as part of "ALR - Any Linux Repository" by Евгений Храмов. // // ALR - Any Linux Repository // Copyright (C) 2025 Евгений Храмов // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package build import ( "context" "log/slog" "os" "path/filepath" "github.com/leonelquinteros/gotext" "gitea.plemya-x.ru/Plemya-x/ALR/internal/config" "gitea.plemya-x.ru/Plemya-x/ALR/internal/db" "gitea.plemya-x.ru/Plemya-x/ALR/internal/types" "gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro" "gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos" ) // InstallPkgs устанавливает нативные пакеты с использованием менеджера пакетов, // затем строит и устанавливает пакеты ALR func InstallPkgs(ctx context.Context, alrPkgs []db.Package, nativePkgs []string, opts types.BuildOpts) { if len(nativePkgs) > 0 { err := opts.Manager.Install(nil, nativePkgs...) // Если есть нативные пакеты, выполняем их установку if err != nil { slog.Error(gotext.Get("Error installing native packages"), "err", err) os.Exit(1) // Логируем и завершаем выполнение при ошибке } } InstallALRPackages(ctx, alrPkgs, opts) // Устанавливаем скрипты сборки через функцию InstallScripts } func UpdateOpts(ctx context.Context, opts *types.BuildOpts, pkg *db.Package) { repodir := config.GetPaths(ctx).RepoDir if pkg.BasePkgName != "" { opts.Script = filepath.Join(repodir, pkg.Repository, pkg.BasePkgName, "alr.sh") opts.Package = pkg.Name } else { opts.Script = filepath.Join(repodir, pkg.Repository, pkg.Name, "alr.sh") } } // InstallALRPackages строит и устанавливает переданные alr скрипты сборки func InstallALRPackages(ctx context.Context, pkgs []db.Package, opts types.BuildOpts) { info, err := distro.ParseOSRelease(ctx) if err != nil { slog.Error(gotext.Get("Error parsing os release"), "err", err) os.Exit(1) } for _, pkg := range pkgs { UpdateOpts(ctx, &opts, &pkg) builder := New( ctx, opts, repos.GetInstance(ctx), info, config.GetInstance(ctx), ) builtPkgs, _, err := builder.BuildPackage(ctx) // Выполняем сборку пакета if err != nil { slog.Error(gotext.Get("Error building package"), "err", err) os.Exit(1) // Логируем и завершаем выполнение при ошибке сборки } err = opts.Manager.InstallLocal(nil, builtPkgs...) // Устанавливаем локально собранные пакеты if err != nil { slog.Error(gotext.Get("Error installing package"), "err", err) os.Exit(1) // Логируем и завершаем выполнение при ошибке установки } } }