0
0
Fork 0
mirror of https://gitea.plemya-x.ru/Plemya-x/ALR.git synced 2025-01-11 01:36:45 +00:00
ALR/pkg/build/install.go

73 lines
2.2 KiB
Go
Raw Permalink Normal View History

2024-01-22 10:36:06 +00:00
/*
2024-05-05 10:32:08 +00:00
* ALR - Any Linux Repository
* Copyright (C) 2024 Евгений Храмов
2024-01-22 10:36:06 +00:00
*
* 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"
"path/filepath"
2024-05-05 10:32:08 +00:00
"plemya-x.ru/alr/internal/config"
"plemya-x.ru/alr/internal/db"
"plemya-x.ru/alr/internal/types"
"plemya-x.ru/alr/pkg/loggerctx"
2024-01-22 10:36:06 +00:00
)
// InstallPkgs installs native packages via the package manager,
2024-05-05 10:32:08 +00:00
// then builds and installs the ALR packages
func InstallPkgs(ctx context.Context, alrPkgs []db.Package, nativePkgs []string, opts types.BuildOpts) {
2024-01-22 10:36:06 +00:00
log := loggerctx.From(ctx)
if len(nativePkgs) > 0 {
err := opts.Manager.Install(nil, nativePkgs...)
if err != nil {
log.Fatal("Error installing native packages").Err(err).Send()
}
}
2024-05-05 10:32:08 +00:00
InstallScripts(ctx, GetScriptPaths(ctx, alrPkgs), opts)
2024-01-22 10:36:06 +00:00
}
// GetScriptPaths returns a slice of script paths corresponding to the
// given packages
func GetScriptPaths(ctx context.Context, pkgs []db.Package) []string {
var scripts []string
for _, pkg := range pkgs {
2024-05-05 10:32:08 +00:00
scriptPath := filepath.Join(config.GetPaths(ctx).RepoDir, pkg.Repository, pkg.Name, "alr.sh")
2024-01-22 10:36:06 +00:00
scripts = append(scripts, scriptPath)
}
return scripts
}
2024-05-05 10:32:08 +00:00
// InstallScripts builds and installs the given alr build scripts
2024-01-22 10:36:06 +00:00
func InstallScripts(ctx context.Context, scripts []string, opts types.BuildOpts) {
log := loggerctx.From(ctx)
for _, script := range scripts {
opts.Script = script
builtPkgs, _, err := BuildPackage(ctx, opts)
if err != nil {
log.Fatal("Error building package").Err(err).Send()
}
err = opts.Manager.InstallLocal(nil, builtPkgs...)
if err != nil {
log.Fatal("Error installing package").Err(err).Send()
}
}
}